pdf.worker.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* globals PDFJS, global */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window :
  20. typeof global !== 'undefined' ? global : this).PDFJS = {};
  21. }
  22. PDFJS.version = '1.3.127';
  23. PDFJS.build = 'ad4354c';
  24. (function pdfjsWrapper() {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. (function (root, factory) {
  28. {
  29. factory((root.pdfjsSharedGlobal = {}));
  30. }
  31. }(this, function (exports) {
  32. var globalScope = (typeof window !== 'undefined') ? window :
  33. (typeof global !== 'undefined') ? global :
  34. (typeof self !== 'undefined') ? self : this;
  35. var isWorker = (typeof window === 'undefined');
  36. // The global PDFJS object exposes the API
  37. // In production, it will be declared outside a global wrapper
  38. // In development, it will be declared here
  39. if (!globalScope.PDFJS) {
  40. globalScope.PDFJS = {};
  41. }
  42. globalScope.PDFJS.pdfBug = false;
  43. exports.globalScope = globalScope;
  44. exports.isWorker = isWorker;
  45. exports.PDFJS = globalScope.PDFJS;
  46. }));
  47. (function (root, factory) {
  48. {
  49. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  50. }
  51. }(this, function (exports, sharedGlobal) {
  52. var PDFJS = sharedGlobal.PDFJS;
  53. var globalScope = sharedGlobal.globalScope;
  54. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  55. var TextRenderingMode = {
  56. FILL: 0,
  57. STROKE: 1,
  58. FILL_STROKE: 2,
  59. INVISIBLE: 3,
  60. FILL_ADD_TO_PATH: 4,
  61. STROKE_ADD_TO_PATH: 5,
  62. FILL_STROKE_ADD_TO_PATH: 6,
  63. ADD_TO_PATH: 7,
  64. FILL_STROKE_MASK: 3,
  65. ADD_TO_PATH_FLAG: 4
  66. };
  67. var ImageKind = {
  68. GRAYSCALE_1BPP: 1,
  69. RGB_24BPP: 2,
  70. RGBA_32BPP: 3
  71. };
  72. var AnnotationType = {
  73. TEXT: 1,
  74. LINK: 2,
  75. FREETEXT: 3,
  76. LINE: 4,
  77. SQUARE: 5,
  78. CIRCLE: 6,
  79. POLYGON: 7,
  80. POLYLINE: 8,
  81. HIGHLIGHT: 9,
  82. UNDERLINE: 10,
  83. SQUIGGLY: 11,
  84. STRIKEOUT: 12,
  85. STAMP: 13,
  86. CARET: 14,
  87. INK: 15,
  88. POPUP: 16,
  89. FILEATTACHMENT: 17,
  90. SOUND: 18,
  91. MOVIE: 19,
  92. WIDGET: 20,
  93. SCREEN: 21,
  94. PRINTERMARK: 22,
  95. TRAPNET: 23,
  96. WATERMARK: 24,
  97. THREED: 25,
  98. REDACT: 26
  99. };
  100. var AnnotationFlag = {
  101. INVISIBLE: 0x01,
  102. HIDDEN: 0x02,
  103. PRINT: 0x04,
  104. NOZOOM: 0x08,
  105. NOROTATE: 0x10,
  106. NOVIEW: 0x20,
  107. READONLY: 0x40,
  108. LOCKED: 0x80,
  109. TOGGLENOVIEW: 0x100,
  110. LOCKEDCONTENTS: 0x200
  111. };
  112. var AnnotationBorderStyleType = {
  113. SOLID: 1,
  114. DASHED: 2,
  115. BEVELED: 3,
  116. INSET: 4,
  117. UNDERLINE: 5
  118. };
  119. var StreamType = {
  120. UNKNOWN: 0,
  121. FLATE: 1,
  122. LZW: 2,
  123. DCT: 3,
  124. JPX: 4,
  125. JBIG: 5,
  126. A85: 6,
  127. AHX: 7,
  128. CCF: 8,
  129. RL: 9
  130. };
  131. var FontType = {
  132. UNKNOWN: 0,
  133. TYPE1: 1,
  134. TYPE1C: 2,
  135. CIDFONTTYPE0: 3,
  136. CIDFONTTYPE0C: 4,
  137. TRUETYPE: 5,
  138. CIDFONTTYPE2: 6,
  139. TYPE3: 7,
  140. OPENTYPE: 8,
  141. TYPE0: 9,
  142. MMTYPE1: 10
  143. };
  144. PDFJS.VERBOSITY_LEVELS = {
  145. errors: 0,
  146. warnings: 1,
  147. infos: 5
  148. };
  149. // All the possible operations for an operator list.
  150. var OPS = PDFJS.OPS = {
  151. // Intentionally start from 1 so it is easy to spot bad operators that will be
  152. // 0's.
  153. dependency: 1,
  154. setLineWidth: 2,
  155. setLineCap: 3,
  156. setLineJoin: 4,
  157. setMiterLimit: 5,
  158. setDash: 6,
  159. setRenderingIntent: 7,
  160. setFlatness: 8,
  161. setGState: 9,
  162. save: 10,
  163. restore: 11,
  164. transform: 12,
  165. moveTo: 13,
  166. lineTo: 14,
  167. curveTo: 15,
  168. curveTo2: 16,
  169. curveTo3: 17,
  170. closePath: 18,
  171. rectangle: 19,
  172. stroke: 20,
  173. closeStroke: 21,
  174. fill: 22,
  175. eoFill: 23,
  176. fillStroke: 24,
  177. eoFillStroke: 25,
  178. closeFillStroke: 26,
  179. closeEOFillStroke: 27,
  180. endPath: 28,
  181. clip: 29,
  182. eoClip: 30,
  183. beginText: 31,
  184. endText: 32,
  185. setCharSpacing: 33,
  186. setWordSpacing: 34,
  187. setHScale: 35,
  188. setLeading: 36,
  189. setFont: 37,
  190. setTextRenderingMode: 38,
  191. setTextRise: 39,
  192. moveText: 40,
  193. setLeadingMoveText: 41,
  194. setTextMatrix: 42,
  195. nextLine: 43,
  196. showText: 44,
  197. showSpacedText: 45,
  198. nextLineShowText: 46,
  199. nextLineSetSpacingShowText: 47,
  200. setCharWidth: 48,
  201. setCharWidthAndBounds: 49,
  202. setStrokeColorSpace: 50,
  203. setFillColorSpace: 51,
  204. setStrokeColor: 52,
  205. setStrokeColorN: 53,
  206. setFillColor: 54,
  207. setFillColorN: 55,
  208. setStrokeGray: 56,
  209. setFillGray: 57,
  210. setStrokeRGBColor: 58,
  211. setFillRGBColor: 59,
  212. setStrokeCMYKColor: 60,
  213. setFillCMYKColor: 61,
  214. shadingFill: 62,
  215. beginInlineImage: 63,
  216. beginImageData: 64,
  217. endInlineImage: 65,
  218. paintXObject: 66,
  219. markPoint: 67,
  220. markPointProps: 68,
  221. beginMarkedContent: 69,
  222. beginMarkedContentProps: 70,
  223. endMarkedContent: 71,
  224. beginCompat: 72,
  225. endCompat: 73,
  226. paintFormXObjectBegin: 74,
  227. paintFormXObjectEnd: 75,
  228. beginGroup: 76,
  229. endGroup: 77,
  230. beginAnnotations: 78,
  231. endAnnotations: 79,
  232. beginAnnotation: 80,
  233. endAnnotation: 81,
  234. paintJpegXObject: 82,
  235. paintImageMaskXObject: 83,
  236. paintImageMaskXObjectGroup: 84,
  237. paintImageXObject: 85,
  238. paintInlineImageXObject: 86,
  239. paintInlineImageXObjectGroup: 87,
  240. paintImageXObjectRepeat: 88,
  241. paintImageMaskXObjectRepeat: 89,
  242. paintSolidColorImageMask: 90,
  243. constructPath: 91
  244. };
  245. // A notice for devs. These are good for things that are helpful to devs, such
  246. // as warning that Workers were disabled, which is important to devs but not
  247. // end users.
  248. function info(msg) {
  249. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  250. console.log('Info: ' + msg);
  251. }
  252. }
  253. // Non-fatal warnings.
  254. function warn(msg) {
  255. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  256. console.log('Warning: ' + msg);
  257. }
  258. }
  259. // Deprecated API function -- treated as warnings.
  260. function deprecated(details) {
  261. warn('Deprecated API usage: ' + details);
  262. }
  263. // Fatal errors that should trigger the fallback UI and halt execution by
  264. // throwing an exception.
  265. function error(msg) {
  266. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  267. console.log('Error: ' + msg);
  268. console.log(backtrace());
  269. }
  270. throw new Error(msg);
  271. }
  272. function backtrace() {
  273. try {
  274. throw new Error();
  275. } catch (e) {
  276. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  277. }
  278. }
  279. function assert(cond, msg) {
  280. if (!cond) {
  281. error(msg);
  282. }
  283. }
  284. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  285. unknown: 'unknown',
  286. forms: 'forms',
  287. javaScript: 'javaScript',
  288. smask: 'smask',
  289. shadingPattern: 'shadingPattern',
  290. font: 'font'
  291. };
  292. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  293. // absolute URL, it will be returned as is.
  294. function combineUrl(baseUrl, url) {
  295. if (!url) {
  296. return baseUrl;
  297. }
  298. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  299. return url;
  300. }
  301. var i;
  302. if (url.charAt(0) === '/') {
  303. // absolute path
  304. i = baseUrl.indexOf('://');
  305. if (url.charAt(1) === '/') {
  306. ++i;
  307. } else {
  308. i = baseUrl.indexOf('/', i + 3);
  309. }
  310. return baseUrl.substring(0, i) + url;
  311. } else {
  312. // relative path
  313. var pathLength = baseUrl.length;
  314. i = baseUrl.lastIndexOf('#');
  315. pathLength = i >= 0 ? i : pathLength;
  316. i = baseUrl.lastIndexOf('?', pathLength);
  317. pathLength = i >= 0 ? i : pathLength;
  318. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  319. return baseUrl.substring(0, prefixLength + 1) + url;
  320. }
  321. }
  322. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  323. function isValidUrl(url, allowRelative) {
  324. if (!url) {
  325. return false;
  326. }
  327. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  328. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  329. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  330. if (!protocol) {
  331. return allowRelative;
  332. }
  333. protocol = protocol[0].toLowerCase();
  334. switch (protocol) {
  335. case 'http':
  336. case 'https':
  337. case 'ftp':
  338. case 'mailto':
  339. case 'tel':
  340. return true;
  341. default:
  342. return false;
  343. }
  344. }
  345. PDFJS.isValidUrl = isValidUrl;
  346. function shadow(obj, prop, value) {
  347. Object.defineProperty(obj, prop, { value: value,
  348. enumerable: true,
  349. configurable: true,
  350. writable: false });
  351. return value;
  352. }
  353. PDFJS.shadow = shadow;
  354. var LinkTarget = PDFJS.LinkTarget = {
  355. NONE: 0, // Default value.
  356. SELF: 1,
  357. BLANK: 2,
  358. PARENT: 3,
  359. TOP: 4,
  360. };
  361. var LinkTargetStringMap = [
  362. '',
  363. '_self',
  364. '_blank',
  365. '_parent',
  366. '_top'
  367. ];
  368. function isExternalLinkTargetSet() {
  369. if (PDFJS.openExternalLinksInNewWindow) {
  370. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  371. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  372. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  373. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  374. }
  375. // Reset the deprecated parameter, to suppress further warnings.
  376. PDFJS.openExternalLinksInNewWindow = false;
  377. }
  378. switch (PDFJS.externalLinkTarget) {
  379. case LinkTarget.NONE:
  380. return false;
  381. case LinkTarget.SELF:
  382. case LinkTarget.BLANK:
  383. case LinkTarget.PARENT:
  384. case LinkTarget.TOP:
  385. return true;
  386. }
  387. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  388. // Reset the external link target, to suppress further warnings.
  389. PDFJS.externalLinkTarget = LinkTarget.NONE;
  390. return false;
  391. }
  392. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  393. var PasswordResponses = PDFJS.PasswordResponses = {
  394. NEED_PASSWORD: 1,
  395. INCORRECT_PASSWORD: 2
  396. };
  397. var PasswordException = (function PasswordExceptionClosure() {
  398. function PasswordException(msg, code) {
  399. this.name = 'PasswordException';
  400. this.message = msg;
  401. this.code = code;
  402. }
  403. PasswordException.prototype = new Error();
  404. PasswordException.constructor = PasswordException;
  405. return PasswordException;
  406. })();
  407. PDFJS.PasswordException = PasswordException;
  408. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  409. function UnknownErrorException(msg, details) {
  410. this.name = 'UnknownErrorException';
  411. this.message = msg;
  412. this.details = details;
  413. }
  414. UnknownErrorException.prototype = new Error();
  415. UnknownErrorException.constructor = UnknownErrorException;
  416. return UnknownErrorException;
  417. })();
  418. PDFJS.UnknownErrorException = UnknownErrorException;
  419. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  420. function InvalidPDFException(msg) {
  421. this.name = 'InvalidPDFException';
  422. this.message = msg;
  423. }
  424. InvalidPDFException.prototype = new Error();
  425. InvalidPDFException.constructor = InvalidPDFException;
  426. return InvalidPDFException;
  427. })();
  428. PDFJS.InvalidPDFException = InvalidPDFException;
  429. var MissingPDFException = (function MissingPDFExceptionClosure() {
  430. function MissingPDFException(msg) {
  431. this.name = 'MissingPDFException';
  432. this.message = msg;
  433. }
  434. MissingPDFException.prototype = new Error();
  435. MissingPDFException.constructor = MissingPDFException;
  436. return MissingPDFException;
  437. })();
  438. PDFJS.MissingPDFException = MissingPDFException;
  439. var UnexpectedResponseException =
  440. (function UnexpectedResponseExceptionClosure() {
  441. function UnexpectedResponseException(msg, status) {
  442. this.name = 'UnexpectedResponseException';
  443. this.message = msg;
  444. this.status = status;
  445. }
  446. UnexpectedResponseException.prototype = new Error();
  447. UnexpectedResponseException.constructor = UnexpectedResponseException;
  448. return UnexpectedResponseException;
  449. })();
  450. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  451. var NotImplementedException = (function NotImplementedExceptionClosure() {
  452. function NotImplementedException(msg) {
  453. this.message = msg;
  454. }
  455. NotImplementedException.prototype = new Error();
  456. NotImplementedException.prototype.name = 'NotImplementedException';
  457. NotImplementedException.constructor = NotImplementedException;
  458. return NotImplementedException;
  459. })();
  460. var MissingDataException = (function MissingDataExceptionClosure() {
  461. function MissingDataException(begin, end) {
  462. this.begin = begin;
  463. this.end = end;
  464. this.message = 'Missing data [' + begin + ', ' + end + ')';
  465. }
  466. MissingDataException.prototype = new Error();
  467. MissingDataException.prototype.name = 'MissingDataException';
  468. MissingDataException.constructor = MissingDataException;
  469. return MissingDataException;
  470. })();
  471. var XRefParseException = (function XRefParseExceptionClosure() {
  472. function XRefParseException(msg) {
  473. this.message = msg;
  474. }
  475. XRefParseException.prototype = new Error();
  476. XRefParseException.prototype.name = 'XRefParseException';
  477. XRefParseException.constructor = XRefParseException;
  478. return XRefParseException;
  479. })();
  480. function bytesToString(bytes) {
  481. assert(bytes !== null && typeof bytes === 'object' &&
  482. bytes.length !== undefined, 'Invalid argument for bytesToString');
  483. var length = bytes.length;
  484. var MAX_ARGUMENT_COUNT = 8192;
  485. if (length < MAX_ARGUMENT_COUNT) {
  486. return String.fromCharCode.apply(null, bytes);
  487. }
  488. var strBuf = [];
  489. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  490. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  491. var chunk = bytes.subarray(i, chunkEnd);
  492. strBuf.push(String.fromCharCode.apply(null, chunk));
  493. }
  494. return strBuf.join('');
  495. }
  496. function stringToBytes(str) {
  497. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  498. var length = str.length;
  499. var bytes = new Uint8Array(length);
  500. for (var i = 0; i < length; ++i) {
  501. bytes[i] = str.charCodeAt(i) & 0xFF;
  502. }
  503. return bytes;
  504. }
  505. function string32(value) {
  506. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  507. (value >> 8) & 0xff, value & 0xff);
  508. }
  509. function log2(x) {
  510. var n = 1, i = 0;
  511. while (x > n) {
  512. n <<= 1;
  513. i++;
  514. }
  515. return i;
  516. }
  517. function readInt8(data, start) {
  518. return (data[start] << 24) >> 24;
  519. }
  520. function readUint16(data, offset) {
  521. return (data[offset] << 8) | data[offset + 1];
  522. }
  523. function readUint32(data, offset) {
  524. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  525. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  526. }
  527. // Lazy test the endianness of the platform
  528. // NOTE: This will be 'true' for simulated TypedArrays
  529. function isLittleEndian() {
  530. var buffer8 = new Uint8Array(2);
  531. buffer8[0] = 1;
  532. var buffer16 = new Uint16Array(buffer8.buffer);
  533. return (buffer16[0] === 1);
  534. }
  535. Object.defineProperty(PDFJS, 'isLittleEndian', {
  536. configurable: true,
  537. get: function PDFJS_isLittleEndian() {
  538. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  539. }
  540. });
  541. // Lazy test if the userAgent support CanvasTypedArrays
  542. function hasCanvasTypedArrays() {
  543. var canvas = document.createElement('canvas');
  544. canvas.width = canvas.height = 1;
  545. var ctx = canvas.getContext('2d');
  546. var imageData = ctx.createImageData(1, 1);
  547. return (typeof imageData.data.buffer !== 'undefined');
  548. }
  549. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  550. configurable: true,
  551. get: function PDFJS_hasCanvasTypedArrays() {
  552. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  553. }
  554. });
  555. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  556. function Uint32ArrayView(buffer, length) {
  557. this.buffer = buffer;
  558. this.byteLength = buffer.length;
  559. this.length = length === undefined ? (this.byteLength >> 2) : length;
  560. ensureUint32ArrayViewProps(this.length);
  561. }
  562. Uint32ArrayView.prototype = Object.create(null);
  563. var uint32ArrayViewSetters = 0;
  564. function createUint32ArrayProp(index) {
  565. return {
  566. get: function () {
  567. var buffer = this.buffer, offset = index << 2;
  568. return (buffer[offset] | (buffer[offset + 1] << 8) |
  569. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  570. },
  571. set: function (value) {
  572. var buffer = this.buffer, offset = index << 2;
  573. buffer[offset] = value & 255;
  574. buffer[offset + 1] = (value >> 8) & 255;
  575. buffer[offset + 2] = (value >> 16) & 255;
  576. buffer[offset + 3] = (value >>> 24) & 255;
  577. }
  578. };
  579. }
  580. function ensureUint32ArrayViewProps(length) {
  581. while (uint32ArrayViewSetters < length) {
  582. Object.defineProperty(Uint32ArrayView.prototype,
  583. uint32ArrayViewSetters,
  584. createUint32ArrayProp(uint32ArrayViewSetters));
  585. uint32ArrayViewSetters++;
  586. }
  587. }
  588. return Uint32ArrayView;
  589. })();
  590. exports.Uint32ArrayView = Uint32ArrayView;
  591. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  592. var Util = PDFJS.Util = (function UtilClosure() {
  593. function Util() {}
  594. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  595. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  596. // creating many intermediate strings.
  597. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  598. rgbBuf[1] = r;
  599. rgbBuf[3] = g;
  600. rgbBuf[5] = b;
  601. return rgbBuf.join('');
  602. };
  603. // Concatenates two transformation matrices together and returns the result.
  604. Util.transform = function Util_transform(m1, m2) {
  605. return [
  606. m1[0] * m2[0] + m1[2] * m2[1],
  607. m1[1] * m2[0] + m1[3] * m2[1],
  608. m1[0] * m2[2] + m1[2] * m2[3],
  609. m1[1] * m2[2] + m1[3] * m2[3],
  610. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  611. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  612. ];
  613. };
  614. // For 2d affine transforms
  615. Util.applyTransform = function Util_applyTransform(p, m) {
  616. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  617. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  618. return [xt, yt];
  619. };
  620. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  621. var d = m[0] * m[3] - m[1] * m[2];
  622. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  623. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  624. return [xt, yt];
  625. };
  626. // Applies the transform to the rectangle and finds the minimum axially
  627. // aligned bounding box.
  628. Util.getAxialAlignedBoundingBox =
  629. function Util_getAxialAlignedBoundingBox(r, m) {
  630. var p1 = Util.applyTransform(r, m);
  631. var p2 = Util.applyTransform(r.slice(2, 4), m);
  632. var p3 = Util.applyTransform([r[0], r[3]], m);
  633. var p4 = Util.applyTransform([r[2], r[1]], m);
  634. return [
  635. Math.min(p1[0], p2[0], p3[0], p4[0]),
  636. Math.min(p1[1], p2[1], p3[1], p4[1]),
  637. Math.max(p1[0], p2[0], p3[0], p4[0]),
  638. Math.max(p1[1], p2[1], p3[1], p4[1])
  639. ];
  640. };
  641. Util.inverseTransform = function Util_inverseTransform(m) {
  642. var d = m[0] * m[3] - m[1] * m[2];
  643. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  644. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  645. };
  646. // Apply a generic 3d matrix M on a 3-vector v:
  647. // | a b c | | X |
  648. // | d e f | x | Y |
  649. // | g h i | | Z |
  650. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  651. // with v as [X,Y,Z]
  652. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  653. return [
  654. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  655. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  656. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  657. ];
  658. };
  659. // This calculation uses Singular Value Decomposition.
  660. // The SVD can be represented with formula A = USV. We are interested in the
  661. // matrix S here because it represents the scale values.
  662. Util.singularValueDecompose2dScale =
  663. function Util_singularValueDecompose2dScale(m) {
  664. var transpose = [m[0], m[2], m[1], m[3]];
  665. // Multiply matrix m with its transpose.
  666. var a = m[0] * transpose[0] + m[1] * transpose[2];
  667. var b = m[0] * transpose[1] + m[1] * transpose[3];
  668. var c = m[2] * transpose[0] + m[3] * transpose[2];
  669. var d = m[2] * transpose[1] + m[3] * transpose[3];
  670. // Solve the second degree polynomial to get roots.
  671. var first = (a + d) / 2;
  672. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  673. var sx = first + second || 1;
  674. var sy = first - second || 1;
  675. // Scale values are the square roots of the eigenvalues.
  676. return [Math.sqrt(sx), Math.sqrt(sy)];
  677. };
  678. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  679. // For coordinate systems whose origin lies in the bottom-left, this
  680. // means normalization to (BL,TR) ordering. For systems with origin in the
  681. // top-left, this means (TL,BR) ordering.
  682. Util.normalizeRect = function Util_normalizeRect(rect) {
  683. var r = rect.slice(0); // clone rect
  684. if (rect[0] > rect[2]) {
  685. r[0] = rect[2];
  686. r[2] = rect[0];
  687. }
  688. if (rect[1] > rect[3]) {
  689. r[1] = rect[3];
  690. r[3] = rect[1];
  691. }
  692. return r;
  693. };
  694. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  695. // intersection of rect1 and rect2. If no intersection, returns 'false'
  696. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  697. Util.intersect = function Util_intersect(rect1, rect2) {
  698. function compare(a, b) {
  699. return a - b;
  700. }
  701. // Order points along the axes
  702. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  703. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  704. result = [];
  705. rect1 = Util.normalizeRect(rect1);
  706. rect2 = Util.normalizeRect(rect2);
  707. // X: first and second points belong to different rectangles?
  708. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  709. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  710. // Intersection must be between second and third points
  711. result[0] = orderedX[1];
  712. result[2] = orderedX[2];
  713. } else {
  714. return false;
  715. }
  716. // Y: first and second points belong to different rectangles?
  717. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  718. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  719. // Intersection must be between second and third points
  720. result[1] = orderedY[1];
  721. result[3] = orderedY[2];
  722. } else {
  723. return false;
  724. }
  725. return result;
  726. };
  727. Util.sign = function Util_sign(num) {
  728. return num < 0 ? -1 : 1;
  729. };
  730. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  731. Array.prototype.push.apply(arr1, arr2);
  732. };
  733. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  734. Array.prototype.unshift.apply(arr1, arr2);
  735. };
  736. Util.extendObj = function extendObj(obj1, obj2) {
  737. for (var key in obj2) {
  738. obj1[key] = obj2[key];
  739. }
  740. };
  741. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  742. name) {
  743. while (dict && !dict.has(name)) {
  744. dict = dict.get('Parent');
  745. }
  746. if (!dict) {
  747. return null;
  748. }
  749. return dict.get(name);
  750. };
  751. Util.inherit = function Util_inherit(sub, base, prototype) {
  752. sub.prototype = Object.create(base.prototype);
  753. sub.prototype.constructor = sub;
  754. for (var prop in prototype) {
  755. sub.prototype[prop] = prototype[prop];
  756. }
  757. };
  758. Util.loadScript = function Util_loadScript(src, callback) {
  759. var script = document.createElement('script');
  760. var loaded = false;
  761. script.setAttribute('src', src);
  762. if (callback) {
  763. script.onload = function() {
  764. if (!loaded) {
  765. callback();
  766. }
  767. loaded = true;
  768. };
  769. }
  770. document.getElementsByTagName('head')[0].appendChild(script);
  771. };
  772. return Util;
  773. })();
  774. /**
  775. * PDF page viewport created based on scale, rotation and offset.
  776. * @class
  777. * @alias PDFJS.PageViewport
  778. */
  779. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  780. /**
  781. * @constructor
  782. * @private
  783. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  784. * @param scale {number} scale of the viewport.
  785. * @param rotation {number} rotations of the viewport in degrees.
  786. * @param offsetX {number} offset X
  787. * @param offsetY {number} offset Y
  788. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  789. */
  790. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  791. this.viewBox = viewBox;
  792. this.scale = scale;
  793. this.rotation = rotation;
  794. this.offsetX = offsetX;
  795. this.offsetY = offsetY;
  796. // creating transform to convert pdf coordinate system to the normal
  797. // canvas like coordinates taking in account scale and rotation
  798. var centerX = (viewBox[2] + viewBox[0]) / 2;
  799. var centerY = (viewBox[3] + viewBox[1]) / 2;
  800. var rotateA, rotateB, rotateC, rotateD;
  801. rotation = rotation % 360;
  802. rotation = rotation < 0 ? rotation + 360 : rotation;
  803. switch (rotation) {
  804. case 180:
  805. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  806. break;
  807. case 90:
  808. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  809. break;
  810. case 270:
  811. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  812. break;
  813. //case 0:
  814. default:
  815. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  816. break;
  817. }
  818. if (dontFlip) {
  819. rotateC = -rotateC; rotateD = -rotateD;
  820. }
  821. var offsetCanvasX, offsetCanvasY;
  822. var width, height;
  823. if (rotateA === 0) {
  824. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  825. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  826. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  827. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  828. } else {
  829. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  830. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  831. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  832. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  833. }
  834. // creating transform for the following operations:
  835. // translate(-centerX, -centerY), rotate and flip vertically,
  836. // scale, and translate(offsetCanvasX, offsetCanvasY)
  837. this.transform = [
  838. rotateA * scale,
  839. rotateB * scale,
  840. rotateC * scale,
  841. rotateD * scale,
  842. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  843. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  844. ];
  845. this.width = width;
  846. this.height = height;
  847. this.fontScale = scale;
  848. }
  849. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  850. /**
  851. * Clones viewport with additional properties.
  852. * @param args {Object} (optional) If specified, may contain the 'scale' or
  853. * 'rotation' properties to override the corresponding properties in
  854. * the cloned viewport.
  855. * @returns {PDFJS.PageViewport} Cloned viewport.
  856. */
  857. clone: function PageViewPort_clone(args) {
  858. args = args || {};
  859. var scale = 'scale' in args ? args.scale : this.scale;
  860. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  861. return new PageViewport(this.viewBox.slice(), scale, rotation,
  862. this.offsetX, this.offsetY, args.dontFlip);
  863. },
  864. /**
  865. * Converts PDF point to the viewport coordinates. For examples, useful for
  866. * converting PDF location into canvas pixel coordinates.
  867. * @param x {number} X coordinate.
  868. * @param y {number} Y coordinate.
  869. * @returns {Object} Object that contains 'x' and 'y' properties of the
  870. * point in the viewport coordinate space.
  871. * @see {@link convertToPdfPoint}
  872. * @see {@link convertToViewportRectangle}
  873. */
  874. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  875. return Util.applyTransform([x, y], this.transform);
  876. },
  877. /**
  878. * Converts PDF rectangle to the viewport coordinates.
  879. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  880. * @returns {Array} Contains corresponding coordinates of the rectangle
  881. * in the viewport coordinate space.
  882. * @see {@link convertToViewportPoint}
  883. */
  884. convertToViewportRectangle:
  885. function PageViewport_convertToViewportRectangle(rect) {
  886. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  887. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  888. return [tl[0], tl[1], br[0], br[1]];
  889. },
  890. /**
  891. * Converts viewport coordinates to the PDF location. For examples, useful
  892. * for converting canvas pixel location into PDF one.
  893. * @param x {number} X coordinate.
  894. * @param y {number} Y coordinate.
  895. * @returns {Object} Object that contains 'x' and 'y' properties of the
  896. * point in the PDF coordinate space.
  897. * @see {@link convertToViewportPoint}
  898. */
  899. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  900. return Util.applyInverseTransform([x, y], this.transform);
  901. }
  902. };
  903. return PageViewport;
  904. })();
  905. var PDFStringTranslateTable = [
  906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  907. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  908. 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,
  909. 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,
  910. 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,
  911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  912. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  913. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  914. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  915. ];
  916. function stringToPDFString(str) {
  917. var i, n = str.length, strBuf = [];
  918. if (str[0] === '\xFE' && str[1] === '\xFF') {
  919. // UTF16BE BOM
  920. for (i = 2; i < n; i += 2) {
  921. strBuf.push(String.fromCharCode(
  922. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  923. }
  924. } else {
  925. for (i = 0; i < n; ++i) {
  926. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  927. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  928. }
  929. }
  930. return strBuf.join('');
  931. }
  932. function stringToUTF8String(str) {
  933. return decodeURIComponent(escape(str));
  934. }
  935. function utf8StringToString(str) {
  936. return unescape(encodeURIComponent(str));
  937. }
  938. function isEmptyObj(obj) {
  939. for (var key in obj) {
  940. return false;
  941. }
  942. return true;
  943. }
  944. function isBool(v) {
  945. return typeof v === 'boolean';
  946. }
  947. function isInt(v) {
  948. return typeof v === 'number' && ((v | 0) === v);
  949. }
  950. function isNum(v) {
  951. return typeof v === 'number';
  952. }
  953. function isString(v) {
  954. return typeof v === 'string';
  955. }
  956. function isArray(v) {
  957. return v instanceof Array;
  958. }
  959. function isArrayBuffer(v) {
  960. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  961. }
  962. /**
  963. * Promise Capability object.
  964. *
  965. * @typedef {Object} PromiseCapability
  966. * @property {Promise} promise - A promise object.
  967. * @property {function} resolve - Fullfills the promise.
  968. * @property {function} reject - Rejects the promise.
  969. */
  970. /**
  971. * Creates a promise capability object.
  972. * @alias PDFJS.createPromiseCapability
  973. *
  974. * @return {PromiseCapability} A capability object contains:
  975. * - a Promise, resolve and reject methods.
  976. */
  977. function createPromiseCapability() {
  978. var capability = {};
  979. capability.promise = new Promise(function (resolve, reject) {
  980. capability.resolve = resolve;
  981. capability.reject = reject;
  982. });
  983. return capability;
  984. }
  985. PDFJS.createPromiseCapability = createPromiseCapability;
  986. /**
  987. * Polyfill for Promises:
  988. * The following promise implementation tries to generally implement the
  989. * Promise/A+ spec. Some notable differences from other promise libaries are:
  990. * - There currently isn't a seperate deferred and promise object.
  991. * - Unhandled rejections eventually show an error if they aren't handled.
  992. *
  993. * Based off of the work in:
  994. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  995. */
  996. (function PromiseClosure() {
  997. if (globalScope.Promise) {
  998. // Promises existing in the DOM/Worker, checking presence of all/resolve
  999. if (typeof globalScope.Promise.all !== 'function') {
  1000. globalScope.Promise.all = function (iterable) {
  1001. var count = 0, results = [], resolve, reject;
  1002. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1003. resolve = resolve_;
  1004. reject = reject_;
  1005. });
  1006. iterable.forEach(function (p, i) {
  1007. count++;
  1008. p.then(function (result) {
  1009. results[i] = result;
  1010. count--;
  1011. if (count === 0) {
  1012. resolve(results);
  1013. }
  1014. }, reject);
  1015. });
  1016. if (count === 0) {
  1017. resolve(results);
  1018. }
  1019. return promise;
  1020. };
  1021. }
  1022. if (typeof globalScope.Promise.resolve !== 'function') {
  1023. globalScope.Promise.resolve = function (value) {
  1024. return new globalScope.Promise(function (resolve) { resolve(value); });
  1025. };
  1026. }
  1027. if (typeof globalScope.Promise.reject !== 'function') {
  1028. globalScope.Promise.reject = function (reason) {
  1029. return new globalScope.Promise(function (resolve, reject) {
  1030. reject(reason);
  1031. });
  1032. };
  1033. }
  1034. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1035. globalScope.Promise.prototype.catch = function (onReject) {
  1036. return globalScope.Promise.prototype.then(undefined, onReject);
  1037. };
  1038. }
  1039. return;
  1040. }
  1041. var STATUS_PENDING = 0;
  1042. var STATUS_RESOLVED = 1;
  1043. var STATUS_REJECTED = 2;
  1044. // In an attempt to avoid silent exceptions, unhandled rejections are
  1045. // tracked and if they aren't handled in a certain amount of time an
  1046. // error is logged.
  1047. var REJECTION_TIMEOUT = 500;
  1048. var HandlerManager = {
  1049. handlers: [],
  1050. running: false,
  1051. unhandledRejections: [],
  1052. pendingRejectionCheck: false,
  1053. scheduleHandlers: function scheduleHandlers(promise) {
  1054. if (promise._status === STATUS_PENDING) {
  1055. return;
  1056. }
  1057. this.handlers = this.handlers.concat(promise._handlers);
  1058. promise._handlers = [];
  1059. if (this.running) {
  1060. return;
  1061. }
  1062. this.running = true;
  1063. setTimeout(this.runHandlers.bind(this), 0);
  1064. },
  1065. runHandlers: function runHandlers() {
  1066. var RUN_TIMEOUT = 1; // ms
  1067. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1068. while (this.handlers.length > 0) {
  1069. var handler = this.handlers.shift();
  1070. var nextStatus = handler.thisPromise._status;
  1071. var nextValue = handler.thisPromise._value;
  1072. try {
  1073. if (nextStatus === STATUS_RESOLVED) {
  1074. if (typeof handler.onResolve === 'function') {
  1075. nextValue = handler.onResolve(nextValue);
  1076. }
  1077. } else if (typeof handler.onReject === 'function') {
  1078. nextValue = handler.onReject(nextValue);
  1079. nextStatus = STATUS_RESOLVED;
  1080. if (handler.thisPromise._unhandledRejection) {
  1081. this.removeUnhandeledRejection(handler.thisPromise);
  1082. }
  1083. }
  1084. } catch (ex) {
  1085. nextStatus = STATUS_REJECTED;
  1086. nextValue = ex;
  1087. }
  1088. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1089. if (Date.now() >= timeoutAt) {
  1090. break;
  1091. }
  1092. }
  1093. if (this.handlers.length > 0) {
  1094. setTimeout(this.runHandlers.bind(this), 0);
  1095. return;
  1096. }
  1097. this.running = false;
  1098. },
  1099. addUnhandledRejection: function addUnhandledRejection(promise) {
  1100. this.unhandledRejections.push({
  1101. promise: promise,
  1102. time: Date.now()
  1103. });
  1104. this.scheduleRejectionCheck();
  1105. },
  1106. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1107. promise._unhandledRejection = false;
  1108. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1109. if (this.unhandledRejections[i].promise === promise) {
  1110. this.unhandledRejections.splice(i);
  1111. i--;
  1112. }
  1113. }
  1114. },
  1115. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1116. if (this.pendingRejectionCheck) {
  1117. return;
  1118. }
  1119. this.pendingRejectionCheck = true;
  1120. setTimeout(function rejectionCheck() {
  1121. this.pendingRejectionCheck = false;
  1122. var now = Date.now();
  1123. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1124. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1125. var unhandled = this.unhandledRejections[i].promise._value;
  1126. var msg = 'Unhandled rejection: ' + unhandled;
  1127. if (unhandled.stack) {
  1128. msg += '\n' + unhandled.stack;
  1129. }
  1130. warn(msg);
  1131. this.unhandledRejections.splice(i);
  1132. i--;
  1133. }
  1134. }
  1135. if (this.unhandledRejections.length) {
  1136. this.scheduleRejectionCheck();
  1137. }
  1138. }.bind(this), REJECTION_TIMEOUT);
  1139. }
  1140. };
  1141. function Promise(resolver) {
  1142. this._status = STATUS_PENDING;
  1143. this._handlers = [];
  1144. try {
  1145. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1146. } catch (e) {
  1147. this._reject(e);
  1148. }
  1149. }
  1150. /**
  1151. * Builds a promise that is resolved when all the passed in promises are
  1152. * resolved.
  1153. * @param {array} array of data and/or promises to wait for.
  1154. * @return {Promise} New dependant promise.
  1155. */
  1156. Promise.all = function Promise_all(promises) {
  1157. var resolveAll, rejectAll;
  1158. var deferred = new Promise(function (resolve, reject) {
  1159. resolveAll = resolve;
  1160. rejectAll = reject;
  1161. });
  1162. var unresolved = promises.length;
  1163. var results = [];
  1164. if (unresolved === 0) {
  1165. resolveAll(results);
  1166. return deferred;
  1167. }
  1168. function reject(reason) {
  1169. if (deferred._status === STATUS_REJECTED) {
  1170. return;
  1171. }
  1172. results = [];
  1173. rejectAll(reason);
  1174. }
  1175. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1176. var promise = promises[i];
  1177. var resolve = (function(i) {
  1178. return function(value) {
  1179. if (deferred._status === STATUS_REJECTED) {
  1180. return;
  1181. }
  1182. results[i] = value;
  1183. unresolved--;
  1184. if (unresolved === 0) {
  1185. resolveAll(results);
  1186. }
  1187. };
  1188. })(i);
  1189. if (Promise.isPromise(promise)) {
  1190. promise.then(resolve, reject);
  1191. } else {
  1192. resolve(promise);
  1193. }
  1194. }
  1195. return deferred;
  1196. };
  1197. /**
  1198. * Checks if the value is likely a promise (has a 'then' function).
  1199. * @return {boolean} true if value is thenable
  1200. */
  1201. Promise.isPromise = function Promise_isPromise(value) {
  1202. return value && typeof value.then === 'function';
  1203. };
  1204. /**
  1205. * Creates resolved promise
  1206. * @param value resolve value
  1207. * @returns {Promise}
  1208. */
  1209. Promise.resolve = function Promise_resolve(value) {
  1210. return new Promise(function (resolve) { resolve(value); });
  1211. };
  1212. /**
  1213. * Creates rejected promise
  1214. * @param reason rejection value
  1215. * @returns {Promise}
  1216. */
  1217. Promise.reject = function Promise_reject(reason) {
  1218. return new Promise(function (resolve, reject) { reject(reason); });
  1219. };
  1220. Promise.prototype = {
  1221. _status: null,
  1222. _value: null,
  1223. _handlers: null,
  1224. _unhandledRejection: null,
  1225. _updateStatus: function Promise__updateStatus(status, value) {
  1226. if (this._status === STATUS_RESOLVED ||
  1227. this._status === STATUS_REJECTED) {
  1228. return;
  1229. }
  1230. if (status === STATUS_RESOLVED &&
  1231. Promise.isPromise(value)) {
  1232. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1233. this._updateStatus.bind(this, STATUS_REJECTED));
  1234. return;
  1235. }
  1236. this._status = status;
  1237. this._value = value;
  1238. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1239. this._unhandledRejection = true;
  1240. HandlerManager.addUnhandledRejection(this);
  1241. }
  1242. HandlerManager.scheduleHandlers(this);
  1243. },
  1244. _resolve: function Promise_resolve(value) {
  1245. this._updateStatus(STATUS_RESOLVED, value);
  1246. },
  1247. _reject: function Promise_reject(reason) {
  1248. this._updateStatus(STATUS_REJECTED, reason);
  1249. },
  1250. then: function Promise_then(onResolve, onReject) {
  1251. var nextPromise = new Promise(function (resolve, reject) {
  1252. this.resolve = resolve;
  1253. this.reject = reject;
  1254. });
  1255. this._handlers.push({
  1256. thisPromise: this,
  1257. onResolve: onResolve,
  1258. onReject: onReject,
  1259. nextPromise: nextPromise
  1260. });
  1261. HandlerManager.scheduleHandlers(this);
  1262. return nextPromise;
  1263. },
  1264. catch: function Promise_catch(onReject) {
  1265. return this.then(undefined, onReject);
  1266. }
  1267. };
  1268. globalScope.Promise = Promise;
  1269. })();
  1270. var StatTimer = (function StatTimerClosure() {
  1271. function rpad(str, pad, length) {
  1272. while (str.length < length) {
  1273. str += pad;
  1274. }
  1275. return str;
  1276. }
  1277. function StatTimer() {
  1278. this.started = {};
  1279. this.times = [];
  1280. this.enabled = true;
  1281. }
  1282. StatTimer.prototype = {
  1283. time: function StatTimer_time(name) {
  1284. if (!this.enabled) {
  1285. return;
  1286. }
  1287. if (name in this.started) {
  1288. warn('Timer is already running for ' + name);
  1289. }
  1290. this.started[name] = Date.now();
  1291. },
  1292. timeEnd: function StatTimer_timeEnd(name) {
  1293. if (!this.enabled) {
  1294. return;
  1295. }
  1296. if (!(name in this.started)) {
  1297. warn('Timer has not been started for ' + name);
  1298. }
  1299. this.times.push({
  1300. 'name': name,
  1301. 'start': this.started[name],
  1302. 'end': Date.now()
  1303. });
  1304. // Remove timer from started so it can be called again.
  1305. delete this.started[name];
  1306. },
  1307. toString: function StatTimer_toString() {
  1308. var i, ii;
  1309. var times = this.times;
  1310. var out = '';
  1311. // Find the longest name for padding purposes.
  1312. var longest = 0;
  1313. for (i = 0, ii = times.length; i < ii; ++i) {
  1314. var name = times[i]['name'];
  1315. if (name.length > longest) {
  1316. longest = name.length;
  1317. }
  1318. }
  1319. for (i = 0, ii = times.length; i < ii; ++i) {
  1320. var span = times[i];
  1321. var duration = span.end - span.start;
  1322. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1323. }
  1324. return out;
  1325. }
  1326. };
  1327. return StatTimer;
  1328. })();
  1329. PDFJS.createBlob = function createBlob(data, contentType) {
  1330. if (typeof Blob !== 'undefined') {
  1331. return new Blob([data], { type: contentType });
  1332. }
  1333. // Blob builder is deprecated in FF14 and removed in FF18.
  1334. var bb = new MozBlobBuilder();
  1335. bb.append(data);
  1336. return bb.getBlob(contentType);
  1337. };
  1338. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1339. // Blob/createObjectURL is not available, falling back to data schema.
  1340. var digits =
  1341. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1342. return function createObjectURL(data, contentType) {
  1343. if (!PDFJS.disableCreateObjectURL &&
  1344. typeof URL !== 'undefined' && URL.createObjectURL) {
  1345. var blob = PDFJS.createBlob(data, contentType);
  1346. return URL.createObjectURL(blob);
  1347. }
  1348. var buffer = 'data:' + contentType + ';base64,';
  1349. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1350. var b1 = data[i] & 0xFF;
  1351. var b2 = data[i + 1] & 0xFF;
  1352. var b3 = data[i + 2] & 0xFF;
  1353. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1354. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1355. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1356. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1357. }
  1358. return buffer;
  1359. };
  1360. })();
  1361. function MessageHandler(sourceName, targetName, comObj) {
  1362. this.sourceName = sourceName;
  1363. this.targetName = targetName;
  1364. this.comObj = comObj;
  1365. this.callbackIndex = 1;
  1366. this.postMessageTransfers = true;
  1367. var callbacksCapabilities = this.callbacksCapabilities = {};
  1368. var ah = this.actionHandler = {};
  1369. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1370. var data = event.data;
  1371. if (data.targetName !== this.sourceName) {
  1372. return;
  1373. }
  1374. if (data.isReply) {
  1375. var callbackId = data.callbackId;
  1376. if (data.callbackId in callbacksCapabilities) {
  1377. var callback = callbacksCapabilities[callbackId];
  1378. delete callbacksCapabilities[callbackId];
  1379. if ('error' in data) {
  1380. callback.reject(data.error);
  1381. } else {
  1382. callback.resolve(data.data);
  1383. }
  1384. } else {
  1385. error('Cannot resolve callback ' + callbackId);
  1386. }
  1387. } else if (data.action in ah) {
  1388. var action = ah[data.action];
  1389. if (data.callbackId) {
  1390. var sourceName = this.sourceName;
  1391. var targetName = data.sourceName;
  1392. Promise.resolve().then(function () {
  1393. return action[0].call(action[1], data.data);
  1394. }).then(function (result) {
  1395. comObj.postMessage({
  1396. sourceName: sourceName,
  1397. targetName: targetName,
  1398. isReply: true,
  1399. callbackId: data.callbackId,
  1400. data: result
  1401. });
  1402. }, function (reason) {
  1403. if (reason instanceof Error) {
  1404. // Serialize error to avoid "DataCloneError"
  1405. reason = reason + '';
  1406. }
  1407. comObj.postMessage({
  1408. sourceName: sourceName,
  1409. targetName: targetName,
  1410. isReply: true,
  1411. callbackId: data.callbackId,
  1412. error: reason
  1413. });
  1414. });
  1415. } else {
  1416. action[0].call(action[1], data.data);
  1417. }
  1418. } else {
  1419. error('Unknown action from worker: ' + data.action);
  1420. }
  1421. }.bind(this);
  1422. comObj.addEventListener('message', this._onComObjOnMessage);
  1423. }
  1424. MessageHandler.prototype = {
  1425. on: function messageHandlerOn(actionName, handler, scope) {
  1426. var ah = this.actionHandler;
  1427. if (ah[actionName]) {
  1428. error('There is already an actionName called "' + actionName + '"');
  1429. }
  1430. ah[actionName] = [handler, scope];
  1431. },
  1432. /**
  1433. * Sends a message to the comObj to invoke the action with the supplied data.
  1434. * @param {String} actionName Action to call.
  1435. * @param {JSON} data JSON data to send.
  1436. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1437. */
  1438. send: function messageHandlerSend(actionName, data, transfers) {
  1439. var message = {
  1440. sourceName: this.sourceName,
  1441. targetName: this.targetName,
  1442. action: actionName,
  1443. data: data
  1444. };
  1445. this.postMessage(message, transfers);
  1446. },
  1447. /**
  1448. * Sends a message to the comObj to invoke the action with the supplied data.
  1449. * Expects that other side will callback with the response.
  1450. * @param {String} actionName Action to call.
  1451. * @param {JSON} data JSON data to send.
  1452. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1453. * @returns {Promise} Promise to be resolved with response data.
  1454. */
  1455. sendWithPromise:
  1456. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1457. var callbackId = this.callbackIndex++;
  1458. var message = {
  1459. sourceName: this.sourceName,
  1460. targetName: this.targetName,
  1461. action: actionName,
  1462. data: data,
  1463. callbackId: callbackId
  1464. };
  1465. var capability = createPromiseCapability();
  1466. this.callbacksCapabilities[callbackId] = capability;
  1467. try {
  1468. this.postMessage(message, transfers);
  1469. } catch (e) {
  1470. capability.reject(e);
  1471. }
  1472. return capability.promise;
  1473. },
  1474. /**
  1475. * Sends raw message to the comObj.
  1476. * @private
  1477. * @param message {Object} Raw message.
  1478. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1479. */
  1480. postMessage: function (message, transfers) {
  1481. if (transfers && this.postMessageTransfers) {
  1482. this.comObj.postMessage(message, transfers);
  1483. } else {
  1484. this.comObj.postMessage(message);
  1485. }
  1486. },
  1487. destroy: function () {
  1488. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1489. }
  1490. };
  1491. function loadJpegStream(id, imageUrl, objs) {
  1492. var img = new Image();
  1493. img.onload = (function loadJpegStream_onloadClosure() {
  1494. objs.resolve(id, img);
  1495. });
  1496. img.onerror = (function loadJpegStream_onerrorClosure() {
  1497. objs.resolve(id, null);
  1498. warn('Error during JPEG image loading');
  1499. });
  1500. img.src = imageUrl;
  1501. }
  1502. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1503. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1504. exports.OPS = OPS;
  1505. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1506. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1507. exports.AnnotationFlag = AnnotationFlag;
  1508. exports.AnnotationType = AnnotationType;
  1509. exports.FontType = FontType;
  1510. exports.ImageKind = ImageKind;
  1511. exports.InvalidPDFException = InvalidPDFException;
  1512. exports.LinkTarget = LinkTarget;
  1513. exports.LinkTargetStringMap = LinkTargetStringMap;
  1514. exports.MessageHandler = MessageHandler;
  1515. exports.MissingDataException = MissingDataException;
  1516. exports.MissingPDFException = MissingPDFException;
  1517. exports.NotImplementedException = NotImplementedException;
  1518. exports.PasswordException = PasswordException;
  1519. exports.PasswordResponses = PasswordResponses;
  1520. exports.StatTimer = StatTimer;
  1521. exports.StreamType = StreamType;
  1522. exports.TextRenderingMode = TextRenderingMode;
  1523. exports.UnexpectedResponseException = UnexpectedResponseException;
  1524. exports.UnknownErrorException = UnknownErrorException;
  1525. exports.Util = Util;
  1526. exports.XRefParseException = XRefParseException;
  1527. exports.assert = assert;
  1528. exports.bytesToString = bytesToString;
  1529. exports.combineUrl = combineUrl;
  1530. exports.createPromiseCapability = createPromiseCapability;
  1531. exports.deprecated = deprecated;
  1532. exports.error = error;
  1533. exports.info = info;
  1534. exports.isArray = isArray;
  1535. exports.isArrayBuffer = isArrayBuffer;
  1536. exports.isBool = isBool;
  1537. exports.isEmptyObj = isEmptyObj;
  1538. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1539. exports.isInt = isInt;
  1540. exports.isNum = isNum;
  1541. exports.isString = isString;
  1542. exports.isValidUrl = isValidUrl;
  1543. exports.loadJpegStream = loadJpegStream;
  1544. exports.log2 = log2;
  1545. exports.readInt8 = readInt8;
  1546. exports.readUint16 = readUint16;
  1547. exports.readUint32 = readUint32;
  1548. exports.shadow = shadow;
  1549. exports.string32 = string32;
  1550. exports.stringToBytes = stringToBytes;
  1551. exports.stringToPDFString = stringToPDFString;
  1552. exports.stringToUTF8String = stringToUTF8String;
  1553. exports.utf8StringToString = utf8StringToString;
  1554. exports.warn = warn;
  1555. }));
  1556. var NetworkManager = (function NetworkManagerClosure() {
  1557. var OK_RESPONSE = 200;
  1558. var PARTIAL_CONTENT_RESPONSE = 206;
  1559. function NetworkManager(url, args) {
  1560. this.url = url;
  1561. args = args || {};
  1562. this.isHttp = /^https?:/i.test(url);
  1563. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1564. this.withCredentials = args.withCredentials || false;
  1565. this.getXhr = args.getXhr ||
  1566. function NetworkManager_getXhr() {
  1567. return new XMLHttpRequest();
  1568. };
  1569. this.currXhrId = 0;
  1570. this.pendingRequests = {};
  1571. this.loadedRequests = {};
  1572. }
  1573. function getArrayBuffer(xhr) {
  1574. var data = xhr.response;
  1575. if (typeof data !== 'string') {
  1576. return data;
  1577. }
  1578. var length = data.length;
  1579. var array = new Uint8Array(length);
  1580. for (var i = 0; i < length; i++) {
  1581. array[i] = data.charCodeAt(i) & 0xFF;
  1582. }
  1583. return array.buffer;
  1584. }
  1585. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1586. try {
  1587. var x = new XMLHttpRequest();
  1588. // Firefox 37- required .open() to be called before setting responseType.
  1589. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1590. // Even though the URL is not visited, .open() could fail if the URL is
  1591. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1592. // When this error occurs, this feature detection method will mistakenly
  1593. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1594. x.open('GET', 'https://example.com');
  1595. x.responseType = 'moz-chunked-arraybuffer';
  1596. return x.responseType === 'moz-chunked-arraybuffer';
  1597. } catch (e) {
  1598. return false;
  1599. }
  1600. })();
  1601. NetworkManager.prototype = {
  1602. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1603. var args = {
  1604. begin: begin,
  1605. end: end
  1606. };
  1607. for (var prop in listeners) {
  1608. args[prop] = listeners[prop];
  1609. }
  1610. return this.request(args);
  1611. },
  1612. requestFull: function NetworkManager_requestFull(listeners) {
  1613. return this.request(listeners);
  1614. },
  1615. request: function NetworkManager_request(args) {
  1616. var xhr = this.getXhr();
  1617. var xhrId = this.currXhrId++;
  1618. var pendingRequest = this.pendingRequests[xhrId] = {
  1619. xhr: xhr
  1620. };
  1621. xhr.open('GET', this.url);
  1622. xhr.withCredentials = this.withCredentials;
  1623. for (var property in this.httpHeaders) {
  1624. var value = this.httpHeaders[property];
  1625. if (typeof value === 'undefined') {
  1626. continue;
  1627. }
  1628. xhr.setRequestHeader(property, value);
  1629. }
  1630. if (this.isHttp && 'begin' in args && 'end' in args) {
  1631. var rangeStr = args.begin + '-' + (args.end - 1);
  1632. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1633. pendingRequest.expectedStatus = 206;
  1634. } else {
  1635. pendingRequest.expectedStatus = 200;
  1636. }
  1637. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1638. if (useMozChunkedLoading) {
  1639. xhr.responseType = 'moz-chunked-arraybuffer';
  1640. pendingRequest.onProgressiveData = args.onProgressiveData;
  1641. pendingRequest.mozChunked = true;
  1642. } else {
  1643. xhr.responseType = 'arraybuffer';
  1644. }
  1645. if (args.onError) {
  1646. xhr.onerror = function(evt) {
  1647. args.onError(xhr.status);
  1648. };
  1649. }
  1650. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1651. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1652. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1653. pendingRequest.onDone = args.onDone;
  1654. pendingRequest.onError = args.onError;
  1655. pendingRequest.onProgress = args.onProgress;
  1656. xhr.send(null);
  1657. return xhrId;
  1658. },
  1659. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1660. var pendingRequest = this.pendingRequests[xhrId];
  1661. if (!pendingRequest) {
  1662. // Maybe abortRequest was called...
  1663. return;
  1664. }
  1665. if (pendingRequest.mozChunked) {
  1666. var chunk = getArrayBuffer(pendingRequest.xhr);
  1667. pendingRequest.onProgressiveData(chunk);
  1668. }
  1669. var onProgress = pendingRequest.onProgress;
  1670. if (onProgress) {
  1671. onProgress(evt);
  1672. }
  1673. },
  1674. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1675. var pendingRequest = this.pendingRequests[xhrId];
  1676. if (!pendingRequest) {
  1677. // Maybe abortRequest was called...
  1678. return;
  1679. }
  1680. var xhr = pendingRequest.xhr;
  1681. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1682. pendingRequest.onHeadersReceived();
  1683. delete pendingRequest.onHeadersReceived;
  1684. }
  1685. if (xhr.readyState !== 4) {
  1686. return;
  1687. }
  1688. if (!(xhrId in this.pendingRequests)) {
  1689. // The XHR request might have been aborted in onHeadersReceived()
  1690. // callback, in which case we should abort request
  1691. return;
  1692. }
  1693. delete this.pendingRequests[xhrId];
  1694. // success status == 0 can be on ftp, file and other protocols
  1695. if (xhr.status === 0 && this.isHttp) {
  1696. if (pendingRequest.onError) {
  1697. pendingRequest.onError(xhr.status);
  1698. }
  1699. return;
  1700. }
  1701. var xhrStatus = xhr.status || OK_RESPONSE;
  1702. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1703. // "A server MAY ignore the Range header". This means it's possible to
  1704. // get a 200 rather than a 206 response from a range request.
  1705. var ok_response_on_range_request =
  1706. xhrStatus === OK_RESPONSE &&
  1707. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1708. if (!ok_response_on_range_request &&
  1709. xhrStatus !== pendingRequest.expectedStatus) {
  1710. if (pendingRequest.onError) {
  1711. pendingRequest.onError(xhr.status);
  1712. }
  1713. return;
  1714. }
  1715. this.loadedRequests[xhrId] = true;
  1716. var chunk = getArrayBuffer(xhr);
  1717. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1718. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1719. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1720. var begin = parseInt(matches[1], 10);
  1721. pendingRequest.onDone({
  1722. begin: begin,
  1723. chunk: chunk
  1724. });
  1725. } else if (pendingRequest.onProgressiveData) {
  1726. pendingRequest.onDone(null);
  1727. } else if (chunk) {
  1728. pendingRequest.onDone({
  1729. begin: 0,
  1730. chunk: chunk
  1731. });
  1732. } else if (pendingRequest.onError) {
  1733. pendingRequest.onError(xhr.status);
  1734. }
  1735. },
  1736. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1737. for (var xhrId in this.pendingRequests) {
  1738. return true;
  1739. }
  1740. return false;
  1741. },
  1742. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1743. return this.pendingRequests[xhrId].xhr;
  1744. },
  1745. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1746. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1747. },
  1748. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1749. return xhrId in this.pendingRequests;
  1750. },
  1751. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1752. return xhrId in this.loadedRequests;
  1753. },
  1754. abortAllRequests: function NetworkManager_abortAllRequests() {
  1755. for (var xhrId in this.pendingRequests) {
  1756. this.abortRequest(xhrId | 0);
  1757. }
  1758. },
  1759. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1760. var xhr = this.pendingRequests[xhrId].xhr;
  1761. delete this.pendingRequests[xhrId];
  1762. xhr.abort();
  1763. }
  1764. };
  1765. return NetworkManager;
  1766. })();
  1767. (function (root, factory) {
  1768. {
  1769. factory((root.pdfjsCoreArithmeticDecoder = {}));
  1770. }
  1771. }(this, function (exports) {
  1772. /* This class implements the QM Coder decoding as defined in
  1773. * JPEG 2000 Part I Final Committee Draft Version 1.0
  1774. * Annex C.3 Arithmetic decoding procedure
  1775. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  1776. *
  1777. * The arithmetic decoder is used in conjunction with context models to decode
  1778. * JPEG2000 and JBIG2 streams.
  1779. */
  1780. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  1781. // Table C-2
  1782. var QeTable = [
  1783. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  1784. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  1785. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  1786. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  1787. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  1788. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  1789. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  1790. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  1791. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  1792. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  1793. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  1794. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  1795. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  1796. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  1797. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  1798. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  1799. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  1800. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  1801. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  1802. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  1803. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  1804. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  1805. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  1806. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  1807. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  1808. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  1809. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  1810. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  1811. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  1812. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  1813. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  1814. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  1815. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  1816. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  1817. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  1818. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  1819. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  1820. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  1821. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  1822. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  1823. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  1824. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  1825. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  1826. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  1827. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  1828. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  1829. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  1830. ];
  1831. // C.3.5 Initialisation of the decoder (INITDEC)
  1832. function ArithmeticDecoder(data, start, end) {
  1833. this.data = data;
  1834. this.bp = start;
  1835. this.dataEnd = end;
  1836. this.chigh = data[start];
  1837. this.clow = 0;
  1838. this.byteIn();
  1839. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  1840. this.clow = (this.clow << 7) & 0xFFFF;
  1841. this.ct -= 7;
  1842. this.a = 0x8000;
  1843. }
  1844. ArithmeticDecoder.prototype = {
  1845. // C.3.4 Compressed data input (BYTEIN)
  1846. byteIn: function ArithmeticDecoder_byteIn() {
  1847. var data = this.data;
  1848. var bp = this.bp;
  1849. if (data[bp] === 0xFF) {
  1850. var b1 = data[bp + 1];
  1851. if (b1 > 0x8F) {
  1852. this.clow += 0xFF00;
  1853. this.ct = 8;
  1854. } else {
  1855. bp++;
  1856. this.clow += (data[bp] << 9);
  1857. this.ct = 7;
  1858. this.bp = bp;
  1859. }
  1860. } else {
  1861. bp++;
  1862. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  1863. this.ct = 8;
  1864. this.bp = bp;
  1865. }
  1866. if (this.clow > 0xFFFF) {
  1867. this.chigh += (this.clow >> 16);
  1868. this.clow &= 0xFFFF;
  1869. }
  1870. },
  1871. // C.3.2 Decoding a decision (DECODE)
  1872. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  1873. // contexts are packed into 1 byte:
  1874. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  1875. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  1876. var qeTableIcx = QeTable[cx_index];
  1877. var qeIcx = qeTableIcx.qe;
  1878. var d;
  1879. var a = this.a - qeIcx;
  1880. if (this.chigh < qeIcx) {
  1881. // exchangeLps
  1882. if (a < qeIcx) {
  1883. a = qeIcx;
  1884. d = cx_mps;
  1885. cx_index = qeTableIcx.nmps;
  1886. } else {
  1887. a = qeIcx;
  1888. d = 1 ^ cx_mps;
  1889. if (qeTableIcx.switchFlag === 1) {
  1890. cx_mps = d;
  1891. }
  1892. cx_index = qeTableIcx.nlps;
  1893. }
  1894. } else {
  1895. this.chigh -= qeIcx;
  1896. if ((a & 0x8000) !== 0) {
  1897. this.a = a;
  1898. return cx_mps;
  1899. }
  1900. // exchangeMps
  1901. if (a < qeIcx) {
  1902. d = 1 ^ cx_mps;
  1903. if (qeTableIcx.switchFlag === 1) {
  1904. cx_mps = d;
  1905. }
  1906. cx_index = qeTableIcx.nlps;
  1907. } else {
  1908. d = cx_mps;
  1909. cx_index = qeTableIcx.nmps;
  1910. }
  1911. }
  1912. // C.3.3 renormD;
  1913. do {
  1914. if (this.ct === 0) {
  1915. this.byteIn();
  1916. }
  1917. a <<= 1;
  1918. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  1919. this.clow = (this.clow << 1) & 0xFFFF;
  1920. this.ct--;
  1921. } while ((a & 0x8000) === 0);
  1922. this.a = a;
  1923. contexts[pos] = cx_index << 1 | cx_mps;
  1924. return d;
  1925. }
  1926. };
  1927. return ArithmeticDecoder;
  1928. })();
  1929. exports.ArithmeticDecoder = ArithmeticDecoder;
  1930. }));
  1931. (function (root, factory) {
  1932. {
  1933. factory((root.pdfjsCoreCharsets = {}));
  1934. }
  1935. }(this, function (exports) {
  1936. var ISOAdobeCharset = [
  1937. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  1938. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  1939. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  1940. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  1941. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  1942. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  1943. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  1944. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  1945. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  1946. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  1947. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  1948. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  1949. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  1950. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  1951. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  1952. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  1953. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  1954. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  1955. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  1956. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  1957. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  1958. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  1959. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  1960. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  1961. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  1962. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  1963. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  1964. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  1965. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  1966. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  1967. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  1968. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  1969. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  1970. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  1971. ];
  1972. var ExpertCharset = [
  1973. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  1974. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  1975. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  1976. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  1977. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  1978. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  1979. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  1980. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  1981. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  1982. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  1983. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  1984. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  1985. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  1986. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  1987. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  1988. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  1989. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  1990. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  1991. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  1992. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  1993. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  1994. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  1995. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  1996. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  1997. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  1998. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  1999. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  2000. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2001. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  2002. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  2003. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  2004. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  2005. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  2006. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  2007. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  2008. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  2009. 'Ydieresissmall'
  2010. ];
  2011. var ExpertSubsetCharset = [
  2012. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  2013. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  2014. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  2015. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  2016. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  2017. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  2018. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  2019. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  2020. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  2021. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  2022. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  2023. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  2024. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  2025. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  2026. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  2027. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  2028. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  2029. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  2030. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2031. 'periodinferior', 'commainferior'
  2032. ];
  2033. exports.ISOAdobeCharset = ISOAdobeCharset;
  2034. exports.ExpertCharset = ExpertCharset;
  2035. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  2036. }));
  2037. (function (root, factory) {
  2038. {
  2039. factory((root.pdfjsCoreGlyphList = {}));
  2040. }
  2041. }(this, function (exports) {
  2042. var GlyphsUnicode = {
  2043. A: 0x0041,
  2044. AE: 0x00C6,
  2045. AEacute: 0x01FC,
  2046. AEmacron: 0x01E2,
  2047. AEsmall: 0xF7E6,
  2048. Aacute: 0x00C1,
  2049. Aacutesmall: 0xF7E1,
  2050. Abreve: 0x0102,
  2051. Abreveacute: 0x1EAE,
  2052. Abrevecyrillic: 0x04D0,
  2053. Abrevedotbelow: 0x1EB6,
  2054. Abrevegrave: 0x1EB0,
  2055. Abrevehookabove: 0x1EB2,
  2056. Abrevetilde: 0x1EB4,
  2057. Acaron: 0x01CD,
  2058. Acircle: 0x24B6,
  2059. Acircumflex: 0x00C2,
  2060. Acircumflexacute: 0x1EA4,
  2061. Acircumflexdotbelow: 0x1EAC,
  2062. Acircumflexgrave: 0x1EA6,
  2063. Acircumflexhookabove: 0x1EA8,
  2064. Acircumflexsmall: 0xF7E2,
  2065. Acircumflextilde: 0x1EAA,
  2066. Acute: 0xF6C9,
  2067. Acutesmall: 0xF7B4,
  2068. Acyrillic: 0x0410,
  2069. Adblgrave: 0x0200,
  2070. Adieresis: 0x00C4,
  2071. Adieresiscyrillic: 0x04D2,
  2072. Adieresismacron: 0x01DE,
  2073. Adieresissmall: 0xF7E4,
  2074. Adotbelow: 0x1EA0,
  2075. Adotmacron: 0x01E0,
  2076. Agrave: 0x00C0,
  2077. Agravesmall: 0xF7E0,
  2078. Ahookabove: 0x1EA2,
  2079. Aiecyrillic: 0x04D4,
  2080. Ainvertedbreve: 0x0202,
  2081. Alpha: 0x0391,
  2082. Alphatonos: 0x0386,
  2083. Amacron: 0x0100,
  2084. Amonospace: 0xFF21,
  2085. Aogonek: 0x0104,
  2086. Aring: 0x00C5,
  2087. Aringacute: 0x01FA,
  2088. Aringbelow: 0x1E00,
  2089. Aringsmall: 0xF7E5,
  2090. Asmall: 0xF761,
  2091. Atilde: 0x00C3,
  2092. Atildesmall: 0xF7E3,
  2093. Aybarmenian: 0x0531,
  2094. B: 0x0042,
  2095. Bcircle: 0x24B7,
  2096. Bdotaccent: 0x1E02,
  2097. Bdotbelow: 0x1E04,
  2098. Becyrillic: 0x0411,
  2099. Benarmenian: 0x0532,
  2100. Beta: 0x0392,
  2101. Bhook: 0x0181,
  2102. Blinebelow: 0x1E06,
  2103. Bmonospace: 0xFF22,
  2104. Brevesmall: 0xF6F4,
  2105. Bsmall: 0xF762,
  2106. Btopbar: 0x0182,
  2107. C: 0x0043,
  2108. Caarmenian: 0x053E,
  2109. Cacute: 0x0106,
  2110. Caron: 0xF6CA,
  2111. Caronsmall: 0xF6F5,
  2112. Ccaron: 0x010C,
  2113. Ccedilla: 0x00C7,
  2114. Ccedillaacute: 0x1E08,
  2115. Ccedillasmall: 0xF7E7,
  2116. Ccircle: 0x24B8,
  2117. Ccircumflex: 0x0108,
  2118. Cdot: 0x010A,
  2119. Cdotaccent: 0x010A,
  2120. Cedillasmall: 0xF7B8,
  2121. Chaarmenian: 0x0549,
  2122. Cheabkhasiancyrillic: 0x04BC,
  2123. Checyrillic: 0x0427,
  2124. Chedescenderabkhasiancyrillic: 0x04BE,
  2125. Chedescendercyrillic: 0x04B6,
  2126. Chedieresiscyrillic: 0x04F4,
  2127. Cheharmenian: 0x0543,
  2128. Chekhakassiancyrillic: 0x04CB,
  2129. Cheverticalstrokecyrillic: 0x04B8,
  2130. Chi: 0x03A7,
  2131. Chook: 0x0187,
  2132. Circumflexsmall: 0xF6F6,
  2133. Cmonospace: 0xFF23,
  2134. Coarmenian: 0x0551,
  2135. Csmall: 0xF763,
  2136. D: 0x0044,
  2137. DZ: 0x01F1,
  2138. DZcaron: 0x01C4,
  2139. Daarmenian: 0x0534,
  2140. Dafrican: 0x0189,
  2141. Dcaron: 0x010E,
  2142. Dcedilla: 0x1E10,
  2143. Dcircle: 0x24B9,
  2144. Dcircumflexbelow: 0x1E12,
  2145. Dcroat: 0x0110,
  2146. Ddotaccent: 0x1E0A,
  2147. Ddotbelow: 0x1E0C,
  2148. Decyrillic: 0x0414,
  2149. Deicoptic: 0x03EE,
  2150. Delta: 0x2206,
  2151. Deltagreek: 0x0394,
  2152. Dhook: 0x018A,
  2153. Dieresis: 0xF6CB,
  2154. DieresisAcute: 0xF6CC,
  2155. DieresisGrave: 0xF6CD,
  2156. Dieresissmall: 0xF7A8,
  2157. Digammagreek: 0x03DC,
  2158. Djecyrillic: 0x0402,
  2159. Dlinebelow: 0x1E0E,
  2160. Dmonospace: 0xFF24,
  2161. Dotaccentsmall: 0xF6F7,
  2162. Dslash: 0x0110,
  2163. Dsmall: 0xF764,
  2164. Dtopbar: 0x018B,
  2165. Dz: 0x01F2,
  2166. Dzcaron: 0x01C5,
  2167. Dzeabkhasiancyrillic: 0x04E0,
  2168. Dzecyrillic: 0x0405,
  2169. Dzhecyrillic: 0x040F,
  2170. E: 0x0045,
  2171. Eacute: 0x00C9,
  2172. Eacutesmall: 0xF7E9,
  2173. Ebreve: 0x0114,
  2174. Ecaron: 0x011A,
  2175. Ecedillabreve: 0x1E1C,
  2176. Echarmenian: 0x0535,
  2177. Ecircle: 0x24BA,
  2178. Ecircumflex: 0x00CA,
  2179. Ecircumflexacute: 0x1EBE,
  2180. Ecircumflexbelow: 0x1E18,
  2181. Ecircumflexdotbelow: 0x1EC6,
  2182. Ecircumflexgrave: 0x1EC0,
  2183. Ecircumflexhookabove: 0x1EC2,
  2184. Ecircumflexsmall: 0xF7EA,
  2185. Ecircumflextilde: 0x1EC4,
  2186. Ecyrillic: 0x0404,
  2187. Edblgrave: 0x0204,
  2188. Edieresis: 0x00CB,
  2189. Edieresissmall: 0xF7EB,
  2190. Edot: 0x0116,
  2191. Edotaccent: 0x0116,
  2192. Edotbelow: 0x1EB8,
  2193. Efcyrillic: 0x0424,
  2194. Egrave: 0x00C8,
  2195. Egravesmall: 0xF7E8,
  2196. Eharmenian: 0x0537,
  2197. Ehookabove: 0x1EBA,
  2198. Eightroman: 0x2167,
  2199. Einvertedbreve: 0x0206,
  2200. Eiotifiedcyrillic: 0x0464,
  2201. Elcyrillic: 0x041B,
  2202. Elevenroman: 0x216A,
  2203. Emacron: 0x0112,
  2204. Emacronacute: 0x1E16,
  2205. Emacrongrave: 0x1E14,
  2206. Emcyrillic: 0x041C,
  2207. Emonospace: 0xFF25,
  2208. Encyrillic: 0x041D,
  2209. Endescendercyrillic: 0x04A2,
  2210. Eng: 0x014A,
  2211. Enghecyrillic: 0x04A4,
  2212. Enhookcyrillic: 0x04C7,
  2213. Eogonek: 0x0118,
  2214. Eopen: 0x0190,
  2215. Epsilon: 0x0395,
  2216. Epsilontonos: 0x0388,
  2217. Ercyrillic: 0x0420,
  2218. Ereversed: 0x018E,
  2219. Ereversedcyrillic: 0x042D,
  2220. Escyrillic: 0x0421,
  2221. Esdescendercyrillic: 0x04AA,
  2222. Esh: 0x01A9,
  2223. Esmall: 0xF765,
  2224. Eta: 0x0397,
  2225. Etarmenian: 0x0538,
  2226. Etatonos: 0x0389,
  2227. Eth: 0x00D0,
  2228. Ethsmall: 0xF7F0,
  2229. Etilde: 0x1EBC,
  2230. Etildebelow: 0x1E1A,
  2231. Euro: 0x20AC,
  2232. Ezh: 0x01B7,
  2233. Ezhcaron: 0x01EE,
  2234. Ezhreversed: 0x01B8,
  2235. F: 0x0046,
  2236. Fcircle: 0x24BB,
  2237. Fdotaccent: 0x1E1E,
  2238. Feharmenian: 0x0556,
  2239. Feicoptic: 0x03E4,
  2240. Fhook: 0x0191,
  2241. Fitacyrillic: 0x0472,
  2242. Fiveroman: 0x2164,
  2243. Fmonospace: 0xFF26,
  2244. Fourroman: 0x2163,
  2245. Fsmall: 0xF766,
  2246. G: 0x0047,
  2247. GBsquare: 0x3387,
  2248. Gacute: 0x01F4,
  2249. Gamma: 0x0393,
  2250. Gammaafrican: 0x0194,
  2251. Gangiacoptic: 0x03EA,
  2252. Gbreve: 0x011E,
  2253. Gcaron: 0x01E6,
  2254. Gcedilla: 0x0122,
  2255. Gcircle: 0x24BC,
  2256. Gcircumflex: 0x011C,
  2257. Gcommaaccent: 0x0122,
  2258. Gdot: 0x0120,
  2259. Gdotaccent: 0x0120,
  2260. Gecyrillic: 0x0413,
  2261. Ghadarmenian: 0x0542,
  2262. Ghemiddlehookcyrillic: 0x0494,
  2263. Ghestrokecyrillic: 0x0492,
  2264. Gheupturncyrillic: 0x0490,
  2265. Ghook: 0x0193,
  2266. Gimarmenian: 0x0533,
  2267. Gjecyrillic: 0x0403,
  2268. Gmacron: 0x1E20,
  2269. Gmonospace: 0xFF27,
  2270. Grave: 0xF6CE,
  2271. Gravesmall: 0xF760,
  2272. Gsmall: 0xF767,
  2273. Gsmallhook: 0x029B,
  2274. Gstroke: 0x01E4,
  2275. H: 0x0048,
  2276. H18533: 0x25CF,
  2277. H18543: 0x25AA,
  2278. H18551: 0x25AB,
  2279. H22073: 0x25A1,
  2280. HPsquare: 0x33CB,
  2281. Haabkhasiancyrillic: 0x04A8,
  2282. Hadescendercyrillic: 0x04B2,
  2283. Hardsigncyrillic: 0x042A,
  2284. Hbar: 0x0126,
  2285. Hbrevebelow: 0x1E2A,
  2286. Hcedilla: 0x1E28,
  2287. Hcircle: 0x24BD,
  2288. Hcircumflex: 0x0124,
  2289. Hdieresis: 0x1E26,
  2290. Hdotaccent: 0x1E22,
  2291. Hdotbelow: 0x1E24,
  2292. Hmonospace: 0xFF28,
  2293. Hoarmenian: 0x0540,
  2294. Horicoptic: 0x03E8,
  2295. Hsmall: 0xF768,
  2296. Hungarumlaut: 0xF6CF,
  2297. Hungarumlautsmall: 0xF6F8,
  2298. Hzsquare: 0x3390,
  2299. I: 0x0049,
  2300. IAcyrillic: 0x042F,
  2301. IJ: 0x0132,
  2302. IUcyrillic: 0x042E,
  2303. Iacute: 0x00CD,
  2304. Iacutesmall: 0xF7ED,
  2305. Ibreve: 0x012C,
  2306. Icaron: 0x01CF,
  2307. Icircle: 0x24BE,
  2308. Icircumflex: 0x00CE,
  2309. Icircumflexsmall: 0xF7EE,
  2310. Icyrillic: 0x0406,
  2311. Idblgrave: 0x0208,
  2312. Idieresis: 0x00CF,
  2313. Idieresisacute: 0x1E2E,
  2314. Idieresiscyrillic: 0x04E4,
  2315. Idieresissmall: 0xF7EF,
  2316. Idot: 0x0130,
  2317. Idotaccent: 0x0130,
  2318. Idotbelow: 0x1ECA,
  2319. Iebrevecyrillic: 0x04D6,
  2320. Iecyrillic: 0x0415,
  2321. Ifraktur: 0x2111,
  2322. Igrave: 0x00CC,
  2323. Igravesmall: 0xF7EC,
  2324. Ihookabove: 0x1EC8,
  2325. Iicyrillic: 0x0418,
  2326. Iinvertedbreve: 0x020A,
  2327. Iishortcyrillic: 0x0419,
  2328. Imacron: 0x012A,
  2329. Imacroncyrillic: 0x04E2,
  2330. Imonospace: 0xFF29,
  2331. Iniarmenian: 0x053B,
  2332. Iocyrillic: 0x0401,
  2333. Iogonek: 0x012E,
  2334. Iota: 0x0399,
  2335. Iotaafrican: 0x0196,
  2336. Iotadieresis: 0x03AA,
  2337. Iotatonos: 0x038A,
  2338. Ismall: 0xF769,
  2339. Istroke: 0x0197,
  2340. Itilde: 0x0128,
  2341. Itildebelow: 0x1E2C,
  2342. Izhitsacyrillic: 0x0474,
  2343. Izhitsadblgravecyrillic: 0x0476,
  2344. J: 0x004A,
  2345. Jaarmenian: 0x0541,
  2346. Jcircle: 0x24BF,
  2347. Jcircumflex: 0x0134,
  2348. Jecyrillic: 0x0408,
  2349. Jheharmenian: 0x054B,
  2350. Jmonospace: 0xFF2A,
  2351. Jsmall: 0xF76A,
  2352. K: 0x004B,
  2353. KBsquare: 0x3385,
  2354. KKsquare: 0x33CD,
  2355. Kabashkircyrillic: 0x04A0,
  2356. Kacute: 0x1E30,
  2357. Kacyrillic: 0x041A,
  2358. Kadescendercyrillic: 0x049A,
  2359. Kahookcyrillic: 0x04C3,
  2360. Kappa: 0x039A,
  2361. Kastrokecyrillic: 0x049E,
  2362. Kaverticalstrokecyrillic: 0x049C,
  2363. Kcaron: 0x01E8,
  2364. Kcedilla: 0x0136,
  2365. Kcircle: 0x24C0,
  2366. Kcommaaccent: 0x0136,
  2367. Kdotbelow: 0x1E32,
  2368. Keharmenian: 0x0554,
  2369. Kenarmenian: 0x053F,
  2370. Khacyrillic: 0x0425,
  2371. Kheicoptic: 0x03E6,
  2372. Khook: 0x0198,
  2373. Kjecyrillic: 0x040C,
  2374. Klinebelow: 0x1E34,
  2375. Kmonospace: 0xFF2B,
  2376. Koppacyrillic: 0x0480,
  2377. Koppagreek: 0x03DE,
  2378. Ksicyrillic: 0x046E,
  2379. Ksmall: 0xF76B,
  2380. L: 0x004C,
  2381. LJ: 0x01C7,
  2382. LL: 0xF6BF,
  2383. Lacute: 0x0139,
  2384. Lambda: 0x039B,
  2385. Lcaron: 0x013D,
  2386. Lcedilla: 0x013B,
  2387. Lcircle: 0x24C1,
  2388. Lcircumflexbelow: 0x1E3C,
  2389. Lcommaaccent: 0x013B,
  2390. Ldot: 0x013F,
  2391. Ldotaccent: 0x013F,
  2392. Ldotbelow: 0x1E36,
  2393. Ldotbelowmacron: 0x1E38,
  2394. Liwnarmenian: 0x053C,
  2395. Lj: 0x01C8,
  2396. Ljecyrillic: 0x0409,
  2397. Llinebelow: 0x1E3A,
  2398. Lmonospace: 0xFF2C,
  2399. Lslash: 0x0141,
  2400. Lslashsmall: 0xF6F9,
  2401. Lsmall: 0xF76C,
  2402. M: 0x004D,
  2403. MBsquare: 0x3386,
  2404. Macron: 0xF6D0,
  2405. Macronsmall: 0xF7AF,
  2406. Macute: 0x1E3E,
  2407. Mcircle: 0x24C2,
  2408. Mdotaccent: 0x1E40,
  2409. Mdotbelow: 0x1E42,
  2410. Menarmenian: 0x0544,
  2411. Mmonospace: 0xFF2D,
  2412. Msmall: 0xF76D,
  2413. Mturned: 0x019C,
  2414. Mu: 0x039C,
  2415. N: 0x004E,
  2416. NJ: 0x01CA,
  2417. Nacute: 0x0143,
  2418. Ncaron: 0x0147,
  2419. Ncedilla: 0x0145,
  2420. Ncircle: 0x24C3,
  2421. Ncircumflexbelow: 0x1E4A,
  2422. Ncommaaccent: 0x0145,
  2423. Ndotaccent: 0x1E44,
  2424. Ndotbelow: 0x1E46,
  2425. Nhookleft: 0x019D,
  2426. Nineroman: 0x2168,
  2427. Nj: 0x01CB,
  2428. Njecyrillic: 0x040A,
  2429. Nlinebelow: 0x1E48,
  2430. Nmonospace: 0xFF2E,
  2431. Nowarmenian: 0x0546,
  2432. Nsmall: 0xF76E,
  2433. Ntilde: 0x00D1,
  2434. Ntildesmall: 0xF7F1,
  2435. Nu: 0x039D,
  2436. O: 0x004F,
  2437. OE: 0x0152,
  2438. OEsmall: 0xF6FA,
  2439. Oacute: 0x00D3,
  2440. Oacutesmall: 0xF7F3,
  2441. Obarredcyrillic: 0x04E8,
  2442. Obarreddieresiscyrillic: 0x04EA,
  2443. Obreve: 0x014E,
  2444. Ocaron: 0x01D1,
  2445. Ocenteredtilde: 0x019F,
  2446. Ocircle: 0x24C4,
  2447. Ocircumflex: 0x00D4,
  2448. Ocircumflexacute: 0x1ED0,
  2449. Ocircumflexdotbelow: 0x1ED8,
  2450. Ocircumflexgrave: 0x1ED2,
  2451. Ocircumflexhookabove: 0x1ED4,
  2452. Ocircumflexsmall: 0xF7F4,
  2453. Ocircumflextilde: 0x1ED6,
  2454. Ocyrillic: 0x041E,
  2455. Odblacute: 0x0150,
  2456. Odblgrave: 0x020C,
  2457. Odieresis: 0x00D6,
  2458. Odieresiscyrillic: 0x04E6,
  2459. Odieresissmall: 0xF7F6,
  2460. Odotbelow: 0x1ECC,
  2461. Ogoneksmall: 0xF6FB,
  2462. Ograve: 0x00D2,
  2463. Ogravesmall: 0xF7F2,
  2464. Oharmenian: 0x0555,
  2465. Ohm: 0x2126,
  2466. Ohookabove: 0x1ECE,
  2467. Ohorn: 0x01A0,
  2468. Ohornacute: 0x1EDA,
  2469. Ohorndotbelow: 0x1EE2,
  2470. Ohorngrave: 0x1EDC,
  2471. Ohornhookabove: 0x1EDE,
  2472. Ohorntilde: 0x1EE0,
  2473. Ohungarumlaut: 0x0150,
  2474. Oi: 0x01A2,
  2475. Oinvertedbreve: 0x020E,
  2476. Omacron: 0x014C,
  2477. Omacronacute: 0x1E52,
  2478. Omacrongrave: 0x1E50,
  2479. Omega: 0x2126,
  2480. Omegacyrillic: 0x0460,
  2481. Omegagreek: 0x03A9,
  2482. Omegaroundcyrillic: 0x047A,
  2483. Omegatitlocyrillic: 0x047C,
  2484. Omegatonos: 0x038F,
  2485. Omicron: 0x039F,
  2486. Omicrontonos: 0x038C,
  2487. Omonospace: 0xFF2F,
  2488. Oneroman: 0x2160,
  2489. Oogonek: 0x01EA,
  2490. Oogonekmacron: 0x01EC,
  2491. Oopen: 0x0186,
  2492. Oslash: 0x00D8,
  2493. Oslashacute: 0x01FE,
  2494. Oslashsmall: 0xF7F8,
  2495. Osmall: 0xF76F,
  2496. Ostrokeacute: 0x01FE,
  2497. Otcyrillic: 0x047E,
  2498. Otilde: 0x00D5,
  2499. Otildeacute: 0x1E4C,
  2500. Otildedieresis: 0x1E4E,
  2501. Otildesmall: 0xF7F5,
  2502. P: 0x0050,
  2503. Pacute: 0x1E54,
  2504. Pcircle: 0x24C5,
  2505. Pdotaccent: 0x1E56,
  2506. Pecyrillic: 0x041F,
  2507. Peharmenian: 0x054A,
  2508. Pemiddlehookcyrillic: 0x04A6,
  2509. Phi: 0x03A6,
  2510. Phook: 0x01A4,
  2511. Pi: 0x03A0,
  2512. Piwrarmenian: 0x0553,
  2513. Pmonospace: 0xFF30,
  2514. Psi: 0x03A8,
  2515. Psicyrillic: 0x0470,
  2516. Psmall: 0xF770,
  2517. Q: 0x0051,
  2518. Qcircle: 0x24C6,
  2519. Qmonospace: 0xFF31,
  2520. Qsmall: 0xF771,
  2521. R: 0x0052,
  2522. Raarmenian: 0x054C,
  2523. Racute: 0x0154,
  2524. Rcaron: 0x0158,
  2525. Rcedilla: 0x0156,
  2526. Rcircle: 0x24C7,
  2527. Rcommaaccent: 0x0156,
  2528. Rdblgrave: 0x0210,
  2529. Rdotaccent: 0x1E58,
  2530. Rdotbelow: 0x1E5A,
  2531. Rdotbelowmacron: 0x1E5C,
  2532. Reharmenian: 0x0550,
  2533. Rfraktur: 0x211C,
  2534. Rho: 0x03A1,
  2535. Ringsmall: 0xF6FC,
  2536. Rinvertedbreve: 0x0212,
  2537. Rlinebelow: 0x1E5E,
  2538. Rmonospace: 0xFF32,
  2539. Rsmall: 0xF772,
  2540. Rsmallinverted: 0x0281,
  2541. Rsmallinvertedsuperior: 0x02B6,
  2542. S: 0x0053,
  2543. SF010000: 0x250C,
  2544. SF020000: 0x2514,
  2545. SF030000: 0x2510,
  2546. SF040000: 0x2518,
  2547. SF050000: 0x253C,
  2548. SF060000: 0x252C,
  2549. SF070000: 0x2534,
  2550. SF080000: 0x251C,
  2551. SF090000: 0x2524,
  2552. SF100000: 0x2500,
  2553. SF110000: 0x2502,
  2554. SF190000: 0x2561,
  2555. SF200000: 0x2562,
  2556. SF210000: 0x2556,
  2557. SF220000: 0x2555,
  2558. SF230000: 0x2563,
  2559. SF240000: 0x2551,
  2560. SF250000: 0x2557,
  2561. SF260000: 0x255D,
  2562. SF270000: 0x255C,
  2563. SF280000: 0x255B,
  2564. SF360000: 0x255E,
  2565. SF370000: 0x255F,
  2566. SF380000: 0x255A,
  2567. SF390000: 0x2554,
  2568. SF400000: 0x2569,
  2569. SF410000: 0x2566,
  2570. SF420000: 0x2560,
  2571. SF430000: 0x2550,
  2572. SF440000: 0x256C,
  2573. SF450000: 0x2567,
  2574. SF460000: 0x2568,
  2575. SF470000: 0x2564,
  2576. SF480000: 0x2565,
  2577. SF490000: 0x2559,
  2578. SF500000: 0x2558,
  2579. SF510000: 0x2552,
  2580. SF520000: 0x2553,
  2581. SF530000: 0x256B,
  2582. SF540000: 0x256A,
  2583. Sacute: 0x015A,
  2584. Sacutedotaccent: 0x1E64,
  2585. Sampigreek: 0x03E0,
  2586. Scaron: 0x0160,
  2587. Scarondotaccent: 0x1E66,
  2588. Scaronsmall: 0xF6FD,
  2589. Scedilla: 0x015E,
  2590. Schwa: 0x018F,
  2591. Schwacyrillic: 0x04D8,
  2592. Schwadieresiscyrillic: 0x04DA,
  2593. Scircle: 0x24C8,
  2594. Scircumflex: 0x015C,
  2595. Scommaaccent: 0x0218,
  2596. Sdotaccent: 0x1E60,
  2597. Sdotbelow: 0x1E62,
  2598. Sdotbelowdotaccent: 0x1E68,
  2599. Seharmenian: 0x054D,
  2600. Sevenroman: 0x2166,
  2601. Shaarmenian: 0x0547,
  2602. Shacyrillic: 0x0428,
  2603. Shchacyrillic: 0x0429,
  2604. Sheicoptic: 0x03E2,
  2605. Shhacyrillic: 0x04BA,
  2606. Shimacoptic: 0x03EC,
  2607. Sigma: 0x03A3,
  2608. Sixroman: 0x2165,
  2609. Smonospace: 0xFF33,
  2610. Softsigncyrillic: 0x042C,
  2611. Ssmall: 0xF773,
  2612. Stigmagreek: 0x03DA,
  2613. T: 0x0054,
  2614. Tau: 0x03A4,
  2615. Tbar: 0x0166,
  2616. Tcaron: 0x0164,
  2617. Tcedilla: 0x0162,
  2618. Tcircle: 0x24C9,
  2619. Tcircumflexbelow: 0x1E70,
  2620. Tcommaaccent: 0x0162,
  2621. Tdotaccent: 0x1E6A,
  2622. Tdotbelow: 0x1E6C,
  2623. Tecyrillic: 0x0422,
  2624. Tedescendercyrillic: 0x04AC,
  2625. Tenroman: 0x2169,
  2626. Tetsecyrillic: 0x04B4,
  2627. Theta: 0x0398,
  2628. Thook: 0x01AC,
  2629. Thorn: 0x00DE,
  2630. Thornsmall: 0xF7FE,
  2631. Threeroman: 0x2162,
  2632. Tildesmall: 0xF6FE,
  2633. Tiwnarmenian: 0x054F,
  2634. Tlinebelow: 0x1E6E,
  2635. Tmonospace: 0xFF34,
  2636. Toarmenian: 0x0539,
  2637. Tonefive: 0x01BC,
  2638. Tonesix: 0x0184,
  2639. Tonetwo: 0x01A7,
  2640. Tretroflexhook: 0x01AE,
  2641. Tsecyrillic: 0x0426,
  2642. Tshecyrillic: 0x040B,
  2643. Tsmall: 0xF774,
  2644. Twelveroman: 0x216B,
  2645. Tworoman: 0x2161,
  2646. U: 0x0055,
  2647. Uacute: 0x00DA,
  2648. Uacutesmall: 0xF7FA,
  2649. Ubreve: 0x016C,
  2650. Ucaron: 0x01D3,
  2651. Ucircle: 0x24CA,
  2652. Ucircumflex: 0x00DB,
  2653. Ucircumflexbelow: 0x1E76,
  2654. Ucircumflexsmall: 0xF7FB,
  2655. Ucyrillic: 0x0423,
  2656. Udblacute: 0x0170,
  2657. Udblgrave: 0x0214,
  2658. Udieresis: 0x00DC,
  2659. Udieresisacute: 0x01D7,
  2660. Udieresisbelow: 0x1E72,
  2661. Udieresiscaron: 0x01D9,
  2662. Udieresiscyrillic: 0x04F0,
  2663. Udieresisgrave: 0x01DB,
  2664. Udieresismacron: 0x01D5,
  2665. Udieresissmall: 0xF7FC,
  2666. Udotbelow: 0x1EE4,
  2667. Ugrave: 0x00D9,
  2668. Ugravesmall: 0xF7F9,
  2669. Uhookabove: 0x1EE6,
  2670. Uhorn: 0x01AF,
  2671. Uhornacute: 0x1EE8,
  2672. Uhorndotbelow: 0x1EF0,
  2673. Uhorngrave: 0x1EEA,
  2674. Uhornhookabove: 0x1EEC,
  2675. Uhorntilde: 0x1EEE,
  2676. Uhungarumlaut: 0x0170,
  2677. Uhungarumlautcyrillic: 0x04F2,
  2678. Uinvertedbreve: 0x0216,
  2679. Ukcyrillic: 0x0478,
  2680. Umacron: 0x016A,
  2681. Umacroncyrillic: 0x04EE,
  2682. Umacrondieresis: 0x1E7A,
  2683. Umonospace: 0xFF35,
  2684. Uogonek: 0x0172,
  2685. Upsilon: 0x03A5,
  2686. Upsilon1: 0x03D2,
  2687. Upsilonacutehooksymbolgreek: 0x03D3,
  2688. Upsilonafrican: 0x01B1,
  2689. Upsilondieresis: 0x03AB,
  2690. Upsilondieresishooksymbolgreek: 0x03D4,
  2691. Upsilonhooksymbol: 0x03D2,
  2692. Upsilontonos: 0x038E,
  2693. Uring: 0x016E,
  2694. Ushortcyrillic: 0x040E,
  2695. Usmall: 0xF775,
  2696. Ustraightcyrillic: 0x04AE,
  2697. Ustraightstrokecyrillic: 0x04B0,
  2698. Utilde: 0x0168,
  2699. Utildeacute: 0x1E78,
  2700. Utildebelow: 0x1E74,
  2701. V: 0x0056,
  2702. Vcircle: 0x24CB,
  2703. Vdotbelow: 0x1E7E,
  2704. Vecyrillic: 0x0412,
  2705. Vewarmenian: 0x054E,
  2706. Vhook: 0x01B2,
  2707. Vmonospace: 0xFF36,
  2708. Voarmenian: 0x0548,
  2709. Vsmall: 0xF776,
  2710. Vtilde: 0x1E7C,
  2711. W: 0x0057,
  2712. Wacute: 0x1E82,
  2713. Wcircle: 0x24CC,
  2714. Wcircumflex: 0x0174,
  2715. Wdieresis: 0x1E84,
  2716. Wdotaccent: 0x1E86,
  2717. Wdotbelow: 0x1E88,
  2718. Wgrave: 0x1E80,
  2719. Wmonospace: 0xFF37,
  2720. Wsmall: 0xF777,
  2721. X: 0x0058,
  2722. Xcircle: 0x24CD,
  2723. Xdieresis: 0x1E8C,
  2724. Xdotaccent: 0x1E8A,
  2725. Xeharmenian: 0x053D,
  2726. Xi: 0x039E,
  2727. Xmonospace: 0xFF38,
  2728. Xsmall: 0xF778,
  2729. Y: 0x0059,
  2730. Yacute: 0x00DD,
  2731. Yacutesmall: 0xF7FD,
  2732. Yatcyrillic: 0x0462,
  2733. Ycircle: 0x24CE,
  2734. Ycircumflex: 0x0176,
  2735. Ydieresis: 0x0178,
  2736. Ydieresissmall: 0xF7FF,
  2737. Ydotaccent: 0x1E8E,
  2738. Ydotbelow: 0x1EF4,
  2739. Yericyrillic: 0x042B,
  2740. Yerudieresiscyrillic: 0x04F8,
  2741. Ygrave: 0x1EF2,
  2742. Yhook: 0x01B3,
  2743. Yhookabove: 0x1EF6,
  2744. Yiarmenian: 0x0545,
  2745. Yicyrillic: 0x0407,
  2746. Yiwnarmenian: 0x0552,
  2747. Ymonospace: 0xFF39,
  2748. Ysmall: 0xF779,
  2749. Ytilde: 0x1EF8,
  2750. Yusbigcyrillic: 0x046A,
  2751. Yusbigiotifiedcyrillic: 0x046C,
  2752. Yuslittlecyrillic: 0x0466,
  2753. Yuslittleiotifiedcyrillic: 0x0468,
  2754. Z: 0x005A,
  2755. Zaarmenian: 0x0536,
  2756. Zacute: 0x0179,
  2757. Zcaron: 0x017D,
  2758. Zcaronsmall: 0xF6FF,
  2759. Zcircle: 0x24CF,
  2760. Zcircumflex: 0x1E90,
  2761. Zdot: 0x017B,
  2762. Zdotaccent: 0x017B,
  2763. Zdotbelow: 0x1E92,
  2764. Zecyrillic: 0x0417,
  2765. Zedescendercyrillic: 0x0498,
  2766. Zedieresiscyrillic: 0x04DE,
  2767. Zeta: 0x0396,
  2768. Zhearmenian: 0x053A,
  2769. Zhebrevecyrillic: 0x04C1,
  2770. Zhecyrillic: 0x0416,
  2771. Zhedescendercyrillic: 0x0496,
  2772. Zhedieresiscyrillic: 0x04DC,
  2773. Zlinebelow: 0x1E94,
  2774. Zmonospace: 0xFF3A,
  2775. Zsmall: 0xF77A,
  2776. Zstroke: 0x01B5,
  2777. a: 0x0061,
  2778. aabengali: 0x0986,
  2779. aacute: 0x00E1,
  2780. aadeva: 0x0906,
  2781. aagujarati: 0x0A86,
  2782. aagurmukhi: 0x0A06,
  2783. aamatragurmukhi: 0x0A3E,
  2784. aarusquare: 0x3303,
  2785. aavowelsignbengali: 0x09BE,
  2786. aavowelsigndeva: 0x093E,
  2787. aavowelsigngujarati: 0x0ABE,
  2788. abbreviationmarkarmenian: 0x055F,
  2789. abbreviationsigndeva: 0x0970,
  2790. abengali: 0x0985,
  2791. abopomofo: 0x311A,
  2792. abreve: 0x0103,
  2793. abreveacute: 0x1EAF,
  2794. abrevecyrillic: 0x04D1,
  2795. abrevedotbelow: 0x1EB7,
  2796. abrevegrave: 0x1EB1,
  2797. abrevehookabove: 0x1EB3,
  2798. abrevetilde: 0x1EB5,
  2799. acaron: 0x01CE,
  2800. acircle: 0x24D0,
  2801. acircumflex: 0x00E2,
  2802. acircumflexacute: 0x1EA5,
  2803. acircumflexdotbelow: 0x1EAD,
  2804. acircumflexgrave: 0x1EA7,
  2805. acircumflexhookabove: 0x1EA9,
  2806. acircumflextilde: 0x1EAB,
  2807. acute: 0x00B4,
  2808. acutebelowcmb: 0x0317,
  2809. acutecmb: 0x0301,
  2810. acutecomb: 0x0301,
  2811. acutedeva: 0x0954,
  2812. acutelowmod: 0x02CF,
  2813. acutetonecmb: 0x0341,
  2814. acyrillic: 0x0430,
  2815. adblgrave: 0x0201,
  2816. addakgurmukhi: 0x0A71,
  2817. adeva: 0x0905,
  2818. adieresis: 0x00E4,
  2819. adieresiscyrillic: 0x04D3,
  2820. adieresismacron: 0x01DF,
  2821. adotbelow: 0x1EA1,
  2822. adotmacron: 0x01E1,
  2823. ae: 0x00E6,
  2824. aeacute: 0x01FD,
  2825. aekorean: 0x3150,
  2826. aemacron: 0x01E3,
  2827. afii00208: 0x2015,
  2828. afii08941: 0x20A4,
  2829. afii10017: 0x0410,
  2830. afii10018: 0x0411,
  2831. afii10019: 0x0412,
  2832. afii10020: 0x0413,
  2833. afii10021: 0x0414,
  2834. afii10022: 0x0415,
  2835. afii10023: 0x0401,
  2836. afii10024: 0x0416,
  2837. afii10025: 0x0417,
  2838. afii10026: 0x0418,
  2839. afii10027: 0x0419,
  2840. afii10028: 0x041A,
  2841. afii10029: 0x041B,
  2842. afii10030: 0x041C,
  2843. afii10031: 0x041D,
  2844. afii10032: 0x041E,
  2845. afii10033: 0x041F,
  2846. afii10034: 0x0420,
  2847. afii10035: 0x0421,
  2848. afii10036: 0x0422,
  2849. afii10037: 0x0423,
  2850. afii10038: 0x0424,
  2851. afii10039: 0x0425,
  2852. afii10040: 0x0426,
  2853. afii10041: 0x0427,
  2854. afii10042: 0x0428,
  2855. afii10043: 0x0429,
  2856. afii10044: 0x042A,
  2857. afii10045: 0x042B,
  2858. afii10046: 0x042C,
  2859. afii10047: 0x042D,
  2860. afii10048: 0x042E,
  2861. afii10049: 0x042F,
  2862. afii10050: 0x0490,
  2863. afii10051: 0x0402,
  2864. afii10052: 0x0403,
  2865. afii10053: 0x0404,
  2866. afii10054: 0x0405,
  2867. afii10055: 0x0406,
  2868. afii10056: 0x0407,
  2869. afii10057: 0x0408,
  2870. afii10058: 0x0409,
  2871. afii10059: 0x040A,
  2872. afii10060: 0x040B,
  2873. afii10061: 0x040C,
  2874. afii10062: 0x040E,
  2875. afii10063: 0xF6C4,
  2876. afii10064: 0xF6C5,
  2877. afii10065: 0x0430,
  2878. afii10066: 0x0431,
  2879. afii10067: 0x0432,
  2880. afii10068: 0x0433,
  2881. afii10069: 0x0434,
  2882. afii10070: 0x0435,
  2883. afii10071: 0x0451,
  2884. afii10072: 0x0436,
  2885. afii10073: 0x0437,
  2886. afii10074: 0x0438,
  2887. afii10075: 0x0439,
  2888. afii10076: 0x043A,
  2889. afii10077: 0x043B,
  2890. afii10078: 0x043C,
  2891. afii10079: 0x043D,
  2892. afii10080: 0x043E,
  2893. afii10081: 0x043F,
  2894. afii10082: 0x0440,
  2895. afii10083: 0x0441,
  2896. afii10084: 0x0442,
  2897. afii10085: 0x0443,
  2898. afii10086: 0x0444,
  2899. afii10087: 0x0445,
  2900. afii10088: 0x0446,
  2901. afii10089: 0x0447,
  2902. afii10090: 0x0448,
  2903. afii10091: 0x0449,
  2904. afii10092: 0x044A,
  2905. afii10093: 0x044B,
  2906. afii10094: 0x044C,
  2907. afii10095: 0x044D,
  2908. afii10096: 0x044E,
  2909. afii10097: 0x044F,
  2910. afii10098: 0x0491,
  2911. afii10099: 0x0452,
  2912. afii10100: 0x0453,
  2913. afii10101: 0x0454,
  2914. afii10102: 0x0455,
  2915. afii10103: 0x0456,
  2916. afii10104: 0x0457,
  2917. afii10105: 0x0458,
  2918. afii10106: 0x0459,
  2919. afii10107: 0x045A,
  2920. afii10108: 0x045B,
  2921. afii10109: 0x045C,
  2922. afii10110: 0x045E,
  2923. afii10145: 0x040F,
  2924. afii10146: 0x0462,
  2925. afii10147: 0x0472,
  2926. afii10148: 0x0474,
  2927. afii10192: 0xF6C6,
  2928. afii10193: 0x045F,
  2929. afii10194: 0x0463,
  2930. afii10195: 0x0473,
  2931. afii10196: 0x0475,
  2932. afii10831: 0xF6C7,
  2933. afii10832: 0xF6C8,
  2934. afii10846: 0x04D9,
  2935. afii299: 0x200E,
  2936. afii300: 0x200F,
  2937. afii301: 0x200D,
  2938. afii57381: 0x066A,
  2939. afii57388: 0x060C,
  2940. afii57392: 0x0660,
  2941. afii57393: 0x0661,
  2942. afii57394: 0x0662,
  2943. afii57395: 0x0663,
  2944. afii57396: 0x0664,
  2945. afii57397: 0x0665,
  2946. afii57398: 0x0666,
  2947. afii57399: 0x0667,
  2948. afii57400: 0x0668,
  2949. afii57401: 0x0669,
  2950. afii57403: 0x061B,
  2951. afii57407: 0x061F,
  2952. afii57409: 0x0621,
  2953. afii57410: 0x0622,
  2954. afii57411: 0x0623,
  2955. afii57412: 0x0624,
  2956. afii57413: 0x0625,
  2957. afii57414: 0x0626,
  2958. afii57415: 0x0627,
  2959. afii57416: 0x0628,
  2960. afii57417: 0x0629,
  2961. afii57418: 0x062A,
  2962. afii57419: 0x062B,
  2963. afii57420: 0x062C,
  2964. afii57421: 0x062D,
  2965. afii57422: 0x062E,
  2966. afii57423: 0x062F,
  2967. afii57424: 0x0630,
  2968. afii57425: 0x0631,
  2969. afii57426: 0x0632,
  2970. afii57427: 0x0633,
  2971. afii57428: 0x0634,
  2972. afii57429: 0x0635,
  2973. afii57430: 0x0636,
  2974. afii57431: 0x0637,
  2975. afii57432: 0x0638,
  2976. afii57433: 0x0639,
  2977. afii57434: 0x063A,
  2978. afii57440: 0x0640,
  2979. afii57441: 0x0641,
  2980. afii57442: 0x0642,
  2981. afii57443: 0x0643,
  2982. afii57444: 0x0644,
  2983. afii57445: 0x0645,
  2984. afii57446: 0x0646,
  2985. afii57448: 0x0648,
  2986. afii57449: 0x0649,
  2987. afii57450: 0x064A,
  2988. afii57451: 0x064B,
  2989. afii57452: 0x064C,
  2990. afii57453: 0x064D,
  2991. afii57454: 0x064E,
  2992. afii57455: 0x064F,
  2993. afii57456: 0x0650,
  2994. afii57457: 0x0651,
  2995. afii57458: 0x0652,
  2996. afii57470: 0x0647,
  2997. afii57505: 0x06A4,
  2998. afii57506: 0x067E,
  2999. afii57507: 0x0686,
  3000. afii57508: 0x0698,
  3001. afii57509: 0x06AF,
  3002. afii57511: 0x0679,
  3003. afii57512: 0x0688,
  3004. afii57513: 0x0691,
  3005. afii57514: 0x06BA,
  3006. afii57519: 0x06D2,
  3007. afii57534: 0x06D5,
  3008. afii57636: 0x20AA,
  3009. afii57645: 0x05BE,
  3010. afii57658: 0x05C3,
  3011. afii57664: 0x05D0,
  3012. afii57665: 0x05D1,
  3013. afii57666: 0x05D2,
  3014. afii57667: 0x05D3,
  3015. afii57668: 0x05D4,
  3016. afii57669: 0x05D5,
  3017. afii57670: 0x05D6,
  3018. afii57671: 0x05D7,
  3019. afii57672: 0x05D8,
  3020. afii57673: 0x05D9,
  3021. afii57674: 0x05DA,
  3022. afii57675: 0x05DB,
  3023. afii57676: 0x05DC,
  3024. afii57677: 0x05DD,
  3025. afii57678: 0x05DE,
  3026. afii57679: 0x05DF,
  3027. afii57680: 0x05E0,
  3028. afii57681: 0x05E1,
  3029. afii57682: 0x05E2,
  3030. afii57683: 0x05E3,
  3031. afii57684: 0x05E4,
  3032. afii57685: 0x05E5,
  3033. afii57686: 0x05E6,
  3034. afii57687: 0x05E7,
  3035. afii57688: 0x05E8,
  3036. afii57689: 0x05E9,
  3037. afii57690: 0x05EA,
  3038. afii57694: 0xFB2A,
  3039. afii57695: 0xFB2B,
  3040. afii57700: 0xFB4B,
  3041. afii57705: 0xFB1F,
  3042. afii57716: 0x05F0,
  3043. afii57717: 0x05F1,
  3044. afii57718: 0x05F2,
  3045. afii57723: 0xFB35,
  3046. afii57793: 0x05B4,
  3047. afii57794: 0x05B5,
  3048. afii57795: 0x05B6,
  3049. afii57796: 0x05BB,
  3050. afii57797: 0x05B8,
  3051. afii57798: 0x05B7,
  3052. afii57799: 0x05B0,
  3053. afii57800: 0x05B2,
  3054. afii57801: 0x05B1,
  3055. afii57802: 0x05B3,
  3056. afii57803: 0x05C2,
  3057. afii57804: 0x05C1,
  3058. afii57806: 0x05B9,
  3059. afii57807: 0x05BC,
  3060. afii57839: 0x05BD,
  3061. afii57841: 0x05BF,
  3062. afii57842: 0x05C0,
  3063. afii57929: 0x02BC,
  3064. afii61248: 0x2105,
  3065. afii61289: 0x2113,
  3066. afii61352: 0x2116,
  3067. afii61573: 0x202C,
  3068. afii61574: 0x202D,
  3069. afii61575: 0x202E,
  3070. afii61664: 0x200C,
  3071. afii63167: 0x066D,
  3072. afii64937: 0x02BD,
  3073. agrave: 0x00E0,
  3074. agujarati: 0x0A85,
  3075. agurmukhi: 0x0A05,
  3076. ahiragana: 0x3042,
  3077. ahookabove: 0x1EA3,
  3078. aibengali: 0x0990,
  3079. aibopomofo: 0x311E,
  3080. aideva: 0x0910,
  3081. aiecyrillic: 0x04D5,
  3082. aigujarati: 0x0A90,
  3083. aigurmukhi: 0x0A10,
  3084. aimatragurmukhi: 0x0A48,
  3085. ainarabic: 0x0639,
  3086. ainfinalarabic: 0xFECA,
  3087. aininitialarabic: 0xFECB,
  3088. ainmedialarabic: 0xFECC,
  3089. ainvertedbreve: 0x0203,
  3090. aivowelsignbengali: 0x09C8,
  3091. aivowelsigndeva: 0x0948,
  3092. aivowelsigngujarati: 0x0AC8,
  3093. akatakana: 0x30A2,
  3094. akatakanahalfwidth: 0xFF71,
  3095. akorean: 0x314F,
  3096. alef: 0x05D0,
  3097. alefarabic: 0x0627,
  3098. alefdageshhebrew: 0xFB30,
  3099. aleffinalarabic: 0xFE8E,
  3100. alefhamzaabovearabic: 0x0623,
  3101. alefhamzaabovefinalarabic: 0xFE84,
  3102. alefhamzabelowarabic: 0x0625,
  3103. alefhamzabelowfinalarabic: 0xFE88,
  3104. alefhebrew: 0x05D0,
  3105. aleflamedhebrew: 0xFB4F,
  3106. alefmaddaabovearabic: 0x0622,
  3107. alefmaddaabovefinalarabic: 0xFE82,
  3108. alefmaksuraarabic: 0x0649,
  3109. alefmaksurafinalarabic: 0xFEF0,
  3110. alefmaksurainitialarabic: 0xFEF3,
  3111. alefmaksuramedialarabic: 0xFEF4,
  3112. alefpatahhebrew: 0xFB2E,
  3113. alefqamatshebrew: 0xFB2F,
  3114. aleph: 0x2135,
  3115. allequal: 0x224C,
  3116. alpha: 0x03B1,
  3117. alphatonos: 0x03AC,
  3118. amacron: 0x0101,
  3119. amonospace: 0xFF41,
  3120. ampersand: 0x0026,
  3121. ampersandmonospace: 0xFF06,
  3122. ampersandsmall: 0xF726,
  3123. amsquare: 0x33C2,
  3124. anbopomofo: 0x3122,
  3125. angbopomofo: 0x3124,
  3126. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  3127. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  3128. angkhankhuthai: 0x0E5A,
  3129. angle: 0x2220,
  3130. anglebracketleft: 0x3008,
  3131. anglebracketleftvertical: 0xFE3F,
  3132. anglebracketright: 0x3009,
  3133. anglebracketrightvertical: 0xFE40,
  3134. angleleft: 0x2329,
  3135. angleright: 0x232A,
  3136. angstrom: 0x212B,
  3137. anoteleia: 0x0387,
  3138. anudattadeva: 0x0952,
  3139. anusvarabengali: 0x0982,
  3140. anusvaradeva: 0x0902,
  3141. anusvaragujarati: 0x0A82,
  3142. aogonek: 0x0105,
  3143. apaatosquare: 0x3300,
  3144. aparen: 0x249C,
  3145. apostrophearmenian: 0x055A,
  3146. apostrophemod: 0x02BC,
  3147. apple: 0xF8FF,
  3148. approaches: 0x2250,
  3149. approxequal: 0x2248,
  3150. approxequalorimage: 0x2252,
  3151. approximatelyequal: 0x2245,
  3152. araeaekorean: 0x318E,
  3153. araeakorean: 0x318D,
  3154. arc: 0x2312,
  3155. arighthalfring: 0x1E9A,
  3156. aring: 0x00E5,
  3157. aringacute: 0x01FB,
  3158. aringbelow: 0x1E01,
  3159. arrowboth: 0x2194,
  3160. arrowdashdown: 0x21E3,
  3161. arrowdashleft: 0x21E0,
  3162. arrowdashright: 0x21E2,
  3163. arrowdashup: 0x21E1,
  3164. arrowdblboth: 0x21D4,
  3165. arrowdbldown: 0x21D3,
  3166. arrowdblleft: 0x21D0,
  3167. arrowdblright: 0x21D2,
  3168. arrowdblup: 0x21D1,
  3169. arrowdown: 0x2193,
  3170. arrowdownleft: 0x2199,
  3171. arrowdownright: 0x2198,
  3172. arrowdownwhite: 0x21E9,
  3173. arrowheaddownmod: 0x02C5,
  3174. arrowheadleftmod: 0x02C2,
  3175. arrowheadrightmod: 0x02C3,
  3176. arrowheadupmod: 0x02C4,
  3177. arrowhorizex: 0xF8E7,
  3178. arrowleft: 0x2190,
  3179. arrowleftdbl: 0x21D0,
  3180. arrowleftdblstroke: 0x21CD,
  3181. arrowleftoverright: 0x21C6,
  3182. arrowleftwhite: 0x21E6,
  3183. arrowright: 0x2192,
  3184. arrowrightdblstroke: 0x21CF,
  3185. arrowrightheavy: 0x279E,
  3186. arrowrightoverleft: 0x21C4,
  3187. arrowrightwhite: 0x21E8,
  3188. arrowtableft: 0x21E4,
  3189. arrowtabright: 0x21E5,
  3190. arrowup: 0x2191,
  3191. arrowupdn: 0x2195,
  3192. arrowupdnbse: 0x21A8,
  3193. arrowupdownbase: 0x21A8,
  3194. arrowupleft: 0x2196,
  3195. arrowupleftofdown: 0x21C5,
  3196. arrowupright: 0x2197,
  3197. arrowupwhite: 0x21E7,
  3198. arrowvertex: 0xF8E6,
  3199. asciicircum: 0x005E,
  3200. asciicircummonospace: 0xFF3E,
  3201. asciitilde: 0x007E,
  3202. asciitildemonospace: 0xFF5E,
  3203. ascript: 0x0251,
  3204. ascriptturned: 0x0252,
  3205. asmallhiragana: 0x3041,
  3206. asmallkatakana: 0x30A1,
  3207. asmallkatakanahalfwidth: 0xFF67,
  3208. asterisk: 0x002A,
  3209. asteriskaltonearabic: 0x066D,
  3210. asteriskarabic: 0x066D,
  3211. asteriskmath: 0x2217,
  3212. asteriskmonospace: 0xFF0A,
  3213. asterisksmall: 0xFE61,
  3214. asterism: 0x2042,
  3215. asuperior: 0xF6E9,
  3216. asymptoticallyequal: 0x2243,
  3217. at: 0x0040,
  3218. atilde: 0x00E3,
  3219. atmonospace: 0xFF20,
  3220. atsmall: 0xFE6B,
  3221. aturned: 0x0250,
  3222. aubengali: 0x0994,
  3223. aubopomofo: 0x3120,
  3224. audeva: 0x0914,
  3225. augujarati: 0x0A94,
  3226. augurmukhi: 0x0A14,
  3227. aulengthmarkbengali: 0x09D7,
  3228. aumatragurmukhi: 0x0A4C,
  3229. auvowelsignbengali: 0x09CC,
  3230. auvowelsigndeva: 0x094C,
  3231. auvowelsigngujarati: 0x0ACC,
  3232. avagrahadeva: 0x093D,
  3233. aybarmenian: 0x0561,
  3234. ayin: 0x05E2,
  3235. ayinaltonehebrew: 0xFB20,
  3236. ayinhebrew: 0x05E2,
  3237. b: 0x0062,
  3238. babengali: 0x09AC,
  3239. backslash: 0x005C,
  3240. backslashmonospace: 0xFF3C,
  3241. badeva: 0x092C,
  3242. bagujarati: 0x0AAC,
  3243. bagurmukhi: 0x0A2C,
  3244. bahiragana: 0x3070,
  3245. bahtthai: 0x0E3F,
  3246. bakatakana: 0x30D0,
  3247. bar: 0x007C,
  3248. barmonospace: 0xFF5C,
  3249. bbopomofo: 0x3105,
  3250. bcircle: 0x24D1,
  3251. bdotaccent: 0x1E03,
  3252. bdotbelow: 0x1E05,
  3253. beamedsixteenthnotes: 0x266C,
  3254. because: 0x2235,
  3255. becyrillic: 0x0431,
  3256. beharabic: 0x0628,
  3257. behfinalarabic: 0xFE90,
  3258. behinitialarabic: 0xFE91,
  3259. behiragana: 0x3079,
  3260. behmedialarabic: 0xFE92,
  3261. behmeeminitialarabic: 0xFC9F,
  3262. behmeemisolatedarabic: 0xFC08,
  3263. behnoonfinalarabic: 0xFC6D,
  3264. bekatakana: 0x30D9,
  3265. benarmenian: 0x0562,
  3266. bet: 0x05D1,
  3267. beta: 0x03B2,
  3268. betasymbolgreek: 0x03D0,
  3269. betdagesh: 0xFB31,
  3270. betdageshhebrew: 0xFB31,
  3271. bethebrew: 0x05D1,
  3272. betrafehebrew: 0xFB4C,
  3273. bhabengali: 0x09AD,
  3274. bhadeva: 0x092D,
  3275. bhagujarati: 0x0AAD,
  3276. bhagurmukhi: 0x0A2D,
  3277. bhook: 0x0253,
  3278. bihiragana: 0x3073,
  3279. bikatakana: 0x30D3,
  3280. bilabialclick: 0x0298,
  3281. bindigurmukhi: 0x0A02,
  3282. birusquare: 0x3331,
  3283. blackcircle: 0x25CF,
  3284. blackdiamond: 0x25C6,
  3285. blackdownpointingtriangle: 0x25BC,
  3286. blackleftpointingpointer: 0x25C4,
  3287. blackleftpointingtriangle: 0x25C0,
  3288. blacklenticularbracketleft: 0x3010,
  3289. blacklenticularbracketleftvertical: 0xFE3B,
  3290. blacklenticularbracketright: 0x3011,
  3291. blacklenticularbracketrightvertical: 0xFE3C,
  3292. blacklowerlefttriangle: 0x25E3,
  3293. blacklowerrighttriangle: 0x25E2,
  3294. blackrectangle: 0x25AC,
  3295. blackrightpointingpointer: 0x25BA,
  3296. blackrightpointingtriangle: 0x25B6,
  3297. blacksmallsquare: 0x25AA,
  3298. blacksmilingface: 0x263B,
  3299. blacksquare: 0x25A0,
  3300. blackstar: 0x2605,
  3301. blackupperlefttriangle: 0x25E4,
  3302. blackupperrighttriangle: 0x25E5,
  3303. blackuppointingsmalltriangle: 0x25B4,
  3304. blackuppointingtriangle: 0x25B2,
  3305. blank: 0x2423,
  3306. blinebelow: 0x1E07,
  3307. block: 0x2588,
  3308. bmonospace: 0xFF42,
  3309. bobaimaithai: 0x0E1A,
  3310. bohiragana: 0x307C,
  3311. bokatakana: 0x30DC,
  3312. bparen: 0x249D,
  3313. bqsquare: 0x33C3,
  3314. braceex: 0xF8F4,
  3315. braceleft: 0x007B,
  3316. braceleftbt: 0xF8F3,
  3317. braceleftmid: 0xF8F2,
  3318. braceleftmonospace: 0xFF5B,
  3319. braceleftsmall: 0xFE5B,
  3320. bracelefttp: 0xF8F1,
  3321. braceleftvertical: 0xFE37,
  3322. braceright: 0x007D,
  3323. bracerightbt: 0xF8FE,
  3324. bracerightmid: 0xF8FD,
  3325. bracerightmonospace: 0xFF5D,
  3326. bracerightsmall: 0xFE5C,
  3327. bracerighttp: 0xF8FC,
  3328. bracerightvertical: 0xFE38,
  3329. bracketleft: 0x005B,
  3330. bracketleftbt: 0xF8F0,
  3331. bracketleftex: 0xF8EF,
  3332. bracketleftmonospace: 0xFF3B,
  3333. bracketlefttp: 0xF8EE,
  3334. bracketright: 0x005D,
  3335. bracketrightbt: 0xF8FB,
  3336. bracketrightex: 0xF8FA,
  3337. bracketrightmonospace: 0xFF3D,
  3338. bracketrighttp: 0xF8F9,
  3339. breve: 0x02D8,
  3340. brevebelowcmb: 0x032E,
  3341. brevecmb: 0x0306,
  3342. breveinvertedbelowcmb: 0x032F,
  3343. breveinvertedcmb: 0x0311,
  3344. breveinverteddoublecmb: 0x0361,
  3345. bridgebelowcmb: 0x032A,
  3346. bridgeinvertedbelowcmb: 0x033A,
  3347. brokenbar: 0x00A6,
  3348. bstroke: 0x0180,
  3349. bsuperior: 0xF6EA,
  3350. btopbar: 0x0183,
  3351. buhiragana: 0x3076,
  3352. bukatakana: 0x30D6,
  3353. bullet: 0x2022,
  3354. bulletinverse: 0x25D8,
  3355. bulletoperator: 0x2219,
  3356. bullseye: 0x25CE,
  3357. c: 0x0063,
  3358. caarmenian: 0x056E,
  3359. cabengali: 0x099A,
  3360. cacute: 0x0107,
  3361. cadeva: 0x091A,
  3362. cagujarati: 0x0A9A,
  3363. cagurmukhi: 0x0A1A,
  3364. calsquare: 0x3388,
  3365. candrabindubengali: 0x0981,
  3366. candrabinducmb: 0x0310,
  3367. candrabindudeva: 0x0901,
  3368. candrabindugujarati: 0x0A81,
  3369. capslock: 0x21EA,
  3370. careof: 0x2105,
  3371. caron: 0x02C7,
  3372. caronbelowcmb: 0x032C,
  3373. caroncmb: 0x030C,
  3374. carriagereturn: 0x21B5,
  3375. cbopomofo: 0x3118,
  3376. ccaron: 0x010D,
  3377. ccedilla: 0x00E7,
  3378. ccedillaacute: 0x1E09,
  3379. ccircle: 0x24D2,
  3380. ccircumflex: 0x0109,
  3381. ccurl: 0x0255,
  3382. cdot: 0x010B,
  3383. cdotaccent: 0x010B,
  3384. cdsquare: 0x33C5,
  3385. cedilla: 0x00B8,
  3386. cedillacmb: 0x0327,
  3387. cent: 0x00A2,
  3388. centigrade: 0x2103,
  3389. centinferior: 0xF6DF,
  3390. centmonospace: 0xFFE0,
  3391. centoldstyle: 0xF7A2,
  3392. centsuperior: 0xF6E0,
  3393. chaarmenian: 0x0579,
  3394. chabengali: 0x099B,
  3395. chadeva: 0x091B,
  3396. chagujarati: 0x0A9B,
  3397. chagurmukhi: 0x0A1B,
  3398. chbopomofo: 0x3114,
  3399. cheabkhasiancyrillic: 0x04BD,
  3400. checkmark: 0x2713,
  3401. checyrillic: 0x0447,
  3402. chedescenderabkhasiancyrillic: 0x04BF,
  3403. chedescendercyrillic: 0x04B7,
  3404. chedieresiscyrillic: 0x04F5,
  3405. cheharmenian: 0x0573,
  3406. chekhakassiancyrillic: 0x04CC,
  3407. cheverticalstrokecyrillic: 0x04B9,
  3408. chi: 0x03C7,
  3409. chieuchacirclekorean: 0x3277,
  3410. chieuchaparenkorean: 0x3217,
  3411. chieuchcirclekorean: 0x3269,
  3412. chieuchkorean: 0x314A,
  3413. chieuchparenkorean: 0x3209,
  3414. chochangthai: 0x0E0A,
  3415. chochanthai: 0x0E08,
  3416. chochingthai: 0x0E09,
  3417. chochoethai: 0x0E0C,
  3418. chook: 0x0188,
  3419. cieucacirclekorean: 0x3276,
  3420. cieucaparenkorean: 0x3216,
  3421. cieuccirclekorean: 0x3268,
  3422. cieuckorean: 0x3148,
  3423. cieucparenkorean: 0x3208,
  3424. cieucuparenkorean: 0x321C,
  3425. circle: 0x25CB,
  3426. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  3427. circlemultiply: 0x2297,
  3428. circleot: 0x2299,
  3429. circleplus: 0x2295,
  3430. circlepostalmark: 0x3036,
  3431. circlewithlefthalfblack: 0x25D0,
  3432. circlewithrighthalfblack: 0x25D1,
  3433. circumflex: 0x02C6,
  3434. circumflexbelowcmb: 0x032D,
  3435. circumflexcmb: 0x0302,
  3436. clear: 0x2327,
  3437. clickalveolar: 0x01C2,
  3438. clickdental: 0x01C0,
  3439. clicklateral: 0x01C1,
  3440. clickretroflex: 0x01C3,
  3441. club: 0x2663,
  3442. clubsuitblack: 0x2663,
  3443. clubsuitwhite: 0x2667,
  3444. cmcubedsquare: 0x33A4,
  3445. cmonospace: 0xFF43,
  3446. cmsquaredsquare: 0x33A0,
  3447. coarmenian: 0x0581,
  3448. colon: 0x003A,
  3449. colonmonetary: 0x20A1,
  3450. colonmonospace: 0xFF1A,
  3451. colonsign: 0x20A1,
  3452. colonsmall: 0xFE55,
  3453. colontriangularhalfmod: 0x02D1,
  3454. colontriangularmod: 0x02D0,
  3455. comma: 0x002C,
  3456. commaabovecmb: 0x0313,
  3457. commaaboverightcmb: 0x0315,
  3458. commaaccent: 0xF6C3,
  3459. commaarabic: 0x060C,
  3460. commaarmenian: 0x055D,
  3461. commainferior: 0xF6E1,
  3462. commamonospace: 0xFF0C,
  3463. commareversedabovecmb: 0x0314,
  3464. commareversedmod: 0x02BD,
  3465. commasmall: 0xFE50,
  3466. commasuperior: 0xF6E2,
  3467. commaturnedabovecmb: 0x0312,
  3468. commaturnedmod: 0x02BB,
  3469. compass: 0x263C,
  3470. congruent: 0x2245,
  3471. contourintegral: 0x222E,
  3472. control: 0x2303,
  3473. controlACK: 0x0006,
  3474. controlBEL: 0x0007,
  3475. controlBS: 0x0008,
  3476. controlCAN: 0x0018,
  3477. controlCR: 0x000D,
  3478. controlDC1: 0x0011,
  3479. controlDC2: 0x0012,
  3480. controlDC3: 0x0013,
  3481. controlDC4: 0x0014,
  3482. controlDEL: 0x007F,
  3483. controlDLE: 0x0010,
  3484. controlEM: 0x0019,
  3485. controlENQ: 0x0005,
  3486. controlEOT: 0x0004,
  3487. controlESC: 0x001B,
  3488. controlETB: 0x0017,
  3489. controlETX: 0x0003,
  3490. controlFF: 0x000C,
  3491. controlFS: 0x001C,
  3492. controlGS: 0x001D,
  3493. controlHT: 0x0009,
  3494. controlLF: 0x000A,
  3495. controlNAK: 0x0015,
  3496. controlRS: 0x001E,
  3497. controlSI: 0x000F,
  3498. controlSO: 0x000E,
  3499. controlSOT: 0x0002,
  3500. controlSTX: 0x0001,
  3501. controlSUB: 0x001A,
  3502. controlSYN: 0x0016,
  3503. controlUS: 0x001F,
  3504. controlVT: 0x000B,
  3505. copyright: 0x00A9,
  3506. copyrightsans: 0xF8E9,
  3507. copyrightserif: 0xF6D9,
  3508. cornerbracketleft: 0x300C,
  3509. cornerbracketlefthalfwidth: 0xFF62,
  3510. cornerbracketleftvertical: 0xFE41,
  3511. cornerbracketright: 0x300D,
  3512. cornerbracketrighthalfwidth: 0xFF63,
  3513. cornerbracketrightvertical: 0xFE42,
  3514. corporationsquare: 0x337F,
  3515. cosquare: 0x33C7,
  3516. coverkgsquare: 0x33C6,
  3517. cparen: 0x249E,
  3518. cruzeiro: 0x20A2,
  3519. cstretched: 0x0297,
  3520. curlyand: 0x22CF,
  3521. curlyor: 0x22CE,
  3522. currency: 0x00A4,
  3523. cyrBreve: 0xF6D1,
  3524. cyrFlex: 0xF6D2,
  3525. cyrbreve: 0xF6D4,
  3526. cyrflex: 0xF6D5,
  3527. d: 0x0064,
  3528. daarmenian: 0x0564,
  3529. dabengali: 0x09A6,
  3530. dadarabic: 0x0636,
  3531. dadeva: 0x0926,
  3532. dadfinalarabic: 0xFEBE,
  3533. dadinitialarabic: 0xFEBF,
  3534. dadmedialarabic: 0xFEC0,
  3535. dagesh: 0x05BC,
  3536. dageshhebrew: 0x05BC,
  3537. dagger: 0x2020,
  3538. daggerdbl: 0x2021,
  3539. dagujarati: 0x0AA6,
  3540. dagurmukhi: 0x0A26,
  3541. dahiragana: 0x3060,
  3542. dakatakana: 0x30C0,
  3543. dalarabic: 0x062F,
  3544. dalet: 0x05D3,
  3545. daletdagesh: 0xFB33,
  3546. daletdageshhebrew: 0xFB33,
  3547. dalethebrew: 0x05D3,
  3548. dalfinalarabic: 0xFEAA,
  3549. dammaarabic: 0x064F,
  3550. dammalowarabic: 0x064F,
  3551. dammatanaltonearabic: 0x064C,
  3552. dammatanarabic: 0x064C,
  3553. danda: 0x0964,
  3554. dargahebrew: 0x05A7,
  3555. dargalefthebrew: 0x05A7,
  3556. dasiapneumatacyrilliccmb: 0x0485,
  3557. dblGrave: 0xF6D3,
  3558. dblanglebracketleft: 0x300A,
  3559. dblanglebracketleftvertical: 0xFE3D,
  3560. dblanglebracketright: 0x300B,
  3561. dblanglebracketrightvertical: 0xFE3E,
  3562. dblarchinvertedbelowcmb: 0x032B,
  3563. dblarrowleft: 0x21D4,
  3564. dblarrowright: 0x21D2,
  3565. dbldanda: 0x0965,
  3566. dblgrave: 0xF6D6,
  3567. dblgravecmb: 0x030F,
  3568. dblintegral: 0x222C,
  3569. dbllowline: 0x2017,
  3570. dbllowlinecmb: 0x0333,
  3571. dbloverlinecmb: 0x033F,
  3572. dblprimemod: 0x02BA,
  3573. dblverticalbar: 0x2016,
  3574. dblverticallineabovecmb: 0x030E,
  3575. dbopomofo: 0x3109,
  3576. dbsquare: 0x33C8,
  3577. dcaron: 0x010F,
  3578. dcedilla: 0x1E11,
  3579. dcircle: 0x24D3,
  3580. dcircumflexbelow: 0x1E13,
  3581. dcroat: 0x0111,
  3582. ddabengali: 0x09A1,
  3583. ddadeva: 0x0921,
  3584. ddagujarati: 0x0AA1,
  3585. ddagurmukhi: 0x0A21,
  3586. ddalarabic: 0x0688,
  3587. ddalfinalarabic: 0xFB89,
  3588. dddhadeva: 0x095C,
  3589. ddhabengali: 0x09A2,
  3590. ddhadeva: 0x0922,
  3591. ddhagujarati: 0x0AA2,
  3592. ddhagurmukhi: 0x0A22,
  3593. ddotaccent: 0x1E0B,
  3594. ddotbelow: 0x1E0D,
  3595. decimalseparatorarabic: 0x066B,
  3596. decimalseparatorpersian: 0x066B,
  3597. decyrillic: 0x0434,
  3598. degree: 0x00B0,
  3599. dehihebrew: 0x05AD,
  3600. dehiragana: 0x3067,
  3601. deicoptic: 0x03EF,
  3602. dekatakana: 0x30C7,
  3603. deleteleft: 0x232B,
  3604. deleteright: 0x2326,
  3605. delta: 0x03B4,
  3606. deltaturned: 0x018D,
  3607. denominatorminusonenumeratorbengali: 0x09F8,
  3608. dezh: 0x02A4,
  3609. dhabengali: 0x09A7,
  3610. dhadeva: 0x0927,
  3611. dhagujarati: 0x0AA7,
  3612. dhagurmukhi: 0x0A27,
  3613. dhook: 0x0257,
  3614. dialytikatonos: 0x0385,
  3615. dialytikatonoscmb: 0x0344,
  3616. diamond: 0x2666,
  3617. diamondsuitwhite: 0x2662,
  3618. dieresis: 0x00A8,
  3619. dieresisacute: 0xF6D7,
  3620. dieresisbelowcmb: 0x0324,
  3621. dieresiscmb: 0x0308,
  3622. dieresisgrave: 0xF6D8,
  3623. dieresistonos: 0x0385,
  3624. dihiragana: 0x3062,
  3625. dikatakana: 0x30C2,
  3626. dittomark: 0x3003,
  3627. divide: 0x00F7,
  3628. divides: 0x2223,
  3629. divisionslash: 0x2215,
  3630. djecyrillic: 0x0452,
  3631. dkshade: 0x2593,
  3632. dlinebelow: 0x1E0F,
  3633. dlsquare: 0x3397,
  3634. dmacron: 0x0111,
  3635. dmonospace: 0xFF44,
  3636. dnblock: 0x2584,
  3637. dochadathai: 0x0E0E,
  3638. dodekthai: 0x0E14,
  3639. dohiragana: 0x3069,
  3640. dokatakana: 0x30C9,
  3641. dollar: 0x0024,
  3642. dollarinferior: 0xF6E3,
  3643. dollarmonospace: 0xFF04,
  3644. dollaroldstyle: 0xF724,
  3645. dollarsmall: 0xFE69,
  3646. dollarsuperior: 0xF6E4,
  3647. dong: 0x20AB,
  3648. dorusquare: 0x3326,
  3649. dotaccent: 0x02D9,
  3650. dotaccentcmb: 0x0307,
  3651. dotbelowcmb: 0x0323,
  3652. dotbelowcomb: 0x0323,
  3653. dotkatakana: 0x30FB,
  3654. dotlessi: 0x0131,
  3655. dotlessj: 0xF6BE,
  3656. dotlessjstrokehook: 0x0284,
  3657. dotmath: 0x22C5,
  3658. dottedcircle: 0x25CC,
  3659. doubleyodpatah: 0xFB1F,
  3660. doubleyodpatahhebrew: 0xFB1F,
  3661. downtackbelowcmb: 0x031E,
  3662. downtackmod: 0x02D5,
  3663. dparen: 0x249F,
  3664. dsuperior: 0xF6EB,
  3665. dtail: 0x0256,
  3666. dtopbar: 0x018C,
  3667. duhiragana: 0x3065,
  3668. dukatakana: 0x30C5,
  3669. dz: 0x01F3,
  3670. dzaltone: 0x02A3,
  3671. dzcaron: 0x01C6,
  3672. dzcurl: 0x02A5,
  3673. dzeabkhasiancyrillic: 0x04E1,
  3674. dzecyrillic: 0x0455,
  3675. dzhecyrillic: 0x045F,
  3676. e: 0x0065,
  3677. eacute: 0x00E9,
  3678. earth: 0x2641,
  3679. ebengali: 0x098F,
  3680. ebopomofo: 0x311C,
  3681. ebreve: 0x0115,
  3682. ecandradeva: 0x090D,
  3683. ecandragujarati: 0x0A8D,
  3684. ecandravowelsigndeva: 0x0945,
  3685. ecandravowelsigngujarati: 0x0AC5,
  3686. ecaron: 0x011B,
  3687. ecedillabreve: 0x1E1D,
  3688. echarmenian: 0x0565,
  3689. echyiwnarmenian: 0x0587,
  3690. ecircle: 0x24D4,
  3691. ecircumflex: 0x00EA,
  3692. ecircumflexacute: 0x1EBF,
  3693. ecircumflexbelow: 0x1E19,
  3694. ecircumflexdotbelow: 0x1EC7,
  3695. ecircumflexgrave: 0x1EC1,
  3696. ecircumflexhookabove: 0x1EC3,
  3697. ecircumflextilde: 0x1EC5,
  3698. ecyrillic: 0x0454,
  3699. edblgrave: 0x0205,
  3700. edeva: 0x090F,
  3701. edieresis: 0x00EB,
  3702. edot: 0x0117,
  3703. edotaccent: 0x0117,
  3704. edotbelow: 0x1EB9,
  3705. eegurmukhi: 0x0A0F,
  3706. eematragurmukhi: 0x0A47,
  3707. efcyrillic: 0x0444,
  3708. egrave: 0x00E8,
  3709. egujarati: 0x0A8F,
  3710. eharmenian: 0x0567,
  3711. ehbopomofo: 0x311D,
  3712. ehiragana: 0x3048,
  3713. ehookabove: 0x1EBB,
  3714. eibopomofo: 0x311F,
  3715. eight: 0x0038,
  3716. eightarabic: 0x0668,
  3717. eightbengali: 0x09EE,
  3718. eightcircle: 0x2467,
  3719. eightcircleinversesansserif: 0x2791,
  3720. eightdeva: 0x096E,
  3721. eighteencircle: 0x2471,
  3722. eighteenparen: 0x2485,
  3723. eighteenperiod: 0x2499,
  3724. eightgujarati: 0x0AEE,
  3725. eightgurmukhi: 0x0A6E,
  3726. eighthackarabic: 0x0668,
  3727. eighthangzhou: 0x3028,
  3728. eighthnotebeamed: 0x266B,
  3729. eightideographicparen: 0x3227,
  3730. eightinferior: 0x2088,
  3731. eightmonospace: 0xFF18,
  3732. eightoldstyle: 0xF738,
  3733. eightparen: 0x247B,
  3734. eightperiod: 0x248F,
  3735. eightpersian: 0x06F8,
  3736. eightroman: 0x2177,
  3737. eightsuperior: 0x2078,
  3738. eightthai: 0x0E58,
  3739. einvertedbreve: 0x0207,
  3740. eiotifiedcyrillic: 0x0465,
  3741. ekatakana: 0x30A8,
  3742. ekatakanahalfwidth: 0xFF74,
  3743. ekonkargurmukhi: 0x0A74,
  3744. ekorean: 0x3154,
  3745. elcyrillic: 0x043B,
  3746. element: 0x2208,
  3747. elevencircle: 0x246A,
  3748. elevenparen: 0x247E,
  3749. elevenperiod: 0x2492,
  3750. elevenroman: 0x217A,
  3751. ellipsis: 0x2026,
  3752. ellipsisvertical: 0x22EE,
  3753. emacron: 0x0113,
  3754. emacronacute: 0x1E17,
  3755. emacrongrave: 0x1E15,
  3756. emcyrillic: 0x043C,
  3757. emdash: 0x2014,
  3758. emdashvertical: 0xFE31,
  3759. emonospace: 0xFF45,
  3760. emphasismarkarmenian: 0x055B,
  3761. emptyset: 0x2205,
  3762. enbopomofo: 0x3123,
  3763. encyrillic: 0x043D,
  3764. endash: 0x2013,
  3765. endashvertical: 0xFE32,
  3766. endescendercyrillic: 0x04A3,
  3767. eng: 0x014B,
  3768. engbopomofo: 0x3125,
  3769. enghecyrillic: 0x04A5,
  3770. enhookcyrillic: 0x04C8,
  3771. enspace: 0x2002,
  3772. eogonek: 0x0119,
  3773. eokorean: 0x3153,
  3774. eopen: 0x025B,
  3775. eopenclosed: 0x029A,
  3776. eopenreversed: 0x025C,
  3777. eopenreversedclosed: 0x025E,
  3778. eopenreversedhook: 0x025D,
  3779. eparen: 0x24A0,
  3780. epsilon: 0x03B5,
  3781. epsilontonos: 0x03AD,
  3782. equal: 0x003D,
  3783. equalmonospace: 0xFF1D,
  3784. equalsmall: 0xFE66,
  3785. equalsuperior: 0x207C,
  3786. equivalence: 0x2261,
  3787. erbopomofo: 0x3126,
  3788. ercyrillic: 0x0440,
  3789. ereversed: 0x0258,
  3790. ereversedcyrillic: 0x044D,
  3791. escyrillic: 0x0441,
  3792. esdescendercyrillic: 0x04AB,
  3793. esh: 0x0283,
  3794. eshcurl: 0x0286,
  3795. eshortdeva: 0x090E,
  3796. eshortvowelsigndeva: 0x0946,
  3797. eshreversedloop: 0x01AA,
  3798. eshsquatreversed: 0x0285,
  3799. esmallhiragana: 0x3047,
  3800. esmallkatakana: 0x30A7,
  3801. esmallkatakanahalfwidth: 0xFF6A,
  3802. estimated: 0x212E,
  3803. esuperior: 0xF6EC,
  3804. eta: 0x03B7,
  3805. etarmenian: 0x0568,
  3806. etatonos: 0x03AE,
  3807. eth: 0x00F0,
  3808. etilde: 0x1EBD,
  3809. etildebelow: 0x1E1B,
  3810. etnahtafoukhhebrew: 0x0591,
  3811. etnahtafoukhlefthebrew: 0x0591,
  3812. etnahtahebrew: 0x0591,
  3813. etnahtalefthebrew: 0x0591,
  3814. eturned: 0x01DD,
  3815. eukorean: 0x3161,
  3816. euro: 0x20AC,
  3817. evowelsignbengali: 0x09C7,
  3818. evowelsigndeva: 0x0947,
  3819. evowelsigngujarati: 0x0AC7,
  3820. exclam: 0x0021,
  3821. exclamarmenian: 0x055C,
  3822. exclamdbl: 0x203C,
  3823. exclamdown: 0x00A1,
  3824. exclamdownsmall: 0xF7A1,
  3825. exclammonospace: 0xFF01,
  3826. exclamsmall: 0xF721,
  3827. existential: 0x2203,
  3828. ezh: 0x0292,
  3829. ezhcaron: 0x01EF,
  3830. ezhcurl: 0x0293,
  3831. ezhreversed: 0x01B9,
  3832. ezhtail: 0x01BA,
  3833. f: 0x0066,
  3834. fadeva: 0x095E,
  3835. fagurmukhi: 0x0A5E,
  3836. fahrenheit: 0x2109,
  3837. fathaarabic: 0x064E,
  3838. fathalowarabic: 0x064E,
  3839. fathatanarabic: 0x064B,
  3840. fbopomofo: 0x3108,
  3841. fcircle: 0x24D5,
  3842. fdotaccent: 0x1E1F,
  3843. feharabic: 0x0641,
  3844. feharmenian: 0x0586,
  3845. fehfinalarabic: 0xFED2,
  3846. fehinitialarabic: 0xFED3,
  3847. fehmedialarabic: 0xFED4,
  3848. feicoptic: 0x03E5,
  3849. female: 0x2640,
  3850. ff: 0xFB00,
  3851. ffi: 0xFB03,
  3852. ffl: 0xFB04,
  3853. fi: 0xFB01,
  3854. fifteencircle: 0x246E,
  3855. fifteenparen: 0x2482,
  3856. fifteenperiod: 0x2496,
  3857. figuredash: 0x2012,
  3858. filledbox: 0x25A0,
  3859. filledrect: 0x25AC,
  3860. finalkaf: 0x05DA,
  3861. finalkafdagesh: 0xFB3A,
  3862. finalkafdageshhebrew: 0xFB3A,
  3863. finalkafhebrew: 0x05DA,
  3864. finalmem: 0x05DD,
  3865. finalmemhebrew: 0x05DD,
  3866. finalnun: 0x05DF,
  3867. finalnunhebrew: 0x05DF,
  3868. finalpe: 0x05E3,
  3869. finalpehebrew: 0x05E3,
  3870. finaltsadi: 0x05E5,
  3871. finaltsadihebrew: 0x05E5,
  3872. firsttonechinese: 0x02C9,
  3873. fisheye: 0x25C9,
  3874. fitacyrillic: 0x0473,
  3875. five: 0x0035,
  3876. fivearabic: 0x0665,
  3877. fivebengali: 0x09EB,
  3878. fivecircle: 0x2464,
  3879. fivecircleinversesansserif: 0x278E,
  3880. fivedeva: 0x096B,
  3881. fiveeighths: 0x215D,
  3882. fivegujarati: 0x0AEB,
  3883. fivegurmukhi: 0x0A6B,
  3884. fivehackarabic: 0x0665,
  3885. fivehangzhou: 0x3025,
  3886. fiveideographicparen: 0x3224,
  3887. fiveinferior: 0x2085,
  3888. fivemonospace: 0xFF15,
  3889. fiveoldstyle: 0xF735,
  3890. fiveparen: 0x2478,
  3891. fiveperiod: 0x248C,
  3892. fivepersian: 0x06F5,
  3893. fiveroman: 0x2174,
  3894. fivesuperior: 0x2075,
  3895. fivethai: 0x0E55,
  3896. fl: 0xFB02,
  3897. florin: 0x0192,
  3898. fmonospace: 0xFF46,
  3899. fmsquare: 0x3399,
  3900. fofanthai: 0x0E1F,
  3901. fofathai: 0x0E1D,
  3902. fongmanthai: 0x0E4F,
  3903. forall: 0x2200,
  3904. four: 0x0034,
  3905. fourarabic: 0x0664,
  3906. fourbengali: 0x09EA,
  3907. fourcircle: 0x2463,
  3908. fourcircleinversesansserif: 0x278D,
  3909. fourdeva: 0x096A,
  3910. fourgujarati: 0x0AEA,
  3911. fourgurmukhi: 0x0A6A,
  3912. fourhackarabic: 0x0664,
  3913. fourhangzhou: 0x3024,
  3914. fourideographicparen: 0x3223,
  3915. fourinferior: 0x2084,
  3916. fourmonospace: 0xFF14,
  3917. fournumeratorbengali: 0x09F7,
  3918. fouroldstyle: 0xF734,
  3919. fourparen: 0x2477,
  3920. fourperiod: 0x248B,
  3921. fourpersian: 0x06F4,
  3922. fourroman: 0x2173,
  3923. foursuperior: 0x2074,
  3924. fourteencircle: 0x246D,
  3925. fourteenparen: 0x2481,
  3926. fourteenperiod: 0x2495,
  3927. fourthai: 0x0E54,
  3928. fourthtonechinese: 0x02CB,
  3929. fparen: 0x24A1,
  3930. fraction: 0x2044,
  3931. franc: 0x20A3,
  3932. g: 0x0067,
  3933. gabengali: 0x0997,
  3934. gacute: 0x01F5,
  3935. gadeva: 0x0917,
  3936. gafarabic: 0x06AF,
  3937. gaffinalarabic: 0xFB93,
  3938. gafinitialarabic: 0xFB94,
  3939. gafmedialarabic: 0xFB95,
  3940. gagujarati: 0x0A97,
  3941. gagurmukhi: 0x0A17,
  3942. gahiragana: 0x304C,
  3943. gakatakana: 0x30AC,
  3944. gamma: 0x03B3,
  3945. gammalatinsmall: 0x0263,
  3946. gammasuperior: 0x02E0,
  3947. gangiacoptic: 0x03EB,
  3948. gbopomofo: 0x310D,
  3949. gbreve: 0x011F,
  3950. gcaron: 0x01E7,
  3951. gcedilla: 0x0123,
  3952. gcircle: 0x24D6,
  3953. gcircumflex: 0x011D,
  3954. gcommaaccent: 0x0123,
  3955. gdot: 0x0121,
  3956. gdotaccent: 0x0121,
  3957. gecyrillic: 0x0433,
  3958. gehiragana: 0x3052,
  3959. gekatakana: 0x30B2,
  3960. geometricallyequal: 0x2251,
  3961. gereshaccenthebrew: 0x059C,
  3962. gereshhebrew: 0x05F3,
  3963. gereshmuqdamhebrew: 0x059D,
  3964. germandbls: 0x00DF,
  3965. gershayimaccenthebrew: 0x059E,
  3966. gershayimhebrew: 0x05F4,
  3967. getamark: 0x3013,
  3968. ghabengali: 0x0998,
  3969. ghadarmenian: 0x0572,
  3970. ghadeva: 0x0918,
  3971. ghagujarati: 0x0A98,
  3972. ghagurmukhi: 0x0A18,
  3973. ghainarabic: 0x063A,
  3974. ghainfinalarabic: 0xFECE,
  3975. ghaininitialarabic: 0xFECF,
  3976. ghainmedialarabic: 0xFED0,
  3977. ghemiddlehookcyrillic: 0x0495,
  3978. ghestrokecyrillic: 0x0493,
  3979. gheupturncyrillic: 0x0491,
  3980. ghhadeva: 0x095A,
  3981. ghhagurmukhi: 0x0A5A,
  3982. ghook: 0x0260,
  3983. ghzsquare: 0x3393,
  3984. gihiragana: 0x304E,
  3985. gikatakana: 0x30AE,
  3986. gimarmenian: 0x0563,
  3987. gimel: 0x05D2,
  3988. gimeldagesh: 0xFB32,
  3989. gimeldageshhebrew: 0xFB32,
  3990. gimelhebrew: 0x05D2,
  3991. gjecyrillic: 0x0453,
  3992. glottalinvertedstroke: 0x01BE,
  3993. glottalstop: 0x0294,
  3994. glottalstopinverted: 0x0296,
  3995. glottalstopmod: 0x02C0,
  3996. glottalstopreversed: 0x0295,
  3997. glottalstopreversedmod: 0x02C1,
  3998. glottalstopreversedsuperior: 0x02E4,
  3999. glottalstopstroke: 0x02A1,
  4000. glottalstopstrokereversed: 0x02A2,
  4001. gmacron: 0x1E21,
  4002. gmonospace: 0xFF47,
  4003. gohiragana: 0x3054,
  4004. gokatakana: 0x30B4,
  4005. gparen: 0x24A2,
  4006. gpasquare: 0x33AC,
  4007. gradient: 0x2207,
  4008. grave: 0x0060,
  4009. gravebelowcmb: 0x0316,
  4010. gravecmb: 0x0300,
  4011. gravecomb: 0x0300,
  4012. gravedeva: 0x0953,
  4013. gravelowmod: 0x02CE,
  4014. gravemonospace: 0xFF40,
  4015. gravetonecmb: 0x0340,
  4016. greater: 0x003E,
  4017. greaterequal: 0x2265,
  4018. greaterequalorless: 0x22DB,
  4019. greatermonospace: 0xFF1E,
  4020. greaterorequivalent: 0x2273,
  4021. greaterorless: 0x2277,
  4022. greateroverequal: 0x2267,
  4023. greatersmall: 0xFE65,
  4024. gscript: 0x0261,
  4025. gstroke: 0x01E5,
  4026. guhiragana: 0x3050,
  4027. guillemotleft: 0x00AB,
  4028. guillemotright: 0x00BB,
  4029. guilsinglleft: 0x2039,
  4030. guilsinglright: 0x203A,
  4031. gukatakana: 0x30B0,
  4032. guramusquare: 0x3318,
  4033. gysquare: 0x33C9,
  4034. h: 0x0068,
  4035. haabkhasiancyrillic: 0x04A9,
  4036. haaltonearabic: 0x06C1,
  4037. habengali: 0x09B9,
  4038. hadescendercyrillic: 0x04B3,
  4039. hadeva: 0x0939,
  4040. hagujarati: 0x0AB9,
  4041. hagurmukhi: 0x0A39,
  4042. haharabic: 0x062D,
  4043. hahfinalarabic: 0xFEA2,
  4044. hahinitialarabic: 0xFEA3,
  4045. hahiragana: 0x306F,
  4046. hahmedialarabic: 0xFEA4,
  4047. haitusquare: 0x332A,
  4048. hakatakana: 0x30CF,
  4049. hakatakanahalfwidth: 0xFF8A,
  4050. halantgurmukhi: 0x0A4D,
  4051. hamzaarabic: 0x0621,
  4052. hamzalowarabic: 0x0621,
  4053. hangulfiller: 0x3164,
  4054. hardsigncyrillic: 0x044A,
  4055. harpoonleftbarbup: 0x21BC,
  4056. harpoonrightbarbup: 0x21C0,
  4057. hasquare: 0x33CA,
  4058. hatafpatah: 0x05B2,
  4059. hatafpatah16: 0x05B2,
  4060. hatafpatah23: 0x05B2,
  4061. hatafpatah2f: 0x05B2,
  4062. hatafpatahhebrew: 0x05B2,
  4063. hatafpatahnarrowhebrew: 0x05B2,
  4064. hatafpatahquarterhebrew: 0x05B2,
  4065. hatafpatahwidehebrew: 0x05B2,
  4066. hatafqamats: 0x05B3,
  4067. hatafqamats1b: 0x05B3,
  4068. hatafqamats28: 0x05B3,
  4069. hatafqamats34: 0x05B3,
  4070. hatafqamatshebrew: 0x05B3,
  4071. hatafqamatsnarrowhebrew: 0x05B3,
  4072. hatafqamatsquarterhebrew: 0x05B3,
  4073. hatafqamatswidehebrew: 0x05B3,
  4074. hatafsegol: 0x05B1,
  4075. hatafsegol17: 0x05B1,
  4076. hatafsegol24: 0x05B1,
  4077. hatafsegol30: 0x05B1,
  4078. hatafsegolhebrew: 0x05B1,
  4079. hatafsegolnarrowhebrew: 0x05B1,
  4080. hatafsegolquarterhebrew: 0x05B1,
  4081. hatafsegolwidehebrew: 0x05B1,
  4082. hbar: 0x0127,
  4083. hbopomofo: 0x310F,
  4084. hbrevebelow: 0x1E2B,
  4085. hcedilla: 0x1E29,
  4086. hcircle: 0x24D7,
  4087. hcircumflex: 0x0125,
  4088. hdieresis: 0x1E27,
  4089. hdotaccent: 0x1E23,
  4090. hdotbelow: 0x1E25,
  4091. he: 0x05D4,
  4092. heart: 0x2665,
  4093. heartsuitblack: 0x2665,
  4094. heartsuitwhite: 0x2661,
  4095. hedagesh: 0xFB34,
  4096. hedageshhebrew: 0xFB34,
  4097. hehaltonearabic: 0x06C1,
  4098. heharabic: 0x0647,
  4099. hehebrew: 0x05D4,
  4100. hehfinalaltonearabic: 0xFBA7,
  4101. hehfinalalttwoarabic: 0xFEEA,
  4102. hehfinalarabic: 0xFEEA,
  4103. hehhamzaabovefinalarabic: 0xFBA5,
  4104. hehhamzaaboveisolatedarabic: 0xFBA4,
  4105. hehinitialaltonearabic: 0xFBA8,
  4106. hehinitialarabic: 0xFEEB,
  4107. hehiragana: 0x3078,
  4108. hehmedialaltonearabic: 0xFBA9,
  4109. hehmedialarabic: 0xFEEC,
  4110. heiseierasquare: 0x337B,
  4111. hekatakana: 0x30D8,
  4112. hekatakanahalfwidth: 0xFF8D,
  4113. hekutaarusquare: 0x3336,
  4114. henghook: 0x0267,
  4115. herutusquare: 0x3339,
  4116. het: 0x05D7,
  4117. hethebrew: 0x05D7,
  4118. hhook: 0x0266,
  4119. hhooksuperior: 0x02B1,
  4120. hieuhacirclekorean: 0x327B,
  4121. hieuhaparenkorean: 0x321B,
  4122. hieuhcirclekorean: 0x326D,
  4123. hieuhkorean: 0x314E,
  4124. hieuhparenkorean: 0x320D,
  4125. hihiragana: 0x3072,
  4126. hikatakana: 0x30D2,
  4127. hikatakanahalfwidth: 0xFF8B,
  4128. hiriq: 0x05B4,
  4129. hiriq14: 0x05B4,
  4130. hiriq21: 0x05B4,
  4131. hiriq2d: 0x05B4,
  4132. hiriqhebrew: 0x05B4,
  4133. hiriqnarrowhebrew: 0x05B4,
  4134. hiriqquarterhebrew: 0x05B4,
  4135. hiriqwidehebrew: 0x05B4,
  4136. hlinebelow: 0x1E96,
  4137. hmonospace: 0xFF48,
  4138. hoarmenian: 0x0570,
  4139. hohipthai: 0x0E2B,
  4140. hohiragana: 0x307B,
  4141. hokatakana: 0x30DB,
  4142. hokatakanahalfwidth: 0xFF8E,
  4143. holam: 0x05B9,
  4144. holam19: 0x05B9,
  4145. holam26: 0x05B9,
  4146. holam32: 0x05B9,
  4147. holamhebrew: 0x05B9,
  4148. holamnarrowhebrew: 0x05B9,
  4149. holamquarterhebrew: 0x05B9,
  4150. holamwidehebrew: 0x05B9,
  4151. honokhukthai: 0x0E2E,
  4152. hookabovecomb: 0x0309,
  4153. hookcmb: 0x0309,
  4154. hookpalatalizedbelowcmb: 0x0321,
  4155. hookretroflexbelowcmb: 0x0322,
  4156. hoonsquare: 0x3342,
  4157. horicoptic: 0x03E9,
  4158. horizontalbar: 0x2015,
  4159. horncmb: 0x031B,
  4160. hotsprings: 0x2668,
  4161. house: 0x2302,
  4162. hparen: 0x24A3,
  4163. hsuperior: 0x02B0,
  4164. hturned: 0x0265,
  4165. huhiragana: 0x3075,
  4166. huiitosquare: 0x3333,
  4167. hukatakana: 0x30D5,
  4168. hukatakanahalfwidth: 0xFF8C,
  4169. hungarumlaut: 0x02DD,
  4170. hungarumlautcmb: 0x030B,
  4171. hv: 0x0195,
  4172. hyphen: 0x002D,
  4173. hypheninferior: 0xF6E5,
  4174. hyphenmonospace: 0xFF0D,
  4175. hyphensmall: 0xFE63,
  4176. hyphensuperior: 0xF6E6,
  4177. hyphentwo: 0x2010,
  4178. i: 0x0069,
  4179. iacute: 0x00ED,
  4180. iacyrillic: 0x044F,
  4181. ibengali: 0x0987,
  4182. ibopomofo: 0x3127,
  4183. ibreve: 0x012D,
  4184. icaron: 0x01D0,
  4185. icircle: 0x24D8,
  4186. icircumflex: 0x00EE,
  4187. icyrillic: 0x0456,
  4188. idblgrave: 0x0209,
  4189. ideographearthcircle: 0x328F,
  4190. ideographfirecircle: 0x328B,
  4191. ideographicallianceparen: 0x323F,
  4192. ideographiccallparen: 0x323A,
  4193. ideographiccentrecircle: 0x32A5,
  4194. ideographicclose: 0x3006,
  4195. ideographiccomma: 0x3001,
  4196. ideographiccommaleft: 0xFF64,
  4197. ideographiccongratulationparen: 0x3237,
  4198. ideographiccorrectcircle: 0x32A3,
  4199. ideographicearthparen: 0x322F,
  4200. ideographicenterpriseparen: 0x323D,
  4201. ideographicexcellentcircle: 0x329D,
  4202. ideographicfestivalparen: 0x3240,
  4203. ideographicfinancialcircle: 0x3296,
  4204. ideographicfinancialparen: 0x3236,
  4205. ideographicfireparen: 0x322B,
  4206. ideographichaveparen: 0x3232,
  4207. ideographichighcircle: 0x32A4,
  4208. ideographiciterationmark: 0x3005,
  4209. ideographiclaborcircle: 0x3298,
  4210. ideographiclaborparen: 0x3238,
  4211. ideographicleftcircle: 0x32A7,
  4212. ideographiclowcircle: 0x32A6,
  4213. ideographicmedicinecircle: 0x32A9,
  4214. ideographicmetalparen: 0x322E,
  4215. ideographicmoonparen: 0x322A,
  4216. ideographicnameparen: 0x3234,
  4217. ideographicperiod: 0x3002,
  4218. ideographicprintcircle: 0x329E,
  4219. ideographicreachparen: 0x3243,
  4220. ideographicrepresentparen: 0x3239,
  4221. ideographicresourceparen: 0x323E,
  4222. ideographicrightcircle: 0x32A8,
  4223. ideographicsecretcircle: 0x3299,
  4224. ideographicselfparen: 0x3242,
  4225. ideographicsocietyparen: 0x3233,
  4226. ideographicspace: 0x3000,
  4227. ideographicspecialparen: 0x3235,
  4228. ideographicstockparen: 0x3231,
  4229. ideographicstudyparen: 0x323B,
  4230. ideographicsunparen: 0x3230,
  4231. ideographicsuperviseparen: 0x323C,
  4232. ideographicwaterparen: 0x322C,
  4233. ideographicwoodparen: 0x322D,
  4234. ideographiczero: 0x3007,
  4235. ideographmetalcircle: 0x328E,
  4236. ideographmooncircle: 0x328A,
  4237. ideographnamecircle: 0x3294,
  4238. ideographsuncircle: 0x3290,
  4239. ideographwatercircle: 0x328C,
  4240. ideographwoodcircle: 0x328D,
  4241. ideva: 0x0907,
  4242. idieresis: 0x00EF,
  4243. idieresisacute: 0x1E2F,
  4244. idieresiscyrillic: 0x04E5,
  4245. idotbelow: 0x1ECB,
  4246. iebrevecyrillic: 0x04D7,
  4247. iecyrillic: 0x0435,
  4248. ieungacirclekorean: 0x3275,
  4249. ieungaparenkorean: 0x3215,
  4250. ieungcirclekorean: 0x3267,
  4251. ieungkorean: 0x3147,
  4252. ieungparenkorean: 0x3207,
  4253. igrave: 0x00EC,
  4254. igujarati: 0x0A87,
  4255. igurmukhi: 0x0A07,
  4256. ihiragana: 0x3044,
  4257. ihookabove: 0x1EC9,
  4258. iibengali: 0x0988,
  4259. iicyrillic: 0x0438,
  4260. iideva: 0x0908,
  4261. iigujarati: 0x0A88,
  4262. iigurmukhi: 0x0A08,
  4263. iimatragurmukhi: 0x0A40,
  4264. iinvertedbreve: 0x020B,
  4265. iishortcyrillic: 0x0439,
  4266. iivowelsignbengali: 0x09C0,
  4267. iivowelsigndeva: 0x0940,
  4268. iivowelsigngujarati: 0x0AC0,
  4269. ij: 0x0133,
  4270. ikatakana: 0x30A4,
  4271. ikatakanahalfwidth: 0xFF72,
  4272. ikorean: 0x3163,
  4273. ilde: 0x02DC,
  4274. iluyhebrew: 0x05AC,
  4275. imacron: 0x012B,
  4276. imacroncyrillic: 0x04E3,
  4277. imageorapproximatelyequal: 0x2253,
  4278. imatragurmukhi: 0x0A3F,
  4279. imonospace: 0xFF49,
  4280. increment: 0x2206,
  4281. infinity: 0x221E,
  4282. iniarmenian: 0x056B,
  4283. integral: 0x222B,
  4284. integralbottom: 0x2321,
  4285. integralbt: 0x2321,
  4286. integralex: 0xF8F5,
  4287. integraltop: 0x2320,
  4288. integraltp: 0x2320,
  4289. intersection: 0x2229,
  4290. intisquare: 0x3305,
  4291. invbullet: 0x25D8,
  4292. invcircle: 0x25D9,
  4293. invsmileface: 0x263B,
  4294. iocyrillic: 0x0451,
  4295. iogonek: 0x012F,
  4296. iota: 0x03B9,
  4297. iotadieresis: 0x03CA,
  4298. iotadieresistonos: 0x0390,
  4299. iotalatin: 0x0269,
  4300. iotatonos: 0x03AF,
  4301. iparen: 0x24A4,
  4302. irigurmukhi: 0x0A72,
  4303. ismallhiragana: 0x3043,
  4304. ismallkatakana: 0x30A3,
  4305. ismallkatakanahalfwidth: 0xFF68,
  4306. issharbengali: 0x09FA,
  4307. istroke: 0x0268,
  4308. isuperior: 0xF6ED,
  4309. iterationhiragana: 0x309D,
  4310. iterationkatakana: 0x30FD,
  4311. itilde: 0x0129,
  4312. itildebelow: 0x1E2D,
  4313. iubopomofo: 0x3129,
  4314. iucyrillic: 0x044E,
  4315. ivowelsignbengali: 0x09BF,
  4316. ivowelsigndeva: 0x093F,
  4317. ivowelsigngujarati: 0x0ABF,
  4318. izhitsacyrillic: 0x0475,
  4319. izhitsadblgravecyrillic: 0x0477,
  4320. j: 0x006A,
  4321. jaarmenian: 0x0571,
  4322. jabengali: 0x099C,
  4323. jadeva: 0x091C,
  4324. jagujarati: 0x0A9C,
  4325. jagurmukhi: 0x0A1C,
  4326. jbopomofo: 0x3110,
  4327. jcaron: 0x01F0,
  4328. jcircle: 0x24D9,
  4329. jcircumflex: 0x0135,
  4330. jcrossedtail: 0x029D,
  4331. jdotlessstroke: 0x025F,
  4332. jecyrillic: 0x0458,
  4333. jeemarabic: 0x062C,
  4334. jeemfinalarabic: 0xFE9E,
  4335. jeeminitialarabic: 0xFE9F,
  4336. jeemmedialarabic: 0xFEA0,
  4337. jeharabic: 0x0698,
  4338. jehfinalarabic: 0xFB8B,
  4339. jhabengali: 0x099D,
  4340. jhadeva: 0x091D,
  4341. jhagujarati: 0x0A9D,
  4342. jhagurmukhi: 0x0A1D,
  4343. jheharmenian: 0x057B,
  4344. jis: 0x3004,
  4345. jmonospace: 0xFF4A,
  4346. jparen: 0x24A5,
  4347. jsuperior: 0x02B2,
  4348. k: 0x006B,
  4349. kabashkircyrillic: 0x04A1,
  4350. kabengali: 0x0995,
  4351. kacute: 0x1E31,
  4352. kacyrillic: 0x043A,
  4353. kadescendercyrillic: 0x049B,
  4354. kadeva: 0x0915,
  4355. kaf: 0x05DB,
  4356. kafarabic: 0x0643,
  4357. kafdagesh: 0xFB3B,
  4358. kafdageshhebrew: 0xFB3B,
  4359. kaffinalarabic: 0xFEDA,
  4360. kafhebrew: 0x05DB,
  4361. kafinitialarabic: 0xFEDB,
  4362. kafmedialarabic: 0xFEDC,
  4363. kafrafehebrew: 0xFB4D,
  4364. kagujarati: 0x0A95,
  4365. kagurmukhi: 0x0A15,
  4366. kahiragana: 0x304B,
  4367. kahookcyrillic: 0x04C4,
  4368. kakatakana: 0x30AB,
  4369. kakatakanahalfwidth: 0xFF76,
  4370. kappa: 0x03BA,
  4371. kappasymbolgreek: 0x03F0,
  4372. kapyeounmieumkorean: 0x3171,
  4373. kapyeounphieuphkorean: 0x3184,
  4374. kapyeounpieupkorean: 0x3178,
  4375. kapyeounssangpieupkorean: 0x3179,
  4376. karoriisquare: 0x330D,
  4377. kashidaautoarabic: 0x0640,
  4378. kashidaautonosidebearingarabic: 0x0640,
  4379. kasmallkatakana: 0x30F5,
  4380. kasquare: 0x3384,
  4381. kasraarabic: 0x0650,
  4382. kasratanarabic: 0x064D,
  4383. kastrokecyrillic: 0x049F,
  4384. katahiraprolongmarkhalfwidth: 0xFF70,
  4385. kaverticalstrokecyrillic: 0x049D,
  4386. kbopomofo: 0x310E,
  4387. kcalsquare: 0x3389,
  4388. kcaron: 0x01E9,
  4389. kcedilla: 0x0137,
  4390. kcircle: 0x24DA,
  4391. kcommaaccent: 0x0137,
  4392. kdotbelow: 0x1E33,
  4393. keharmenian: 0x0584,
  4394. kehiragana: 0x3051,
  4395. kekatakana: 0x30B1,
  4396. kekatakanahalfwidth: 0xFF79,
  4397. kenarmenian: 0x056F,
  4398. kesmallkatakana: 0x30F6,
  4399. kgreenlandic: 0x0138,
  4400. khabengali: 0x0996,
  4401. khacyrillic: 0x0445,
  4402. khadeva: 0x0916,
  4403. khagujarati: 0x0A96,
  4404. khagurmukhi: 0x0A16,
  4405. khaharabic: 0x062E,
  4406. khahfinalarabic: 0xFEA6,
  4407. khahinitialarabic: 0xFEA7,
  4408. khahmedialarabic: 0xFEA8,
  4409. kheicoptic: 0x03E7,
  4410. khhadeva: 0x0959,
  4411. khhagurmukhi: 0x0A59,
  4412. khieukhacirclekorean: 0x3278,
  4413. khieukhaparenkorean: 0x3218,
  4414. khieukhcirclekorean: 0x326A,
  4415. khieukhkorean: 0x314B,
  4416. khieukhparenkorean: 0x320A,
  4417. khokhaithai: 0x0E02,
  4418. khokhonthai: 0x0E05,
  4419. khokhuatthai: 0x0E03,
  4420. khokhwaithai: 0x0E04,
  4421. khomutthai: 0x0E5B,
  4422. khook: 0x0199,
  4423. khorakhangthai: 0x0E06,
  4424. khzsquare: 0x3391,
  4425. kihiragana: 0x304D,
  4426. kikatakana: 0x30AD,
  4427. kikatakanahalfwidth: 0xFF77,
  4428. kiroguramusquare: 0x3315,
  4429. kiromeetorusquare: 0x3316,
  4430. kirosquare: 0x3314,
  4431. kiyeokacirclekorean: 0x326E,
  4432. kiyeokaparenkorean: 0x320E,
  4433. kiyeokcirclekorean: 0x3260,
  4434. kiyeokkorean: 0x3131,
  4435. kiyeokparenkorean: 0x3200,
  4436. kiyeoksioskorean: 0x3133,
  4437. kjecyrillic: 0x045C,
  4438. klinebelow: 0x1E35,
  4439. klsquare: 0x3398,
  4440. kmcubedsquare: 0x33A6,
  4441. kmonospace: 0xFF4B,
  4442. kmsquaredsquare: 0x33A2,
  4443. kohiragana: 0x3053,
  4444. kohmsquare: 0x33C0,
  4445. kokaithai: 0x0E01,
  4446. kokatakana: 0x30B3,
  4447. kokatakanahalfwidth: 0xFF7A,
  4448. kooposquare: 0x331E,
  4449. koppacyrillic: 0x0481,
  4450. koreanstandardsymbol: 0x327F,
  4451. koroniscmb: 0x0343,
  4452. kparen: 0x24A6,
  4453. kpasquare: 0x33AA,
  4454. ksicyrillic: 0x046F,
  4455. ktsquare: 0x33CF,
  4456. kturned: 0x029E,
  4457. kuhiragana: 0x304F,
  4458. kukatakana: 0x30AF,
  4459. kukatakanahalfwidth: 0xFF78,
  4460. kvsquare: 0x33B8,
  4461. kwsquare: 0x33BE,
  4462. l: 0x006C,
  4463. labengali: 0x09B2,
  4464. lacute: 0x013A,
  4465. ladeva: 0x0932,
  4466. lagujarati: 0x0AB2,
  4467. lagurmukhi: 0x0A32,
  4468. lakkhangyaothai: 0x0E45,
  4469. lamaleffinalarabic: 0xFEFC,
  4470. lamalefhamzaabovefinalarabic: 0xFEF8,
  4471. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  4472. lamalefhamzabelowfinalarabic: 0xFEFA,
  4473. lamalefhamzabelowisolatedarabic: 0xFEF9,
  4474. lamalefisolatedarabic: 0xFEFB,
  4475. lamalefmaddaabovefinalarabic: 0xFEF6,
  4476. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  4477. lamarabic: 0x0644,
  4478. lambda: 0x03BB,
  4479. lambdastroke: 0x019B,
  4480. lamed: 0x05DC,
  4481. lameddagesh: 0xFB3C,
  4482. lameddageshhebrew: 0xFB3C,
  4483. lamedhebrew: 0x05DC,
  4484. lamfinalarabic: 0xFEDE,
  4485. lamhahinitialarabic: 0xFCCA,
  4486. laminitialarabic: 0xFEDF,
  4487. lamjeeminitialarabic: 0xFCC9,
  4488. lamkhahinitialarabic: 0xFCCB,
  4489. lamlamhehisolatedarabic: 0xFDF2,
  4490. lammedialarabic: 0xFEE0,
  4491. lammeemhahinitialarabic: 0xFD88,
  4492. lammeeminitialarabic: 0xFCCC,
  4493. largecircle: 0x25EF,
  4494. lbar: 0x019A,
  4495. lbelt: 0x026C,
  4496. lbopomofo: 0x310C,
  4497. lcaron: 0x013E,
  4498. lcedilla: 0x013C,
  4499. lcircle: 0x24DB,
  4500. lcircumflexbelow: 0x1E3D,
  4501. lcommaaccent: 0x013C,
  4502. ldot: 0x0140,
  4503. ldotaccent: 0x0140,
  4504. ldotbelow: 0x1E37,
  4505. ldotbelowmacron: 0x1E39,
  4506. leftangleabovecmb: 0x031A,
  4507. lefttackbelowcmb: 0x0318,
  4508. less: 0x003C,
  4509. lessequal: 0x2264,
  4510. lessequalorgreater: 0x22DA,
  4511. lessmonospace: 0xFF1C,
  4512. lessorequivalent: 0x2272,
  4513. lessorgreater: 0x2276,
  4514. lessoverequal: 0x2266,
  4515. lesssmall: 0xFE64,
  4516. lezh: 0x026E,
  4517. lfblock: 0x258C,
  4518. lhookretroflex: 0x026D,
  4519. lira: 0x20A4,
  4520. liwnarmenian: 0x056C,
  4521. lj: 0x01C9,
  4522. ljecyrillic: 0x0459,
  4523. ll: 0xF6C0,
  4524. lladeva: 0x0933,
  4525. llagujarati: 0x0AB3,
  4526. llinebelow: 0x1E3B,
  4527. llladeva: 0x0934,
  4528. llvocalicbengali: 0x09E1,
  4529. llvocalicdeva: 0x0961,
  4530. llvocalicvowelsignbengali: 0x09E3,
  4531. llvocalicvowelsigndeva: 0x0963,
  4532. lmiddletilde: 0x026B,
  4533. lmonospace: 0xFF4C,
  4534. lmsquare: 0x33D0,
  4535. lochulathai: 0x0E2C,
  4536. logicaland: 0x2227,
  4537. logicalnot: 0x00AC,
  4538. logicalnotreversed: 0x2310,
  4539. logicalor: 0x2228,
  4540. lolingthai: 0x0E25,
  4541. longs: 0x017F,
  4542. lowlinecenterline: 0xFE4E,
  4543. lowlinecmb: 0x0332,
  4544. lowlinedashed: 0xFE4D,
  4545. lozenge: 0x25CA,
  4546. lparen: 0x24A7,
  4547. lslash: 0x0142,
  4548. lsquare: 0x2113,
  4549. lsuperior: 0xF6EE,
  4550. ltshade: 0x2591,
  4551. luthai: 0x0E26,
  4552. lvocalicbengali: 0x098C,
  4553. lvocalicdeva: 0x090C,
  4554. lvocalicvowelsignbengali: 0x09E2,
  4555. lvocalicvowelsigndeva: 0x0962,
  4556. lxsquare: 0x33D3,
  4557. m: 0x006D,
  4558. mabengali: 0x09AE,
  4559. macron: 0x00AF,
  4560. macronbelowcmb: 0x0331,
  4561. macroncmb: 0x0304,
  4562. macronlowmod: 0x02CD,
  4563. macronmonospace: 0xFFE3,
  4564. macute: 0x1E3F,
  4565. madeva: 0x092E,
  4566. magujarati: 0x0AAE,
  4567. magurmukhi: 0x0A2E,
  4568. mahapakhhebrew: 0x05A4,
  4569. mahapakhlefthebrew: 0x05A4,
  4570. mahiragana: 0x307E,
  4571. maichattawalowleftthai: 0xF895,
  4572. maichattawalowrightthai: 0xF894,
  4573. maichattawathai: 0x0E4B,
  4574. maichattawaupperleftthai: 0xF893,
  4575. maieklowleftthai: 0xF88C,
  4576. maieklowrightthai: 0xF88B,
  4577. maiekthai: 0x0E48,
  4578. maiekupperleftthai: 0xF88A,
  4579. maihanakatleftthai: 0xF884,
  4580. maihanakatthai: 0x0E31,
  4581. maitaikhuleftthai: 0xF889,
  4582. maitaikhuthai: 0x0E47,
  4583. maitholowleftthai: 0xF88F,
  4584. maitholowrightthai: 0xF88E,
  4585. maithothai: 0x0E49,
  4586. maithoupperleftthai: 0xF88D,
  4587. maitrilowleftthai: 0xF892,
  4588. maitrilowrightthai: 0xF891,
  4589. maitrithai: 0x0E4A,
  4590. maitriupperleftthai: 0xF890,
  4591. maiyamokthai: 0x0E46,
  4592. makatakana: 0x30DE,
  4593. makatakanahalfwidth: 0xFF8F,
  4594. male: 0x2642,
  4595. mansyonsquare: 0x3347,
  4596. maqafhebrew: 0x05BE,
  4597. mars: 0x2642,
  4598. masoracirclehebrew: 0x05AF,
  4599. masquare: 0x3383,
  4600. mbopomofo: 0x3107,
  4601. mbsquare: 0x33D4,
  4602. mcircle: 0x24DC,
  4603. mcubedsquare: 0x33A5,
  4604. mdotaccent: 0x1E41,
  4605. mdotbelow: 0x1E43,
  4606. meemarabic: 0x0645,
  4607. meemfinalarabic: 0xFEE2,
  4608. meeminitialarabic: 0xFEE3,
  4609. meemmedialarabic: 0xFEE4,
  4610. meemmeeminitialarabic: 0xFCD1,
  4611. meemmeemisolatedarabic: 0xFC48,
  4612. meetorusquare: 0x334D,
  4613. mehiragana: 0x3081,
  4614. meizierasquare: 0x337E,
  4615. mekatakana: 0x30E1,
  4616. mekatakanahalfwidth: 0xFF92,
  4617. mem: 0x05DE,
  4618. memdagesh: 0xFB3E,
  4619. memdageshhebrew: 0xFB3E,
  4620. memhebrew: 0x05DE,
  4621. menarmenian: 0x0574,
  4622. merkhahebrew: 0x05A5,
  4623. merkhakefulahebrew: 0x05A6,
  4624. merkhakefulalefthebrew: 0x05A6,
  4625. merkhalefthebrew: 0x05A5,
  4626. mhook: 0x0271,
  4627. mhzsquare: 0x3392,
  4628. middledotkatakanahalfwidth: 0xFF65,
  4629. middot: 0x00B7,
  4630. mieumacirclekorean: 0x3272,
  4631. mieumaparenkorean: 0x3212,
  4632. mieumcirclekorean: 0x3264,
  4633. mieumkorean: 0x3141,
  4634. mieumpansioskorean: 0x3170,
  4635. mieumparenkorean: 0x3204,
  4636. mieumpieupkorean: 0x316E,
  4637. mieumsioskorean: 0x316F,
  4638. mihiragana: 0x307F,
  4639. mikatakana: 0x30DF,
  4640. mikatakanahalfwidth: 0xFF90,
  4641. minus: 0x2212,
  4642. minusbelowcmb: 0x0320,
  4643. minuscircle: 0x2296,
  4644. minusmod: 0x02D7,
  4645. minusplus: 0x2213,
  4646. minute: 0x2032,
  4647. miribaarusquare: 0x334A,
  4648. mirisquare: 0x3349,
  4649. mlonglegturned: 0x0270,
  4650. mlsquare: 0x3396,
  4651. mmcubedsquare: 0x33A3,
  4652. mmonospace: 0xFF4D,
  4653. mmsquaredsquare: 0x339F,
  4654. mohiragana: 0x3082,
  4655. mohmsquare: 0x33C1,
  4656. mokatakana: 0x30E2,
  4657. mokatakanahalfwidth: 0xFF93,
  4658. molsquare: 0x33D6,
  4659. momathai: 0x0E21,
  4660. moverssquare: 0x33A7,
  4661. moverssquaredsquare: 0x33A8,
  4662. mparen: 0x24A8,
  4663. mpasquare: 0x33AB,
  4664. mssquare: 0x33B3,
  4665. msuperior: 0xF6EF,
  4666. mturned: 0x026F,
  4667. mu: 0x00B5,
  4668. mu1: 0x00B5,
  4669. muasquare: 0x3382,
  4670. muchgreater: 0x226B,
  4671. muchless: 0x226A,
  4672. mufsquare: 0x338C,
  4673. mugreek: 0x03BC,
  4674. mugsquare: 0x338D,
  4675. muhiragana: 0x3080,
  4676. mukatakana: 0x30E0,
  4677. mukatakanahalfwidth: 0xFF91,
  4678. mulsquare: 0x3395,
  4679. multiply: 0x00D7,
  4680. mumsquare: 0x339B,
  4681. munahhebrew: 0x05A3,
  4682. munahlefthebrew: 0x05A3,
  4683. musicalnote: 0x266A,
  4684. musicalnotedbl: 0x266B,
  4685. musicflatsign: 0x266D,
  4686. musicsharpsign: 0x266F,
  4687. mussquare: 0x33B2,
  4688. muvsquare: 0x33B6,
  4689. muwsquare: 0x33BC,
  4690. mvmegasquare: 0x33B9,
  4691. mvsquare: 0x33B7,
  4692. mwmegasquare: 0x33BF,
  4693. mwsquare: 0x33BD,
  4694. n: 0x006E,
  4695. nabengali: 0x09A8,
  4696. nabla: 0x2207,
  4697. nacute: 0x0144,
  4698. nadeva: 0x0928,
  4699. nagujarati: 0x0AA8,
  4700. nagurmukhi: 0x0A28,
  4701. nahiragana: 0x306A,
  4702. nakatakana: 0x30CA,
  4703. nakatakanahalfwidth: 0xFF85,
  4704. napostrophe: 0x0149,
  4705. nasquare: 0x3381,
  4706. nbopomofo: 0x310B,
  4707. nbspace: 0x00A0,
  4708. ncaron: 0x0148,
  4709. ncedilla: 0x0146,
  4710. ncircle: 0x24DD,
  4711. ncircumflexbelow: 0x1E4B,
  4712. ncommaaccent: 0x0146,
  4713. ndotaccent: 0x1E45,
  4714. ndotbelow: 0x1E47,
  4715. nehiragana: 0x306D,
  4716. nekatakana: 0x30CD,
  4717. nekatakanahalfwidth: 0xFF88,
  4718. newsheqelsign: 0x20AA,
  4719. nfsquare: 0x338B,
  4720. ngabengali: 0x0999,
  4721. ngadeva: 0x0919,
  4722. ngagujarati: 0x0A99,
  4723. ngagurmukhi: 0x0A19,
  4724. ngonguthai: 0x0E07,
  4725. nhiragana: 0x3093,
  4726. nhookleft: 0x0272,
  4727. nhookretroflex: 0x0273,
  4728. nieunacirclekorean: 0x326F,
  4729. nieunaparenkorean: 0x320F,
  4730. nieuncieuckorean: 0x3135,
  4731. nieuncirclekorean: 0x3261,
  4732. nieunhieuhkorean: 0x3136,
  4733. nieunkorean: 0x3134,
  4734. nieunpansioskorean: 0x3168,
  4735. nieunparenkorean: 0x3201,
  4736. nieunsioskorean: 0x3167,
  4737. nieuntikeutkorean: 0x3166,
  4738. nihiragana: 0x306B,
  4739. nikatakana: 0x30CB,
  4740. nikatakanahalfwidth: 0xFF86,
  4741. nikhahitleftthai: 0xF899,
  4742. nikhahitthai: 0x0E4D,
  4743. nine: 0x0039,
  4744. ninearabic: 0x0669,
  4745. ninebengali: 0x09EF,
  4746. ninecircle: 0x2468,
  4747. ninecircleinversesansserif: 0x2792,
  4748. ninedeva: 0x096F,
  4749. ninegujarati: 0x0AEF,
  4750. ninegurmukhi: 0x0A6F,
  4751. ninehackarabic: 0x0669,
  4752. ninehangzhou: 0x3029,
  4753. nineideographicparen: 0x3228,
  4754. nineinferior: 0x2089,
  4755. ninemonospace: 0xFF19,
  4756. nineoldstyle: 0xF739,
  4757. nineparen: 0x247C,
  4758. nineperiod: 0x2490,
  4759. ninepersian: 0x06F9,
  4760. nineroman: 0x2178,
  4761. ninesuperior: 0x2079,
  4762. nineteencircle: 0x2472,
  4763. nineteenparen: 0x2486,
  4764. nineteenperiod: 0x249A,
  4765. ninethai: 0x0E59,
  4766. nj: 0x01CC,
  4767. njecyrillic: 0x045A,
  4768. nkatakana: 0x30F3,
  4769. nkatakanahalfwidth: 0xFF9D,
  4770. nlegrightlong: 0x019E,
  4771. nlinebelow: 0x1E49,
  4772. nmonospace: 0xFF4E,
  4773. nmsquare: 0x339A,
  4774. nnabengali: 0x09A3,
  4775. nnadeva: 0x0923,
  4776. nnagujarati: 0x0AA3,
  4777. nnagurmukhi: 0x0A23,
  4778. nnnadeva: 0x0929,
  4779. nohiragana: 0x306E,
  4780. nokatakana: 0x30CE,
  4781. nokatakanahalfwidth: 0xFF89,
  4782. nonbreakingspace: 0x00A0,
  4783. nonenthai: 0x0E13,
  4784. nonuthai: 0x0E19,
  4785. noonarabic: 0x0646,
  4786. noonfinalarabic: 0xFEE6,
  4787. noonghunnaarabic: 0x06BA,
  4788. noonghunnafinalarabic: 0xFB9F,
  4789. nooninitialarabic: 0xFEE7,
  4790. noonjeeminitialarabic: 0xFCD2,
  4791. noonjeemisolatedarabic: 0xFC4B,
  4792. noonmedialarabic: 0xFEE8,
  4793. noonmeeminitialarabic: 0xFCD5,
  4794. noonmeemisolatedarabic: 0xFC4E,
  4795. noonnoonfinalarabic: 0xFC8D,
  4796. notcontains: 0x220C,
  4797. notelement: 0x2209,
  4798. notelementof: 0x2209,
  4799. notequal: 0x2260,
  4800. notgreater: 0x226F,
  4801. notgreaternorequal: 0x2271,
  4802. notgreaternorless: 0x2279,
  4803. notidentical: 0x2262,
  4804. notless: 0x226E,
  4805. notlessnorequal: 0x2270,
  4806. notparallel: 0x2226,
  4807. notprecedes: 0x2280,
  4808. notsubset: 0x2284,
  4809. notsucceeds: 0x2281,
  4810. notsuperset: 0x2285,
  4811. nowarmenian: 0x0576,
  4812. nparen: 0x24A9,
  4813. nssquare: 0x33B1,
  4814. nsuperior: 0x207F,
  4815. ntilde: 0x00F1,
  4816. nu: 0x03BD,
  4817. nuhiragana: 0x306C,
  4818. nukatakana: 0x30CC,
  4819. nukatakanahalfwidth: 0xFF87,
  4820. nuktabengali: 0x09BC,
  4821. nuktadeva: 0x093C,
  4822. nuktagujarati: 0x0ABC,
  4823. nuktagurmukhi: 0x0A3C,
  4824. numbersign: 0x0023,
  4825. numbersignmonospace: 0xFF03,
  4826. numbersignsmall: 0xFE5F,
  4827. numeralsigngreek: 0x0374,
  4828. numeralsignlowergreek: 0x0375,
  4829. numero: 0x2116,
  4830. nun: 0x05E0,
  4831. nundagesh: 0xFB40,
  4832. nundageshhebrew: 0xFB40,
  4833. nunhebrew: 0x05E0,
  4834. nvsquare: 0x33B5,
  4835. nwsquare: 0x33BB,
  4836. nyabengali: 0x099E,
  4837. nyadeva: 0x091E,
  4838. nyagujarati: 0x0A9E,
  4839. nyagurmukhi: 0x0A1E,
  4840. o: 0x006F,
  4841. oacute: 0x00F3,
  4842. oangthai: 0x0E2D,
  4843. obarred: 0x0275,
  4844. obarredcyrillic: 0x04E9,
  4845. obarreddieresiscyrillic: 0x04EB,
  4846. obengali: 0x0993,
  4847. obopomofo: 0x311B,
  4848. obreve: 0x014F,
  4849. ocandradeva: 0x0911,
  4850. ocandragujarati: 0x0A91,
  4851. ocandravowelsigndeva: 0x0949,
  4852. ocandravowelsigngujarati: 0x0AC9,
  4853. ocaron: 0x01D2,
  4854. ocircle: 0x24DE,
  4855. ocircumflex: 0x00F4,
  4856. ocircumflexacute: 0x1ED1,
  4857. ocircumflexdotbelow: 0x1ED9,
  4858. ocircumflexgrave: 0x1ED3,
  4859. ocircumflexhookabove: 0x1ED5,
  4860. ocircumflextilde: 0x1ED7,
  4861. ocyrillic: 0x043E,
  4862. odblacute: 0x0151,
  4863. odblgrave: 0x020D,
  4864. odeva: 0x0913,
  4865. odieresis: 0x00F6,
  4866. odieresiscyrillic: 0x04E7,
  4867. odotbelow: 0x1ECD,
  4868. oe: 0x0153,
  4869. oekorean: 0x315A,
  4870. ogonek: 0x02DB,
  4871. ogonekcmb: 0x0328,
  4872. ograve: 0x00F2,
  4873. ogujarati: 0x0A93,
  4874. oharmenian: 0x0585,
  4875. ohiragana: 0x304A,
  4876. ohookabove: 0x1ECF,
  4877. ohorn: 0x01A1,
  4878. ohornacute: 0x1EDB,
  4879. ohorndotbelow: 0x1EE3,
  4880. ohorngrave: 0x1EDD,
  4881. ohornhookabove: 0x1EDF,
  4882. ohorntilde: 0x1EE1,
  4883. ohungarumlaut: 0x0151,
  4884. oi: 0x01A3,
  4885. oinvertedbreve: 0x020F,
  4886. okatakana: 0x30AA,
  4887. okatakanahalfwidth: 0xFF75,
  4888. okorean: 0x3157,
  4889. olehebrew: 0x05AB,
  4890. omacron: 0x014D,
  4891. omacronacute: 0x1E53,
  4892. omacrongrave: 0x1E51,
  4893. omdeva: 0x0950,
  4894. omega: 0x03C9,
  4895. omega1: 0x03D6,
  4896. omegacyrillic: 0x0461,
  4897. omegalatinclosed: 0x0277,
  4898. omegaroundcyrillic: 0x047B,
  4899. omegatitlocyrillic: 0x047D,
  4900. omegatonos: 0x03CE,
  4901. omgujarati: 0x0AD0,
  4902. omicron: 0x03BF,
  4903. omicrontonos: 0x03CC,
  4904. omonospace: 0xFF4F,
  4905. one: 0x0031,
  4906. onearabic: 0x0661,
  4907. onebengali: 0x09E7,
  4908. onecircle: 0x2460,
  4909. onecircleinversesansserif: 0x278A,
  4910. onedeva: 0x0967,
  4911. onedotenleader: 0x2024,
  4912. oneeighth: 0x215B,
  4913. onefitted: 0xF6DC,
  4914. onegujarati: 0x0AE7,
  4915. onegurmukhi: 0x0A67,
  4916. onehackarabic: 0x0661,
  4917. onehalf: 0x00BD,
  4918. onehangzhou: 0x3021,
  4919. oneideographicparen: 0x3220,
  4920. oneinferior: 0x2081,
  4921. onemonospace: 0xFF11,
  4922. onenumeratorbengali: 0x09F4,
  4923. oneoldstyle: 0xF731,
  4924. oneparen: 0x2474,
  4925. oneperiod: 0x2488,
  4926. onepersian: 0x06F1,
  4927. onequarter: 0x00BC,
  4928. oneroman: 0x2170,
  4929. onesuperior: 0x00B9,
  4930. onethai: 0x0E51,
  4931. onethird: 0x2153,
  4932. oogonek: 0x01EB,
  4933. oogonekmacron: 0x01ED,
  4934. oogurmukhi: 0x0A13,
  4935. oomatragurmukhi: 0x0A4B,
  4936. oopen: 0x0254,
  4937. oparen: 0x24AA,
  4938. openbullet: 0x25E6,
  4939. option: 0x2325,
  4940. ordfeminine: 0x00AA,
  4941. ordmasculine: 0x00BA,
  4942. orthogonal: 0x221F,
  4943. oshortdeva: 0x0912,
  4944. oshortvowelsigndeva: 0x094A,
  4945. oslash: 0x00F8,
  4946. oslashacute: 0x01FF,
  4947. osmallhiragana: 0x3049,
  4948. osmallkatakana: 0x30A9,
  4949. osmallkatakanahalfwidth: 0xFF6B,
  4950. ostrokeacute: 0x01FF,
  4951. osuperior: 0xF6F0,
  4952. otcyrillic: 0x047F,
  4953. otilde: 0x00F5,
  4954. otildeacute: 0x1E4D,
  4955. otildedieresis: 0x1E4F,
  4956. oubopomofo: 0x3121,
  4957. overline: 0x203E,
  4958. overlinecenterline: 0xFE4A,
  4959. overlinecmb: 0x0305,
  4960. overlinedashed: 0xFE49,
  4961. overlinedblwavy: 0xFE4C,
  4962. overlinewavy: 0xFE4B,
  4963. overscore: 0x00AF,
  4964. ovowelsignbengali: 0x09CB,
  4965. ovowelsigndeva: 0x094B,
  4966. ovowelsigngujarati: 0x0ACB,
  4967. p: 0x0070,
  4968. paampssquare: 0x3380,
  4969. paasentosquare: 0x332B,
  4970. pabengali: 0x09AA,
  4971. pacute: 0x1E55,
  4972. padeva: 0x092A,
  4973. pagedown: 0x21DF,
  4974. pageup: 0x21DE,
  4975. pagujarati: 0x0AAA,
  4976. pagurmukhi: 0x0A2A,
  4977. pahiragana: 0x3071,
  4978. paiyannoithai: 0x0E2F,
  4979. pakatakana: 0x30D1,
  4980. palatalizationcyrilliccmb: 0x0484,
  4981. palochkacyrillic: 0x04C0,
  4982. pansioskorean: 0x317F,
  4983. paragraph: 0x00B6,
  4984. parallel: 0x2225,
  4985. parenleft: 0x0028,
  4986. parenleftaltonearabic: 0xFD3E,
  4987. parenleftbt: 0xF8ED,
  4988. parenleftex: 0xF8EC,
  4989. parenleftinferior: 0x208D,
  4990. parenleftmonospace: 0xFF08,
  4991. parenleftsmall: 0xFE59,
  4992. parenleftsuperior: 0x207D,
  4993. parenlefttp: 0xF8EB,
  4994. parenleftvertical: 0xFE35,
  4995. parenright: 0x0029,
  4996. parenrightaltonearabic: 0xFD3F,
  4997. parenrightbt: 0xF8F8,
  4998. parenrightex: 0xF8F7,
  4999. parenrightinferior: 0x208E,
  5000. parenrightmonospace: 0xFF09,
  5001. parenrightsmall: 0xFE5A,
  5002. parenrightsuperior: 0x207E,
  5003. parenrighttp: 0xF8F6,
  5004. parenrightvertical: 0xFE36,
  5005. partialdiff: 0x2202,
  5006. paseqhebrew: 0x05C0,
  5007. pashtahebrew: 0x0599,
  5008. pasquare: 0x33A9,
  5009. patah: 0x05B7,
  5010. patah11: 0x05B7,
  5011. patah1d: 0x05B7,
  5012. patah2a: 0x05B7,
  5013. patahhebrew: 0x05B7,
  5014. patahnarrowhebrew: 0x05B7,
  5015. patahquarterhebrew: 0x05B7,
  5016. patahwidehebrew: 0x05B7,
  5017. pazerhebrew: 0x05A1,
  5018. pbopomofo: 0x3106,
  5019. pcircle: 0x24DF,
  5020. pdotaccent: 0x1E57,
  5021. pe: 0x05E4,
  5022. pecyrillic: 0x043F,
  5023. pedagesh: 0xFB44,
  5024. pedageshhebrew: 0xFB44,
  5025. peezisquare: 0x333B,
  5026. pefinaldageshhebrew: 0xFB43,
  5027. peharabic: 0x067E,
  5028. peharmenian: 0x057A,
  5029. pehebrew: 0x05E4,
  5030. pehfinalarabic: 0xFB57,
  5031. pehinitialarabic: 0xFB58,
  5032. pehiragana: 0x307A,
  5033. pehmedialarabic: 0xFB59,
  5034. pekatakana: 0x30DA,
  5035. pemiddlehookcyrillic: 0x04A7,
  5036. perafehebrew: 0xFB4E,
  5037. percent: 0x0025,
  5038. percentarabic: 0x066A,
  5039. percentmonospace: 0xFF05,
  5040. percentsmall: 0xFE6A,
  5041. period: 0x002E,
  5042. periodarmenian: 0x0589,
  5043. periodcentered: 0x00B7,
  5044. periodhalfwidth: 0xFF61,
  5045. periodinferior: 0xF6E7,
  5046. periodmonospace: 0xFF0E,
  5047. periodsmall: 0xFE52,
  5048. periodsuperior: 0xF6E8,
  5049. perispomenigreekcmb: 0x0342,
  5050. perpendicular: 0x22A5,
  5051. perthousand: 0x2030,
  5052. peseta: 0x20A7,
  5053. pfsquare: 0x338A,
  5054. phabengali: 0x09AB,
  5055. phadeva: 0x092B,
  5056. phagujarati: 0x0AAB,
  5057. phagurmukhi: 0x0A2B,
  5058. phi: 0x03C6,
  5059. phi1: 0x03D5,
  5060. phieuphacirclekorean: 0x327A,
  5061. phieuphaparenkorean: 0x321A,
  5062. phieuphcirclekorean: 0x326C,
  5063. phieuphkorean: 0x314D,
  5064. phieuphparenkorean: 0x320C,
  5065. philatin: 0x0278,
  5066. phinthuthai: 0x0E3A,
  5067. phisymbolgreek: 0x03D5,
  5068. phook: 0x01A5,
  5069. phophanthai: 0x0E1E,
  5070. phophungthai: 0x0E1C,
  5071. phosamphaothai: 0x0E20,
  5072. pi: 0x03C0,
  5073. pieupacirclekorean: 0x3273,
  5074. pieupaparenkorean: 0x3213,
  5075. pieupcieuckorean: 0x3176,
  5076. pieupcirclekorean: 0x3265,
  5077. pieupkiyeokkorean: 0x3172,
  5078. pieupkorean: 0x3142,
  5079. pieupparenkorean: 0x3205,
  5080. pieupsioskiyeokkorean: 0x3174,
  5081. pieupsioskorean: 0x3144,
  5082. pieupsiostikeutkorean: 0x3175,
  5083. pieupthieuthkorean: 0x3177,
  5084. pieuptikeutkorean: 0x3173,
  5085. pihiragana: 0x3074,
  5086. pikatakana: 0x30D4,
  5087. pisymbolgreek: 0x03D6,
  5088. piwrarmenian: 0x0583,
  5089. plus: 0x002B,
  5090. plusbelowcmb: 0x031F,
  5091. pluscircle: 0x2295,
  5092. plusminus: 0x00B1,
  5093. plusmod: 0x02D6,
  5094. plusmonospace: 0xFF0B,
  5095. plussmall: 0xFE62,
  5096. plussuperior: 0x207A,
  5097. pmonospace: 0xFF50,
  5098. pmsquare: 0x33D8,
  5099. pohiragana: 0x307D,
  5100. pointingindexdownwhite: 0x261F,
  5101. pointingindexleftwhite: 0x261C,
  5102. pointingindexrightwhite: 0x261E,
  5103. pointingindexupwhite: 0x261D,
  5104. pokatakana: 0x30DD,
  5105. poplathai: 0x0E1B,
  5106. postalmark: 0x3012,
  5107. postalmarkface: 0x3020,
  5108. pparen: 0x24AB,
  5109. precedes: 0x227A,
  5110. prescription: 0x211E,
  5111. primemod: 0x02B9,
  5112. primereversed: 0x2035,
  5113. product: 0x220F,
  5114. projective: 0x2305,
  5115. prolongedkana: 0x30FC,
  5116. propellor: 0x2318,
  5117. propersubset: 0x2282,
  5118. propersuperset: 0x2283,
  5119. proportion: 0x2237,
  5120. proportional: 0x221D,
  5121. psi: 0x03C8,
  5122. psicyrillic: 0x0471,
  5123. psilipneumatacyrilliccmb: 0x0486,
  5124. pssquare: 0x33B0,
  5125. puhiragana: 0x3077,
  5126. pukatakana: 0x30D7,
  5127. pvsquare: 0x33B4,
  5128. pwsquare: 0x33BA,
  5129. q: 0x0071,
  5130. qadeva: 0x0958,
  5131. qadmahebrew: 0x05A8,
  5132. qafarabic: 0x0642,
  5133. qaffinalarabic: 0xFED6,
  5134. qafinitialarabic: 0xFED7,
  5135. qafmedialarabic: 0xFED8,
  5136. qamats: 0x05B8,
  5137. qamats10: 0x05B8,
  5138. qamats1a: 0x05B8,
  5139. qamats1c: 0x05B8,
  5140. qamats27: 0x05B8,
  5141. qamats29: 0x05B8,
  5142. qamats33: 0x05B8,
  5143. qamatsde: 0x05B8,
  5144. qamatshebrew: 0x05B8,
  5145. qamatsnarrowhebrew: 0x05B8,
  5146. qamatsqatanhebrew: 0x05B8,
  5147. qamatsqatannarrowhebrew: 0x05B8,
  5148. qamatsqatanquarterhebrew: 0x05B8,
  5149. qamatsqatanwidehebrew: 0x05B8,
  5150. qamatsquarterhebrew: 0x05B8,
  5151. qamatswidehebrew: 0x05B8,
  5152. qarneyparahebrew: 0x059F,
  5153. qbopomofo: 0x3111,
  5154. qcircle: 0x24E0,
  5155. qhook: 0x02A0,
  5156. qmonospace: 0xFF51,
  5157. qof: 0x05E7,
  5158. qofdagesh: 0xFB47,
  5159. qofdageshhebrew: 0xFB47,
  5160. qofhebrew: 0x05E7,
  5161. qparen: 0x24AC,
  5162. quarternote: 0x2669,
  5163. qubuts: 0x05BB,
  5164. qubuts18: 0x05BB,
  5165. qubuts25: 0x05BB,
  5166. qubuts31: 0x05BB,
  5167. qubutshebrew: 0x05BB,
  5168. qubutsnarrowhebrew: 0x05BB,
  5169. qubutsquarterhebrew: 0x05BB,
  5170. qubutswidehebrew: 0x05BB,
  5171. question: 0x003F,
  5172. questionarabic: 0x061F,
  5173. questionarmenian: 0x055E,
  5174. questiondown: 0x00BF,
  5175. questiondownsmall: 0xF7BF,
  5176. questiongreek: 0x037E,
  5177. questionmonospace: 0xFF1F,
  5178. questionsmall: 0xF73F,
  5179. quotedbl: 0x0022,
  5180. quotedblbase: 0x201E,
  5181. quotedblleft: 0x201C,
  5182. quotedblmonospace: 0xFF02,
  5183. quotedblprime: 0x301E,
  5184. quotedblprimereversed: 0x301D,
  5185. quotedblright: 0x201D,
  5186. quoteleft: 0x2018,
  5187. quoteleftreversed: 0x201B,
  5188. quotereversed: 0x201B,
  5189. quoteright: 0x2019,
  5190. quoterightn: 0x0149,
  5191. quotesinglbase: 0x201A,
  5192. quotesingle: 0x0027,
  5193. quotesinglemonospace: 0xFF07,
  5194. r: 0x0072,
  5195. raarmenian: 0x057C,
  5196. rabengali: 0x09B0,
  5197. racute: 0x0155,
  5198. radeva: 0x0930,
  5199. radical: 0x221A,
  5200. radicalex: 0xF8E5,
  5201. radoverssquare: 0x33AE,
  5202. radoverssquaredsquare: 0x33AF,
  5203. radsquare: 0x33AD,
  5204. rafe: 0x05BF,
  5205. rafehebrew: 0x05BF,
  5206. ragujarati: 0x0AB0,
  5207. ragurmukhi: 0x0A30,
  5208. rahiragana: 0x3089,
  5209. rakatakana: 0x30E9,
  5210. rakatakanahalfwidth: 0xFF97,
  5211. ralowerdiagonalbengali: 0x09F1,
  5212. ramiddlediagonalbengali: 0x09F0,
  5213. ramshorn: 0x0264,
  5214. ratio: 0x2236,
  5215. rbopomofo: 0x3116,
  5216. rcaron: 0x0159,
  5217. rcedilla: 0x0157,
  5218. rcircle: 0x24E1,
  5219. rcommaaccent: 0x0157,
  5220. rdblgrave: 0x0211,
  5221. rdotaccent: 0x1E59,
  5222. rdotbelow: 0x1E5B,
  5223. rdotbelowmacron: 0x1E5D,
  5224. referencemark: 0x203B,
  5225. reflexsubset: 0x2286,
  5226. reflexsuperset: 0x2287,
  5227. registered: 0x00AE,
  5228. registersans: 0xF8E8,
  5229. registerserif: 0xF6DA,
  5230. reharabic: 0x0631,
  5231. reharmenian: 0x0580,
  5232. rehfinalarabic: 0xFEAE,
  5233. rehiragana: 0x308C,
  5234. rekatakana: 0x30EC,
  5235. rekatakanahalfwidth: 0xFF9A,
  5236. resh: 0x05E8,
  5237. reshdageshhebrew: 0xFB48,
  5238. reshhebrew: 0x05E8,
  5239. reversedtilde: 0x223D,
  5240. reviahebrew: 0x0597,
  5241. reviamugrashhebrew: 0x0597,
  5242. revlogicalnot: 0x2310,
  5243. rfishhook: 0x027E,
  5244. rfishhookreversed: 0x027F,
  5245. rhabengali: 0x09DD,
  5246. rhadeva: 0x095D,
  5247. rho: 0x03C1,
  5248. rhook: 0x027D,
  5249. rhookturned: 0x027B,
  5250. rhookturnedsuperior: 0x02B5,
  5251. rhosymbolgreek: 0x03F1,
  5252. rhotichookmod: 0x02DE,
  5253. rieulacirclekorean: 0x3271,
  5254. rieulaparenkorean: 0x3211,
  5255. rieulcirclekorean: 0x3263,
  5256. rieulhieuhkorean: 0x3140,
  5257. rieulkiyeokkorean: 0x313A,
  5258. rieulkiyeoksioskorean: 0x3169,
  5259. rieulkorean: 0x3139,
  5260. rieulmieumkorean: 0x313B,
  5261. rieulpansioskorean: 0x316C,
  5262. rieulparenkorean: 0x3203,
  5263. rieulphieuphkorean: 0x313F,
  5264. rieulpieupkorean: 0x313C,
  5265. rieulpieupsioskorean: 0x316B,
  5266. rieulsioskorean: 0x313D,
  5267. rieulthieuthkorean: 0x313E,
  5268. rieultikeutkorean: 0x316A,
  5269. rieulyeorinhieuhkorean: 0x316D,
  5270. rightangle: 0x221F,
  5271. righttackbelowcmb: 0x0319,
  5272. righttriangle: 0x22BF,
  5273. rihiragana: 0x308A,
  5274. rikatakana: 0x30EA,
  5275. rikatakanahalfwidth: 0xFF98,
  5276. ring: 0x02DA,
  5277. ringbelowcmb: 0x0325,
  5278. ringcmb: 0x030A,
  5279. ringhalfleft: 0x02BF,
  5280. ringhalfleftarmenian: 0x0559,
  5281. ringhalfleftbelowcmb: 0x031C,
  5282. ringhalfleftcentered: 0x02D3,
  5283. ringhalfright: 0x02BE,
  5284. ringhalfrightbelowcmb: 0x0339,
  5285. ringhalfrightcentered: 0x02D2,
  5286. rinvertedbreve: 0x0213,
  5287. rittorusquare: 0x3351,
  5288. rlinebelow: 0x1E5F,
  5289. rlongleg: 0x027C,
  5290. rlonglegturned: 0x027A,
  5291. rmonospace: 0xFF52,
  5292. rohiragana: 0x308D,
  5293. rokatakana: 0x30ED,
  5294. rokatakanahalfwidth: 0xFF9B,
  5295. roruathai: 0x0E23,
  5296. rparen: 0x24AD,
  5297. rrabengali: 0x09DC,
  5298. rradeva: 0x0931,
  5299. rragurmukhi: 0x0A5C,
  5300. rreharabic: 0x0691,
  5301. rrehfinalarabic: 0xFB8D,
  5302. rrvocalicbengali: 0x09E0,
  5303. rrvocalicdeva: 0x0960,
  5304. rrvocalicgujarati: 0x0AE0,
  5305. rrvocalicvowelsignbengali: 0x09C4,
  5306. rrvocalicvowelsigndeva: 0x0944,
  5307. rrvocalicvowelsigngujarati: 0x0AC4,
  5308. rsuperior: 0xF6F1,
  5309. rtblock: 0x2590,
  5310. rturned: 0x0279,
  5311. rturnedsuperior: 0x02B4,
  5312. ruhiragana: 0x308B,
  5313. rukatakana: 0x30EB,
  5314. rukatakanahalfwidth: 0xFF99,
  5315. rupeemarkbengali: 0x09F2,
  5316. rupeesignbengali: 0x09F3,
  5317. rupiah: 0xF6DD,
  5318. ruthai: 0x0E24,
  5319. rvocalicbengali: 0x098B,
  5320. rvocalicdeva: 0x090B,
  5321. rvocalicgujarati: 0x0A8B,
  5322. rvocalicvowelsignbengali: 0x09C3,
  5323. rvocalicvowelsigndeva: 0x0943,
  5324. rvocalicvowelsigngujarati: 0x0AC3,
  5325. s: 0x0073,
  5326. sabengali: 0x09B8,
  5327. sacute: 0x015B,
  5328. sacutedotaccent: 0x1E65,
  5329. sadarabic: 0x0635,
  5330. sadeva: 0x0938,
  5331. sadfinalarabic: 0xFEBA,
  5332. sadinitialarabic: 0xFEBB,
  5333. sadmedialarabic: 0xFEBC,
  5334. sagujarati: 0x0AB8,
  5335. sagurmukhi: 0x0A38,
  5336. sahiragana: 0x3055,
  5337. sakatakana: 0x30B5,
  5338. sakatakanahalfwidth: 0xFF7B,
  5339. sallallahoualayhewasallamarabic: 0xFDFA,
  5340. samekh: 0x05E1,
  5341. samekhdagesh: 0xFB41,
  5342. samekhdageshhebrew: 0xFB41,
  5343. samekhhebrew: 0x05E1,
  5344. saraaathai: 0x0E32,
  5345. saraaethai: 0x0E41,
  5346. saraaimaimalaithai: 0x0E44,
  5347. saraaimaimuanthai: 0x0E43,
  5348. saraamthai: 0x0E33,
  5349. saraathai: 0x0E30,
  5350. saraethai: 0x0E40,
  5351. saraiileftthai: 0xF886,
  5352. saraiithai: 0x0E35,
  5353. saraileftthai: 0xF885,
  5354. saraithai: 0x0E34,
  5355. saraothai: 0x0E42,
  5356. saraueeleftthai: 0xF888,
  5357. saraueethai: 0x0E37,
  5358. saraueleftthai: 0xF887,
  5359. sarauethai: 0x0E36,
  5360. sarauthai: 0x0E38,
  5361. sarauuthai: 0x0E39,
  5362. sbopomofo: 0x3119,
  5363. scaron: 0x0161,
  5364. scarondotaccent: 0x1E67,
  5365. scedilla: 0x015F,
  5366. schwa: 0x0259,
  5367. schwacyrillic: 0x04D9,
  5368. schwadieresiscyrillic: 0x04DB,
  5369. schwahook: 0x025A,
  5370. scircle: 0x24E2,
  5371. scircumflex: 0x015D,
  5372. scommaaccent: 0x0219,
  5373. sdotaccent: 0x1E61,
  5374. sdotbelow: 0x1E63,
  5375. sdotbelowdotaccent: 0x1E69,
  5376. seagullbelowcmb: 0x033C,
  5377. second: 0x2033,
  5378. secondtonechinese: 0x02CA,
  5379. section: 0x00A7,
  5380. seenarabic: 0x0633,
  5381. seenfinalarabic: 0xFEB2,
  5382. seeninitialarabic: 0xFEB3,
  5383. seenmedialarabic: 0xFEB4,
  5384. segol: 0x05B6,
  5385. segol13: 0x05B6,
  5386. segol1f: 0x05B6,
  5387. segol2c: 0x05B6,
  5388. segolhebrew: 0x05B6,
  5389. segolnarrowhebrew: 0x05B6,
  5390. segolquarterhebrew: 0x05B6,
  5391. segoltahebrew: 0x0592,
  5392. segolwidehebrew: 0x05B6,
  5393. seharmenian: 0x057D,
  5394. sehiragana: 0x305B,
  5395. sekatakana: 0x30BB,
  5396. sekatakanahalfwidth: 0xFF7E,
  5397. semicolon: 0x003B,
  5398. semicolonarabic: 0x061B,
  5399. semicolonmonospace: 0xFF1B,
  5400. semicolonsmall: 0xFE54,
  5401. semivoicedmarkkana: 0x309C,
  5402. semivoicedmarkkanahalfwidth: 0xFF9F,
  5403. sentisquare: 0x3322,
  5404. sentosquare: 0x3323,
  5405. seven: 0x0037,
  5406. sevenarabic: 0x0667,
  5407. sevenbengali: 0x09ED,
  5408. sevencircle: 0x2466,
  5409. sevencircleinversesansserif: 0x2790,
  5410. sevendeva: 0x096D,
  5411. seveneighths: 0x215E,
  5412. sevengujarati: 0x0AED,
  5413. sevengurmukhi: 0x0A6D,
  5414. sevenhackarabic: 0x0667,
  5415. sevenhangzhou: 0x3027,
  5416. sevenideographicparen: 0x3226,
  5417. seveninferior: 0x2087,
  5418. sevenmonospace: 0xFF17,
  5419. sevenoldstyle: 0xF737,
  5420. sevenparen: 0x247A,
  5421. sevenperiod: 0x248E,
  5422. sevenpersian: 0x06F7,
  5423. sevenroman: 0x2176,
  5424. sevensuperior: 0x2077,
  5425. seventeencircle: 0x2470,
  5426. seventeenparen: 0x2484,
  5427. seventeenperiod: 0x2498,
  5428. seventhai: 0x0E57,
  5429. sfthyphen: 0x00AD,
  5430. shaarmenian: 0x0577,
  5431. shabengali: 0x09B6,
  5432. shacyrillic: 0x0448,
  5433. shaddaarabic: 0x0651,
  5434. shaddadammaarabic: 0xFC61,
  5435. shaddadammatanarabic: 0xFC5E,
  5436. shaddafathaarabic: 0xFC60,
  5437. shaddakasraarabic: 0xFC62,
  5438. shaddakasratanarabic: 0xFC5F,
  5439. shade: 0x2592,
  5440. shadedark: 0x2593,
  5441. shadelight: 0x2591,
  5442. shademedium: 0x2592,
  5443. shadeva: 0x0936,
  5444. shagujarati: 0x0AB6,
  5445. shagurmukhi: 0x0A36,
  5446. shalshelethebrew: 0x0593,
  5447. shbopomofo: 0x3115,
  5448. shchacyrillic: 0x0449,
  5449. sheenarabic: 0x0634,
  5450. sheenfinalarabic: 0xFEB6,
  5451. sheeninitialarabic: 0xFEB7,
  5452. sheenmedialarabic: 0xFEB8,
  5453. sheicoptic: 0x03E3,
  5454. sheqel: 0x20AA,
  5455. sheqelhebrew: 0x20AA,
  5456. sheva: 0x05B0,
  5457. sheva115: 0x05B0,
  5458. sheva15: 0x05B0,
  5459. sheva22: 0x05B0,
  5460. sheva2e: 0x05B0,
  5461. shevahebrew: 0x05B0,
  5462. shevanarrowhebrew: 0x05B0,
  5463. shevaquarterhebrew: 0x05B0,
  5464. shevawidehebrew: 0x05B0,
  5465. shhacyrillic: 0x04BB,
  5466. shimacoptic: 0x03ED,
  5467. shin: 0x05E9,
  5468. shindagesh: 0xFB49,
  5469. shindageshhebrew: 0xFB49,
  5470. shindageshshindot: 0xFB2C,
  5471. shindageshshindothebrew: 0xFB2C,
  5472. shindageshsindot: 0xFB2D,
  5473. shindageshsindothebrew: 0xFB2D,
  5474. shindothebrew: 0x05C1,
  5475. shinhebrew: 0x05E9,
  5476. shinshindot: 0xFB2A,
  5477. shinshindothebrew: 0xFB2A,
  5478. shinsindot: 0xFB2B,
  5479. shinsindothebrew: 0xFB2B,
  5480. shook: 0x0282,
  5481. sigma: 0x03C3,
  5482. sigma1: 0x03C2,
  5483. sigmafinal: 0x03C2,
  5484. sigmalunatesymbolgreek: 0x03F2,
  5485. sihiragana: 0x3057,
  5486. sikatakana: 0x30B7,
  5487. sikatakanahalfwidth: 0xFF7C,
  5488. siluqhebrew: 0x05BD,
  5489. siluqlefthebrew: 0x05BD,
  5490. similar: 0x223C,
  5491. sindothebrew: 0x05C2,
  5492. siosacirclekorean: 0x3274,
  5493. siosaparenkorean: 0x3214,
  5494. sioscieuckorean: 0x317E,
  5495. sioscirclekorean: 0x3266,
  5496. sioskiyeokkorean: 0x317A,
  5497. sioskorean: 0x3145,
  5498. siosnieunkorean: 0x317B,
  5499. siosparenkorean: 0x3206,
  5500. siospieupkorean: 0x317D,
  5501. siostikeutkorean: 0x317C,
  5502. six: 0x0036,
  5503. sixarabic: 0x0666,
  5504. sixbengali: 0x09EC,
  5505. sixcircle: 0x2465,
  5506. sixcircleinversesansserif: 0x278F,
  5507. sixdeva: 0x096C,
  5508. sixgujarati: 0x0AEC,
  5509. sixgurmukhi: 0x0A6C,
  5510. sixhackarabic: 0x0666,
  5511. sixhangzhou: 0x3026,
  5512. sixideographicparen: 0x3225,
  5513. sixinferior: 0x2086,
  5514. sixmonospace: 0xFF16,
  5515. sixoldstyle: 0xF736,
  5516. sixparen: 0x2479,
  5517. sixperiod: 0x248D,
  5518. sixpersian: 0x06F6,
  5519. sixroman: 0x2175,
  5520. sixsuperior: 0x2076,
  5521. sixteencircle: 0x246F,
  5522. sixteencurrencydenominatorbengali: 0x09F9,
  5523. sixteenparen: 0x2483,
  5524. sixteenperiod: 0x2497,
  5525. sixthai: 0x0E56,
  5526. slash: 0x002F,
  5527. slashmonospace: 0xFF0F,
  5528. slong: 0x017F,
  5529. slongdotaccent: 0x1E9B,
  5530. smileface: 0x263A,
  5531. smonospace: 0xFF53,
  5532. sofpasuqhebrew: 0x05C3,
  5533. softhyphen: 0x00AD,
  5534. softsigncyrillic: 0x044C,
  5535. sohiragana: 0x305D,
  5536. sokatakana: 0x30BD,
  5537. sokatakanahalfwidth: 0xFF7F,
  5538. soliduslongoverlaycmb: 0x0338,
  5539. solidusshortoverlaycmb: 0x0337,
  5540. sorusithai: 0x0E29,
  5541. sosalathai: 0x0E28,
  5542. sosothai: 0x0E0B,
  5543. sosuathai: 0x0E2A,
  5544. space: 0x0020,
  5545. spacehackarabic: 0x0020,
  5546. spade: 0x2660,
  5547. spadesuitblack: 0x2660,
  5548. spadesuitwhite: 0x2664,
  5549. sparen: 0x24AE,
  5550. squarebelowcmb: 0x033B,
  5551. squarecc: 0x33C4,
  5552. squarecm: 0x339D,
  5553. squarediagonalcrosshatchfill: 0x25A9,
  5554. squarehorizontalfill: 0x25A4,
  5555. squarekg: 0x338F,
  5556. squarekm: 0x339E,
  5557. squarekmcapital: 0x33CE,
  5558. squareln: 0x33D1,
  5559. squarelog: 0x33D2,
  5560. squaremg: 0x338E,
  5561. squaremil: 0x33D5,
  5562. squaremm: 0x339C,
  5563. squaremsquared: 0x33A1,
  5564. squareorthogonalcrosshatchfill: 0x25A6,
  5565. squareupperlefttolowerrightfill: 0x25A7,
  5566. squareupperrighttolowerleftfill: 0x25A8,
  5567. squareverticalfill: 0x25A5,
  5568. squarewhitewithsmallblack: 0x25A3,
  5569. srsquare: 0x33DB,
  5570. ssabengali: 0x09B7,
  5571. ssadeva: 0x0937,
  5572. ssagujarati: 0x0AB7,
  5573. ssangcieuckorean: 0x3149,
  5574. ssanghieuhkorean: 0x3185,
  5575. ssangieungkorean: 0x3180,
  5576. ssangkiyeokkorean: 0x3132,
  5577. ssangnieunkorean: 0x3165,
  5578. ssangpieupkorean: 0x3143,
  5579. ssangsioskorean: 0x3146,
  5580. ssangtikeutkorean: 0x3138,
  5581. ssuperior: 0xF6F2,
  5582. sterling: 0x00A3,
  5583. sterlingmonospace: 0xFFE1,
  5584. strokelongoverlaycmb: 0x0336,
  5585. strokeshortoverlaycmb: 0x0335,
  5586. subset: 0x2282,
  5587. subsetnotequal: 0x228A,
  5588. subsetorequal: 0x2286,
  5589. succeeds: 0x227B,
  5590. suchthat: 0x220B,
  5591. suhiragana: 0x3059,
  5592. sukatakana: 0x30B9,
  5593. sukatakanahalfwidth: 0xFF7D,
  5594. sukunarabic: 0x0652,
  5595. summation: 0x2211,
  5596. sun: 0x263C,
  5597. superset: 0x2283,
  5598. supersetnotequal: 0x228B,
  5599. supersetorequal: 0x2287,
  5600. svsquare: 0x33DC,
  5601. syouwaerasquare: 0x337C,
  5602. t: 0x0074,
  5603. tabengali: 0x09A4,
  5604. tackdown: 0x22A4,
  5605. tackleft: 0x22A3,
  5606. tadeva: 0x0924,
  5607. tagujarati: 0x0AA4,
  5608. tagurmukhi: 0x0A24,
  5609. taharabic: 0x0637,
  5610. tahfinalarabic: 0xFEC2,
  5611. tahinitialarabic: 0xFEC3,
  5612. tahiragana: 0x305F,
  5613. tahmedialarabic: 0xFEC4,
  5614. taisyouerasquare: 0x337D,
  5615. takatakana: 0x30BF,
  5616. takatakanahalfwidth: 0xFF80,
  5617. tatweelarabic: 0x0640,
  5618. tau: 0x03C4,
  5619. tav: 0x05EA,
  5620. tavdages: 0xFB4A,
  5621. tavdagesh: 0xFB4A,
  5622. tavdageshhebrew: 0xFB4A,
  5623. tavhebrew: 0x05EA,
  5624. tbar: 0x0167,
  5625. tbopomofo: 0x310A,
  5626. tcaron: 0x0165,
  5627. tccurl: 0x02A8,
  5628. tcedilla: 0x0163,
  5629. tcheharabic: 0x0686,
  5630. tchehfinalarabic: 0xFB7B,
  5631. tchehinitialarabic: 0xFB7C,
  5632. tchehmedialarabic: 0xFB7D,
  5633. tcircle: 0x24E3,
  5634. tcircumflexbelow: 0x1E71,
  5635. tcommaaccent: 0x0163,
  5636. tdieresis: 0x1E97,
  5637. tdotaccent: 0x1E6B,
  5638. tdotbelow: 0x1E6D,
  5639. tecyrillic: 0x0442,
  5640. tedescendercyrillic: 0x04AD,
  5641. teharabic: 0x062A,
  5642. tehfinalarabic: 0xFE96,
  5643. tehhahinitialarabic: 0xFCA2,
  5644. tehhahisolatedarabic: 0xFC0C,
  5645. tehinitialarabic: 0xFE97,
  5646. tehiragana: 0x3066,
  5647. tehjeeminitialarabic: 0xFCA1,
  5648. tehjeemisolatedarabic: 0xFC0B,
  5649. tehmarbutaarabic: 0x0629,
  5650. tehmarbutafinalarabic: 0xFE94,
  5651. tehmedialarabic: 0xFE98,
  5652. tehmeeminitialarabic: 0xFCA4,
  5653. tehmeemisolatedarabic: 0xFC0E,
  5654. tehnoonfinalarabic: 0xFC73,
  5655. tekatakana: 0x30C6,
  5656. tekatakanahalfwidth: 0xFF83,
  5657. telephone: 0x2121,
  5658. telephoneblack: 0x260E,
  5659. telishagedolahebrew: 0x05A0,
  5660. telishaqetanahebrew: 0x05A9,
  5661. tencircle: 0x2469,
  5662. tenideographicparen: 0x3229,
  5663. tenparen: 0x247D,
  5664. tenperiod: 0x2491,
  5665. tenroman: 0x2179,
  5666. tesh: 0x02A7,
  5667. tet: 0x05D8,
  5668. tetdagesh: 0xFB38,
  5669. tetdageshhebrew: 0xFB38,
  5670. tethebrew: 0x05D8,
  5671. tetsecyrillic: 0x04B5,
  5672. tevirhebrew: 0x059B,
  5673. tevirlefthebrew: 0x059B,
  5674. thabengali: 0x09A5,
  5675. thadeva: 0x0925,
  5676. thagujarati: 0x0AA5,
  5677. thagurmukhi: 0x0A25,
  5678. thalarabic: 0x0630,
  5679. thalfinalarabic: 0xFEAC,
  5680. thanthakhatlowleftthai: 0xF898,
  5681. thanthakhatlowrightthai: 0xF897,
  5682. thanthakhatthai: 0x0E4C,
  5683. thanthakhatupperleftthai: 0xF896,
  5684. theharabic: 0x062B,
  5685. thehfinalarabic: 0xFE9A,
  5686. thehinitialarabic: 0xFE9B,
  5687. thehmedialarabic: 0xFE9C,
  5688. thereexists: 0x2203,
  5689. therefore: 0x2234,
  5690. theta: 0x03B8,
  5691. theta1: 0x03D1,
  5692. thetasymbolgreek: 0x03D1,
  5693. thieuthacirclekorean: 0x3279,
  5694. thieuthaparenkorean: 0x3219,
  5695. thieuthcirclekorean: 0x326B,
  5696. thieuthkorean: 0x314C,
  5697. thieuthparenkorean: 0x320B,
  5698. thirteencircle: 0x246C,
  5699. thirteenparen: 0x2480,
  5700. thirteenperiod: 0x2494,
  5701. thonangmonthothai: 0x0E11,
  5702. thook: 0x01AD,
  5703. thophuthaothai: 0x0E12,
  5704. thorn: 0x00FE,
  5705. thothahanthai: 0x0E17,
  5706. thothanthai: 0x0E10,
  5707. thothongthai: 0x0E18,
  5708. thothungthai: 0x0E16,
  5709. thousandcyrillic: 0x0482,
  5710. thousandsseparatorarabic: 0x066C,
  5711. thousandsseparatorpersian: 0x066C,
  5712. three: 0x0033,
  5713. threearabic: 0x0663,
  5714. threebengali: 0x09E9,
  5715. threecircle: 0x2462,
  5716. threecircleinversesansserif: 0x278C,
  5717. threedeva: 0x0969,
  5718. threeeighths: 0x215C,
  5719. threegujarati: 0x0AE9,
  5720. threegurmukhi: 0x0A69,
  5721. threehackarabic: 0x0663,
  5722. threehangzhou: 0x3023,
  5723. threeideographicparen: 0x3222,
  5724. threeinferior: 0x2083,
  5725. threemonospace: 0xFF13,
  5726. threenumeratorbengali: 0x09F6,
  5727. threeoldstyle: 0xF733,
  5728. threeparen: 0x2476,
  5729. threeperiod: 0x248A,
  5730. threepersian: 0x06F3,
  5731. threequarters: 0x00BE,
  5732. threequartersemdash: 0xF6DE,
  5733. threeroman: 0x2172,
  5734. threesuperior: 0x00B3,
  5735. threethai: 0x0E53,
  5736. thzsquare: 0x3394,
  5737. tihiragana: 0x3061,
  5738. tikatakana: 0x30C1,
  5739. tikatakanahalfwidth: 0xFF81,
  5740. tikeutacirclekorean: 0x3270,
  5741. tikeutaparenkorean: 0x3210,
  5742. tikeutcirclekorean: 0x3262,
  5743. tikeutkorean: 0x3137,
  5744. tikeutparenkorean: 0x3202,
  5745. tilde: 0x02DC,
  5746. tildebelowcmb: 0x0330,
  5747. tildecmb: 0x0303,
  5748. tildecomb: 0x0303,
  5749. tildedoublecmb: 0x0360,
  5750. tildeoperator: 0x223C,
  5751. tildeoverlaycmb: 0x0334,
  5752. tildeverticalcmb: 0x033E,
  5753. timescircle: 0x2297,
  5754. tipehahebrew: 0x0596,
  5755. tipehalefthebrew: 0x0596,
  5756. tippigurmukhi: 0x0A70,
  5757. titlocyrilliccmb: 0x0483,
  5758. tiwnarmenian: 0x057F,
  5759. tlinebelow: 0x1E6F,
  5760. tmonospace: 0xFF54,
  5761. toarmenian: 0x0569,
  5762. tohiragana: 0x3068,
  5763. tokatakana: 0x30C8,
  5764. tokatakanahalfwidth: 0xFF84,
  5765. tonebarextrahighmod: 0x02E5,
  5766. tonebarextralowmod: 0x02E9,
  5767. tonebarhighmod: 0x02E6,
  5768. tonebarlowmod: 0x02E8,
  5769. tonebarmidmod: 0x02E7,
  5770. tonefive: 0x01BD,
  5771. tonesix: 0x0185,
  5772. tonetwo: 0x01A8,
  5773. tonos: 0x0384,
  5774. tonsquare: 0x3327,
  5775. topatakthai: 0x0E0F,
  5776. tortoiseshellbracketleft: 0x3014,
  5777. tortoiseshellbracketleftsmall: 0xFE5D,
  5778. tortoiseshellbracketleftvertical: 0xFE39,
  5779. tortoiseshellbracketright: 0x3015,
  5780. tortoiseshellbracketrightsmall: 0xFE5E,
  5781. tortoiseshellbracketrightvertical: 0xFE3A,
  5782. totaothai: 0x0E15,
  5783. tpalatalhook: 0x01AB,
  5784. tparen: 0x24AF,
  5785. trademark: 0x2122,
  5786. trademarksans: 0xF8EA,
  5787. trademarkserif: 0xF6DB,
  5788. tretroflexhook: 0x0288,
  5789. triagdn: 0x25BC,
  5790. triaglf: 0x25C4,
  5791. triagrt: 0x25BA,
  5792. triagup: 0x25B2,
  5793. ts: 0x02A6,
  5794. tsadi: 0x05E6,
  5795. tsadidagesh: 0xFB46,
  5796. tsadidageshhebrew: 0xFB46,
  5797. tsadihebrew: 0x05E6,
  5798. tsecyrillic: 0x0446,
  5799. tsere: 0x05B5,
  5800. tsere12: 0x05B5,
  5801. tsere1e: 0x05B5,
  5802. tsere2b: 0x05B5,
  5803. tserehebrew: 0x05B5,
  5804. tserenarrowhebrew: 0x05B5,
  5805. tserequarterhebrew: 0x05B5,
  5806. tserewidehebrew: 0x05B5,
  5807. tshecyrillic: 0x045B,
  5808. tsuperior: 0xF6F3,
  5809. ttabengali: 0x099F,
  5810. ttadeva: 0x091F,
  5811. ttagujarati: 0x0A9F,
  5812. ttagurmukhi: 0x0A1F,
  5813. tteharabic: 0x0679,
  5814. ttehfinalarabic: 0xFB67,
  5815. ttehinitialarabic: 0xFB68,
  5816. ttehmedialarabic: 0xFB69,
  5817. tthabengali: 0x09A0,
  5818. tthadeva: 0x0920,
  5819. tthagujarati: 0x0AA0,
  5820. tthagurmukhi: 0x0A20,
  5821. tturned: 0x0287,
  5822. tuhiragana: 0x3064,
  5823. tukatakana: 0x30C4,
  5824. tukatakanahalfwidth: 0xFF82,
  5825. tusmallhiragana: 0x3063,
  5826. tusmallkatakana: 0x30C3,
  5827. tusmallkatakanahalfwidth: 0xFF6F,
  5828. twelvecircle: 0x246B,
  5829. twelveparen: 0x247F,
  5830. twelveperiod: 0x2493,
  5831. twelveroman: 0x217B,
  5832. twentycircle: 0x2473,
  5833. twentyhangzhou: 0x5344,
  5834. twentyparen: 0x2487,
  5835. twentyperiod: 0x249B,
  5836. two: 0x0032,
  5837. twoarabic: 0x0662,
  5838. twobengali: 0x09E8,
  5839. twocircle: 0x2461,
  5840. twocircleinversesansserif: 0x278B,
  5841. twodeva: 0x0968,
  5842. twodotenleader: 0x2025,
  5843. twodotleader: 0x2025,
  5844. twodotleadervertical: 0xFE30,
  5845. twogujarati: 0x0AE8,
  5846. twogurmukhi: 0x0A68,
  5847. twohackarabic: 0x0662,
  5848. twohangzhou: 0x3022,
  5849. twoideographicparen: 0x3221,
  5850. twoinferior: 0x2082,
  5851. twomonospace: 0xFF12,
  5852. twonumeratorbengali: 0x09F5,
  5853. twooldstyle: 0xF732,
  5854. twoparen: 0x2475,
  5855. twoperiod: 0x2489,
  5856. twopersian: 0x06F2,
  5857. tworoman: 0x2171,
  5858. twostroke: 0x01BB,
  5859. twosuperior: 0x00B2,
  5860. twothai: 0x0E52,
  5861. twothirds: 0x2154,
  5862. u: 0x0075,
  5863. uacute: 0x00FA,
  5864. ubar: 0x0289,
  5865. ubengali: 0x0989,
  5866. ubopomofo: 0x3128,
  5867. ubreve: 0x016D,
  5868. ucaron: 0x01D4,
  5869. ucircle: 0x24E4,
  5870. ucircumflex: 0x00FB,
  5871. ucircumflexbelow: 0x1E77,
  5872. ucyrillic: 0x0443,
  5873. udattadeva: 0x0951,
  5874. udblacute: 0x0171,
  5875. udblgrave: 0x0215,
  5876. udeva: 0x0909,
  5877. udieresis: 0x00FC,
  5878. udieresisacute: 0x01D8,
  5879. udieresisbelow: 0x1E73,
  5880. udieresiscaron: 0x01DA,
  5881. udieresiscyrillic: 0x04F1,
  5882. udieresisgrave: 0x01DC,
  5883. udieresismacron: 0x01D6,
  5884. udotbelow: 0x1EE5,
  5885. ugrave: 0x00F9,
  5886. ugujarati: 0x0A89,
  5887. ugurmukhi: 0x0A09,
  5888. uhiragana: 0x3046,
  5889. uhookabove: 0x1EE7,
  5890. uhorn: 0x01B0,
  5891. uhornacute: 0x1EE9,
  5892. uhorndotbelow: 0x1EF1,
  5893. uhorngrave: 0x1EEB,
  5894. uhornhookabove: 0x1EED,
  5895. uhorntilde: 0x1EEF,
  5896. uhungarumlaut: 0x0171,
  5897. uhungarumlautcyrillic: 0x04F3,
  5898. uinvertedbreve: 0x0217,
  5899. ukatakana: 0x30A6,
  5900. ukatakanahalfwidth: 0xFF73,
  5901. ukcyrillic: 0x0479,
  5902. ukorean: 0x315C,
  5903. umacron: 0x016B,
  5904. umacroncyrillic: 0x04EF,
  5905. umacrondieresis: 0x1E7B,
  5906. umatragurmukhi: 0x0A41,
  5907. umonospace: 0xFF55,
  5908. underscore: 0x005F,
  5909. underscoredbl: 0x2017,
  5910. underscoremonospace: 0xFF3F,
  5911. underscorevertical: 0xFE33,
  5912. underscorewavy: 0xFE4F,
  5913. union: 0x222A,
  5914. universal: 0x2200,
  5915. uogonek: 0x0173,
  5916. uparen: 0x24B0,
  5917. upblock: 0x2580,
  5918. upperdothebrew: 0x05C4,
  5919. upsilon: 0x03C5,
  5920. upsilondieresis: 0x03CB,
  5921. upsilondieresistonos: 0x03B0,
  5922. upsilonlatin: 0x028A,
  5923. upsilontonos: 0x03CD,
  5924. uptackbelowcmb: 0x031D,
  5925. uptackmod: 0x02D4,
  5926. uragurmukhi: 0x0A73,
  5927. uring: 0x016F,
  5928. ushortcyrillic: 0x045E,
  5929. usmallhiragana: 0x3045,
  5930. usmallkatakana: 0x30A5,
  5931. usmallkatakanahalfwidth: 0xFF69,
  5932. ustraightcyrillic: 0x04AF,
  5933. ustraightstrokecyrillic: 0x04B1,
  5934. utilde: 0x0169,
  5935. utildeacute: 0x1E79,
  5936. utildebelow: 0x1E75,
  5937. uubengali: 0x098A,
  5938. uudeva: 0x090A,
  5939. uugujarati: 0x0A8A,
  5940. uugurmukhi: 0x0A0A,
  5941. uumatragurmukhi: 0x0A42,
  5942. uuvowelsignbengali: 0x09C2,
  5943. uuvowelsigndeva: 0x0942,
  5944. uuvowelsigngujarati: 0x0AC2,
  5945. uvowelsignbengali: 0x09C1,
  5946. uvowelsigndeva: 0x0941,
  5947. uvowelsigngujarati: 0x0AC1,
  5948. v: 0x0076,
  5949. vadeva: 0x0935,
  5950. vagujarati: 0x0AB5,
  5951. vagurmukhi: 0x0A35,
  5952. vakatakana: 0x30F7,
  5953. vav: 0x05D5,
  5954. vavdagesh: 0xFB35,
  5955. vavdagesh65: 0xFB35,
  5956. vavdageshhebrew: 0xFB35,
  5957. vavhebrew: 0x05D5,
  5958. vavholam: 0xFB4B,
  5959. vavholamhebrew: 0xFB4B,
  5960. vavvavhebrew: 0x05F0,
  5961. vavyodhebrew: 0x05F1,
  5962. vcircle: 0x24E5,
  5963. vdotbelow: 0x1E7F,
  5964. vecyrillic: 0x0432,
  5965. veharabic: 0x06A4,
  5966. vehfinalarabic: 0xFB6B,
  5967. vehinitialarabic: 0xFB6C,
  5968. vehmedialarabic: 0xFB6D,
  5969. vekatakana: 0x30F9,
  5970. venus: 0x2640,
  5971. verticalbar: 0x007C,
  5972. verticallineabovecmb: 0x030D,
  5973. verticallinebelowcmb: 0x0329,
  5974. verticallinelowmod: 0x02CC,
  5975. verticallinemod: 0x02C8,
  5976. vewarmenian: 0x057E,
  5977. vhook: 0x028B,
  5978. vikatakana: 0x30F8,
  5979. viramabengali: 0x09CD,
  5980. viramadeva: 0x094D,
  5981. viramagujarati: 0x0ACD,
  5982. visargabengali: 0x0983,
  5983. visargadeva: 0x0903,
  5984. visargagujarati: 0x0A83,
  5985. vmonospace: 0xFF56,
  5986. voarmenian: 0x0578,
  5987. voicediterationhiragana: 0x309E,
  5988. voicediterationkatakana: 0x30FE,
  5989. voicedmarkkana: 0x309B,
  5990. voicedmarkkanahalfwidth: 0xFF9E,
  5991. vokatakana: 0x30FA,
  5992. vparen: 0x24B1,
  5993. vtilde: 0x1E7D,
  5994. vturned: 0x028C,
  5995. vuhiragana: 0x3094,
  5996. vukatakana: 0x30F4,
  5997. w: 0x0077,
  5998. wacute: 0x1E83,
  5999. waekorean: 0x3159,
  6000. wahiragana: 0x308F,
  6001. wakatakana: 0x30EF,
  6002. wakatakanahalfwidth: 0xFF9C,
  6003. wakorean: 0x3158,
  6004. wasmallhiragana: 0x308E,
  6005. wasmallkatakana: 0x30EE,
  6006. wattosquare: 0x3357,
  6007. wavedash: 0x301C,
  6008. wavyunderscorevertical: 0xFE34,
  6009. wawarabic: 0x0648,
  6010. wawfinalarabic: 0xFEEE,
  6011. wawhamzaabovearabic: 0x0624,
  6012. wawhamzaabovefinalarabic: 0xFE86,
  6013. wbsquare: 0x33DD,
  6014. wcircle: 0x24E6,
  6015. wcircumflex: 0x0175,
  6016. wdieresis: 0x1E85,
  6017. wdotaccent: 0x1E87,
  6018. wdotbelow: 0x1E89,
  6019. wehiragana: 0x3091,
  6020. weierstrass: 0x2118,
  6021. wekatakana: 0x30F1,
  6022. wekorean: 0x315E,
  6023. weokorean: 0x315D,
  6024. wgrave: 0x1E81,
  6025. whitebullet: 0x25E6,
  6026. whitecircle: 0x25CB,
  6027. whitecircleinverse: 0x25D9,
  6028. whitecornerbracketleft: 0x300E,
  6029. whitecornerbracketleftvertical: 0xFE43,
  6030. whitecornerbracketright: 0x300F,
  6031. whitecornerbracketrightvertical: 0xFE44,
  6032. whitediamond: 0x25C7,
  6033. whitediamondcontainingblacksmalldiamond: 0x25C8,
  6034. whitedownpointingsmalltriangle: 0x25BF,
  6035. whitedownpointingtriangle: 0x25BD,
  6036. whiteleftpointingsmalltriangle: 0x25C3,
  6037. whiteleftpointingtriangle: 0x25C1,
  6038. whitelenticularbracketleft: 0x3016,
  6039. whitelenticularbracketright: 0x3017,
  6040. whiterightpointingsmalltriangle: 0x25B9,
  6041. whiterightpointingtriangle: 0x25B7,
  6042. whitesmallsquare: 0x25AB,
  6043. whitesmilingface: 0x263A,
  6044. whitesquare: 0x25A1,
  6045. whitestar: 0x2606,
  6046. whitetelephone: 0x260F,
  6047. whitetortoiseshellbracketleft: 0x3018,
  6048. whitetortoiseshellbracketright: 0x3019,
  6049. whiteuppointingsmalltriangle: 0x25B5,
  6050. whiteuppointingtriangle: 0x25B3,
  6051. wihiragana: 0x3090,
  6052. wikatakana: 0x30F0,
  6053. wikorean: 0x315F,
  6054. wmonospace: 0xFF57,
  6055. wohiragana: 0x3092,
  6056. wokatakana: 0x30F2,
  6057. wokatakanahalfwidth: 0xFF66,
  6058. won: 0x20A9,
  6059. wonmonospace: 0xFFE6,
  6060. wowaenthai: 0x0E27,
  6061. wparen: 0x24B2,
  6062. wring: 0x1E98,
  6063. wsuperior: 0x02B7,
  6064. wturned: 0x028D,
  6065. wynn: 0x01BF,
  6066. x: 0x0078,
  6067. xabovecmb: 0x033D,
  6068. xbopomofo: 0x3112,
  6069. xcircle: 0x24E7,
  6070. xdieresis: 0x1E8D,
  6071. xdotaccent: 0x1E8B,
  6072. xeharmenian: 0x056D,
  6073. xi: 0x03BE,
  6074. xmonospace: 0xFF58,
  6075. xparen: 0x24B3,
  6076. xsuperior: 0x02E3,
  6077. y: 0x0079,
  6078. yaadosquare: 0x334E,
  6079. yabengali: 0x09AF,
  6080. yacute: 0x00FD,
  6081. yadeva: 0x092F,
  6082. yaekorean: 0x3152,
  6083. yagujarati: 0x0AAF,
  6084. yagurmukhi: 0x0A2F,
  6085. yahiragana: 0x3084,
  6086. yakatakana: 0x30E4,
  6087. yakatakanahalfwidth: 0xFF94,
  6088. yakorean: 0x3151,
  6089. yamakkanthai: 0x0E4E,
  6090. yasmallhiragana: 0x3083,
  6091. yasmallkatakana: 0x30E3,
  6092. yasmallkatakanahalfwidth: 0xFF6C,
  6093. yatcyrillic: 0x0463,
  6094. ycircle: 0x24E8,
  6095. ycircumflex: 0x0177,
  6096. ydieresis: 0x00FF,
  6097. ydotaccent: 0x1E8F,
  6098. ydotbelow: 0x1EF5,
  6099. yeharabic: 0x064A,
  6100. yehbarreearabic: 0x06D2,
  6101. yehbarreefinalarabic: 0xFBAF,
  6102. yehfinalarabic: 0xFEF2,
  6103. yehhamzaabovearabic: 0x0626,
  6104. yehhamzaabovefinalarabic: 0xFE8A,
  6105. yehhamzaaboveinitialarabic: 0xFE8B,
  6106. yehhamzaabovemedialarabic: 0xFE8C,
  6107. yehinitialarabic: 0xFEF3,
  6108. yehmedialarabic: 0xFEF4,
  6109. yehmeeminitialarabic: 0xFCDD,
  6110. yehmeemisolatedarabic: 0xFC58,
  6111. yehnoonfinalarabic: 0xFC94,
  6112. yehthreedotsbelowarabic: 0x06D1,
  6113. yekorean: 0x3156,
  6114. yen: 0x00A5,
  6115. yenmonospace: 0xFFE5,
  6116. yeokorean: 0x3155,
  6117. yeorinhieuhkorean: 0x3186,
  6118. yerahbenyomohebrew: 0x05AA,
  6119. yerahbenyomolefthebrew: 0x05AA,
  6120. yericyrillic: 0x044B,
  6121. yerudieresiscyrillic: 0x04F9,
  6122. yesieungkorean: 0x3181,
  6123. yesieungpansioskorean: 0x3183,
  6124. yesieungsioskorean: 0x3182,
  6125. yetivhebrew: 0x059A,
  6126. ygrave: 0x1EF3,
  6127. yhook: 0x01B4,
  6128. yhookabove: 0x1EF7,
  6129. yiarmenian: 0x0575,
  6130. yicyrillic: 0x0457,
  6131. yikorean: 0x3162,
  6132. yinyang: 0x262F,
  6133. yiwnarmenian: 0x0582,
  6134. ymonospace: 0xFF59,
  6135. yod: 0x05D9,
  6136. yoddagesh: 0xFB39,
  6137. yoddageshhebrew: 0xFB39,
  6138. yodhebrew: 0x05D9,
  6139. yodyodhebrew: 0x05F2,
  6140. yodyodpatahhebrew: 0xFB1F,
  6141. yohiragana: 0x3088,
  6142. yoikorean: 0x3189,
  6143. yokatakana: 0x30E8,
  6144. yokatakanahalfwidth: 0xFF96,
  6145. yokorean: 0x315B,
  6146. yosmallhiragana: 0x3087,
  6147. yosmallkatakana: 0x30E7,
  6148. yosmallkatakanahalfwidth: 0xFF6E,
  6149. yotgreek: 0x03F3,
  6150. yoyaekorean: 0x3188,
  6151. yoyakorean: 0x3187,
  6152. yoyakthai: 0x0E22,
  6153. yoyingthai: 0x0E0D,
  6154. yparen: 0x24B4,
  6155. ypogegrammeni: 0x037A,
  6156. ypogegrammenigreekcmb: 0x0345,
  6157. yr: 0x01A6,
  6158. yring: 0x1E99,
  6159. ysuperior: 0x02B8,
  6160. ytilde: 0x1EF9,
  6161. yturned: 0x028E,
  6162. yuhiragana: 0x3086,
  6163. yuikorean: 0x318C,
  6164. yukatakana: 0x30E6,
  6165. yukatakanahalfwidth: 0xFF95,
  6166. yukorean: 0x3160,
  6167. yusbigcyrillic: 0x046B,
  6168. yusbigiotifiedcyrillic: 0x046D,
  6169. yuslittlecyrillic: 0x0467,
  6170. yuslittleiotifiedcyrillic: 0x0469,
  6171. yusmallhiragana: 0x3085,
  6172. yusmallkatakana: 0x30E5,
  6173. yusmallkatakanahalfwidth: 0xFF6D,
  6174. yuyekorean: 0x318B,
  6175. yuyeokorean: 0x318A,
  6176. yyabengali: 0x09DF,
  6177. yyadeva: 0x095F,
  6178. z: 0x007A,
  6179. zaarmenian: 0x0566,
  6180. zacute: 0x017A,
  6181. zadeva: 0x095B,
  6182. zagurmukhi: 0x0A5B,
  6183. zaharabic: 0x0638,
  6184. zahfinalarabic: 0xFEC6,
  6185. zahinitialarabic: 0xFEC7,
  6186. zahiragana: 0x3056,
  6187. zahmedialarabic: 0xFEC8,
  6188. zainarabic: 0x0632,
  6189. zainfinalarabic: 0xFEB0,
  6190. zakatakana: 0x30B6,
  6191. zaqefgadolhebrew: 0x0595,
  6192. zaqefqatanhebrew: 0x0594,
  6193. zarqahebrew: 0x0598,
  6194. zayin: 0x05D6,
  6195. zayindagesh: 0xFB36,
  6196. zayindageshhebrew: 0xFB36,
  6197. zayinhebrew: 0x05D6,
  6198. zbopomofo: 0x3117,
  6199. zcaron: 0x017E,
  6200. zcircle: 0x24E9,
  6201. zcircumflex: 0x1E91,
  6202. zcurl: 0x0291,
  6203. zdot: 0x017C,
  6204. zdotaccent: 0x017C,
  6205. zdotbelow: 0x1E93,
  6206. zecyrillic: 0x0437,
  6207. zedescendercyrillic: 0x0499,
  6208. zedieresiscyrillic: 0x04DF,
  6209. zehiragana: 0x305C,
  6210. zekatakana: 0x30BC,
  6211. zero: 0x0030,
  6212. zeroarabic: 0x0660,
  6213. zerobengali: 0x09E6,
  6214. zerodeva: 0x0966,
  6215. zerogujarati: 0x0AE6,
  6216. zerogurmukhi: 0x0A66,
  6217. zerohackarabic: 0x0660,
  6218. zeroinferior: 0x2080,
  6219. zeromonospace: 0xFF10,
  6220. zerooldstyle: 0xF730,
  6221. zeropersian: 0x06F0,
  6222. zerosuperior: 0x2070,
  6223. zerothai: 0x0E50,
  6224. zerowidthjoiner: 0xFEFF,
  6225. zerowidthnonjoiner: 0x200C,
  6226. zerowidthspace: 0x200B,
  6227. zeta: 0x03B6,
  6228. zhbopomofo: 0x3113,
  6229. zhearmenian: 0x056A,
  6230. zhebrevecyrillic: 0x04C2,
  6231. zhecyrillic: 0x0436,
  6232. zhedescendercyrillic: 0x0497,
  6233. zhedieresiscyrillic: 0x04DD,
  6234. zihiragana: 0x3058,
  6235. zikatakana: 0x30B8,
  6236. zinorhebrew: 0x05AE,
  6237. zlinebelow: 0x1E95,
  6238. zmonospace: 0xFF5A,
  6239. zohiragana: 0x305E,
  6240. zokatakana: 0x30BE,
  6241. zparen: 0x24B5,
  6242. zretroflexhook: 0x0290,
  6243. zstroke: 0x01B6,
  6244. zuhiragana: 0x305A,
  6245. zukatakana: 0x30BA,
  6246. '.notdef': 0x0000
  6247. };
  6248. var DingbatsGlyphsUnicode = {
  6249. space: 0x0020,
  6250. a1: 0x2701,
  6251. a2: 0x2702,
  6252. a202: 0x2703,
  6253. a3: 0x2704,
  6254. a4: 0x260E,
  6255. a5: 0x2706,
  6256. a119: 0x2707,
  6257. a118: 0x2708,
  6258. a117: 0x2709,
  6259. a11: 0x261B,
  6260. a12: 0x261E,
  6261. a13: 0x270C,
  6262. a14: 0x270D,
  6263. a15: 0x270E,
  6264. a16: 0x270F,
  6265. a105: 0x2710,
  6266. a17: 0x2711,
  6267. a18: 0x2712,
  6268. a19: 0x2713,
  6269. a20: 0x2714,
  6270. a21: 0x2715,
  6271. a22: 0x2716,
  6272. a23: 0x2717,
  6273. a24: 0x2718,
  6274. a25: 0x2719,
  6275. a26: 0x271A,
  6276. a27: 0x271B,
  6277. a28: 0x271C,
  6278. a6: 0x271D,
  6279. a7: 0x271E,
  6280. a8: 0x271F,
  6281. a9: 0x2720,
  6282. a10: 0x2721,
  6283. a29: 0x2722,
  6284. a30: 0x2723,
  6285. a31: 0x2724,
  6286. a32: 0x2725,
  6287. a33: 0x2726,
  6288. a34: 0x2727,
  6289. a35: 0x2605,
  6290. a36: 0x2729,
  6291. a37: 0x272A,
  6292. a38: 0x272B,
  6293. a39: 0x272C,
  6294. a40: 0x272D,
  6295. a41: 0x272E,
  6296. a42: 0x272F,
  6297. a43: 0x2730,
  6298. a44: 0x2731,
  6299. a45: 0x2732,
  6300. a46: 0x2733,
  6301. a47: 0x2734,
  6302. a48: 0x2735,
  6303. a49: 0x2736,
  6304. a50: 0x2737,
  6305. a51: 0x2738,
  6306. a52: 0x2739,
  6307. a53: 0x273A,
  6308. a54: 0x273B,
  6309. a55: 0x273C,
  6310. a56: 0x273D,
  6311. a57: 0x273E,
  6312. a58: 0x273F,
  6313. a59: 0x2740,
  6314. a60: 0x2741,
  6315. a61: 0x2742,
  6316. a62: 0x2743,
  6317. a63: 0x2744,
  6318. a64: 0x2745,
  6319. a65: 0x2746,
  6320. a66: 0x2747,
  6321. a67: 0x2748,
  6322. a68: 0x2749,
  6323. a69: 0x274A,
  6324. a70: 0x274B,
  6325. a71: 0x25CF,
  6326. a72: 0x274D,
  6327. a73: 0x25A0,
  6328. a74: 0x274F,
  6329. a203: 0x2750,
  6330. a75: 0x2751,
  6331. a204: 0x2752,
  6332. a76: 0x25B2,
  6333. a77: 0x25BC,
  6334. a78: 0x25C6,
  6335. a79: 0x2756,
  6336. a81: 0x25D7,
  6337. a82: 0x2758,
  6338. a83: 0x2759,
  6339. a84: 0x275A,
  6340. a97: 0x275B,
  6341. a98: 0x275C,
  6342. a99: 0x275D,
  6343. a100: 0x275E,
  6344. a101: 0x2761,
  6345. a102: 0x2762,
  6346. a103: 0x2763,
  6347. a104: 0x2764,
  6348. a106: 0x2765,
  6349. a107: 0x2766,
  6350. a108: 0x2767,
  6351. a112: 0x2663,
  6352. a111: 0x2666,
  6353. a110: 0x2665,
  6354. a109: 0x2660,
  6355. a120: 0x2460,
  6356. a121: 0x2461,
  6357. a122: 0x2462,
  6358. a123: 0x2463,
  6359. a124: 0x2464,
  6360. a125: 0x2465,
  6361. a126: 0x2466,
  6362. a127: 0x2467,
  6363. a128: 0x2468,
  6364. a129: 0x2469,
  6365. a130: 0x2776,
  6366. a131: 0x2777,
  6367. a132: 0x2778,
  6368. a133: 0x2779,
  6369. a134: 0x277A,
  6370. a135: 0x277B,
  6371. a136: 0x277C,
  6372. a137: 0x277D,
  6373. a138: 0x277E,
  6374. a139: 0x277F,
  6375. a140: 0x2780,
  6376. a141: 0x2781,
  6377. a142: 0x2782,
  6378. a143: 0x2783,
  6379. a144: 0x2784,
  6380. a145: 0x2785,
  6381. a146: 0x2786,
  6382. a147: 0x2787,
  6383. a148: 0x2788,
  6384. a149: 0x2789,
  6385. a150: 0x278A,
  6386. a151: 0x278B,
  6387. a152: 0x278C,
  6388. a153: 0x278D,
  6389. a154: 0x278E,
  6390. a155: 0x278F,
  6391. a156: 0x2790,
  6392. a157: 0x2791,
  6393. a158: 0x2792,
  6394. a159: 0x2793,
  6395. a160: 0x2794,
  6396. a161: 0x2192,
  6397. a163: 0x2194,
  6398. a164: 0x2195,
  6399. a196: 0x2798,
  6400. a165: 0x2799,
  6401. a192: 0x279A,
  6402. a166: 0x279B,
  6403. a167: 0x279C,
  6404. a168: 0x279D,
  6405. a169: 0x279E,
  6406. a170: 0x279F,
  6407. a171: 0x27A0,
  6408. a172: 0x27A1,
  6409. a173: 0x27A2,
  6410. a162: 0x27A3,
  6411. a174: 0x27A4,
  6412. a175: 0x27A5,
  6413. a176: 0x27A6,
  6414. a177: 0x27A7,
  6415. a178: 0x27A8,
  6416. a179: 0x27A9,
  6417. a193: 0x27AA,
  6418. a180: 0x27AB,
  6419. a199: 0x27AC,
  6420. a181: 0x27AD,
  6421. a200: 0x27AE,
  6422. a182: 0x27AF,
  6423. a201: 0x27B1,
  6424. a183: 0x27B2,
  6425. a184: 0x27B3,
  6426. a197: 0x27B4,
  6427. a185: 0x27B5,
  6428. a194: 0x27B6,
  6429. a198: 0x27B7,
  6430. a186: 0x27B8,
  6431. a195: 0x27B9,
  6432. a187: 0x27BA,
  6433. a188: 0x27BB,
  6434. a189: 0x27BC,
  6435. a190: 0x27BD,
  6436. a191: 0x27BE,
  6437. a89: 0x2768, // 0xF8D7
  6438. a90: 0x2769, // 0xF8D8
  6439. a93: 0x276A, // 0xF8D9
  6440. a94: 0x276B, // 0xF8DA
  6441. a91: 0x276C, // 0xF8DB
  6442. a92: 0x276D, // 0xF8DC
  6443. a205: 0x276E, // 0xF8DD
  6444. a85: 0x276F, // 0xF8DE
  6445. a206: 0x2770, // 0xF8DF
  6446. a86: 0x2771, // 0xF8E0
  6447. a87: 0x2772, // 0xF8E1
  6448. a88: 0x2773, // 0xF8E2
  6449. a95: 0x2774, // 0xF8E3
  6450. a96: 0x2775, // 0xF8E4
  6451. '.notdef': 0x0000
  6452. };
  6453. exports.GlyphsUnicode = GlyphsUnicode;
  6454. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  6455. }));
  6456. (function (root, factory) {
  6457. {
  6458. factory((root.pdfjsCoreJpg = {}));
  6459. }
  6460. }(this, function (exports) {
  6461. /*
  6462. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  6463. version was created by github user notmasteryet
  6464. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  6465. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  6466. - The JFIF specification can be found in the JPEG File Interchange Format
  6467. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  6468. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  6469. in PostScript Level 2, Technical Note #5116
  6470. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  6471. */
  6472. var JpegImage = (function jpegImage() {
  6473. var dctZigZag = new Uint8Array([
  6474. 0,
  6475. 1, 8,
  6476. 16, 9, 2,
  6477. 3, 10, 17, 24,
  6478. 32, 25, 18, 11, 4,
  6479. 5, 12, 19, 26, 33, 40,
  6480. 48, 41, 34, 27, 20, 13, 6,
  6481. 7, 14, 21, 28, 35, 42, 49, 56,
  6482. 57, 50, 43, 36, 29, 22, 15,
  6483. 23, 30, 37, 44, 51, 58,
  6484. 59, 52, 45, 38, 31,
  6485. 39, 46, 53, 60,
  6486. 61, 54, 47,
  6487. 55, 62,
  6488. 63
  6489. ]);
  6490. var dctCos1 = 4017; // cos(pi/16)
  6491. var dctSin1 = 799; // sin(pi/16)
  6492. var dctCos3 = 3406; // cos(3*pi/16)
  6493. var dctSin3 = 2276; // sin(3*pi/16)
  6494. var dctCos6 = 1567; // cos(6*pi/16)
  6495. var dctSin6 = 3784; // sin(6*pi/16)
  6496. var dctSqrt2 = 5793; // sqrt(2)
  6497. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  6498. function constructor() {
  6499. }
  6500. function buildHuffmanTable(codeLengths, values) {
  6501. var k = 0, code = [], i, j, length = 16;
  6502. while (length > 0 && !codeLengths[length - 1]) {
  6503. length--;
  6504. }
  6505. code.push({children: [], index: 0});
  6506. var p = code[0], q;
  6507. for (i = 0; i < length; i++) {
  6508. for (j = 0; j < codeLengths[i]; j++) {
  6509. p = code.pop();
  6510. p.children[p.index] = values[k];
  6511. while (p.index > 0) {
  6512. p = code.pop();
  6513. }
  6514. p.index++;
  6515. code.push(p);
  6516. while (code.length <= i) {
  6517. code.push(q = {children: [], index: 0});
  6518. p.children[p.index] = q.children;
  6519. p = q;
  6520. }
  6521. k++;
  6522. }
  6523. if (i + 1 < length) {
  6524. // p here points to last code
  6525. code.push(q = {children: [], index: 0});
  6526. p.children[p.index] = q.children;
  6527. p = q;
  6528. }
  6529. }
  6530. return code[0].children;
  6531. }
  6532. function getBlockBufferOffset(component, row, col) {
  6533. return 64 * ((component.blocksPerLine + 1) * row + col);
  6534. }
  6535. function decodeScan(data, offset, frame, components, resetInterval,
  6536. spectralStart, spectralEnd, successivePrev, successive) {
  6537. var mcusPerLine = frame.mcusPerLine;
  6538. var progressive = frame.progressive;
  6539. var startOffset = offset, bitsData = 0, bitsCount = 0;
  6540. function readBit() {
  6541. if (bitsCount > 0) {
  6542. bitsCount--;
  6543. return (bitsData >> bitsCount) & 1;
  6544. }
  6545. bitsData = data[offset++];
  6546. if (bitsData === 0xFF) {
  6547. var nextByte = data[offset++];
  6548. if (nextByte) {
  6549. throw 'unexpected marker: ' +
  6550. ((bitsData << 8) | nextByte).toString(16);
  6551. }
  6552. // unstuff 0
  6553. }
  6554. bitsCount = 7;
  6555. return bitsData >>> 7;
  6556. }
  6557. function decodeHuffman(tree) {
  6558. var node = tree;
  6559. while (true) {
  6560. node = node[readBit()];
  6561. if (typeof node === 'number') {
  6562. return node;
  6563. }
  6564. if (typeof node !== 'object') {
  6565. throw 'invalid huffman sequence';
  6566. }
  6567. }
  6568. }
  6569. function receive(length) {
  6570. var n = 0;
  6571. while (length > 0) {
  6572. n = (n << 1) | readBit();
  6573. length--;
  6574. }
  6575. return n;
  6576. }
  6577. function receiveAndExtend(length) {
  6578. if (length === 1) {
  6579. return readBit() === 1 ? 1 : -1;
  6580. }
  6581. var n = receive(length);
  6582. if (n >= 1 << (length - 1)) {
  6583. return n;
  6584. }
  6585. return n + (-1 << length) + 1;
  6586. }
  6587. function decodeBaseline(component, offset) {
  6588. var t = decodeHuffman(component.huffmanTableDC);
  6589. var diff = t === 0 ? 0 : receiveAndExtend(t);
  6590. component.blockData[offset] = (component.pred += diff);
  6591. var k = 1;
  6592. while (k < 64) {
  6593. var rs = decodeHuffman(component.huffmanTableAC);
  6594. var s = rs & 15, r = rs >> 4;
  6595. if (s === 0) {
  6596. if (r < 15) {
  6597. break;
  6598. }
  6599. k += 16;
  6600. continue;
  6601. }
  6602. k += r;
  6603. var z = dctZigZag[k];
  6604. component.blockData[offset + z] = receiveAndExtend(s);
  6605. k++;
  6606. }
  6607. }
  6608. function decodeDCFirst(component, offset) {
  6609. var t = decodeHuffman(component.huffmanTableDC);
  6610. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  6611. component.blockData[offset] = (component.pred += diff);
  6612. }
  6613. function decodeDCSuccessive(component, offset) {
  6614. component.blockData[offset] |= readBit() << successive;
  6615. }
  6616. var eobrun = 0;
  6617. function decodeACFirst(component, offset) {
  6618. if (eobrun > 0) {
  6619. eobrun--;
  6620. return;
  6621. }
  6622. var k = spectralStart, e = spectralEnd;
  6623. while (k <= e) {
  6624. var rs = decodeHuffman(component.huffmanTableAC);
  6625. var s = rs & 15, r = rs >> 4;
  6626. if (s === 0) {
  6627. if (r < 15) {
  6628. eobrun = receive(r) + (1 << r) - 1;
  6629. break;
  6630. }
  6631. k += 16;
  6632. continue;
  6633. }
  6634. k += r;
  6635. var z = dctZigZag[k];
  6636. component.blockData[offset + z] =
  6637. receiveAndExtend(s) * (1 << successive);
  6638. k++;
  6639. }
  6640. }
  6641. var successiveACState = 0, successiveACNextValue;
  6642. function decodeACSuccessive(component, offset) {
  6643. var k = spectralStart;
  6644. var e = spectralEnd;
  6645. var r = 0;
  6646. var s;
  6647. var rs;
  6648. while (k <= e) {
  6649. var z = dctZigZag[k];
  6650. switch (successiveACState) {
  6651. case 0: // initial state
  6652. rs = decodeHuffman(component.huffmanTableAC);
  6653. s = rs & 15;
  6654. r = rs >> 4;
  6655. if (s === 0) {
  6656. if (r < 15) {
  6657. eobrun = receive(r) + (1 << r);
  6658. successiveACState = 4;
  6659. } else {
  6660. r = 16;
  6661. successiveACState = 1;
  6662. }
  6663. } else {
  6664. if (s !== 1) {
  6665. throw 'invalid ACn encoding';
  6666. }
  6667. successiveACNextValue = receiveAndExtend(s);
  6668. successiveACState = r ? 2 : 3;
  6669. }
  6670. continue;
  6671. case 1: // skipping r zero items
  6672. case 2:
  6673. if (component.blockData[offset + z]) {
  6674. component.blockData[offset + z] += (readBit() << successive);
  6675. } else {
  6676. r--;
  6677. if (r === 0) {
  6678. successiveACState = successiveACState === 2 ? 3 : 0;
  6679. }
  6680. }
  6681. break;
  6682. case 3: // set value for a zero item
  6683. if (component.blockData[offset + z]) {
  6684. component.blockData[offset + z] += (readBit() << successive);
  6685. } else {
  6686. component.blockData[offset + z] =
  6687. successiveACNextValue << successive;
  6688. successiveACState = 0;
  6689. }
  6690. break;
  6691. case 4: // eob
  6692. if (component.blockData[offset + z]) {
  6693. component.blockData[offset + z] += (readBit() << successive);
  6694. }
  6695. break;
  6696. }
  6697. k++;
  6698. }
  6699. if (successiveACState === 4) {
  6700. eobrun--;
  6701. if (eobrun === 0) {
  6702. successiveACState = 0;
  6703. }
  6704. }
  6705. }
  6706. function decodeMcu(component, decode, mcu, row, col) {
  6707. var mcuRow = (mcu / mcusPerLine) | 0;
  6708. var mcuCol = mcu % mcusPerLine;
  6709. var blockRow = mcuRow * component.v + row;
  6710. var blockCol = mcuCol * component.h + col;
  6711. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6712. decode(component, offset);
  6713. }
  6714. function decodeBlock(component, decode, mcu) {
  6715. var blockRow = (mcu / component.blocksPerLine) | 0;
  6716. var blockCol = mcu % component.blocksPerLine;
  6717. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6718. decode(component, offset);
  6719. }
  6720. var componentsLength = components.length;
  6721. var component, i, j, k, n;
  6722. var decodeFn;
  6723. if (progressive) {
  6724. if (spectralStart === 0) {
  6725. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  6726. } else {
  6727. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  6728. }
  6729. } else {
  6730. decodeFn = decodeBaseline;
  6731. }
  6732. var mcu = 0, marker;
  6733. var mcuExpected;
  6734. if (componentsLength === 1) {
  6735. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  6736. } else {
  6737. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  6738. }
  6739. if (!resetInterval) {
  6740. resetInterval = mcuExpected;
  6741. }
  6742. var h, v;
  6743. while (mcu < mcuExpected) {
  6744. // reset interval stuff
  6745. for (i = 0; i < componentsLength; i++) {
  6746. components[i].pred = 0;
  6747. }
  6748. eobrun = 0;
  6749. if (componentsLength === 1) {
  6750. component = components[0];
  6751. for (n = 0; n < resetInterval; n++) {
  6752. decodeBlock(component, decodeFn, mcu);
  6753. mcu++;
  6754. }
  6755. } else {
  6756. for (n = 0; n < resetInterval; n++) {
  6757. for (i = 0; i < componentsLength; i++) {
  6758. component = components[i];
  6759. h = component.h;
  6760. v = component.v;
  6761. for (j = 0; j < v; j++) {
  6762. for (k = 0; k < h; k++) {
  6763. decodeMcu(component, decodeFn, mcu, j, k);
  6764. }
  6765. }
  6766. }
  6767. mcu++;
  6768. }
  6769. }
  6770. // find marker
  6771. bitsCount = 0;
  6772. marker = (data[offset] << 8) | data[offset + 1];
  6773. if (marker <= 0xFF00) {
  6774. throw 'marker was not found';
  6775. }
  6776. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  6777. offset += 2;
  6778. } else {
  6779. break;
  6780. }
  6781. }
  6782. return offset - startOffset;
  6783. }
  6784. // A port of poppler's IDCT method which in turn is taken from:
  6785. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  6786. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  6787. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  6788. // 988-991.
  6789. function quantizeAndInverse(component, blockBufferOffset, p) {
  6790. var qt = component.quantizationTable, blockData = component.blockData;
  6791. var v0, v1, v2, v3, v4, v5, v6, v7;
  6792. var p0, p1, p2, p3, p4, p5, p6, p7;
  6793. var t;
  6794. // inverse DCT on rows
  6795. for (var row = 0; row < 64; row += 8) {
  6796. // gather block data
  6797. p0 = blockData[blockBufferOffset + row];
  6798. p1 = blockData[blockBufferOffset + row + 1];
  6799. p2 = blockData[blockBufferOffset + row + 2];
  6800. p3 = blockData[blockBufferOffset + row + 3];
  6801. p4 = blockData[blockBufferOffset + row + 4];
  6802. p5 = blockData[blockBufferOffset + row + 5];
  6803. p6 = blockData[blockBufferOffset + row + 6];
  6804. p7 = blockData[blockBufferOffset + row + 7];
  6805. // dequant p0
  6806. p0 *= qt[row];
  6807. // check for all-zero AC coefficients
  6808. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6809. t = (dctSqrt2 * p0 + 512) >> 10;
  6810. p[row] = t;
  6811. p[row + 1] = t;
  6812. p[row + 2] = t;
  6813. p[row + 3] = t;
  6814. p[row + 4] = t;
  6815. p[row + 5] = t;
  6816. p[row + 6] = t;
  6817. p[row + 7] = t;
  6818. continue;
  6819. }
  6820. // dequant p1 ... p7
  6821. p1 *= qt[row + 1];
  6822. p2 *= qt[row + 2];
  6823. p3 *= qt[row + 3];
  6824. p4 *= qt[row + 4];
  6825. p5 *= qt[row + 5];
  6826. p6 *= qt[row + 6];
  6827. p7 *= qt[row + 7];
  6828. // stage 4
  6829. v0 = (dctSqrt2 * p0 + 128) >> 8;
  6830. v1 = (dctSqrt2 * p4 + 128) >> 8;
  6831. v2 = p2;
  6832. v3 = p6;
  6833. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  6834. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  6835. v5 = p3 << 4;
  6836. v6 = p5 << 4;
  6837. // stage 3
  6838. v0 = (v0 + v1 + 1) >> 1;
  6839. v1 = v0 - v1;
  6840. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  6841. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  6842. v3 = t;
  6843. v4 = (v4 + v6 + 1) >> 1;
  6844. v6 = v4 - v6;
  6845. v7 = (v7 + v5 + 1) >> 1;
  6846. v5 = v7 - v5;
  6847. // stage 2
  6848. v0 = (v0 + v3 + 1) >> 1;
  6849. v3 = v0 - v3;
  6850. v1 = (v1 + v2 + 1) >> 1;
  6851. v2 = v1 - v2;
  6852. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6853. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6854. v7 = t;
  6855. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6856. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6857. v6 = t;
  6858. // stage 1
  6859. p[row] = v0 + v7;
  6860. p[row + 7] = v0 - v7;
  6861. p[row + 1] = v1 + v6;
  6862. p[row + 6] = v1 - v6;
  6863. p[row + 2] = v2 + v5;
  6864. p[row + 5] = v2 - v5;
  6865. p[row + 3] = v3 + v4;
  6866. p[row + 4] = v3 - v4;
  6867. }
  6868. // inverse DCT on columns
  6869. for (var col = 0; col < 8; ++col) {
  6870. p0 = p[col];
  6871. p1 = p[col + 8];
  6872. p2 = p[col + 16];
  6873. p3 = p[col + 24];
  6874. p4 = p[col + 32];
  6875. p5 = p[col + 40];
  6876. p6 = p[col + 48];
  6877. p7 = p[col + 56];
  6878. // check for all-zero AC coefficients
  6879. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6880. t = (dctSqrt2 * p0 + 8192) >> 14;
  6881. // convert to 8 bit
  6882. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  6883. blockData[blockBufferOffset + col] = t;
  6884. blockData[blockBufferOffset + col + 8] = t;
  6885. blockData[blockBufferOffset + col + 16] = t;
  6886. blockData[blockBufferOffset + col + 24] = t;
  6887. blockData[blockBufferOffset + col + 32] = t;
  6888. blockData[blockBufferOffset + col + 40] = t;
  6889. blockData[blockBufferOffset + col + 48] = t;
  6890. blockData[blockBufferOffset + col + 56] = t;
  6891. continue;
  6892. }
  6893. // stage 4
  6894. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  6895. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  6896. v2 = p2;
  6897. v3 = p6;
  6898. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  6899. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  6900. v5 = p3;
  6901. v6 = p5;
  6902. // stage 3
  6903. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  6904. // converting to UInt8 range later.
  6905. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  6906. v1 = v0 - v1;
  6907. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  6908. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  6909. v3 = t;
  6910. v4 = (v4 + v6 + 1) >> 1;
  6911. v6 = v4 - v6;
  6912. v7 = (v7 + v5 + 1) >> 1;
  6913. v5 = v7 - v5;
  6914. // stage 2
  6915. v0 = (v0 + v3 + 1) >> 1;
  6916. v3 = v0 - v3;
  6917. v1 = (v1 + v2 + 1) >> 1;
  6918. v2 = v1 - v2;
  6919. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6920. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6921. v7 = t;
  6922. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6923. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6924. v6 = t;
  6925. // stage 1
  6926. p0 = v0 + v7;
  6927. p7 = v0 - v7;
  6928. p1 = v1 + v6;
  6929. p6 = v1 - v6;
  6930. p2 = v2 + v5;
  6931. p5 = v2 - v5;
  6932. p3 = v3 + v4;
  6933. p4 = v3 - v4;
  6934. // convert to 8-bit integers
  6935. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  6936. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  6937. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  6938. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  6939. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  6940. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  6941. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  6942. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  6943. // store block data
  6944. blockData[blockBufferOffset + col] = p0;
  6945. blockData[blockBufferOffset + col + 8] = p1;
  6946. blockData[blockBufferOffset + col + 16] = p2;
  6947. blockData[blockBufferOffset + col + 24] = p3;
  6948. blockData[blockBufferOffset + col + 32] = p4;
  6949. blockData[blockBufferOffset + col + 40] = p5;
  6950. blockData[blockBufferOffset + col + 48] = p6;
  6951. blockData[blockBufferOffset + col + 56] = p7;
  6952. }
  6953. }
  6954. function buildComponentData(frame, component) {
  6955. var blocksPerLine = component.blocksPerLine;
  6956. var blocksPerColumn = component.blocksPerColumn;
  6957. var computationBuffer = new Int16Array(64);
  6958. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  6959. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  6960. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6961. quantizeAndInverse(component, offset, computationBuffer);
  6962. }
  6963. }
  6964. return component.blockData;
  6965. }
  6966. function clamp0to255(a) {
  6967. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  6968. }
  6969. constructor.prototype = {
  6970. parse: function parse(data) {
  6971. function readUint16() {
  6972. var value = (data[offset] << 8) | data[offset + 1];
  6973. offset += 2;
  6974. return value;
  6975. }
  6976. function readDataBlock() {
  6977. var length = readUint16();
  6978. var array = data.subarray(offset, offset + length - 2);
  6979. offset += array.length;
  6980. return array;
  6981. }
  6982. function prepareComponents(frame) {
  6983. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  6984. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  6985. for (var i = 0; i < frame.components.length; i++) {
  6986. component = frame.components[i];
  6987. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  6988. component.h / frame.maxH);
  6989. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  6990. component.v / frame.maxV);
  6991. var blocksPerLineForMcu = mcusPerLine * component.h;
  6992. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  6993. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  6994. (blocksPerLineForMcu + 1);
  6995. component.blockData = new Int16Array(blocksBufferSize);
  6996. component.blocksPerLine = blocksPerLine;
  6997. component.blocksPerColumn = blocksPerColumn;
  6998. }
  6999. frame.mcusPerLine = mcusPerLine;
  7000. frame.mcusPerColumn = mcusPerColumn;
  7001. }
  7002. var offset = 0;
  7003. var jfif = null;
  7004. var adobe = null;
  7005. var frame, resetInterval;
  7006. var quantizationTables = [];
  7007. var huffmanTablesAC = [], huffmanTablesDC = [];
  7008. var fileMarker = readUint16();
  7009. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  7010. throw 'SOI not found';
  7011. }
  7012. fileMarker = readUint16();
  7013. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  7014. var i, j, l;
  7015. switch(fileMarker) {
  7016. case 0xFFE0: // APP0 (Application Specific)
  7017. case 0xFFE1: // APP1
  7018. case 0xFFE2: // APP2
  7019. case 0xFFE3: // APP3
  7020. case 0xFFE4: // APP4
  7021. case 0xFFE5: // APP5
  7022. case 0xFFE6: // APP6
  7023. case 0xFFE7: // APP7
  7024. case 0xFFE8: // APP8
  7025. case 0xFFE9: // APP9
  7026. case 0xFFEA: // APP10
  7027. case 0xFFEB: // APP11
  7028. case 0xFFEC: // APP12
  7029. case 0xFFED: // APP13
  7030. case 0xFFEE: // APP14
  7031. case 0xFFEF: // APP15
  7032. case 0xFFFE: // COM (Comment)
  7033. var appData = readDataBlock();
  7034. if (fileMarker === 0xFFE0) {
  7035. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  7036. appData[2] === 0x49 && appData[3] === 0x46 &&
  7037. appData[4] === 0) { // 'JFIF\x00'
  7038. jfif = {
  7039. version: { major: appData[5], minor: appData[6] },
  7040. densityUnits: appData[7],
  7041. xDensity: (appData[8] << 8) | appData[9],
  7042. yDensity: (appData[10] << 8) | appData[11],
  7043. thumbWidth: appData[12],
  7044. thumbHeight: appData[13],
  7045. thumbData: appData.subarray(14, 14 +
  7046. 3 * appData[12] * appData[13])
  7047. };
  7048. }
  7049. }
  7050. // TODO APP1 - Exif
  7051. if (fileMarker === 0xFFEE) {
  7052. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  7053. appData[2] === 0x6F && appData[3] === 0x62 &&
  7054. appData[4] === 0x65) { // 'Adobe'
  7055. adobe = {
  7056. version: (appData[5] << 8) | appData[6],
  7057. flags0: (appData[7] << 8) | appData[8],
  7058. flags1: (appData[9] << 8) | appData[10],
  7059. transformCode: appData[11]
  7060. };
  7061. }
  7062. }
  7063. break;
  7064. case 0xFFDB: // DQT (Define Quantization Tables)
  7065. var quantizationTablesLength = readUint16();
  7066. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  7067. var z;
  7068. while (offset < quantizationTablesEnd) {
  7069. var quantizationTableSpec = data[offset++];
  7070. var tableData = new Uint16Array(64);
  7071. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  7072. for (j = 0; j < 64; j++) {
  7073. z = dctZigZag[j];
  7074. tableData[z] = data[offset++];
  7075. }
  7076. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  7077. for (j = 0; j < 64; j++) {
  7078. z = dctZigZag[j];
  7079. tableData[z] = readUint16();
  7080. }
  7081. } else {
  7082. throw 'DQT: invalid table spec';
  7083. }
  7084. quantizationTables[quantizationTableSpec & 15] = tableData;
  7085. }
  7086. break;
  7087. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  7088. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  7089. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  7090. if (frame) {
  7091. throw 'Only single frame JPEGs supported';
  7092. }
  7093. readUint16(); // skip data length
  7094. frame = {};
  7095. frame.extended = (fileMarker === 0xFFC1);
  7096. frame.progressive = (fileMarker === 0xFFC2);
  7097. frame.precision = data[offset++];
  7098. frame.scanLines = readUint16();
  7099. frame.samplesPerLine = readUint16();
  7100. frame.components = [];
  7101. frame.componentIds = {};
  7102. var componentsCount = data[offset++], componentId;
  7103. var maxH = 0, maxV = 0;
  7104. for (i = 0; i < componentsCount; i++) {
  7105. componentId = data[offset];
  7106. var h = data[offset + 1] >> 4;
  7107. var v = data[offset + 1] & 15;
  7108. if (maxH < h) {
  7109. maxH = h;
  7110. }
  7111. if (maxV < v) {
  7112. maxV = v;
  7113. }
  7114. var qId = data[offset + 2];
  7115. l = frame.components.push({
  7116. h: h,
  7117. v: v,
  7118. quantizationTable: quantizationTables[qId]
  7119. });
  7120. frame.componentIds[componentId] = l - 1;
  7121. offset += 3;
  7122. }
  7123. frame.maxH = maxH;
  7124. frame.maxV = maxV;
  7125. prepareComponents(frame);
  7126. break;
  7127. case 0xFFC4: // DHT (Define Huffman Tables)
  7128. var huffmanLength = readUint16();
  7129. for (i = 2; i < huffmanLength;) {
  7130. var huffmanTableSpec = data[offset++];
  7131. var codeLengths = new Uint8Array(16);
  7132. var codeLengthSum = 0;
  7133. for (j = 0; j < 16; j++, offset++) {
  7134. codeLengthSum += (codeLengths[j] = data[offset]);
  7135. }
  7136. var huffmanValues = new Uint8Array(codeLengthSum);
  7137. for (j = 0; j < codeLengthSum; j++, offset++) {
  7138. huffmanValues[j] = data[offset];
  7139. }
  7140. i += 17 + codeLengthSum;
  7141. ((huffmanTableSpec >> 4) === 0 ?
  7142. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  7143. buildHuffmanTable(codeLengths, huffmanValues);
  7144. }
  7145. break;
  7146. case 0xFFDD: // DRI (Define Restart Interval)
  7147. readUint16(); // skip data length
  7148. resetInterval = readUint16();
  7149. break;
  7150. case 0xFFDA: // SOS (Start of Scan)
  7151. var scanLength = readUint16();
  7152. var selectorsCount = data[offset++];
  7153. var components = [], component;
  7154. for (i = 0; i < selectorsCount; i++) {
  7155. var componentIndex = frame.componentIds[data[offset++]];
  7156. component = frame.components[componentIndex];
  7157. var tableSpec = data[offset++];
  7158. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  7159. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  7160. components.push(component);
  7161. }
  7162. var spectralStart = data[offset++];
  7163. var spectralEnd = data[offset++];
  7164. var successiveApproximation = data[offset++];
  7165. var processed = decodeScan(data, offset,
  7166. frame, components, resetInterval,
  7167. spectralStart, spectralEnd,
  7168. successiveApproximation >> 4, successiveApproximation & 15);
  7169. offset += processed;
  7170. break;
  7171. case 0xFFFF: // Fill bytes
  7172. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  7173. offset--;
  7174. }
  7175. break;
  7176. default:
  7177. if (data[offset - 3] === 0xFF &&
  7178. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  7179. // could be incorrect encoding -- last 0xFF byte of the previous
  7180. // block was eaten by the encoder
  7181. offset -= 3;
  7182. break;
  7183. }
  7184. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  7185. }
  7186. fileMarker = readUint16();
  7187. }
  7188. this.width = frame.samplesPerLine;
  7189. this.height = frame.scanLines;
  7190. this.jfif = jfif;
  7191. this.adobe = adobe;
  7192. this.components = [];
  7193. for (i = 0; i < frame.components.length; i++) {
  7194. component = frame.components[i];
  7195. this.components.push({
  7196. output: buildComponentData(frame, component),
  7197. scaleX: component.h / frame.maxH,
  7198. scaleY: component.v / frame.maxV,
  7199. blocksPerLine: component.blocksPerLine,
  7200. blocksPerColumn: component.blocksPerColumn
  7201. });
  7202. }
  7203. this.numComponents = this.components.length;
  7204. },
  7205. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  7206. var scaleX = this.width / width, scaleY = this.height / height;
  7207. var component, componentScaleX, componentScaleY, blocksPerScanline;
  7208. var x, y, i, j, k;
  7209. var index;
  7210. var offset = 0;
  7211. var output;
  7212. var numComponents = this.components.length;
  7213. var dataLength = width * height * numComponents;
  7214. var data = new Uint8Array(dataLength);
  7215. var xScaleBlockOffset = new Uint32Array(width);
  7216. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  7217. for (i = 0; i < numComponents; i++) {
  7218. component = this.components[i];
  7219. componentScaleX = component.scaleX * scaleX;
  7220. componentScaleY = component.scaleY * scaleY;
  7221. offset = i;
  7222. output = component.output;
  7223. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  7224. // precalculate the xScaleBlockOffset
  7225. for (x = 0; x < width; x++) {
  7226. j = 0 | (x * componentScaleX);
  7227. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  7228. }
  7229. // linearize the blocks of the component
  7230. for (y = 0; y < height; y++) {
  7231. j = 0 | (y * componentScaleY);
  7232. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  7233. for (x = 0; x < width; x++) {
  7234. data[offset] = output[index + xScaleBlockOffset[x]];
  7235. offset += numComponents;
  7236. }
  7237. }
  7238. }
  7239. // decodeTransform contains pairs of multiplier (-256..256) and additive
  7240. var transform = this.decodeTransform;
  7241. if (transform) {
  7242. for (i = 0; i < dataLength;) {
  7243. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  7244. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  7245. }
  7246. }
  7247. }
  7248. return data;
  7249. },
  7250. _isColorConversionNeeded: function isColorConversionNeeded() {
  7251. if (this.adobe && this.adobe.transformCode) {
  7252. // The adobe transform marker overrides any previous setting
  7253. return true;
  7254. } else if (this.numComponents === 3) {
  7255. return true;
  7256. } else {
  7257. return false;
  7258. }
  7259. },
  7260. _convertYccToRgb: function convertYccToRgb(data) {
  7261. var Y, Cb, Cr;
  7262. for (var i = 0, length = data.length; i < length; i += 3) {
  7263. Y = data[i ];
  7264. Cb = data[i + 1];
  7265. Cr = data[i + 2];
  7266. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  7267. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  7268. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  7269. }
  7270. return data;
  7271. },
  7272. _convertYcckToRgb: function convertYcckToRgb(data) {
  7273. var Y, Cb, Cr, k;
  7274. var offset = 0;
  7275. for (var i = 0, length = data.length; i < length; i += 4) {
  7276. Y = data[i];
  7277. Cb = data[i + 1];
  7278. Cr = data[i + 2];
  7279. k = data[i + 3];
  7280. var r = -122.67195406894 +
  7281. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  7282. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  7283. 0.154362151871126) +
  7284. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  7285. 0.00477271405408747 * k + 1.53380253221734) +
  7286. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  7287. 0.48357088451265) +
  7288. k * (-0.000336197177618394 * k + 0.484791561490776);
  7289. var g = 107.268039397724 +
  7290. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  7291. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  7292. 0.176491792462875) +
  7293. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  7294. 0.000770482631801132 * k - 0.151051492775562) +
  7295. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  7296. 0.25802910206845) +
  7297. k * (-0.000318913117588328 * k - 0.213742400323665);
  7298. var b = -20.810012546947 +
  7299. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  7300. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  7301. 0.814272968359295) +
  7302. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  7303. 0.000560833691242812 * k - 0.195152027534049) +
  7304. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  7305. 0.116935020465145) +
  7306. k * (-0.000343531996510555 * k + 0.24165260232407);
  7307. data[offset++] = clamp0to255(r);
  7308. data[offset++] = clamp0to255(g);
  7309. data[offset++] = clamp0to255(b);
  7310. }
  7311. return data;
  7312. },
  7313. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  7314. var Y, Cb, Cr;
  7315. for (var i = 0, length = data.length; i < length; i += 4) {
  7316. Y = data[i];
  7317. Cb = data[i + 1];
  7318. Cr = data[i + 2];
  7319. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  7320. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  7321. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  7322. // K in data[i + 3] is unchanged
  7323. }
  7324. return data;
  7325. },
  7326. _convertCmykToRgb: function convertCmykToRgb(data) {
  7327. var c, m, y, k;
  7328. var offset = 0;
  7329. var min = -255 * 255 * 255;
  7330. var scale = 1 / 255 / 255;
  7331. for (var i = 0, length = data.length; i < length; i += 4) {
  7332. c = data[i];
  7333. m = data[i + 1];
  7334. y = data[i + 2];
  7335. k = data[i + 3];
  7336. var r =
  7337. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  7338. 18.82290502165302 * y + 212.25662451639585 * k -
  7339. 72734.4411664936) +
  7340. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  7341. 17.873870861415444 * k - 1401.7366389350734) +
  7342. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  7343. 4465.541406466231) -
  7344. k * (21.86122147463605 * k + 48317.86113160301);
  7345. var g =
  7346. c * (8.841041422036149 * c + 60.118027045597366 * m +
  7347. 6.871425592049007 * y + 31.159100130055922 * k -
  7348. 20220.756542821975) +
  7349. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  7350. 131.35250912493976 * k - 48691.05921601825) +
  7351. y * (4.444339102852739 * y + 9.8632861493405 * k -
  7352. 6341.191035517494) -
  7353. k * (20.737325471181034 * k + 47890.15695978492);
  7354. var b =
  7355. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  7356. 30.89978309703729 * y - 0.23883238689178934 * k -
  7357. 3616.812083916688) +
  7358. m * (10.49593273432072 * m + 63.02378494754052 * y +
  7359. 50.606957656360734 * k - 28620.90484698408) +
  7360. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  7361. 49363.43385999684) -
  7362. k * (22.33816807309886 * k + 45932.16563550634);
  7363. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  7364. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  7365. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  7366. }
  7367. return data;
  7368. },
  7369. getData: function getData(width, height, forceRGBoutput) {
  7370. if (this.numComponents > 4) {
  7371. throw 'Unsupported color mode';
  7372. }
  7373. // type of data: Uint8Array(width * height * numComponents)
  7374. var data = this._getLinearizedBlockData(width, height);
  7375. if (this.numComponents === 3) {
  7376. return this._convertYccToRgb(data);
  7377. } else if (this.numComponents === 4) {
  7378. if (this._isColorConversionNeeded()) {
  7379. if (forceRGBoutput) {
  7380. return this._convertYcckToRgb(data);
  7381. } else {
  7382. return this._convertYcckToCmyk(data);
  7383. }
  7384. } else if (forceRGBoutput) {
  7385. return this._convertCmykToRgb(data);
  7386. }
  7387. }
  7388. return data;
  7389. }
  7390. };
  7391. return constructor;
  7392. })();
  7393. exports.JpegImage = JpegImage;
  7394. }));
  7395. (function (root, factory) {
  7396. {
  7397. factory((root.pdfjsCoreMetrics = {}));
  7398. }
  7399. }(this, function (exports) {
  7400. // The Metrics object contains glyph widths (in glyph space units).
  7401. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  7402. // space unit corresponds to 1/1000th of text space unit.
  7403. var Metrics = {
  7404. 'Courier': 600,
  7405. 'Courier-Bold': 600,
  7406. 'Courier-BoldOblique': 600,
  7407. 'Courier-Oblique': 600,
  7408. 'Helvetica' : {
  7409. 'space': 278,
  7410. 'exclam': 278,
  7411. 'quotedbl': 355,
  7412. 'numbersign': 556,
  7413. 'dollar': 556,
  7414. 'percent': 889,
  7415. 'ampersand': 667,
  7416. 'quoteright': 222,
  7417. 'parenleft': 333,
  7418. 'parenright': 333,
  7419. 'asterisk': 389,
  7420. 'plus': 584,
  7421. 'comma': 278,
  7422. 'hyphen': 333,
  7423. 'period': 278,
  7424. 'slash': 278,
  7425. 'zero': 556,
  7426. 'one': 556,
  7427. 'two': 556,
  7428. 'three': 556,
  7429. 'four': 556,
  7430. 'five': 556,
  7431. 'six': 556,
  7432. 'seven': 556,
  7433. 'eight': 556,
  7434. 'nine': 556,
  7435. 'colon': 278,
  7436. 'semicolon': 278,
  7437. 'less': 584,
  7438. 'equal': 584,
  7439. 'greater': 584,
  7440. 'question': 556,
  7441. 'at': 1015,
  7442. 'A': 667,
  7443. 'B': 667,
  7444. 'C': 722,
  7445. 'D': 722,
  7446. 'E': 667,
  7447. 'F': 611,
  7448. 'G': 778,
  7449. 'H': 722,
  7450. 'I': 278,
  7451. 'J': 500,
  7452. 'K': 667,
  7453. 'L': 556,
  7454. 'M': 833,
  7455. 'N': 722,
  7456. 'O': 778,
  7457. 'P': 667,
  7458. 'Q': 778,
  7459. 'R': 722,
  7460. 'S': 667,
  7461. 'T': 611,
  7462. 'U': 722,
  7463. 'V': 667,
  7464. 'W': 944,
  7465. 'X': 667,
  7466. 'Y': 667,
  7467. 'Z': 611,
  7468. 'bracketleft': 278,
  7469. 'backslash': 278,
  7470. 'bracketright': 278,
  7471. 'asciicircum': 469,
  7472. 'underscore': 556,
  7473. 'quoteleft': 222,
  7474. 'a': 556,
  7475. 'b': 556,
  7476. 'c': 500,
  7477. 'd': 556,
  7478. 'e': 556,
  7479. 'f': 278,
  7480. 'g': 556,
  7481. 'h': 556,
  7482. 'i': 222,
  7483. 'j': 222,
  7484. 'k': 500,
  7485. 'l': 222,
  7486. 'm': 833,
  7487. 'n': 556,
  7488. 'o': 556,
  7489. 'p': 556,
  7490. 'q': 556,
  7491. 'r': 333,
  7492. 's': 500,
  7493. 't': 278,
  7494. 'u': 556,
  7495. 'v': 500,
  7496. 'w': 722,
  7497. 'x': 500,
  7498. 'y': 500,
  7499. 'z': 500,
  7500. 'braceleft': 334,
  7501. 'bar': 260,
  7502. 'braceright': 334,
  7503. 'asciitilde': 584,
  7504. 'exclamdown': 333,
  7505. 'cent': 556,
  7506. 'sterling': 556,
  7507. 'fraction': 167,
  7508. 'yen': 556,
  7509. 'florin': 556,
  7510. 'section': 556,
  7511. 'currency': 556,
  7512. 'quotesingle': 191,
  7513. 'quotedblleft': 333,
  7514. 'guillemotleft': 556,
  7515. 'guilsinglleft': 333,
  7516. 'guilsinglright': 333,
  7517. 'fi': 500,
  7518. 'fl': 500,
  7519. 'endash': 556,
  7520. 'dagger': 556,
  7521. 'daggerdbl': 556,
  7522. 'periodcentered': 278,
  7523. 'paragraph': 537,
  7524. 'bullet': 350,
  7525. 'quotesinglbase': 222,
  7526. 'quotedblbase': 333,
  7527. 'quotedblright': 333,
  7528. 'guillemotright': 556,
  7529. 'ellipsis': 1000,
  7530. 'perthousand': 1000,
  7531. 'questiondown': 611,
  7532. 'grave': 333,
  7533. 'acute': 333,
  7534. 'circumflex': 333,
  7535. 'tilde': 333,
  7536. 'macron': 333,
  7537. 'breve': 333,
  7538. 'dotaccent': 333,
  7539. 'dieresis': 333,
  7540. 'ring': 333,
  7541. 'cedilla': 333,
  7542. 'hungarumlaut': 333,
  7543. 'ogonek': 333,
  7544. 'caron': 333,
  7545. 'emdash': 1000,
  7546. 'AE': 1000,
  7547. 'ordfeminine': 370,
  7548. 'Lslash': 556,
  7549. 'Oslash': 778,
  7550. 'OE': 1000,
  7551. 'ordmasculine': 365,
  7552. 'ae': 889,
  7553. 'dotlessi': 278,
  7554. 'lslash': 222,
  7555. 'oslash': 611,
  7556. 'oe': 944,
  7557. 'germandbls': 611,
  7558. 'Idieresis': 278,
  7559. 'eacute': 556,
  7560. 'abreve': 556,
  7561. 'uhungarumlaut': 556,
  7562. 'ecaron': 556,
  7563. 'Ydieresis': 667,
  7564. 'divide': 584,
  7565. 'Yacute': 667,
  7566. 'Acircumflex': 667,
  7567. 'aacute': 556,
  7568. 'Ucircumflex': 722,
  7569. 'yacute': 500,
  7570. 'scommaaccent': 500,
  7571. 'ecircumflex': 556,
  7572. 'Uring': 722,
  7573. 'Udieresis': 722,
  7574. 'aogonek': 556,
  7575. 'Uacute': 722,
  7576. 'uogonek': 556,
  7577. 'Edieresis': 667,
  7578. 'Dcroat': 722,
  7579. 'commaaccent': 250,
  7580. 'copyright': 737,
  7581. 'Emacron': 667,
  7582. 'ccaron': 500,
  7583. 'aring': 556,
  7584. 'Ncommaaccent': 722,
  7585. 'lacute': 222,
  7586. 'agrave': 556,
  7587. 'Tcommaaccent': 611,
  7588. 'Cacute': 722,
  7589. 'atilde': 556,
  7590. 'Edotaccent': 667,
  7591. 'scaron': 500,
  7592. 'scedilla': 500,
  7593. 'iacute': 278,
  7594. 'lozenge': 471,
  7595. 'Rcaron': 722,
  7596. 'Gcommaaccent': 778,
  7597. 'ucircumflex': 556,
  7598. 'acircumflex': 556,
  7599. 'Amacron': 667,
  7600. 'rcaron': 333,
  7601. 'ccedilla': 500,
  7602. 'Zdotaccent': 611,
  7603. 'Thorn': 667,
  7604. 'Omacron': 778,
  7605. 'Racute': 722,
  7606. 'Sacute': 667,
  7607. 'dcaron': 643,
  7608. 'Umacron': 722,
  7609. 'uring': 556,
  7610. 'threesuperior': 333,
  7611. 'Ograve': 778,
  7612. 'Agrave': 667,
  7613. 'Abreve': 667,
  7614. 'multiply': 584,
  7615. 'uacute': 556,
  7616. 'Tcaron': 611,
  7617. 'partialdiff': 476,
  7618. 'ydieresis': 500,
  7619. 'Nacute': 722,
  7620. 'icircumflex': 278,
  7621. 'Ecircumflex': 667,
  7622. 'adieresis': 556,
  7623. 'edieresis': 556,
  7624. 'cacute': 500,
  7625. 'nacute': 556,
  7626. 'umacron': 556,
  7627. 'Ncaron': 722,
  7628. 'Iacute': 278,
  7629. 'plusminus': 584,
  7630. 'brokenbar': 260,
  7631. 'registered': 737,
  7632. 'Gbreve': 778,
  7633. 'Idotaccent': 278,
  7634. 'summation': 600,
  7635. 'Egrave': 667,
  7636. 'racute': 333,
  7637. 'omacron': 556,
  7638. 'Zacute': 611,
  7639. 'Zcaron': 611,
  7640. 'greaterequal': 549,
  7641. 'Eth': 722,
  7642. 'Ccedilla': 722,
  7643. 'lcommaaccent': 222,
  7644. 'tcaron': 317,
  7645. 'eogonek': 556,
  7646. 'Uogonek': 722,
  7647. 'Aacute': 667,
  7648. 'Adieresis': 667,
  7649. 'egrave': 556,
  7650. 'zacute': 500,
  7651. 'iogonek': 222,
  7652. 'Oacute': 778,
  7653. 'oacute': 556,
  7654. 'amacron': 556,
  7655. 'sacute': 500,
  7656. 'idieresis': 278,
  7657. 'Ocircumflex': 778,
  7658. 'Ugrave': 722,
  7659. 'Delta': 612,
  7660. 'thorn': 556,
  7661. 'twosuperior': 333,
  7662. 'Odieresis': 778,
  7663. 'mu': 556,
  7664. 'igrave': 278,
  7665. 'ohungarumlaut': 556,
  7666. 'Eogonek': 667,
  7667. 'dcroat': 556,
  7668. 'threequarters': 834,
  7669. 'Scedilla': 667,
  7670. 'lcaron': 299,
  7671. 'Kcommaaccent': 667,
  7672. 'Lacute': 556,
  7673. 'trademark': 1000,
  7674. 'edotaccent': 556,
  7675. 'Igrave': 278,
  7676. 'Imacron': 278,
  7677. 'Lcaron': 556,
  7678. 'onehalf': 834,
  7679. 'lessequal': 549,
  7680. 'ocircumflex': 556,
  7681. 'ntilde': 556,
  7682. 'Uhungarumlaut': 722,
  7683. 'Eacute': 667,
  7684. 'emacron': 556,
  7685. 'gbreve': 556,
  7686. 'onequarter': 834,
  7687. 'Scaron': 667,
  7688. 'Scommaaccent': 667,
  7689. 'Ohungarumlaut': 778,
  7690. 'degree': 400,
  7691. 'ograve': 556,
  7692. 'Ccaron': 722,
  7693. 'ugrave': 556,
  7694. 'radical': 453,
  7695. 'Dcaron': 722,
  7696. 'rcommaaccent': 333,
  7697. 'Ntilde': 722,
  7698. 'otilde': 556,
  7699. 'Rcommaaccent': 722,
  7700. 'Lcommaaccent': 556,
  7701. 'Atilde': 667,
  7702. 'Aogonek': 667,
  7703. 'Aring': 667,
  7704. 'Otilde': 778,
  7705. 'zdotaccent': 500,
  7706. 'Ecaron': 667,
  7707. 'Iogonek': 278,
  7708. 'kcommaaccent': 500,
  7709. 'minus': 584,
  7710. 'Icircumflex': 278,
  7711. 'ncaron': 556,
  7712. 'tcommaaccent': 278,
  7713. 'logicalnot': 584,
  7714. 'odieresis': 556,
  7715. 'udieresis': 556,
  7716. 'notequal': 549,
  7717. 'gcommaaccent': 556,
  7718. 'eth': 556,
  7719. 'zcaron': 500,
  7720. 'ncommaaccent': 556,
  7721. 'onesuperior': 333,
  7722. 'imacron': 278,
  7723. 'Euro': 556
  7724. },
  7725. 'Helvetica-Bold': {
  7726. 'space': 278,
  7727. 'exclam': 333,
  7728. 'quotedbl': 474,
  7729. 'numbersign': 556,
  7730. 'dollar': 556,
  7731. 'percent': 889,
  7732. 'ampersand': 722,
  7733. 'quoteright': 278,
  7734. 'parenleft': 333,
  7735. 'parenright': 333,
  7736. 'asterisk': 389,
  7737. 'plus': 584,
  7738. 'comma': 278,
  7739. 'hyphen': 333,
  7740. 'period': 278,
  7741. 'slash': 278,
  7742. 'zero': 556,
  7743. 'one': 556,
  7744. 'two': 556,
  7745. 'three': 556,
  7746. 'four': 556,
  7747. 'five': 556,
  7748. 'six': 556,
  7749. 'seven': 556,
  7750. 'eight': 556,
  7751. 'nine': 556,
  7752. 'colon': 333,
  7753. 'semicolon': 333,
  7754. 'less': 584,
  7755. 'equal': 584,
  7756. 'greater': 584,
  7757. 'question': 611,
  7758. 'at': 975,
  7759. 'A': 722,
  7760. 'B': 722,
  7761. 'C': 722,
  7762. 'D': 722,
  7763. 'E': 667,
  7764. 'F': 611,
  7765. 'G': 778,
  7766. 'H': 722,
  7767. 'I': 278,
  7768. 'J': 556,
  7769. 'K': 722,
  7770. 'L': 611,
  7771. 'M': 833,
  7772. 'N': 722,
  7773. 'O': 778,
  7774. 'P': 667,
  7775. 'Q': 778,
  7776. 'R': 722,
  7777. 'S': 667,
  7778. 'T': 611,
  7779. 'U': 722,
  7780. 'V': 667,
  7781. 'W': 944,
  7782. 'X': 667,
  7783. 'Y': 667,
  7784. 'Z': 611,
  7785. 'bracketleft': 333,
  7786. 'backslash': 278,
  7787. 'bracketright': 333,
  7788. 'asciicircum': 584,
  7789. 'underscore': 556,
  7790. 'quoteleft': 278,
  7791. 'a': 556,
  7792. 'b': 611,
  7793. 'c': 556,
  7794. 'd': 611,
  7795. 'e': 556,
  7796. 'f': 333,
  7797. 'g': 611,
  7798. 'h': 611,
  7799. 'i': 278,
  7800. 'j': 278,
  7801. 'k': 556,
  7802. 'l': 278,
  7803. 'm': 889,
  7804. 'n': 611,
  7805. 'o': 611,
  7806. 'p': 611,
  7807. 'q': 611,
  7808. 'r': 389,
  7809. 's': 556,
  7810. 't': 333,
  7811. 'u': 611,
  7812. 'v': 556,
  7813. 'w': 778,
  7814. 'x': 556,
  7815. 'y': 556,
  7816. 'z': 500,
  7817. 'braceleft': 389,
  7818. 'bar': 280,
  7819. 'braceright': 389,
  7820. 'asciitilde': 584,
  7821. 'exclamdown': 333,
  7822. 'cent': 556,
  7823. 'sterling': 556,
  7824. 'fraction': 167,
  7825. 'yen': 556,
  7826. 'florin': 556,
  7827. 'section': 556,
  7828. 'currency': 556,
  7829. 'quotesingle': 238,
  7830. 'quotedblleft': 500,
  7831. 'guillemotleft': 556,
  7832. 'guilsinglleft': 333,
  7833. 'guilsinglright': 333,
  7834. 'fi': 611,
  7835. 'fl': 611,
  7836. 'endash': 556,
  7837. 'dagger': 556,
  7838. 'daggerdbl': 556,
  7839. 'periodcentered': 278,
  7840. 'paragraph': 556,
  7841. 'bullet': 350,
  7842. 'quotesinglbase': 278,
  7843. 'quotedblbase': 500,
  7844. 'quotedblright': 500,
  7845. 'guillemotright': 556,
  7846. 'ellipsis': 1000,
  7847. 'perthousand': 1000,
  7848. 'questiondown': 611,
  7849. 'grave': 333,
  7850. 'acute': 333,
  7851. 'circumflex': 333,
  7852. 'tilde': 333,
  7853. 'macron': 333,
  7854. 'breve': 333,
  7855. 'dotaccent': 333,
  7856. 'dieresis': 333,
  7857. 'ring': 333,
  7858. 'cedilla': 333,
  7859. 'hungarumlaut': 333,
  7860. 'ogonek': 333,
  7861. 'caron': 333,
  7862. 'emdash': 1000,
  7863. 'AE': 1000,
  7864. 'ordfeminine': 370,
  7865. 'Lslash': 611,
  7866. 'Oslash': 778,
  7867. 'OE': 1000,
  7868. 'ordmasculine': 365,
  7869. 'ae': 889,
  7870. 'dotlessi': 278,
  7871. 'lslash': 278,
  7872. 'oslash': 611,
  7873. 'oe': 944,
  7874. 'germandbls': 611,
  7875. 'Idieresis': 278,
  7876. 'eacute': 556,
  7877. 'abreve': 556,
  7878. 'uhungarumlaut': 611,
  7879. 'ecaron': 556,
  7880. 'Ydieresis': 667,
  7881. 'divide': 584,
  7882. 'Yacute': 667,
  7883. 'Acircumflex': 722,
  7884. 'aacute': 556,
  7885. 'Ucircumflex': 722,
  7886. 'yacute': 556,
  7887. 'scommaaccent': 556,
  7888. 'ecircumflex': 556,
  7889. 'Uring': 722,
  7890. 'Udieresis': 722,
  7891. 'aogonek': 556,
  7892. 'Uacute': 722,
  7893. 'uogonek': 611,
  7894. 'Edieresis': 667,
  7895. 'Dcroat': 722,
  7896. 'commaaccent': 250,
  7897. 'copyright': 737,
  7898. 'Emacron': 667,
  7899. 'ccaron': 556,
  7900. 'aring': 556,
  7901. 'Ncommaaccent': 722,
  7902. 'lacute': 278,
  7903. 'agrave': 556,
  7904. 'Tcommaaccent': 611,
  7905. 'Cacute': 722,
  7906. 'atilde': 556,
  7907. 'Edotaccent': 667,
  7908. 'scaron': 556,
  7909. 'scedilla': 556,
  7910. 'iacute': 278,
  7911. 'lozenge': 494,
  7912. 'Rcaron': 722,
  7913. 'Gcommaaccent': 778,
  7914. 'ucircumflex': 611,
  7915. 'acircumflex': 556,
  7916. 'Amacron': 722,
  7917. 'rcaron': 389,
  7918. 'ccedilla': 556,
  7919. 'Zdotaccent': 611,
  7920. 'Thorn': 667,
  7921. 'Omacron': 778,
  7922. 'Racute': 722,
  7923. 'Sacute': 667,
  7924. 'dcaron': 743,
  7925. 'Umacron': 722,
  7926. 'uring': 611,
  7927. 'threesuperior': 333,
  7928. 'Ograve': 778,
  7929. 'Agrave': 722,
  7930. 'Abreve': 722,
  7931. 'multiply': 584,
  7932. 'uacute': 611,
  7933. 'Tcaron': 611,
  7934. 'partialdiff': 494,
  7935. 'ydieresis': 556,
  7936. 'Nacute': 722,
  7937. 'icircumflex': 278,
  7938. 'Ecircumflex': 667,
  7939. 'adieresis': 556,
  7940. 'edieresis': 556,
  7941. 'cacute': 556,
  7942. 'nacute': 611,
  7943. 'umacron': 611,
  7944. 'Ncaron': 722,
  7945. 'Iacute': 278,
  7946. 'plusminus': 584,
  7947. 'brokenbar': 280,
  7948. 'registered': 737,
  7949. 'Gbreve': 778,
  7950. 'Idotaccent': 278,
  7951. 'summation': 600,
  7952. 'Egrave': 667,
  7953. 'racute': 389,
  7954. 'omacron': 611,
  7955. 'Zacute': 611,
  7956. 'Zcaron': 611,
  7957. 'greaterequal': 549,
  7958. 'Eth': 722,
  7959. 'Ccedilla': 722,
  7960. 'lcommaaccent': 278,
  7961. 'tcaron': 389,
  7962. 'eogonek': 556,
  7963. 'Uogonek': 722,
  7964. 'Aacute': 722,
  7965. 'Adieresis': 722,
  7966. 'egrave': 556,
  7967. 'zacute': 500,
  7968. 'iogonek': 278,
  7969. 'Oacute': 778,
  7970. 'oacute': 611,
  7971. 'amacron': 556,
  7972. 'sacute': 556,
  7973. 'idieresis': 278,
  7974. 'Ocircumflex': 778,
  7975. 'Ugrave': 722,
  7976. 'Delta': 612,
  7977. 'thorn': 611,
  7978. 'twosuperior': 333,
  7979. 'Odieresis': 778,
  7980. 'mu': 611,
  7981. 'igrave': 278,
  7982. 'ohungarumlaut': 611,
  7983. 'Eogonek': 667,
  7984. 'dcroat': 611,
  7985. 'threequarters': 834,
  7986. 'Scedilla': 667,
  7987. 'lcaron': 400,
  7988. 'Kcommaaccent': 722,
  7989. 'Lacute': 611,
  7990. 'trademark': 1000,
  7991. 'edotaccent': 556,
  7992. 'Igrave': 278,
  7993. 'Imacron': 278,
  7994. 'Lcaron': 611,
  7995. 'onehalf': 834,
  7996. 'lessequal': 549,
  7997. 'ocircumflex': 611,
  7998. 'ntilde': 611,
  7999. 'Uhungarumlaut': 722,
  8000. 'Eacute': 667,
  8001. 'emacron': 556,
  8002. 'gbreve': 611,
  8003. 'onequarter': 834,
  8004. 'Scaron': 667,
  8005. 'Scommaaccent': 667,
  8006. 'Ohungarumlaut': 778,
  8007. 'degree': 400,
  8008. 'ograve': 611,
  8009. 'Ccaron': 722,
  8010. 'ugrave': 611,
  8011. 'radical': 549,
  8012. 'Dcaron': 722,
  8013. 'rcommaaccent': 389,
  8014. 'Ntilde': 722,
  8015. 'otilde': 611,
  8016. 'Rcommaaccent': 722,
  8017. 'Lcommaaccent': 611,
  8018. 'Atilde': 722,
  8019. 'Aogonek': 722,
  8020. 'Aring': 722,
  8021. 'Otilde': 778,
  8022. 'zdotaccent': 500,
  8023. 'Ecaron': 667,
  8024. 'Iogonek': 278,
  8025. 'kcommaaccent': 556,
  8026. 'minus': 584,
  8027. 'Icircumflex': 278,
  8028. 'ncaron': 611,
  8029. 'tcommaaccent': 333,
  8030. 'logicalnot': 584,
  8031. 'odieresis': 611,
  8032. 'udieresis': 611,
  8033. 'notequal': 549,
  8034. 'gcommaaccent': 611,
  8035. 'eth': 611,
  8036. 'zcaron': 500,
  8037. 'ncommaaccent': 611,
  8038. 'onesuperior': 333,
  8039. 'imacron': 278,
  8040. 'Euro': 556
  8041. },
  8042. 'Helvetica-BoldOblique': {
  8043. 'space': 278,
  8044. 'exclam': 333,
  8045. 'quotedbl': 474,
  8046. 'numbersign': 556,
  8047. 'dollar': 556,
  8048. 'percent': 889,
  8049. 'ampersand': 722,
  8050. 'quoteright': 278,
  8051. 'parenleft': 333,
  8052. 'parenright': 333,
  8053. 'asterisk': 389,
  8054. 'plus': 584,
  8055. 'comma': 278,
  8056. 'hyphen': 333,
  8057. 'period': 278,
  8058. 'slash': 278,
  8059. 'zero': 556,
  8060. 'one': 556,
  8061. 'two': 556,
  8062. 'three': 556,
  8063. 'four': 556,
  8064. 'five': 556,
  8065. 'six': 556,
  8066. 'seven': 556,
  8067. 'eight': 556,
  8068. 'nine': 556,
  8069. 'colon': 333,
  8070. 'semicolon': 333,
  8071. 'less': 584,
  8072. 'equal': 584,
  8073. 'greater': 584,
  8074. 'question': 611,
  8075. 'at': 975,
  8076. 'A': 722,
  8077. 'B': 722,
  8078. 'C': 722,
  8079. 'D': 722,
  8080. 'E': 667,
  8081. 'F': 611,
  8082. 'G': 778,
  8083. 'H': 722,
  8084. 'I': 278,
  8085. 'J': 556,
  8086. 'K': 722,
  8087. 'L': 611,
  8088. 'M': 833,
  8089. 'N': 722,
  8090. 'O': 778,
  8091. 'P': 667,
  8092. 'Q': 778,
  8093. 'R': 722,
  8094. 'S': 667,
  8095. 'T': 611,
  8096. 'U': 722,
  8097. 'V': 667,
  8098. 'W': 944,
  8099. 'X': 667,
  8100. 'Y': 667,
  8101. 'Z': 611,
  8102. 'bracketleft': 333,
  8103. 'backslash': 278,
  8104. 'bracketright': 333,
  8105. 'asciicircum': 584,
  8106. 'underscore': 556,
  8107. 'quoteleft': 278,
  8108. 'a': 556,
  8109. 'b': 611,
  8110. 'c': 556,
  8111. 'd': 611,
  8112. 'e': 556,
  8113. 'f': 333,
  8114. 'g': 611,
  8115. 'h': 611,
  8116. 'i': 278,
  8117. 'j': 278,
  8118. 'k': 556,
  8119. 'l': 278,
  8120. 'm': 889,
  8121. 'n': 611,
  8122. 'o': 611,
  8123. 'p': 611,
  8124. 'q': 611,
  8125. 'r': 389,
  8126. 's': 556,
  8127. 't': 333,
  8128. 'u': 611,
  8129. 'v': 556,
  8130. 'w': 778,
  8131. 'x': 556,
  8132. 'y': 556,
  8133. 'z': 500,
  8134. 'braceleft': 389,
  8135. 'bar': 280,
  8136. 'braceright': 389,
  8137. 'asciitilde': 584,
  8138. 'exclamdown': 333,
  8139. 'cent': 556,
  8140. 'sterling': 556,
  8141. 'fraction': 167,
  8142. 'yen': 556,
  8143. 'florin': 556,
  8144. 'section': 556,
  8145. 'currency': 556,
  8146. 'quotesingle': 238,
  8147. 'quotedblleft': 500,
  8148. 'guillemotleft': 556,
  8149. 'guilsinglleft': 333,
  8150. 'guilsinglright': 333,
  8151. 'fi': 611,
  8152. 'fl': 611,
  8153. 'endash': 556,
  8154. 'dagger': 556,
  8155. 'daggerdbl': 556,
  8156. 'periodcentered': 278,
  8157. 'paragraph': 556,
  8158. 'bullet': 350,
  8159. 'quotesinglbase': 278,
  8160. 'quotedblbase': 500,
  8161. 'quotedblright': 500,
  8162. 'guillemotright': 556,
  8163. 'ellipsis': 1000,
  8164. 'perthousand': 1000,
  8165. 'questiondown': 611,
  8166. 'grave': 333,
  8167. 'acute': 333,
  8168. 'circumflex': 333,
  8169. 'tilde': 333,
  8170. 'macron': 333,
  8171. 'breve': 333,
  8172. 'dotaccent': 333,
  8173. 'dieresis': 333,
  8174. 'ring': 333,
  8175. 'cedilla': 333,
  8176. 'hungarumlaut': 333,
  8177. 'ogonek': 333,
  8178. 'caron': 333,
  8179. 'emdash': 1000,
  8180. 'AE': 1000,
  8181. 'ordfeminine': 370,
  8182. 'Lslash': 611,
  8183. 'Oslash': 778,
  8184. 'OE': 1000,
  8185. 'ordmasculine': 365,
  8186. 'ae': 889,
  8187. 'dotlessi': 278,
  8188. 'lslash': 278,
  8189. 'oslash': 611,
  8190. 'oe': 944,
  8191. 'germandbls': 611,
  8192. 'Idieresis': 278,
  8193. 'eacute': 556,
  8194. 'abreve': 556,
  8195. 'uhungarumlaut': 611,
  8196. 'ecaron': 556,
  8197. 'Ydieresis': 667,
  8198. 'divide': 584,
  8199. 'Yacute': 667,
  8200. 'Acircumflex': 722,
  8201. 'aacute': 556,
  8202. 'Ucircumflex': 722,
  8203. 'yacute': 556,
  8204. 'scommaaccent': 556,
  8205. 'ecircumflex': 556,
  8206. 'Uring': 722,
  8207. 'Udieresis': 722,
  8208. 'aogonek': 556,
  8209. 'Uacute': 722,
  8210. 'uogonek': 611,
  8211. 'Edieresis': 667,
  8212. 'Dcroat': 722,
  8213. 'commaaccent': 250,
  8214. 'copyright': 737,
  8215. 'Emacron': 667,
  8216. 'ccaron': 556,
  8217. 'aring': 556,
  8218. 'Ncommaaccent': 722,
  8219. 'lacute': 278,
  8220. 'agrave': 556,
  8221. 'Tcommaaccent': 611,
  8222. 'Cacute': 722,
  8223. 'atilde': 556,
  8224. 'Edotaccent': 667,
  8225. 'scaron': 556,
  8226. 'scedilla': 556,
  8227. 'iacute': 278,
  8228. 'lozenge': 494,
  8229. 'Rcaron': 722,
  8230. 'Gcommaaccent': 778,
  8231. 'ucircumflex': 611,
  8232. 'acircumflex': 556,
  8233. 'Amacron': 722,
  8234. 'rcaron': 389,
  8235. 'ccedilla': 556,
  8236. 'Zdotaccent': 611,
  8237. 'Thorn': 667,
  8238. 'Omacron': 778,
  8239. 'Racute': 722,
  8240. 'Sacute': 667,
  8241. 'dcaron': 743,
  8242. 'Umacron': 722,
  8243. 'uring': 611,
  8244. 'threesuperior': 333,
  8245. 'Ograve': 778,
  8246. 'Agrave': 722,
  8247. 'Abreve': 722,
  8248. 'multiply': 584,
  8249. 'uacute': 611,
  8250. 'Tcaron': 611,
  8251. 'partialdiff': 494,
  8252. 'ydieresis': 556,
  8253. 'Nacute': 722,
  8254. 'icircumflex': 278,
  8255. 'Ecircumflex': 667,
  8256. 'adieresis': 556,
  8257. 'edieresis': 556,
  8258. 'cacute': 556,
  8259. 'nacute': 611,
  8260. 'umacron': 611,
  8261. 'Ncaron': 722,
  8262. 'Iacute': 278,
  8263. 'plusminus': 584,
  8264. 'brokenbar': 280,
  8265. 'registered': 737,
  8266. 'Gbreve': 778,
  8267. 'Idotaccent': 278,
  8268. 'summation': 600,
  8269. 'Egrave': 667,
  8270. 'racute': 389,
  8271. 'omacron': 611,
  8272. 'Zacute': 611,
  8273. 'Zcaron': 611,
  8274. 'greaterequal': 549,
  8275. 'Eth': 722,
  8276. 'Ccedilla': 722,
  8277. 'lcommaaccent': 278,
  8278. 'tcaron': 389,
  8279. 'eogonek': 556,
  8280. 'Uogonek': 722,
  8281. 'Aacute': 722,
  8282. 'Adieresis': 722,
  8283. 'egrave': 556,
  8284. 'zacute': 500,
  8285. 'iogonek': 278,
  8286. 'Oacute': 778,
  8287. 'oacute': 611,
  8288. 'amacron': 556,
  8289. 'sacute': 556,
  8290. 'idieresis': 278,
  8291. 'Ocircumflex': 778,
  8292. 'Ugrave': 722,
  8293. 'Delta': 612,
  8294. 'thorn': 611,
  8295. 'twosuperior': 333,
  8296. 'Odieresis': 778,
  8297. 'mu': 611,
  8298. 'igrave': 278,
  8299. 'ohungarumlaut': 611,
  8300. 'Eogonek': 667,
  8301. 'dcroat': 611,
  8302. 'threequarters': 834,
  8303. 'Scedilla': 667,
  8304. 'lcaron': 400,
  8305. 'Kcommaaccent': 722,
  8306. 'Lacute': 611,
  8307. 'trademark': 1000,
  8308. 'edotaccent': 556,
  8309. 'Igrave': 278,
  8310. 'Imacron': 278,
  8311. 'Lcaron': 611,
  8312. 'onehalf': 834,
  8313. 'lessequal': 549,
  8314. 'ocircumflex': 611,
  8315. 'ntilde': 611,
  8316. 'Uhungarumlaut': 722,
  8317. 'Eacute': 667,
  8318. 'emacron': 556,
  8319. 'gbreve': 611,
  8320. 'onequarter': 834,
  8321. 'Scaron': 667,
  8322. 'Scommaaccent': 667,
  8323. 'Ohungarumlaut': 778,
  8324. 'degree': 400,
  8325. 'ograve': 611,
  8326. 'Ccaron': 722,
  8327. 'ugrave': 611,
  8328. 'radical': 549,
  8329. 'Dcaron': 722,
  8330. 'rcommaaccent': 389,
  8331. 'Ntilde': 722,
  8332. 'otilde': 611,
  8333. 'Rcommaaccent': 722,
  8334. 'Lcommaaccent': 611,
  8335. 'Atilde': 722,
  8336. 'Aogonek': 722,
  8337. 'Aring': 722,
  8338. 'Otilde': 778,
  8339. 'zdotaccent': 500,
  8340. 'Ecaron': 667,
  8341. 'Iogonek': 278,
  8342. 'kcommaaccent': 556,
  8343. 'minus': 584,
  8344. 'Icircumflex': 278,
  8345. 'ncaron': 611,
  8346. 'tcommaaccent': 333,
  8347. 'logicalnot': 584,
  8348. 'odieresis': 611,
  8349. 'udieresis': 611,
  8350. 'notequal': 549,
  8351. 'gcommaaccent': 611,
  8352. 'eth': 611,
  8353. 'zcaron': 500,
  8354. 'ncommaaccent': 611,
  8355. 'onesuperior': 333,
  8356. 'imacron': 278,
  8357. 'Euro': 556
  8358. },
  8359. 'Helvetica-Oblique' : {
  8360. 'space': 278,
  8361. 'exclam': 278,
  8362. 'quotedbl': 355,
  8363. 'numbersign': 556,
  8364. 'dollar': 556,
  8365. 'percent': 889,
  8366. 'ampersand': 667,
  8367. 'quoteright': 222,
  8368. 'parenleft': 333,
  8369. 'parenright': 333,
  8370. 'asterisk': 389,
  8371. 'plus': 584,
  8372. 'comma': 278,
  8373. 'hyphen': 333,
  8374. 'period': 278,
  8375. 'slash': 278,
  8376. 'zero': 556,
  8377. 'one': 556,
  8378. 'two': 556,
  8379. 'three': 556,
  8380. 'four': 556,
  8381. 'five': 556,
  8382. 'six': 556,
  8383. 'seven': 556,
  8384. 'eight': 556,
  8385. 'nine': 556,
  8386. 'colon': 278,
  8387. 'semicolon': 278,
  8388. 'less': 584,
  8389. 'equal': 584,
  8390. 'greater': 584,
  8391. 'question': 556,
  8392. 'at': 1015,
  8393. 'A': 667,
  8394. 'B': 667,
  8395. 'C': 722,
  8396. 'D': 722,
  8397. 'E': 667,
  8398. 'F': 611,
  8399. 'G': 778,
  8400. 'H': 722,
  8401. 'I': 278,
  8402. 'J': 500,
  8403. 'K': 667,
  8404. 'L': 556,
  8405. 'M': 833,
  8406. 'N': 722,
  8407. 'O': 778,
  8408. 'P': 667,
  8409. 'Q': 778,
  8410. 'R': 722,
  8411. 'S': 667,
  8412. 'T': 611,
  8413. 'U': 722,
  8414. 'V': 667,
  8415. 'W': 944,
  8416. 'X': 667,
  8417. 'Y': 667,
  8418. 'Z': 611,
  8419. 'bracketleft': 278,
  8420. 'backslash': 278,
  8421. 'bracketright': 278,
  8422. 'asciicircum': 469,
  8423. 'underscore': 556,
  8424. 'quoteleft': 222,
  8425. 'a': 556,
  8426. 'b': 556,
  8427. 'c': 500,
  8428. 'd': 556,
  8429. 'e': 556,
  8430. 'f': 278,
  8431. 'g': 556,
  8432. 'h': 556,
  8433. 'i': 222,
  8434. 'j': 222,
  8435. 'k': 500,
  8436. 'l': 222,
  8437. 'm': 833,
  8438. 'n': 556,
  8439. 'o': 556,
  8440. 'p': 556,
  8441. 'q': 556,
  8442. 'r': 333,
  8443. 's': 500,
  8444. 't': 278,
  8445. 'u': 556,
  8446. 'v': 500,
  8447. 'w': 722,
  8448. 'x': 500,
  8449. 'y': 500,
  8450. 'z': 500,
  8451. 'braceleft': 334,
  8452. 'bar': 260,
  8453. 'braceright': 334,
  8454. 'asciitilde': 584,
  8455. 'exclamdown': 333,
  8456. 'cent': 556,
  8457. 'sterling': 556,
  8458. 'fraction': 167,
  8459. 'yen': 556,
  8460. 'florin': 556,
  8461. 'section': 556,
  8462. 'currency': 556,
  8463. 'quotesingle': 191,
  8464. 'quotedblleft': 333,
  8465. 'guillemotleft': 556,
  8466. 'guilsinglleft': 333,
  8467. 'guilsinglright': 333,
  8468. 'fi': 500,
  8469. 'fl': 500,
  8470. 'endash': 556,
  8471. 'dagger': 556,
  8472. 'daggerdbl': 556,
  8473. 'periodcentered': 278,
  8474. 'paragraph': 537,
  8475. 'bullet': 350,
  8476. 'quotesinglbase': 222,
  8477. 'quotedblbase': 333,
  8478. 'quotedblright': 333,
  8479. 'guillemotright': 556,
  8480. 'ellipsis': 1000,
  8481. 'perthousand': 1000,
  8482. 'questiondown': 611,
  8483. 'grave': 333,
  8484. 'acute': 333,
  8485. 'circumflex': 333,
  8486. 'tilde': 333,
  8487. 'macron': 333,
  8488. 'breve': 333,
  8489. 'dotaccent': 333,
  8490. 'dieresis': 333,
  8491. 'ring': 333,
  8492. 'cedilla': 333,
  8493. 'hungarumlaut': 333,
  8494. 'ogonek': 333,
  8495. 'caron': 333,
  8496. 'emdash': 1000,
  8497. 'AE': 1000,
  8498. 'ordfeminine': 370,
  8499. 'Lslash': 556,
  8500. 'Oslash': 778,
  8501. 'OE': 1000,
  8502. 'ordmasculine': 365,
  8503. 'ae': 889,
  8504. 'dotlessi': 278,
  8505. 'lslash': 222,
  8506. 'oslash': 611,
  8507. 'oe': 944,
  8508. 'germandbls': 611,
  8509. 'Idieresis': 278,
  8510. 'eacute': 556,
  8511. 'abreve': 556,
  8512. 'uhungarumlaut': 556,
  8513. 'ecaron': 556,
  8514. 'Ydieresis': 667,
  8515. 'divide': 584,
  8516. 'Yacute': 667,
  8517. 'Acircumflex': 667,
  8518. 'aacute': 556,
  8519. 'Ucircumflex': 722,
  8520. 'yacute': 500,
  8521. 'scommaaccent': 500,
  8522. 'ecircumflex': 556,
  8523. 'Uring': 722,
  8524. 'Udieresis': 722,
  8525. 'aogonek': 556,
  8526. 'Uacute': 722,
  8527. 'uogonek': 556,
  8528. 'Edieresis': 667,
  8529. 'Dcroat': 722,
  8530. 'commaaccent': 250,
  8531. 'copyright': 737,
  8532. 'Emacron': 667,
  8533. 'ccaron': 500,
  8534. 'aring': 556,
  8535. 'Ncommaaccent': 722,
  8536. 'lacute': 222,
  8537. 'agrave': 556,
  8538. 'Tcommaaccent': 611,
  8539. 'Cacute': 722,
  8540. 'atilde': 556,
  8541. 'Edotaccent': 667,
  8542. 'scaron': 500,
  8543. 'scedilla': 500,
  8544. 'iacute': 278,
  8545. 'lozenge': 471,
  8546. 'Rcaron': 722,
  8547. 'Gcommaaccent': 778,
  8548. 'ucircumflex': 556,
  8549. 'acircumflex': 556,
  8550. 'Amacron': 667,
  8551. 'rcaron': 333,
  8552. 'ccedilla': 500,
  8553. 'Zdotaccent': 611,
  8554. 'Thorn': 667,
  8555. 'Omacron': 778,
  8556. 'Racute': 722,
  8557. 'Sacute': 667,
  8558. 'dcaron': 643,
  8559. 'Umacron': 722,
  8560. 'uring': 556,
  8561. 'threesuperior': 333,
  8562. 'Ograve': 778,
  8563. 'Agrave': 667,
  8564. 'Abreve': 667,
  8565. 'multiply': 584,
  8566. 'uacute': 556,
  8567. 'Tcaron': 611,
  8568. 'partialdiff': 476,
  8569. 'ydieresis': 500,
  8570. 'Nacute': 722,
  8571. 'icircumflex': 278,
  8572. 'Ecircumflex': 667,
  8573. 'adieresis': 556,
  8574. 'edieresis': 556,
  8575. 'cacute': 500,
  8576. 'nacute': 556,
  8577. 'umacron': 556,
  8578. 'Ncaron': 722,
  8579. 'Iacute': 278,
  8580. 'plusminus': 584,
  8581. 'brokenbar': 260,
  8582. 'registered': 737,
  8583. 'Gbreve': 778,
  8584. 'Idotaccent': 278,
  8585. 'summation': 600,
  8586. 'Egrave': 667,
  8587. 'racute': 333,
  8588. 'omacron': 556,
  8589. 'Zacute': 611,
  8590. 'Zcaron': 611,
  8591. 'greaterequal': 549,
  8592. 'Eth': 722,
  8593. 'Ccedilla': 722,
  8594. 'lcommaaccent': 222,
  8595. 'tcaron': 317,
  8596. 'eogonek': 556,
  8597. 'Uogonek': 722,
  8598. 'Aacute': 667,
  8599. 'Adieresis': 667,
  8600. 'egrave': 556,
  8601. 'zacute': 500,
  8602. 'iogonek': 222,
  8603. 'Oacute': 778,
  8604. 'oacute': 556,
  8605. 'amacron': 556,
  8606. 'sacute': 500,
  8607. 'idieresis': 278,
  8608. 'Ocircumflex': 778,
  8609. 'Ugrave': 722,
  8610. 'Delta': 612,
  8611. 'thorn': 556,
  8612. 'twosuperior': 333,
  8613. 'Odieresis': 778,
  8614. 'mu': 556,
  8615. 'igrave': 278,
  8616. 'ohungarumlaut': 556,
  8617. 'Eogonek': 667,
  8618. 'dcroat': 556,
  8619. 'threequarters': 834,
  8620. 'Scedilla': 667,
  8621. 'lcaron': 299,
  8622. 'Kcommaaccent': 667,
  8623. 'Lacute': 556,
  8624. 'trademark': 1000,
  8625. 'edotaccent': 556,
  8626. 'Igrave': 278,
  8627. 'Imacron': 278,
  8628. 'Lcaron': 556,
  8629. 'onehalf': 834,
  8630. 'lessequal': 549,
  8631. 'ocircumflex': 556,
  8632. 'ntilde': 556,
  8633. 'Uhungarumlaut': 722,
  8634. 'Eacute': 667,
  8635. 'emacron': 556,
  8636. 'gbreve': 556,
  8637. 'onequarter': 834,
  8638. 'Scaron': 667,
  8639. 'Scommaaccent': 667,
  8640. 'Ohungarumlaut': 778,
  8641. 'degree': 400,
  8642. 'ograve': 556,
  8643. 'Ccaron': 722,
  8644. 'ugrave': 556,
  8645. 'radical': 453,
  8646. 'Dcaron': 722,
  8647. 'rcommaaccent': 333,
  8648. 'Ntilde': 722,
  8649. 'otilde': 556,
  8650. 'Rcommaaccent': 722,
  8651. 'Lcommaaccent': 556,
  8652. 'Atilde': 667,
  8653. 'Aogonek': 667,
  8654. 'Aring': 667,
  8655. 'Otilde': 778,
  8656. 'zdotaccent': 500,
  8657. 'Ecaron': 667,
  8658. 'Iogonek': 278,
  8659. 'kcommaaccent': 500,
  8660. 'minus': 584,
  8661. 'Icircumflex': 278,
  8662. 'ncaron': 556,
  8663. 'tcommaaccent': 278,
  8664. 'logicalnot': 584,
  8665. 'odieresis': 556,
  8666. 'udieresis': 556,
  8667. 'notequal': 549,
  8668. 'gcommaaccent': 556,
  8669. 'eth': 556,
  8670. 'zcaron': 500,
  8671. 'ncommaaccent': 556,
  8672. 'onesuperior': 333,
  8673. 'imacron': 278,
  8674. 'Euro': 556
  8675. },
  8676. 'Symbol': {
  8677. 'space': 250,
  8678. 'exclam': 333,
  8679. 'universal': 713,
  8680. 'numbersign': 500,
  8681. 'existential': 549,
  8682. 'percent': 833,
  8683. 'ampersand': 778,
  8684. 'suchthat': 439,
  8685. 'parenleft': 333,
  8686. 'parenright': 333,
  8687. 'asteriskmath': 500,
  8688. 'plus': 549,
  8689. 'comma': 250,
  8690. 'minus': 549,
  8691. 'period': 250,
  8692. 'slash': 278,
  8693. 'zero': 500,
  8694. 'one': 500,
  8695. 'two': 500,
  8696. 'three': 500,
  8697. 'four': 500,
  8698. 'five': 500,
  8699. 'six': 500,
  8700. 'seven': 500,
  8701. 'eight': 500,
  8702. 'nine': 500,
  8703. 'colon': 278,
  8704. 'semicolon': 278,
  8705. 'less': 549,
  8706. 'equal': 549,
  8707. 'greater': 549,
  8708. 'question': 444,
  8709. 'congruent': 549,
  8710. 'Alpha': 722,
  8711. 'Beta': 667,
  8712. 'Chi': 722,
  8713. 'Delta': 612,
  8714. 'Epsilon': 611,
  8715. 'Phi': 763,
  8716. 'Gamma': 603,
  8717. 'Eta': 722,
  8718. 'Iota': 333,
  8719. 'theta1': 631,
  8720. 'Kappa': 722,
  8721. 'Lambda': 686,
  8722. 'Mu': 889,
  8723. 'Nu': 722,
  8724. 'Omicron': 722,
  8725. 'Pi': 768,
  8726. 'Theta': 741,
  8727. 'Rho': 556,
  8728. 'Sigma': 592,
  8729. 'Tau': 611,
  8730. 'Upsilon': 690,
  8731. 'sigma1': 439,
  8732. 'Omega': 768,
  8733. 'Xi': 645,
  8734. 'Psi': 795,
  8735. 'Zeta': 611,
  8736. 'bracketleft': 333,
  8737. 'therefore': 863,
  8738. 'bracketright': 333,
  8739. 'perpendicular': 658,
  8740. 'underscore': 500,
  8741. 'radicalex': 500,
  8742. 'alpha': 631,
  8743. 'beta': 549,
  8744. 'chi': 549,
  8745. 'delta': 494,
  8746. 'epsilon': 439,
  8747. 'phi': 521,
  8748. 'gamma': 411,
  8749. 'eta': 603,
  8750. 'iota': 329,
  8751. 'phi1': 603,
  8752. 'kappa': 549,
  8753. 'lambda': 549,
  8754. 'mu': 576,
  8755. 'nu': 521,
  8756. 'omicron': 549,
  8757. 'pi': 549,
  8758. 'theta': 521,
  8759. 'rho': 549,
  8760. 'sigma': 603,
  8761. 'tau': 439,
  8762. 'upsilon': 576,
  8763. 'omega1': 713,
  8764. 'omega': 686,
  8765. 'xi': 493,
  8766. 'psi': 686,
  8767. 'zeta': 494,
  8768. 'braceleft': 480,
  8769. 'bar': 200,
  8770. 'braceright': 480,
  8771. 'similar': 549,
  8772. 'Euro': 750,
  8773. 'Upsilon1': 620,
  8774. 'minute': 247,
  8775. 'lessequal': 549,
  8776. 'fraction': 167,
  8777. 'infinity': 713,
  8778. 'florin': 500,
  8779. 'club': 753,
  8780. 'diamond': 753,
  8781. 'heart': 753,
  8782. 'spade': 753,
  8783. 'arrowboth': 1042,
  8784. 'arrowleft': 987,
  8785. 'arrowup': 603,
  8786. 'arrowright': 987,
  8787. 'arrowdown': 603,
  8788. 'degree': 400,
  8789. 'plusminus': 549,
  8790. 'second': 411,
  8791. 'greaterequal': 549,
  8792. 'multiply': 549,
  8793. 'proportional': 713,
  8794. 'partialdiff': 494,
  8795. 'bullet': 460,
  8796. 'divide': 549,
  8797. 'notequal': 549,
  8798. 'equivalence': 549,
  8799. 'approxequal': 549,
  8800. 'ellipsis': 1000,
  8801. 'arrowvertex': 603,
  8802. 'arrowhorizex': 1000,
  8803. 'carriagereturn': 658,
  8804. 'aleph': 823,
  8805. 'Ifraktur': 686,
  8806. 'Rfraktur': 795,
  8807. 'weierstrass': 987,
  8808. 'circlemultiply': 768,
  8809. 'circleplus': 768,
  8810. 'emptyset': 823,
  8811. 'intersection': 768,
  8812. 'union': 768,
  8813. 'propersuperset': 713,
  8814. 'reflexsuperset': 713,
  8815. 'notsubset': 713,
  8816. 'propersubset': 713,
  8817. 'reflexsubset': 713,
  8818. 'element': 713,
  8819. 'notelement': 713,
  8820. 'angle': 768,
  8821. 'gradient': 713,
  8822. 'registerserif': 790,
  8823. 'copyrightserif': 790,
  8824. 'trademarkserif': 890,
  8825. 'product': 823,
  8826. 'radical': 549,
  8827. 'dotmath': 250,
  8828. 'logicalnot': 713,
  8829. 'logicaland': 603,
  8830. 'logicalor': 603,
  8831. 'arrowdblboth': 1042,
  8832. 'arrowdblleft': 987,
  8833. 'arrowdblup': 603,
  8834. 'arrowdblright': 987,
  8835. 'arrowdbldown': 603,
  8836. 'lozenge': 494,
  8837. 'angleleft': 329,
  8838. 'registersans': 790,
  8839. 'copyrightsans': 790,
  8840. 'trademarksans': 786,
  8841. 'summation': 713,
  8842. 'parenlefttp': 384,
  8843. 'parenleftex': 384,
  8844. 'parenleftbt': 384,
  8845. 'bracketlefttp': 384,
  8846. 'bracketleftex': 384,
  8847. 'bracketleftbt': 384,
  8848. 'bracelefttp': 494,
  8849. 'braceleftmid': 494,
  8850. 'braceleftbt': 494,
  8851. 'braceex': 494,
  8852. 'angleright': 329,
  8853. 'integral': 274,
  8854. 'integraltp': 686,
  8855. 'integralex': 686,
  8856. 'integralbt': 686,
  8857. 'parenrighttp': 384,
  8858. 'parenrightex': 384,
  8859. 'parenrightbt': 384,
  8860. 'bracketrighttp': 384,
  8861. 'bracketrightex': 384,
  8862. 'bracketrightbt': 384,
  8863. 'bracerighttp': 494,
  8864. 'bracerightmid': 494,
  8865. 'bracerightbt': 494,
  8866. 'apple': 790
  8867. },
  8868. 'Times-Roman': {
  8869. 'space': 250,
  8870. 'exclam': 333,
  8871. 'quotedbl': 408,
  8872. 'numbersign': 500,
  8873. 'dollar': 500,
  8874. 'percent': 833,
  8875. 'ampersand': 778,
  8876. 'quoteright': 333,
  8877. 'parenleft': 333,
  8878. 'parenright': 333,
  8879. 'asterisk': 500,
  8880. 'plus': 564,
  8881. 'comma': 250,
  8882. 'hyphen': 333,
  8883. 'period': 250,
  8884. 'slash': 278,
  8885. 'zero': 500,
  8886. 'one': 500,
  8887. 'two': 500,
  8888. 'three': 500,
  8889. 'four': 500,
  8890. 'five': 500,
  8891. 'six': 500,
  8892. 'seven': 500,
  8893. 'eight': 500,
  8894. 'nine': 500,
  8895. 'colon': 278,
  8896. 'semicolon': 278,
  8897. 'less': 564,
  8898. 'equal': 564,
  8899. 'greater': 564,
  8900. 'question': 444,
  8901. 'at': 921,
  8902. 'A': 722,
  8903. 'B': 667,
  8904. 'C': 667,
  8905. 'D': 722,
  8906. 'E': 611,
  8907. 'F': 556,
  8908. 'G': 722,
  8909. 'H': 722,
  8910. 'I': 333,
  8911. 'J': 389,
  8912. 'K': 722,
  8913. 'L': 611,
  8914. 'M': 889,
  8915. 'N': 722,
  8916. 'O': 722,
  8917. 'P': 556,
  8918. 'Q': 722,
  8919. 'R': 667,
  8920. 'S': 556,
  8921. 'T': 611,
  8922. 'U': 722,
  8923. 'V': 722,
  8924. 'W': 944,
  8925. 'X': 722,
  8926. 'Y': 722,
  8927. 'Z': 611,
  8928. 'bracketleft': 333,
  8929. 'backslash': 278,
  8930. 'bracketright': 333,
  8931. 'asciicircum': 469,
  8932. 'underscore': 500,
  8933. 'quoteleft': 333,
  8934. 'a': 444,
  8935. 'b': 500,
  8936. 'c': 444,
  8937. 'd': 500,
  8938. 'e': 444,
  8939. 'f': 333,
  8940. 'g': 500,
  8941. 'h': 500,
  8942. 'i': 278,
  8943. 'j': 278,
  8944. 'k': 500,
  8945. 'l': 278,
  8946. 'm': 778,
  8947. 'n': 500,
  8948. 'o': 500,
  8949. 'p': 500,
  8950. 'q': 500,
  8951. 'r': 333,
  8952. 's': 389,
  8953. 't': 278,
  8954. 'u': 500,
  8955. 'v': 500,
  8956. 'w': 722,
  8957. 'x': 500,
  8958. 'y': 500,
  8959. 'z': 444,
  8960. 'braceleft': 480,
  8961. 'bar': 200,
  8962. 'braceright': 480,
  8963. 'asciitilde': 541,
  8964. 'exclamdown': 333,
  8965. 'cent': 500,
  8966. 'sterling': 500,
  8967. 'fraction': 167,
  8968. 'yen': 500,
  8969. 'florin': 500,
  8970. 'section': 500,
  8971. 'currency': 500,
  8972. 'quotesingle': 180,
  8973. 'quotedblleft': 444,
  8974. 'guillemotleft': 500,
  8975. 'guilsinglleft': 333,
  8976. 'guilsinglright': 333,
  8977. 'fi': 556,
  8978. 'fl': 556,
  8979. 'endash': 500,
  8980. 'dagger': 500,
  8981. 'daggerdbl': 500,
  8982. 'periodcentered': 250,
  8983. 'paragraph': 453,
  8984. 'bullet': 350,
  8985. 'quotesinglbase': 333,
  8986. 'quotedblbase': 444,
  8987. 'quotedblright': 444,
  8988. 'guillemotright': 500,
  8989. 'ellipsis': 1000,
  8990. 'perthousand': 1000,
  8991. 'questiondown': 444,
  8992. 'grave': 333,
  8993. 'acute': 333,
  8994. 'circumflex': 333,
  8995. 'tilde': 333,
  8996. 'macron': 333,
  8997. 'breve': 333,
  8998. 'dotaccent': 333,
  8999. 'dieresis': 333,
  9000. 'ring': 333,
  9001. 'cedilla': 333,
  9002. 'hungarumlaut': 333,
  9003. 'ogonek': 333,
  9004. 'caron': 333,
  9005. 'emdash': 1000,
  9006. 'AE': 889,
  9007. 'ordfeminine': 276,
  9008. 'Lslash': 611,
  9009. 'Oslash': 722,
  9010. 'OE': 889,
  9011. 'ordmasculine': 310,
  9012. 'ae': 667,
  9013. 'dotlessi': 278,
  9014. 'lslash': 278,
  9015. 'oslash': 500,
  9016. 'oe': 722,
  9017. 'germandbls': 500,
  9018. 'Idieresis': 333,
  9019. 'eacute': 444,
  9020. 'abreve': 444,
  9021. 'uhungarumlaut': 500,
  9022. 'ecaron': 444,
  9023. 'Ydieresis': 722,
  9024. 'divide': 564,
  9025. 'Yacute': 722,
  9026. 'Acircumflex': 722,
  9027. 'aacute': 444,
  9028. 'Ucircumflex': 722,
  9029. 'yacute': 500,
  9030. 'scommaaccent': 389,
  9031. 'ecircumflex': 444,
  9032. 'Uring': 722,
  9033. 'Udieresis': 722,
  9034. 'aogonek': 444,
  9035. 'Uacute': 722,
  9036. 'uogonek': 500,
  9037. 'Edieresis': 611,
  9038. 'Dcroat': 722,
  9039. 'commaaccent': 250,
  9040. 'copyright': 760,
  9041. 'Emacron': 611,
  9042. 'ccaron': 444,
  9043. 'aring': 444,
  9044. 'Ncommaaccent': 722,
  9045. 'lacute': 278,
  9046. 'agrave': 444,
  9047. 'Tcommaaccent': 611,
  9048. 'Cacute': 667,
  9049. 'atilde': 444,
  9050. 'Edotaccent': 611,
  9051. 'scaron': 389,
  9052. 'scedilla': 389,
  9053. 'iacute': 278,
  9054. 'lozenge': 471,
  9055. 'Rcaron': 667,
  9056. 'Gcommaaccent': 722,
  9057. 'ucircumflex': 500,
  9058. 'acircumflex': 444,
  9059. 'Amacron': 722,
  9060. 'rcaron': 333,
  9061. 'ccedilla': 444,
  9062. 'Zdotaccent': 611,
  9063. 'Thorn': 556,
  9064. 'Omacron': 722,
  9065. 'Racute': 667,
  9066. 'Sacute': 556,
  9067. 'dcaron': 588,
  9068. 'Umacron': 722,
  9069. 'uring': 500,
  9070. 'threesuperior': 300,
  9071. 'Ograve': 722,
  9072. 'Agrave': 722,
  9073. 'Abreve': 722,
  9074. 'multiply': 564,
  9075. 'uacute': 500,
  9076. 'Tcaron': 611,
  9077. 'partialdiff': 476,
  9078. 'ydieresis': 500,
  9079. 'Nacute': 722,
  9080. 'icircumflex': 278,
  9081. 'Ecircumflex': 611,
  9082. 'adieresis': 444,
  9083. 'edieresis': 444,
  9084. 'cacute': 444,
  9085. 'nacute': 500,
  9086. 'umacron': 500,
  9087. 'Ncaron': 722,
  9088. 'Iacute': 333,
  9089. 'plusminus': 564,
  9090. 'brokenbar': 200,
  9091. 'registered': 760,
  9092. 'Gbreve': 722,
  9093. 'Idotaccent': 333,
  9094. 'summation': 600,
  9095. 'Egrave': 611,
  9096. 'racute': 333,
  9097. 'omacron': 500,
  9098. 'Zacute': 611,
  9099. 'Zcaron': 611,
  9100. 'greaterequal': 549,
  9101. 'Eth': 722,
  9102. 'Ccedilla': 667,
  9103. 'lcommaaccent': 278,
  9104. 'tcaron': 326,
  9105. 'eogonek': 444,
  9106. 'Uogonek': 722,
  9107. 'Aacute': 722,
  9108. 'Adieresis': 722,
  9109. 'egrave': 444,
  9110. 'zacute': 444,
  9111. 'iogonek': 278,
  9112. 'Oacute': 722,
  9113. 'oacute': 500,
  9114. 'amacron': 444,
  9115. 'sacute': 389,
  9116. 'idieresis': 278,
  9117. 'Ocircumflex': 722,
  9118. 'Ugrave': 722,
  9119. 'Delta': 612,
  9120. 'thorn': 500,
  9121. 'twosuperior': 300,
  9122. 'Odieresis': 722,
  9123. 'mu': 500,
  9124. 'igrave': 278,
  9125. 'ohungarumlaut': 500,
  9126. 'Eogonek': 611,
  9127. 'dcroat': 500,
  9128. 'threequarters': 750,
  9129. 'Scedilla': 556,
  9130. 'lcaron': 344,
  9131. 'Kcommaaccent': 722,
  9132. 'Lacute': 611,
  9133. 'trademark': 980,
  9134. 'edotaccent': 444,
  9135. 'Igrave': 333,
  9136. 'Imacron': 333,
  9137. 'Lcaron': 611,
  9138. 'onehalf': 750,
  9139. 'lessequal': 549,
  9140. 'ocircumflex': 500,
  9141. 'ntilde': 500,
  9142. 'Uhungarumlaut': 722,
  9143. 'Eacute': 611,
  9144. 'emacron': 444,
  9145. 'gbreve': 500,
  9146. 'onequarter': 750,
  9147. 'Scaron': 556,
  9148. 'Scommaaccent': 556,
  9149. 'Ohungarumlaut': 722,
  9150. 'degree': 400,
  9151. 'ograve': 500,
  9152. 'Ccaron': 667,
  9153. 'ugrave': 500,
  9154. 'radical': 453,
  9155. 'Dcaron': 722,
  9156. 'rcommaaccent': 333,
  9157. 'Ntilde': 722,
  9158. 'otilde': 500,
  9159. 'Rcommaaccent': 667,
  9160. 'Lcommaaccent': 611,
  9161. 'Atilde': 722,
  9162. 'Aogonek': 722,
  9163. 'Aring': 722,
  9164. 'Otilde': 722,
  9165. 'zdotaccent': 444,
  9166. 'Ecaron': 611,
  9167. 'Iogonek': 333,
  9168. 'kcommaaccent': 500,
  9169. 'minus': 564,
  9170. 'Icircumflex': 333,
  9171. 'ncaron': 500,
  9172. 'tcommaaccent': 278,
  9173. 'logicalnot': 564,
  9174. 'odieresis': 500,
  9175. 'udieresis': 500,
  9176. 'notequal': 549,
  9177. 'gcommaaccent': 500,
  9178. 'eth': 500,
  9179. 'zcaron': 444,
  9180. 'ncommaaccent': 500,
  9181. 'onesuperior': 300,
  9182. 'imacron': 278,
  9183. 'Euro': 500
  9184. },
  9185. 'Times-Bold': {
  9186. 'space': 250,
  9187. 'exclam': 333,
  9188. 'quotedbl': 555,
  9189. 'numbersign': 500,
  9190. 'dollar': 500,
  9191. 'percent': 1000,
  9192. 'ampersand': 833,
  9193. 'quoteright': 333,
  9194. 'parenleft': 333,
  9195. 'parenright': 333,
  9196. 'asterisk': 500,
  9197. 'plus': 570,
  9198. 'comma': 250,
  9199. 'hyphen': 333,
  9200. 'period': 250,
  9201. 'slash': 278,
  9202. 'zero': 500,
  9203. 'one': 500,
  9204. 'two': 500,
  9205. 'three': 500,
  9206. 'four': 500,
  9207. 'five': 500,
  9208. 'six': 500,
  9209. 'seven': 500,
  9210. 'eight': 500,
  9211. 'nine': 500,
  9212. 'colon': 333,
  9213. 'semicolon': 333,
  9214. 'less': 570,
  9215. 'equal': 570,
  9216. 'greater': 570,
  9217. 'question': 500,
  9218. 'at': 930,
  9219. 'A': 722,
  9220. 'B': 667,
  9221. 'C': 722,
  9222. 'D': 722,
  9223. 'E': 667,
  9224. 'F': 611,
  9225. 'G': 778,
  9226. 'H': 778,
  9227. 'I': 389,
  9228. 'J': 500,
  9229. 'K': 778,
  9230. 'L': 667,
  9231. 'M': 944,
  9232. 'N': 722,
  9233. 'O': 778,
  9234. 'P': 611,
  9235. 'Q': 778,
  9236. 'R': 722,
  9237. 'S': 556,
  9238. 'T': 667,
  9239. 'U': 722,
  9240. 'V': 722,
  9241. 'W': 1000,
  9242. 'X': 722,
  9243. 'Y': 722,
  9244. 'Z': 667,
  9245. 'bracketleft': 333,
  9246. 'backslash': 278,
  9247. 'bracketright': 333,
  9248. 'asciicircum': 581,
  9249. 'underscore': 500,
  9250. 'quoteleft': 333,
  9251. 'a': 500,
  9252. 'b': 556,
  9253. 'c': 444,
  9254. 'd': 556,
  9255. 'e': 444,
  9256. 'f': 333,
  9257. 'g': 500,
  9258. 'h': 556,
  9259. 'i': 278,
  9260. 'j': 333,
  9261. 'k': 556,
  9262. 'l': 278,
  9263. 'm': 833,
  9264. 'n': 556,
  9265. 'o': 500,
  9266. 'p': 556,
  9267. 'q': 556,
  9268. 'r': 444,
  9269. 's': 389,
  9270. 't': 333,
  9271. 'u': 556,
  9272. 'v': 500,
  9273. 'w': 722,
  9274. 'x': 500,
  9275. 'y': 500,
  9276. 'z': 444,
  9277. 'braceleft': 394,
  9278. 'bar': 220,
  9279. 'braceright': 394,
  9280. 'asciitilde': 520,
  9281. 'exclamdown': 333,
  9282. 'cent': 500,
  9283. 'sterling': 500,
  9284. 'fraction': 167,
  9285. 'yen': 500,
  9286. 'florin': 500,
  9287. 'section': 500,
  9288. 'currency': 500,
  9289. 'quotesingle': 278,
  9290. 'quotedblleft': 500,
  9291. 'guillemotleft': 500,
  9292. 'guilsinglleft': 333,
  9293. 'guilsinglright': 333,
  9294. 'fi': 556,
  9295. 'fl': 556,
  9296. 'endash': 500,
  9297. 'dagger': 500,
  9298. 'daggerdbl': 500,
  9299. 'periodcentered': 250,
  9300. 'paragraph': 540,
  9301. 'bullet': 350,
  9302. 'quotesinglbase': 333,
  9303. 'quotedblbase': 500,
  9304. 'quotedblright': 500,
  9305. 'guillemotright': 500,
  9306. 'ellipsis': 1000,
  9307. 'perthousand': 1000,
  9308. 'questiondown': 500,
  9309. 'grave': 333,
  9310. 'acute': 333,
  9311. 'circumflex': 333,
  9312. 'tilde': 333,
  9313. 'macron': 333,
  9314. 'breve': 333,
  9315. 'dotaccent': 333,
  9316. 'dieresis': 333,
  9317. 'ring': 333,
  9318. 'cedilla': 333,
  9319. 'hungarumlaut': 333,
  9320. 'ogonek': 333,
  9321. 'caron': 333,
  9322. 'emdash': 1000,
  9323. 'AE': 1000,
  9324. 'ordfeminine': 300,
  9325. 'Lslash': 667,
  9326. 'Oslash': 778,
  9327. 'OE': 1000,
  9328. 'ordmasculine': 330,
  9329. 'ae': 722,
  9330. 'dotlessi': 278,
  9331. 'lslash': 278,
  9332. 'oslash': 500,
  9333. 'oe': 722,
  9334. 'germandbls': 556,
  9335. 'Idieresis': 389,
  9336. 'eacute': 444,
  9337. 'abreve': 500,
  9338. 'uhungarumlaut': 556,
  9339. 'ecaron': 444,
  9340. 'Ydieresis': 722,
  9341. 'divide': 570,
  9342. 'Yacute': 722,
  9343. 'Acircumflex': 722,
  9344. 'aacute': 500,
  9345. 'Ucircumflex': 722,
  9346. 'yacute': 500,
  9347. 'scommaaccent': 389,
  9348. 'ecircumflex': 444,
  9349. 'Uring': 722,
  9350. 'Udieresis': 722,
  9351. 'aogonek': 500,
  9352. 'Uacute': 722,
  9353. 'uogonek': 556,
  9354. 'Edieresis': 667,
  9355. 'Dcroat': 722,
  9356. 'commaaccent': 250,
  9357. 'copyright': 747,
  9358. 'Emacron': 667,
  9359. 'ccaron': 444,
  9360. 'aring': 500,
  9361. 'Ncommaaccent': 722,
  9362. 'lacute': 278,
  9363. 'agrave': 500,
  9364. 'Tcommaaccent': 667,
  9365. 'Cacute': 722,
  9366. 'atilde': 500,
  9367. 'Edotaccent': 667,
  9368. 'scaron': 389,
  9369. 'scedilla': 389,
  9370. 'iacute': 278,
  9371. 'lozenge': 494,
  9372. 'Rcaron': 722,
  9373. 'Gcommaaccent': 778,
  9374. 'ucircumflex': 556,
  9375. 'acircumflex': 500,
  9376. 'Amacron': 722,
  9377. 'rcaron': 444,
  9378. 'ccedilla': 444,
  9379. 'Zdotaccent': 667,
  9380. 'Thorn': 611,
  9381. 'Omacron': 778,
  9382. 'Racute': 722,
  9383. 'Sacute': 556,
  9384. 'dcaron': 672,
  9385. 'Umacron': 722,
  9386. 'uring': 556,
  9387. 'threesuperior': 300,
  9388. 'Ograve': 778,
  9389. 'Agrave': 722,
  9390. 'Abreve': 722,
  9391. 'multiply': 570,
  9392. 'uacute': 556,
  9393. 'Tcaron': 667,
  9394. 'partialdiff': 494,
  9395. 'ydieresis': 500,
  9396. 'Nacute': 722,
  9397. 'icircumflex': 278,
  9398. 'Ecircumflex': 667,
  9399. 'adieresis': 500,
  9400. 'edieresis': 444,
  9401. 'cacute': 444,
  9402. 'nacute': 556,
  9403. 'umacron': 556,
  9404. 'Ncaron': 722,
  9405. 'Iacute': 389,
  9406. 'plusminus': 570,
  9407. 'brokenbar': 220,
  9408. 'registered': 747,
  9409. 'Gbreve': 778,
  9410. 'Idotaccent': 389,
  9411. 'summation': 600,
  9412. 'Egrave': 667,
  9413. 'racute': 444,
  9414. 'omacron': 500,
  9415. 'Zacute': 667,
  9416. 'Zcaron': 667,
  9417. 'greaterequal': 549,
  9418. 'Eth': 722,
  9419. 'Ccedilla': 722,
  9420. 'lcommaaccent': 278,
  9421. 'tcaron': 416,
  9422. 'eogonek': 444,
  9423. 'Uogonek': 722,
  9424. 'Aacute': 722,
  9425. 'Adieresis': 722,
  9426. 'egrave': 444,
  9427. 'zacute': 444,
  9428. 'iogonek': 278,
  9429. 'Oacute': 778,
  9430. 'oacute': 500,
  9431. 'amacron': 500,
  9432. 'sacute': 389,
  9433. 'idieresis': 278,
  9434. 'Ocircumflex': 778,
  9435. 'Ugrave': 722,
  9436. 'Delta': 612,
  9437. 'thorn': 556,
  9438. 'twosuperior': 300,
  9439. 'Odieresis': 778,
  9440. 'mu': 556,
  9441. 'igrave': 278,
  9442. 'ohungarumlaut': 500,
  9443. 'Eogonek': 667,
  9444. 'dcroat': 556,
  9445. 'threequarters': 750,
  9446. 'Scedilla': 556,
  9447. 'lcaron': 394,
  9448. 'Kcommaaccent': 778,
  9449. 'Lacute': 667,
  9450. 'trademark': 1000,
  9451. 'edotaccent': 444,
  9452. 'Igrave': 389,
  9453. 'Imacron': 389,
  9454. 'Lcaron': 667,
  9455. 'onehalf': 750,
  9456. 'lessequal': 549,
  9457. 'ocircumflex': 500,
  9458. 'ntilde': 556,
  9459. 'Uhungarumlaut': 722,
  9460. 'Eacute': 667,
  9461. 'emacron': 444,
  9462. 'gbreve': 500,
  9463. 'onequarter': 750,
  9464. 'Scaron': 556,
  9465. 'Scommaaccent': 556,
  9466. 'Ohungarumlaut': 778,
  9467. 'degree': 400,
  9468. 'ograve': 500,
  9469. 'Ccaron': 722,
  9470. 'ugrave': 556,
  9471. 'radical': 549,
  9472. 'Dcaron': 722,
  9473. 'rcommaaccent': 444,
  9474. 'Ntilde': 722,
  9475. 'otilde': 500,
  9476. 'Rcommaaccent': 722,
  9477. 'Lcommaaccent': 667,
  9478. 'Atilde': 722,
  9479. 'Aogonek': 722,
  9480. 'Aring': 722,
  9481. 'Otilde': 778,
  9482. 'zdotaccent': 444,
  9483. 'Ecaron': 667,
  9484. 'Iogonek': 389,
  9485. 'kcommaaccent': 556,
  9486. 'minus': 570,
  9487. 'Icircumflex': 389,
  9488. 'ncaron': 556,
  9489. 'tcommaaccent': 333,
  9490. 'logicalnot': 570,
  9491. 'odieresis': 500,
  9492. 'udieresis': 556,
  9493. 'notequal': 549,
  9494. 'gcommaaccent': 500,
  9495. 'eth': 500,
  9496. 'zcaron': 444,
  9497. 'ncommaaccent': 556,
  9498. 'onesuperior': 300,
  9499. 'imacron': 278,
  9500. 'Euro': 500
  9501. },
  9502. 'Times-BoldItalic': {
  9503. 'space': 250,
  9504. 'exclam': 389,
  9505. 'quotedbl': 555,
  9506. 'numbersign': 500,
  9507. 'dollar': 500,
  9508. 'percent': 833,
  9509. 'ampersand': 778,
  9510. 'quoteright': 333,
  9511. 'parenleft': 333,
  9512. 'parenright': 333,
  9513. 'asterisk': 500,
  9514. 'plus': 570,
  9515. 'comma': 250,
  9516. 'hyphen': 333,
  9517. 'period': 250,
  9518. 'slash': 278,
  9519. 'zero': 500,
  9520. 'one': 500,
  9521. 'two': 500,
  9522. 'three': 500,
  9523. 'four': 500,
  9524. 'five': 500,
  9525. 'six': 500,
  9526. 'seven': 500,
  9527. 'eight': 500,
  9528. 'nine': 500,
  9529. 'colon': 333,
  9530. 'semicolon': 333,
  9531. 'less': 570,
  9532. 'equal': 570,
  9533. 'greater': 570,
  9534. 'question': 500,
  9535. 'at': 832,
  9536. 'A': 667,
  9537. 'B': 667,
  9538. 'C': 667,
  9539. 'D': 722,
  9540. 'E': 667,
  9541. 'F': 667,
  9542. 'G': 722,
  9543. 'H': 778,
  9544. 'I': 389,
  9545. 'J': 500,
  9546. 'K': 667,
  9547. 'L': 611,
  9548. 'M': 889,
  9549. 'N': 722,
  9550. 'O': 722,
  9551. 'P': 611,
  9552. 'Q': 722,
  9553. 'R': 667,
  9554. 'S': 556,
  9555. 'T': 611,
  9556. 'U': 722,
  9557. 'V': 667,
  9558. 'W': 889,
  9559. 'X': 667,
  9560. 'Y': 611,
  9561. 'Z': 611,
  9562. 'bracketleft': 333,
  9563. 'backslash': 278,
  9564. 'bracketright': 333,
  9565. 'asciicircum': 570,
  9566. 'underscore': 500,
  9567. 'quoteleft': 333,
  9568. 'a': 500,
  9569. 'b': 500,
  9570. 'c': 444,
  9571. 'd': 500,
  9572. 'e': 444,
  9573. 'f': 333,
  9574. 'g': 500,
  9575. 'h': 556,
  9576. 'i': 278,
  9577. 'j': 278,
  9578. 'k': 500,
  9579. 'l': 278,
  9580. 'm': 778,
  9581. 'n': 556,
  9582. 'o': 500,
  9583. 'p': 500,
  9584. 'q': 500,
  9585. 'r': 389,
  9586. 's': 389,
  9587. 't': 278,
  9588. 'u': 556,
  9589. 'v': 444,
  9590. 'w': 667,
  9591. 'x': 500,
  9592. 'y': 444,
  9593. 'z': 389,
  9594. 'braceleft': 348,
  9595. 'bar': 220,
  9596. 'braceright': 348,
  9597. 'asciitilde': 570,
  9598. 'exclamdown': 389,
  9599. 'cent': 500,
  9600. 'sterling': 500,
  9601. 'fraction': 167,
  9602. 'yen': 500,
  9603. 'florin': 500,
  9604. 'section': 500,
  9605. 'currency': 500,
  9606. 'quotesingle': 278,
  9607. 'quotedblleft': 500,
  9608. 'guillemotleft': 500,
  9609. 'guilsinglleft': 333,
  9610. 'guilsinglright': 333,
  9611. 'fi': 556,
  9612. 'fl': 556,
  9613. 'endash': 500,
  9614. 'dagger': 500,
  9615. 'daggerdbl': 500,
  9616. 'periodcentered': 250,
  9617. 'paragraph': 500,
  9618. 'bullet': 350,
  9619. 'quotesinglbase': 333,
  9620. 'quotedblbase': 500,
  9621. 'quotedblright': 500,
  9622. 'guillemotright': 500,
  9623. 'ellipsis': 1000,
  9624. 'perthousand': 1000,
  9625. 'questiondown': 500,
  9626. 'grave': 333,
  9627. 'acute': 333,
  9628. 'circumflex': 333,
  9629. 'tilde': 333,
  9630. 'macron': 333,
  9631. 'breve': 333,
  9632. 'dotaccent': 333,
  9633. 'dieresis': 333,
  9634. 'ring': 333,
  9635. 'cedilla': 333,
  9636. 'hungarumlaut': 333,
  9637. 'ogonek': 333,
  9638. 'caron': 333,
  9639. 'emdash': 1000,
  9640. 'AE': 944,
  9641. 'ordfeminine': 266,
  9642. 'Lslash': 611,
  9643. 'Oslash': 722,
  9644. 'OE': 944,
  9645. 'ordmasculine': 300,
  9646. 'ae': 722,
  9647. 'dotlessi': 278,
  9648. 'lslash': 278,
  9649. 'oslash': 500,
  9650. 'oe': 722,
  9651. 'germandbls': 500,
  9652. 'Idieresis': 389,
  9653. 'eacute': 444,
  9654. 'abreve': 500,
  9655. 'uhungarumlaut': 556,
  9656. 'ecaron': 444,
  9657. 'Ydieresis': 611,
  9658. 'divide': 570,
  9659. 'Yacute': 611,
  9660. 'Acircumflex': 667,
  9661. 'aacute': 500,
  9662. 'Ucircumflex': 722,
  9663. 'yacute': 444,
  9664. 'scommaaccent': 389,
  9665. 'ecircumflex': 444,
  9666. 'Uring': 722,
  9667. 'Udieresis': 722,
  9668. 'aogonek': 500,
  9669. 'Uacute': 722,
  9670. 'uogonek': 556,
  9671. 'Edieresis': 667,
  9672. 'Dcroat': 722,
  9673. 'commaaccent': 250,
  9674. 'copyright': 747,
  9675. 'Emacron': 667,
  9676. 'ccaron': 444,
  9677. 'aring': 500,
  9678. 'Ncommaaccent': 722,
  9679. 'lacute': 278,
  9680. 'agrave': 500,
  9681. 'Tcommaaccent': 611,
  9682. 'Cacute': 667,
  9683. 'atilde': 500,
  9684. 'Edotaccent': 667,
  9685. 'scaron': 389,
  9686. 'scedilla': 389,
  9687. 'iacute': 278,
  9688. 'lozenge': 494,
  9689. 'Rcaron': 667,
  9690. 'Gcommaaccent': 722,
  9691. 'ucircumflex': 556,
  9692. 'acircumflex': 500,
  9693. 'Amacron': 667,
  9694. 'rcaron': 389,
  9695. 'ccedilla': 444,
  9696. 'Zdotaccent': 611,
  9697. 'Thorn': 611,
  9698. 'Omacron': 722,
  9699. 'Racute': 667,
  9700. 'Sacute': 556,
  9701. 'dcaron': 608,
  9702. 'Umacron': 722,
  9703. 'uring': 556,
  9704. 'threesuperior': 300,
  9705. 'Ograve': 722,
  9706. 'Agrave': 667,
  9707. 'Abreve': 667,
  9708. 'multiply': 570,
  9709. 'uacute': 556,
  9710. 'Tcaron': 611,
  9711. 'partialdiff': 494,
  9712. 'ydieresis': 444,
  9713. 'Nacute': 722,
  9714. 'icircumflex': 278,
  9715. 'Ecircumflex': 667,
  9716. 'adieresis': 500,
  9717. 'edieresis': 444,
  9718. 'cacute': 444,
  9719. 'nacute': 556,
  9720. 'umacron': 556,
  9721. 'Ncaron': 722,
  9722. 'Iacute': 389,
  9723. 'plusminus': 570,
  9724. 'brokenbar': 220,
  9725. 'registered': 747,
  9726. 'Gbreve': 722,
  9727. 'Idotaccent': 389,
  9728. 'summation': 600,
  9729. 'Egrave': 667,
  9730. 'racute': 389,
  9731. 'omacron': 500,
  9732. 'Zacute': 611,
  9733. 'Zcaron': 611,
  9734. 'greaterequal': 549,
  9735. 'Eth': 722,
  9736. 'Ccedilla': 667,
  9737. 'lcommaaccent': 278,
  9738. 'tcaron': 366,
  9739. 'eogonek': 444,
  9740. 'Uogonek': 722,
  9741. 'Aacute': 667,
  9742. 'Adieresis': 667,
  9743. 'egrave': 444,
  9744. 'zacute': 389,
  9745. 'iogonek': 278,
  9746. 'Oacute': 722,
  9747. 'oacute': 500,
  9748. 'amacron': 500,
  9749. 'sacute': 389,
  9750. 'idieresis': 278,
  9751. 'Ocircumflex': 722,
  9752. 'Ugrave': 722,
  9753. 'Delta': 612,
  9754. 'thorn': 500,
  9755. 'twosuperior': 300,
  9756. 'Odieresis': 722,
  9757. 'mu': 576,
  9758. 'igrave': 278,
  9759. 'ohungarumlaut': 500,
  9760. 'Eogonek': 667,
  9761. 'dcroat': 500,
  9762. 'threequarters': 750,
  9763. 'Scedilla': 556,
  9764. 'lcaron': 382,
  9765. 'Kcommaaccent': 667,
  9766. 'Lacute': 611,
  9767. 'trademark': 1000,
  9768. 'edotaccent': 444,
  9769. 'Igrave': 389,
  9770. 'Imacron': 389,
  9771. 'Lcaron': 611,
  9772. 'onehalf': 750,
  9773. 'lessequal': 549,
  9774. 'ocircumflex': 500,
  9775. 'ntilde': 556,
  9776. 'Uhungarumlaut': 722,
  9777. 'Eacute': 667,
  9778. 'emacron': 444,
  9779. 'gbreve': 500,
  9780. 'onequarter': 750,
  9781. 'Scaron': 556,
  9782. 'Scommaaccent': 556,
  9783. 'Ohungarumlaut': 722,
  9784. 'degree': 400,
  9785. 'ograve': 500,
  9786. 'Ccaron': 667,
  9787. 'ugrave': 556,
  9788. 'radical': 549,
  9789. 'Dcaron': 722,
  9790. 'rcommaaccent': 389,
  9791. 'Ntilde': 722,
  9792. 'otilde': 500,
  9793. 'Rcommaaccent': 667,
  9794. 'Lcommaaccent': 611,
  9795. 'Atilde': 667,
  9796. 'Aogonek': 667,
  9797. 'Aring': 667,
  9798. 'Otilde': 722,
  9799. 'zdotaccent': 389,
  9800. 'Ecaron': 667,
  9801. 'Iogonek': 389,
  9802. 'kcommaaccent': 500,
  9803. 'minus': 606,
  9804. 'Icircumflex': 389,
  9805. 'ncaron': 556,
  9806. 'tcommaaccent': 278,
  9807. 'logicalnot': 606,
  9808. 'odieresis': 500,
  9809. 'udieresis': 556,
  9810. 'notequal': 549,
  9811. 'gcommaaccent': 500,
  9812. 'eth': 500,
  9813. 'zcaron': 389,
  9814. 'ncommaaccent': 556,
  9815. 'onesuperior': 300,
  9816. 'imacron': 278,
  9817. 'Euro': 500
  9818. },
  9819. 'Times-Italic': {
  9820. 'space': 250,
  9821. 'exclam': 333,
  9822. 'quotedbl': 420,
  9823. 'numbersign': 500,
  9824. 'dollar': 500,
  9825. 'percent': 833,
  9826. 'ampersand': 778,
  9827. 'quoteright': 333,
  9828. 'parenleft': 333,
  9829. 'parenright': 333,
  9830. 'asterisk': 500,
  9831. 'plus': 675,
  9832. 'comma': 250,
  9833. 'hyphen': 333,
  9834. 'period': 250,
  9835. 'slash': 278,
  9836. 'zero': 500,
  9837. 'one': 500,
  9838. 'two': 500,
  9839. 'three': 500,
  9840. 'four': 500,
  9841. 'five': 500,
  9842. 'six': 500,
  9843. 'seven': 500,
  9844. 'eight': 500,
  9845. 'nine': 500,
  9846. 'colon': 333,
  9847. 'semicolon': 333,
  9848. 'less': 675,
  9849. 'equal': 675,
  9850. 'greater': 675,
  9851. 'question': 500,
  9852. 'at': 920,
  9853. 'A': 611,
  9854. 'B': 611,
  9855. 'C': 667,
  9856. 'D': 722,
  9857. 'E': 611,
  9858. 'F': 611,
  9859. 'G': 722,
  9860. 'H': 722,
  9861. 'I': 333,
  9862. 'J': 444,
  9863. 'K': 667,
  9864. 'L': 556,
  9865. 'M': 833,
  9866. 'N': 667,
  9867. 'O': 722,
  9868. 'P': 611,
  9869. 'Q': 722,
  9870. 'R': 611,
  9871. 'S': 500,
  9872. 'T': 556,
  9873. 'U': 722,
  9874. 'V': 611,
  9875. 'W': 833,
  9876. 'X': 611,
  9877. 'Y': 556,
  9878. 'Z': 556,
  9879. 'bracketleft': 389,
  9880. 'backslash': 278,
  9881. 'bracketright': 389,
  9882. 'asciicircum': 422,
  9883. 'underscore': 500,
  9884. 'quoteleft': 333,
  9885. 'a': 500,
  9886. 'b': 500,
  9887. 'c': 444,
  9888. 'd': 500,
  9889. 'e': 444,
  9890. 'f': 278,
  9891. 'g': 500,
  9892. 'h': 500,
  9893. 'i': 278,
  9894. 'j': 278,
  9895. 'k': 444,
  9896. 'l': 278,
  9897. 'm': 722,
  9898. 'n': 500,
  9899. 'o': 500,
  9900. 'p': 500,
  9901. 'q': 500,
  9902. 'r': 389,
  9903. 's': 389,
  9904. 't': 278,
  9905. 'u': 500,
  9906. 'v': 444,
  9907. 'w': 667,
  9908. 'x': 444,
  9909. 'y': 444,
  9910. 'z': 389,
  9911. 'braceleft': 400,
  9912. 'bar': 275,
  9913. 'braceright': 400,
  9914. 'asciitilde': 541,
  9915. 'exclamdown': 389,
  9916. 'cent': 500,
  9917. 'sterling': 500,
  9918. 'fraction': 167,
  9919. 'yen': 500,
  9920. 'florin': 500,
  9921. 'section': 500,
  9922. 'currency': 500,
  9923. 'quotesingle': 214,
  9924. 'quotedblleft': 556,
  9925. 'guillemotleft': 500,
  9926. 'guilsinglleft': 333,
  9927. 'guilsinglright': 333,
  9928. 'fi': 500,
  9929. 'fl': 500,
  9930. 'endash': 500,
  9931. 'dagger': 500,
  9932. 'daggerdbl': 500,
  9933. 'periodcentered': 250,
  9934. 'paragraph': 523,
  9935. 'bullet': 350,
  9936. 'quotesinglbase': 333,
  9937. 'quotedblbase': 556,
  9938. 'quotedblright': 556,
  9939. 'guillemotright': 500,
  9940. 'ellipsis': 889,
  9941. 'perthousand': 1000,
  9942. 'questiondown': 500,
  9943. 'grave': 333,
  9944. 'acute': 333,
  9945. 'circumflex': 333,
  9946. 'tilde': 333,
  9947. 'macron': 333,
  9948. 'breve': 333,
  9949. 'dotaccent': 333,
  9950. 'dieresis': 333,
  9951. 'ring': 333,
  9952. 'cedilla': 333,
  9953. 'hungarumlaut': 333,
  9954. 'ogonek': 333,
  9955. 'caron': 333,
  9956. 'emdash': 889,
  9957. 'AE': 889,
  9958. 'ordfeminine': 276,
  9959. 'Lslash': 556,
  9960. 'Oslash': 722,
  9961. 'OE': 944,
  9962. 'ordmasculine': 310,
  9963. 'ae': 667,
  9964. 'dotlessi': 278,
  9965. 'lslash': 278,
  9966. 'oslash': 500,
  9967. 'oe': 667,
  9968. 'germandbls': 500,
  9969. 'Idieresis': 333,
  9970. 'eacute': 444,
  9971. 'abreve': 500,
  9972. 'uhungarumlaut': 500,
  9973. 'ecaron': 444,
  9974. 'Ydieresis': 556,
  9975. 'divide': 675,
  9976. 'Yacute': 556,
  9977. 'Acircumflex': 611,
  9978. 'aacute': 500,
  9979. 'Ucircumflex': 722,
  9980. 'yacute': 444,
  9981. 'scommaaccent': 389,
  9982. 'ecircumflex': 444,
  9983. 'Uring': 722,
  9984. 'Udieresis': 722,
  9985. 'aogonek': 500,
  9986. 'Uacute': 722,
  9987. 'uogonek': 500,
  9988. 'Edieresis': 611,
  9989. 'Dcroat': 722,
  9990. 'commaaccent': 250,
  9991. 'copyright': 760,
  9992. 'Emacron': 611,
  9993. 'ccaron': 444,
  9994. 'aring': 500,
  9995. 'Ncommaaccent': 667,
  9996. 'lacute': 278,
  9997. 'agrave': 500,
  9998. 'Tcommaaccent': 556,
  9999. 'Cacute': 667,
  10000. 'atilde': 500,
  10001. 'Edotaccent': 611,
  10002. 'scaron': 389,
  10003. 'scedilla': 389,
  10004. 'iacute': 278,
  10005. 'lozenge': 471,
  10006. 'Rcaron': 611,
  10007. 'Gcommaaccent': 722,
  10008. 'ucircumflex': 500,
  10009. 'acircumflex': 500,
  10010. 'Amacron': 611,
  10011. 'rcaron': 389,
  10012. 'ccedilla': 444,
  10013. 'Zdotaccent': 556,
  10014. 'Thorn': 611,
  10015. 'Omacron': 722,
  10016. 'Racute': 611,
  10017. 'Sacute': 500,
  10018. 'dcaron': 544,
  10019. 'Umacron': 722,
  10020. 'uring': 500,
  10021. 'threesuperior': 300,
  10022. 'Ograve': 722,
  10023. 'Agrave': 611,
  10024. 'Abreve': 611,
  10025. 'multiply': 675,
  10026. 'uacute': 500,
  10027. 'Tcaron': 556,
  10028. 'partialdiff': 476,
  10029. 'ydieresis': 444,
  10030. 'Nacute': 667,
  10031. 'icircumflex': 278,
  10032. 'Ecircumflex': 611,
  10033. 'adieresis': 500,
  10034. 'edieresis': 444,
  10035. 'cacute': 444,
  10036. 'nacute': 500,
  10037. 'umacron': 500,
  10038. 'Ncaron': 667,
  10039. 'Iacute': 333,
  10040. 'plusminus': 675,
  10041. 'brokenbar': 275,
  10042. 'registered': 760,
  10043. 'Gbreve': 722,
  10044. 'Idotaccent': 333,
  10045. 'summation': 600,
  10046. 'Egrave': 611,
  10047. 'racute': 389,
  10048. 'omacron': 500,
  10049. 'Zacute': 556,
  10050. 'Zcaron': 556,
  10051. 'greaterequal': 549,
  10052. 'Eth': 722,
  10053. 'Ccedilla': 667,
  10054. 'lcommaaccent': 278,
  10055. 'tcaron': 300,
  10056. 'eogonek': 444,
  10057. 'Uogonek': 722,
  10058. 'Aacute': 611,
  10059. 'Adieresis': 611,
  10060. 'egrave': 444,
  10061. 'zacute': 389,
  10062. 'iogonek': 278,
  10063. 'Oacute': 722,
  10064. 'oacute': 500,
  10065. 'amacron': 500,
  10066. 'sacute': 389,
  10067. 'idieresis': 278,
  10068. 'Ocircumflex': 722,
  10069. 'Ugrave': 722,
  10070. 'Delta': 612,
  10071. 'thorn': 500,
  10072. 'twosuperior': 300,
  10073. 'Odieresis': 722,
  10074. 'mu': 500,
  10075. 'igrave': 278,
  10076. 'ohungarumlaut': 500,
  10077. 'Eogonek': 611,
  10078. 'dcroat': 500,
  10079. 'threequarters': 750,
  10080. 'Scedilla': 500,
  10081. 'lcaron': 300,
  10082. 'Kcommaaccent': 667,
  10083. 'Lacute': 556,
  10084. 'trademark': 980,
  10085. 'edotaccent': 444,
  10086. 'Igrave': 333,
  10087. 'Imacron': 333,
  10088. 'Lcaron': 611,
  10089. 'onehalf': 750,
  10090. 'lessequal': 549,
  10091. 'ocircumflex': 500,
  10092. 'ntilde': 500,
  10093. 'Uhungarumlaut': 722,
  10094. 'Eacute': 611,
  10095. 'emacron': 444,
  10096. 'gbreve': 500,
  10097. 'onequarter': 750,
  10098. 'Scaron': 500,
  10099. 'Scommaaccent': 500,
  10100. 'Ohungarumlaut': 722,
  10101. 'degree': 400,
  10102. 'ograve': 500,
  10103. 'Ccaron': 667,
  10104. 'ugrave': 500,
  10105. 'radical': 453,
  10106. 'Dcaron': 722,
  10107. 'rcommaaccent': 389,
  10108. 'Ntilde': 667,
  10109. 'otilde': 500,
  10110. 'Rcommaaccent': 611,
  10111. 'Lcommaaccent': 556,
  10112. 'Atilde': 611,
  10113. 'Aogonek': 611,
  10114. 'Aring': 611,
  10115. 'Otilde': 722,
  10116. 'zdotaccent': 389,
  10117. 'Ecaron': 611,
  10118. 'Iogonek': 333,
  10119. 'kcommaaccent': 444,
  10120. 'minus': 675,
  10121. 'Icircumflex': 333,
  10122. 'ncaron': 500,
  10123. 'tcommaaccent': 278,
  10124. 'logicalnot': 675,
  10125. 'odieresis': 500,
  10126. 'udieresis': 500,
  10127. 'notequal': 549,
  10128. 'gcommaaccent': 500,
  10129. 'eth': 500,
  10130. 'zcaron': 389,
  10131. 'ncommaaccent': 500,
  10132. 'onesuperior': 300,
  10133. 'imacron': 278,
  10134. 'Euro': 500
  10135. },
  10136. 'ZapfDingbats': {
  10137. 'space': 278,
  10138. 'a1': 974,
  10139. 'a2': 961,
  10140. 'a202': 974,
  10141. 'a3': 980,
  10142. 'a4': 719,
  10143. 'a5': 789,
  10144. 'a119': 790,
  10145. 'a118': 791,
  10146. 'a117': 690,
  10147. 'a11': 960,
  10148. 'a12': 939,
  10149. 'a13': 549,
  10150. 'a14': 855,
  10151. 'a15': 911,
  10152. 'a16': 933,
  10153. 'a105': 911,
  10154. 'a17': 945,
  10155. 'a18': 974,
  10156. 'a19': 755,
  10157. 'a20': 846,
  10158. 'a21': 762,
  10159. 'a22': 761,
  10160. 'a23': 571,
  10161. 'a24': 677,
  10162. 'a25': 763,
  10163. 'a26': 760,
  10164. 'a27': 759,
  10165. 'a28': 754,
  10166. 'a6': 494,
  10167. 'a7': 552,
  10168. 'a8': 537,
  10169. 'a9': 577,
  10170. 'a10': 692,
  10171. 'a29': 786,
  10172. 'a30': 788,
  10173. 'a31': 788,
  10174. 'a32': 790,
  10175. 'a33': 793,
  10176. 'a34': 794,
  10177. 'a35': 816,
  10178. 'a36': 823,
  10179. 'a37': 789,
  10180. 'a38': 841,
  10181. 'a39': 823,
  10182. 'a40': 833,
  10183. 'a41': 816,
  10184. 'a42': 831,
  10185. 'a43': 923,
  10186. 'a44': 744,
  10187. 'a45': 723,
  10188. 'a46': 749,
  10189. 'a47': 790,
  10190. 'a48': 792,
  10191. 'a49': 695,
  10192. 'a50': 776,
  10193. 'a51': 768,
  10194. 'a52': 792,
  10195. 'a53': 759,
  10196. 'a54': 707,
  10197. 'a55': 708,
  10198. 'a56': 682,
  10199. 'a57': 701,
  10200. 'a58': 826,
  10201. 'a59': 815,
  10202. 'a60': 789,
  10203. 'a61': 789,
  10204. 'a62': 707,
  10205. 'a63': 687,
  10206. 'a64': 696,
  10207. 'a65': 689,
  10208. 'a66': 786,
  10209. 'a67': 787,
  10210. 'a68': 713,
  10211. 'a69': 791,
  10212. 'a70': 785,
  10213. 'a71': 791,
  10214. 'a72': 873,
  10215. 'a73': 761,
  10216. 'a74': 762,
  10217. 'a203': 762,
  10218. 'a75': 759,
  10219. 'a204': 759,
  10220. 'a76': 892,
  10221. 'a77': 892,
  10222. 'a78': 788,
  10223. 'a79': 784,
  10224. 'a81': 438,
  10225. 'a82': 138,
  10226. 'a83': 277,
  10227. 'a84': 415,
  10228. 'a97': 392,
  10229. 'a98': 392,
  10230. 'a99': 668,
  10231. 'a100': 668,
  10232. 'a89': 390,
  10233. 'a90': 390,
  10234. 'a93': 317,
  10235. 'a94': 317,
  10236. 'a91': 276,
  10237. 'a92': 276,
  10238. 'a205': 509,
  10239. 'a85': 509,
  10240. 'a206': 410,
  10241. 'a86': 410,
  10242. 'a87': 234,
  10243. 'a88': 234,
  10244. 'a95': 334,
  10245. 'a96': 334,
  10246. 'a101': 732,
  10247. 'a102': 544,
  10248. 'a103': 544,
  10249. 'a104': 910,
  10250. 'a106': 667,
  10251. 'a107': 760,
  10252. 'a108': 760,
  10253. 'a112': 776,
  10254. 'a111': 595,
  10255. 'a110': 694,
  10256. 'a109': 626,
  10257. 'a120': 788,
  10258. 'a121': 788,
  10259. 'a122': 788,
  10260. 'a123': 788,
  10261. 'a124': 788,
  10262. 'a125': 788,
  10263. 'a126': 788,
  10264. 'a127': 788,
  10265. 'a128': 788,
  10266. 'a129': 788,
  10267. 'a130': 788,
  10268. 'a131': 788,
  10269. 'a132': 788,
  10270. 'a133': 788,
  10271. 'a134': 788,
  10272. 'a135': 788,
  10273. 'a136': 788,
  10274. 'a137': 788,
  10275. 'a138': 788,
  10276. 'a139': 788,
  10277. 'a140': 788,
  10278. 'a141': 788,
  10279. 'a142': 788,
  10280. 'a143': 788,
  10281. 'a144': 788,
  10282. 'a145': 788,
  10283. 'a146': 788,
  10284. 'a147': 788,
  10285. 'a148': 788,
  10286. 'a149': 788,
  10287. 'a150': 788,
  10288. 'a151': 788,
  10289. 'a152': 788,
  10290. 'a153': 788,
  10291. 'a154': 788,
  10292. 'a155': 788,
  10293. 'a156': 788,
  10294. 'a157': 788,
  10295. 'a158': 788,
  10296. 'a159': 788,
  10297. 'a160': 894,
  10298. 'a161': 838,
  10299. 'a163': 1016,
  10300. 'a164': 458,
  10301. 'a196': 748,
  10302. 'a165': 924,
  10303. 'a192': 748,
  10304. 'a166': 918,
  10305. 'a167': 927,
  10306. 'a168': 928,
  10307. 'a169': 928,
  10308. 'a170': 834,
  10309. 'a171': 873,
  10310. 'a172': 828,
  10311. 'a173': 924,
  10312. 'a162': 924,
  10313. 'a174': 917,
  10314. 'a175': 930,
  10315. 'a176': 931,
  10316. 'a177': 463,
  10317. 'a178': 883,
  10318. 'a179': 836,
  10319. 'a193': 836,
  10320. 'a180': 867,
  10321. 'a199': 867,
  10322. 'a181': 696,
  10323. 'a200': 696,
  10324. 'a182': 874,
  10325. 'a201': 874,
  10326. 'a183': 760,
  10327. 'a184': 946,
  10328. 'a197': 771,
  10329. 'a185': 865,
  10330. 'a194': 771,
  10331. 'a198': 888,
  10332. 'a186': 967,
  10333. 'a195': 888,
  10334. 'a187': 831,
  10335. 'a188': 873,
  10336. 'a189': 927,
  10337. 'a190': 970,
  10338. 'a191': 918
  10339. }
  10340. };
  10341. exports.Metrics = Metrics;
  10342. }));
  10343. (function (root, factory) {
  10344. {
  10345. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  10346. }
  10347. }(this, function (exports, sharedGlobal) {
  10348. var PDFJS = sharedGlobal.PDFJS;
  10349. var bidi = PDFJS.bidi = (function bidiClosure() {
  10350. // Character types for symbols from 0000 to 00FF.
  10351. var baseTypes = [
  10352. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  10353. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10354. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  10355. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  10356. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  10357. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10358. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  10359. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10360. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10361. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  10362. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10363. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10364. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  10365. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  10366. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10367. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10368. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10369. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10370. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  10371. ];
  10372. // Character types for symbols from 0600 to 06FF
  10373. var arabicTypes = [
  10374. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10375. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  10376. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10377. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10378. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10379. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10380. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10381. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10382. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  10383. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10384. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10385. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10386. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10387. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10388. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10389. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10390. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10391. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10392. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10393. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  10394. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10395. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  10396. ];
  10397. function isOdd(i) {
  10398. return (i & 1) !== 0;
  10399. }
  10400. function isEven(i) {
  10401. return (i & 1) === 0;
  10402. }
  10403. function findUnequal(arr, start, value) {
  10404. for (var j = start, jj = arr.length; j < jj; ++j) {
  10405. if (arr[j] !== value) {
  10406. return j;
  10407. }
  10408. }
  10409. return j;
  10410. }
  10411. function setValues(arr, start, end, value) {
  10412. for (var j = start; j < end; ++j) {
  10413. arr[j] = value;
  10414. }
  10415. }
  10416. function reverseValues(arr, start, end) {
  10417. for (var i = start, j = end - 1; i < j; ++i, --j) {
  10418. var temp = arr[i];
  10419. arr[i] = arr[j];
  10420. arr[j] = temp;
  10421. }
  10422. }
  10423. function createBidiText(str, isLTR, vertical) {
  10424. return {
  10425. str: str,
  10426. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  10427. };
  10428. }
  10429. // These are used in bidi(), which is called frequently. We re-use them on
  10430. // each call to avoid unnecessary allocations.
  10431. var chars = [];
  10432. var types = [];
  10433. function bidi(str, startLevel, vertical) {
  10434. var isLTR = true;
  10435. var strLength = str.length;
  10436. if (strLength === 0 || vertical) {
  10437. return createBidiText(str, isLTR, vertical);
  10438. }
  10439. // Get types and fill arrays
  10440. chars.length = strLength;
  10441. types.length = strLength;
  10442. var numBidi = 0;
  10443. var i, ii;
  10444. for (i = 0; i < strLength; ++i) {
  10445. chars[i] = str.charAt(i);
  10446. var charCode = str.charCodeAt(i);
  10447. var charType = 'L';
  10448. if (charCode <= 0x00ff) {
  10449. charType = baseTypes[charCode];
  10450. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  10451. charType = 'R';
  10452. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  10453. charType = arabicTypes[charCode & 0xff];
  10454. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  10455. charType = 'AL';
  10456. }
  10457. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  10458. numBidi++;
  10459. }
  10460. types[i] = charType;
  10461. }
  10462. // Detect the bidi method
  10463. // - If there are no rtl characters then no bidi needed
  10464. // - If less than 30% chars are rtl then string is primarily ltr
  10465. // - If more than 30% chars are rtl then string is primarily rtl
  10466. if (numBidi === 0) {
  10467. isLTR = true;
  10468. return createBidiText(str, isLTR);
  10469. }
  10470. if (startLevel === -1) {
  10471. if ((strLength / numBidi) < 0.3) {
  10472. isLTR = true;
  10473. startLevel = 0;
  10474. } else {
  10475. isLTR = false;
  10476. startLevel = 1;
  10477. }
  10478. }
  10479. var levels = [];
  10480. for (i = 0; i < strLength; ++i) {
  10481. levels[i] = startLevel;
  10482. }
  10483. /*
  10484. X1-X10: skip most of this, since we are NOT doing the embeddings.
  10485. */
  10486. var e = (isOdd(startLevel) ? 'R' : 'L');
  10487. var sor = e;
  10488. var eor = sor;
  10489. /*
  10490. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  10491. type of the NSM to the type of the previous character. If the NSM is at the
  10492. start of the level run, it will get the type of sor.
  10493. */
  10494. var lastType = sor;
  10495. for (i = 0; i < strLength; ++i) {
  10496. if (types[i] === 'NSM') {
  10497. types[i] = lastType;
  10498. } else {
  10499. lastType = types[i];
  10500. }
  10501. }
  10502. /*
  10503. W2. Search backwards from each instance of a European number until the
  10504. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  10505. the type of the European number to Arabic number.
  10506. */
  10507. lastType = sor;
  10508. var t;
  10509. for (i = 0; i < strLength; ++i) {
  10510. t = types[i];
  10511. if (t === 'EN') {
  10512. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  10513. } else if (t === 'R' || t === 'L' || t === 'AL') {
  10514. lastType = t;
  10515. }
  10516. }
  10517. /*
  10518. W3. Change all ALs to R.
  10519. */
  10520. for (i = 0; i < strLength; ++i) {
  10521. t = types[i];
  10522. if (t === 'AL') {
  10523. types[i] = 'R';
  10524. }
  10525. }
  10526. /*
  10527. W4. A single European separator between two European numbers changes to a
  10528. European number. A single common separator between two numbers of the same
  10529. type changes to that type:
  10530. */
  10531. for (i = 1; i < strLength - 1; ++i) {
  10532. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  10533. types[i] = 'EN';
  10534. }
  10535. if (types[i] === 'CS' &&
  10536. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  10537. types[i + 1] === types[i - 1]) {
  10538. types[i] = types[i - 1];
  10539. }
  10540. }
  10541. /*
  10542. W5. A sequence of European terminators adjacent to European numbers changes
  10543. to all European numbers:
  10544. */
  10545. for (i = 0; i < strLength; ++i) {
  10546. if (types[i] === 'EN') {
  10547. // do before
  10548. var j;
  10549. for (j = i - 1; j >= 0; --j) {
  10550. if (types[j] !== 'ET') {
  10551. break;
  10552. }
  10553. types[j] = 'EN';
  10554. }
  10555. // do after
  10556. for (j = i + 1; j < strLength; --j) {
  10557. if (types[j] !== 'ET') {
  10558. break;
  10559. }
  10560. types[j] = 'EN';
  10561. }
  10562. }
  10563. }
  10564. /*
  10565. W6. Otherwise, separators and terminators change to Other Neutral:
  10566. */
  10567. for (i = 0; i < strLength; ++i) {
  10568. t = types[i];
  10569. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  10570. types[i] = 'ON';
  10571. }
  10572. }
  10573. /*
  10574. W7. Search backwards from each instance of a European number until the
  10575. first strong type (R, L, or sor) is found. If an L is found, then change
  10576. the type of the European number to L.
  10577. */
  10578. lastType = sor;
  10579. for (i = 0; i < strLength; ++i) {
  10580. t = types[i];
  10581. if (t === 'EN') {
  10582. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  10583. } else if (t === 'R' || t === 'L') {
  10584. lastType = t;
  10585. }
  10586. }
  10587. /*
  10588. N1. A sequence of neutrals takes the direction of the surrounding strong
  10589. text if the text on both sides has the same direction. European and Arabic
  10590. numbers are treated as though they were R. Start-of-level-run (sor) and
  10591. end-of-level-run (eor) are used at level run boundaries.
  10592. */
  10593. for (i = 0; i < strLength; ++i) {
  10594. if (types[i] === 'ON') {
  10595. var end = findUnequal(types, i + 1, 'ON');
  10596. var before = sor;
  10597. if (i > 0) {
  10598. before = types[i - 1];
  10599. }
  10600. var after = eor;
  10601. if (end + 1 < strLength) {
  10602. after = types[end + 1];
  10603. }
  10604. if (before !== 'L') {
  10605. before = 'R';
  10606. }
  10607. if (after !== 'L') {
  10608. after = 'R';
  10609. }
  10610. if (before === after) {
  10611. setValues(types, i, end, before);
  10612. }
  10613. i = end - 1; // reset to end (-1 so next iteration is ok)
  10614. }
  10615. }
  10616. /*
  10617. N2. Any remaining neutrals take the embedding direction.
  10618. */
  10619. for (i = 0; i < strLength; ++i) {
  10620. if (types[i] === 'ON') {
  10621. types[i] = e;
  10622. }
  10623. }
  10624. /*
  10625. I1. For all characters with an even (left-to-right) embedding direction,
  10626. those of type R go up one level and those of type AN or EN go up two
  10627. levels.
  10628. I2. For all characters with an odd (right-to-left) embedding direction,
  10629. those of type L, EN or AN go up one level.
  10630. */
  10631. for (i = 0; i < strLength; ++i) {
  10632. t = types[i];
  10633. if (isEven(levels[i])) {
  10634. if (t === 'R') {
  10635. levels[i] += 1;
  10636. } else if (t === 'AN' || t === 'EN') {
  10637. levels[i] += 2;
  10638. }
  10639. } else { // isOdd
  10640. if (t === 'L' || t === 'AN' || t === 'EN') {
  10641. levels[i] += 1;
  10642. }
  10643. }
  10644. }
  10645. /*
  10646. L1. On each line, reset the embedding level of the following characters to
  10647. the paragraph embedding level:
  10648. segment separators,
  10649. paragraph separators,
  10650. any sequence of whitespace characters preceding a segment separator or
  10651. paragraph separator, and any sequence of white space characters at the end
  10652. of the line.
  10653. */
  10654. // don't bother as text is only single line
  10655. /*
  10656. L2. From the highest level found in the text to the lowest odd level on
  10657. each line, reverse any contiguous sequence of characters that are at that
  10658. level or higher.
  10659. */
  10660. // find highest level & lowest odd level
  10661. var highestLevel = -1;
  10662. var lowestOddLevel = 99;
  10663. var level;
  10664. for (i = 0, ii = levels.length; i < ii; ++i) {
  10665. level = levels[i];
  10666. if (highestLevel < level) {
  10667. highestLevel = level;
  10668. }
  10669. if (lowestOddLevel > level && isOdd(level)) {
  10670. lowestOddLevel = level;
  10671. }
  10672. }
  10673. // now reverse between those limits
  10674. for (level = highestLevel; level >= lowestOddLevel; --level) {
  10675. // find segments to reverse
  10676. var start = -1;
  10677. for (i = 0, ii = levels.length; i < ii; ++i) {
  10678. if (levels[i] < level) {
  10679. if (start >= 0) {
  10680. reverseValues(chars, start, i);
  10681. start = -1;
  10682. }
  10683. } else if (start < 0) {
  10684. start = i;
  10685. }
  10686. }
  10687. if (start >= 0) {
  10688. reverseValues(chars, start, levels.length);
  10689. }
  10690. }
  10691. /*
  10692. L3. Combining marks applied to a right-to-left base character will at this
  10693. point precede their base character. If the rendering engine expects them to
  10694. follow the base characters in the final display process, then the ordering
  10695. of the marks and the base character must be reversed.
  10696. */
  10697. // don't bother for now
  10698. /*
  10699. L4. A character that possesses the mirrored property as specified by
  10700. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  10701. directionality of that character is R.
  10702. */
  10703. // don't mirror as characters are already mirrored in the pdf
  10704. // Finally, return string
  10705. for (i = 0, ii = chars.length; i < ii; ++i) {
  10706. var ch = chars[i];
  10707. if (ch === '<' || ch === '>') {
  10708. chars[i] = '';
  10709. }
  10710. }
  10711. return createBidiText(chars.join(''), isLTR);
  10712. }
  10713. return bidi;
  10714. })();
  10715. exports.bidi = bidi;
  10716. }));
  10717. (function (root, factory) {
  10718. {
  10719. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  10720. }
  10721. }(this, function (exports, sharedUtil) {
  10722. var MissingDataException = sharedUtil.MissingDataException;
  10723. var assert = sharedUtil.assert;
  10724. var createPromiseCapability = sharedUtil.createPromiseCapability;
  10725. var isInt = sharedUtil.isInt;
  10726. var isEmptyObj = sharedUtil.isEmptyObj;
  10727. var ChunkedStream = (function ChunkedStreamClosure() {
  10728. function ChunkedStream(length, chunkSize, manager) {
  10729. this.bytes = new Uint8Array(length);
  10730. this.start = 0;
  10731. this.pos = 0;
  10732. this.end = length;
  10733. this.chunkSize = chunkSize;
  10734. this.loadedChunks = [];
  10735. this.numChunksLoaded = 0;
  10736. this.numChunks = Math.ceil(length / chunkSize);
  10737. this.manager = manager;
  10738. this.progressiveDataLength = 0;
  10739. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  10740. }
  10741. // required methods for a stream. if a particular stream does not
  10742. // implement these, an error should be thrown
  10743. ChunkedStream.prototype = {
  10744. getMissingChunks: function ChunkedStream_getMissingChunks() {
  10745. var chunks = [];
  10746. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  10747. if (!this.loadedChunks[chunk]) {
  10748. chunks.push(chunk);
  10749. }
  10750. }
  10751. return chunks;
  10752. },
  10753. getBaseStreams: function ChunkedStream_getBaseStreams() {
  10754. return [this];
  10755. },
  10756. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  10757. return this.numChunksLoaded === this.numChunks;
  10758. },
  10759. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  10760. var end = begin + chunk.byteLength;
  10761. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  10762. // Using this.length is inaccurate here since this.start can be moved
  10763. // See ChunkedStream.moveStart()
  10764. var length = this.bytes.length;
  10765. assert(end % this.chunkSize === 0 || end === length,
  10766. 'Bad end offset: ' + end);
  10767. this.bytes.set(new Uint8Array(chunk), begin);
  10768. var chunkSize = this.chunkSize;
  10769. var beginChunk = Math.floor(begin / chunkSize);
  10770. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10771. var curChunk;
  10772. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10773. if (!this.loadedChunks[curChunk]) {
  10774. this.loadedChunks[curChunk] = true;
  10775. ++this.numChunksLoaded;
  10776. }
  10777. }
  10778. },
  10779. onReceiveProgressiveData:
  10780. function ChunkedStream_onReceiveProgressiveData(data) {
  10781. var position = this.progressiveDataLength;
  10782. var beginChunk = Math.floor(position / this.chunkSize);
  10783. this.bytes.set(new Uint8Array(data), position);
  10784. position += data.byteLength;
  10785. this.progressiveDataLength = position;
  10786. var endChunk = position >= this.end ? this.numChunks :
  10787. Math.floor(position / this.chunkSize);
  10788. var curChunk;
  10789. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10790. if (!this.loadedChunks[curChunk]) {
  10791. this.loadedChunks[curChunk] = true;
  10792. ++this.numChunksLoaded;
  10793. }
  10794. }
  10795. },
  10796. ensureByte: function ChunkedStream_ensureByte(pos) {
  10797. var chunk = Math.floor(pos / this.chunkSize);
  10798. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  10799. return;
  10800. }
  10801. if (!this.loadedChunks[chunk]) {
  10802. throw new MissingDataException(pos, pos + 1);
  10803. }
  10804. this.lastSuccessfulEnsureByteChunk = chunk;
  10805. },
  10806. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  10807. if (begin >= end) {
  10808. return;
  10809. }
  10810. if (end <= this.progressiveDataLength) {
  10811. return;
  10812. }
  10813. var chunkSize = this.chunkSize;
  10814. var beginChunk = Math.floor(begin / chunkSize);
  10815. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10816. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10817. if (!this.loadedChunks[chunk]) {
  10818. throw new MissingDataException(begin, end);
  10819. }
  10820. }
  10821. },
  10822. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  10823. var chunk, numChunks = this.numChunks;
  10824. for (var i = 0; i < numChunks; ++i) {
  10825. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  10826. if (!this.loadedChunks[chunk]) {
  10827. return chunk;
  10828. }
  10829. }
  10830. return null;
  10831. },
  10832. hasChunk: function ChunkedStream_hasChunk(chunk) {
  10833. return !!this.loadedChunks[chunk];
  10834. },
  10835. get length() {
  10836. return this.end - this.start;
  10837. },
  10838. get isEmpty() {
  10839. return this.length === 0;
  10840. },
  10841. getByte: function ChunkedStream_getByte() {
  10842. var pos = this.pos;
  10843. if (pos >= this.end) {
  10844. return -1;
  10845. }
  10846. this.ensureByte(pos);
  10847. return this.bytes[this.pos++];
  10848. },
  10849. getUint16: function ChunkedStream_getUint16() {
  10850. var b0 = this.getByte();
  10851. var b1 = this.getByte();
  10852. if (b0 === -1 || b1 === -1) {
  10853. return -1;
  10854. }
  10855. return (b0 << 8) + b1;
  10856. },
  10857. getInt32: function ChunkedStream_getInt32() {
  10858. var b0 = this.getByte();
  10859. var b1 = this.getByte();
  10860. var b2 = this.getByte();
  10861. var b3 = this.getByte();
  10862. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  10863. },
  10864. // returns subarray of original buffer
  10865. // should only be read
  10866. getBytes: function ChunkedStream_getBytes(length) {
  10867. var bytes = this.bytes;
  10868. var pos = this.pos;
  10869. var strEnd = this.end;
  10870. if (!length) {
  10871. this.ensureRange(pos, strEnd);
  10872. return bytes.subarray(pos, strEnd);
  10873. }
  10874. var end = pos + length;
  10875. if (end > strEnd) {
  10876. end = strEnd;
  10877. }
  10878. this.ensureRange(pos, end);
  10879. this.pos = end;
  10880. return bytes.subarray(pos, end);
  10881. },
  10882. peekByte: function ChunkedStream_peekByte() {
  10883. var peekedByte = this.getByte();
  10884. this.pos--;
  10885. return peekedByte;
  10886. },
  10887. peekBytes: function ChunkedStream_peekBytes(length) {
  10888. var bytes = this.getBytes(length);
  10889. this.pos -= bytes.length;
  10890. return bytes;
  10891. },
  10892. getByteRange: function ChunkedStream_getBytes(begin, end) {
  10893. this.ensureRange(begin, end);
  10894. return this.bytes.subarray(begin, end);
  10895. },
  10896. skip: function ChunkedStream_skip(n) {
  10897. if (!n) {
  10898. n = 1;
  10899. }
  10900. this.pos += n;
  10901. },
  10902. reset: function ChunkedStream_reset() {
  10903. this.pos = this.start;
  10904. },
  10905. moveStart: function ChunkedStream_moveStart() {
  10906. this.start = this.pos;
  10907. },
  10908. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  10909. this.ensureRange(start, start + length);
  10910. function ChunkedStreamSubstream() {}
  10911. ChunkedStreamSubstream.prototype = Object.create(this);
  10912. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  10913. var chunkSize = this.chunkSize;
  10914. var beginChunk = Math.floor(this.start / chunkSize);
  10915. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  10916. var missingChunks = [];
  10917. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10918. if (!this.loadedChunks[chunk]) {
  10919. missingChunks.push(chunk);
  10920. }
  10921. }
  10922. return missingChunks;
  10923. };
  10924. var subStream = new ChunkedStreamSubstream();
  10925. subStream.pos = subStream.start = start;
  10926. subStream.end = start + length || this.end;
  10927. subStream.dict = dict;
  10928. return subStream;
  10929. },
  10930. isStream: true
  10931. };
  10932. return ChunkedStream;
  10933. })();
  10934. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  10935. function ChunkedStreamManager(length, chunkSize, url, args) {
  10936. this.stream = new ChunkedStream(length, chunkSize, this);
  10937. this.length = length;
  10938. this.chunkSize = chunkSize;
  10939. this.url = url;
  10940. this.disableAutoFetch = args.disableAutoFetch;
  10941. var msgHandler = this.msgHandler = args.msgHandler;
  10942. if (args.chunkedViewerLoading) {
  10943. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  10944. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  10945. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10946. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  10947. };
  10948. } else {
  10949. var getXhr = function getXhr() {
  10950. return new XMLHttpRequest();
  10951. };
  10952. this.networkManager = new NetworkManager(this.url, {
  10953. getXhr: getXhr,
  10954. httpHeaders: args.httpHeaders,
  10955. withCredentials: args.withCredentials
  10956. });
  10957. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10958. this.networkManager.requestRange(begin, end, {
  10959. onDone: this.onReceiveData.bind(this),
  10960. onProgress: this.onProgress.bind(this)
  10961. });
  10962. };
  10963. }
  10964. this.currRequestId = 0;
  10965. this.chunksNeededByRequest = {};
  10966. this.requestsByChunk = {};
  10967. this.promisesByRequest = {};
  10968. this.progressiveDataLength = 0;
  10969. this._loadedStreamCapability = createPromiseCapability();
  10970. if (args.initialData) {
  10971. this.onReceiveData({chunk: args.initialData});
  10972. }
  10973. }
  10974. ChunkedStreamManager.prototype = {
  10975. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  10976. return this._loadedStreamCapability.promise;
  10977. },
  10978. // Get all the chunks that are not yet loaded and groups them into
  10979. // contiguous ranges to load in as few requests as possible
  10980. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  10981. var missingChunks = this.stream.getMissingChunks();
  10982. this._requestChunks(missingChunks);
  10983. return this._loadedStreamCapability.promise;
  10984. },
  10985. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  10986. var requestId = this.currRequestId++;
  10987. var chunksNeeded;
  10988. var i, ii;
  10989. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  10990. for (i = 0, ii = chunks.length; i < ii; i++) {
  10991. if (!this.stream.hasChunk(chunks[i])) {
  10992. chunksNeeded[chunks[i]] = true;
  10993. }
  10994. }
  10995. if (isEmptyObj(chunksNeeded)) {
  10996. return Promise.resolve();
  10997. }
  10998. var capability = createPromiseCapability();
  10999. this.promisesByRequest[requestId] = capability;
  11000. var chunksToRequest = [];
  11001. for (var chunk in chunksNeeded) {
  11002. chunk = chunk | 0;
  11003. if (!(chunk in this.requestsByChunk)) {
  11004. this.requestsByChunk[chunk] = [];
  11005. chunksToRequest.push(chunk);
  11006. }
  11007. this.requestsByChunk[chunk].push(requestId);
  11008. }
  11009. if (!chunksToRequest.length) {
  11010. return capability.promise;
  11011. }
  11012. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11013. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11014. var groupedChunk = groupedChunksToRequest[i];
  11015. var begin = groupedChunk.beginChunk * this.chunkSize;
  11016. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11017. this.sendRequest(begin, end);
  11018. }
  11019. return capability.promise;
  11020. },
  11021. getStream: function ChunkedStreamManager_getStream() {
  11022. return this.stream;
  11023. },
  11024. // Loads any chunks in the requested range that are not yet loaded
  11025. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11026. end = Math.min(end, this.length);
  11027. var beginChunk = this.getBeginChunk(begin);
  11028. var endChunk = this.getEndChunk(end);
  11029. var chunks = [];
  11030. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11031. chunks.push(chunk);
  11032. }
  11033. return this._requestChunks(chunks);
  11034. },
  11035. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11036. ranges = ranges || [];
  11037. var chunksToRequest = [];
  11038. for (var i = 0; i < ranges.length; i++) {
  11039. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11040. var endChunk = this.getEndChunk(ranges[i].end);
  11041. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11042. if (chunksToRequest.indexOf(chunk) < 0) {
  11043. chunksToRequest.push(chunk);
  11044. }
  11045. }
  11046. }
  11047. chunksToRequest.sort(function(a, b) { return a - b; });
  11048. return this._requestChunks(chunksToRequest);
  11049. },
  11050. // Groups a sorted array of chunks into as few contiguous larger
  11051. // chunks as possible
  11052. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11053. var groupedChunks = [];
  11054. var beginChunk = -1;
  11055. var prevChunk = -1;
  11056. for (var i = 0; i < chunks.length; ++i) {
  11057. var chunk = chunks[i];
  11058. if (beginChunk < 0) {
  11059. beginChunk = chunk;
  11060. }
  11061. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11062. groupedChunks.push({ beginChunk: beginChunk,
  11063. endChunk: prevChunk + 1 });
  11064. beginChunk = chunk;
  11065. }
  11066. if (i + 1 === chunks.length) {
  11067. groupedChunks.push({ beginChunk: beginChunk,
  11068. endChunk: chunk + 1 });
  11069. }
  11070. prevChunk = chunk;
  11071. }
  11072. return groupedChunks;
  11073. },
  11074. onProgress: function ChunkedStreamManager_onProgress(args) {
  11075. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11076. args.loaded);
  11077. this.msgHandler.send('DocProgress', {
  11078. loaded: bytesLoaded,
  11079. total: this.length
  11080. });
  11081. },
  11082. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11083. var chunk = args.chunk;
  11084. var isProgressive = args.begin === undefined;
  11085. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11086. var end = begin + chunk.byteLength;
  11087. var beginChunk = Math.floor(begin / this.chunkSize);
  11088. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11089. Math.ceil(end / this.chunkSize);
  11090. if (isProgressive) {
  11091. this.stream.onReceiveProgressiveData(chunk);
  11092. this.progressiveDataLength = end;
  11093. } else {
  11094. this.stream.onReceiveData(begin, chunk);
  11095. }
  11096. if (this.stream.allChunksLoaded()) {
  11097. this._loadedStreamCapability.resolve(this.stream);
  11098. }
  11099. var loadedRequests = [];
  11100. var i, requestId;
  11101. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11102. // The server might return more chunks than requested
  11103. var requestIds = this.requestsByChunk[chunk] || [];
  11104. delete this.requestsByChunk[chunk];
  11105. for (i = 0; i < requestIds.length; ++i) {
  11106. requestId = requestIds[i];
  11107. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11108. if (chunk in chunksNeeded) {
  11109. delete chunksNeeded[chunk];
  11110. }
  11111. if (!isEmptyObj(chunksNeeded)) {
  11112. continue;
  11113. }
  11114. loadedRequests.push(requestId);
  11115. }
  11116. }
  11117. // If there are no pending requests, automatically fetch the next
  11118. // unfetched chunk of the PDF
  11119. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11120. var nextEmptyChunk;
  11121. if (this.stream.numChunksLoaded === 1) {
  11122. // This is a special optimization so that after fetching the first
  11123. // chunk, rather than fetching the second chunk, we fetch the last
  11124. // chunk.
  11125. var lastChunk = this.stream.numChunks - 1;
  11126. if (!this.stream.hasChunk(lastChunk)) {
  11127. nextEmptyChunk = lastChunk;
  11128. }
  11129. } else {
  11130. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11131. }
  11132. if (isInt(nextEmptyChunk)) {
  11133. this._requestChunks([nextEmptyChunk]);
  11134. }
  11135. }
  11136. for (i = 0; i < loadedRequests.length; ++i) {
  11137. requestId = loadedRequests[i];
  11138. var capability = this.promisesByRequest[requestId];
  11139. delete this.promisesByRequest[requestId];
  11140. capability.resolve();
  11141. }
  11142. this.msgHandler.send('DocProgress', {
  11143. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11144. total: this.length
  11145. });
  11146. },
  11147. onError: function ChunkedStreamManager_onError(err) {
  11148. this._loadedStreamCapability.reject(err);
  11149. },
  11150. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11151. var chunk = Math.floor(begin / this.chunkSize);
  11152. return chunk;
  11153. },
  11154. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11155. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11156. return chunk;
  11157. },
  11158. abort: function ChunkedStreamManager_abort() {
  11159. if (this.networkManager) {
  11160. this.networkManager.abortAllRequests();
  11161. }
  11162. for(var requestId in this.promisesByRequest) {
  11163. var capability = this.promisesByRequest[requestId];
  11164. capability.reject(new Error('Request was aborted'));
  11165. }
  11166. }
  11167. };
  11168. return ChunkedStreamManager;
  11169. })();
  11170. exports.ChunkedStream = ChunkedStream;
  11171. exports.ChunkedStreamManager = ChunkedStreamManager;
  11172. }));
  11173. (function (root, factory) {
  11174. {
  11175. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11176. root.pdfjsCoreArithmeticDecoder);
  11177. }
  11178. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11179. var error = sharedUtil.error;
  11180. var log2 = sharedUtil.log2;
  11181. var readInt8 = sharedUtil.readInt8;
  11182. var readUint16 = sharedUtil.readUint16;
  11183. var readUint32 = sharedUtil.readUint32;
  11184. var shadow = sharedUtil.shadow;
  11185. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11186. var Jbig2Image = (function Jbig2ImageClosure() {
  11187. // Utility data structures
  11188. function ContextCache() {}
  11189. ContextCache.prototype = {
  11190. getContexts: function(id) {
  11191. if (id in this) {
  11192. return this[id];
  11193. }
  11194. return (this[id] = new Int8Array(1 << 16));
  11195. }
  11196. };
  11197. function DecodingContext(data, start, end) {
  11198. this.data = data;
  11199. this.start = start;
  11200. this.end = end;
  11201. }
  11202. DecodingContext.prototype = {
  11203. get decoder() {
  11204. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11205. return shadow(this, 'decoder', decoder);
  11206. },
  11207. get contextCache() {
  11208. var cache = new ContextCache();
  11209. return shadow(this, 'contextCache', cache);
  11210. }
  11211. };
  11212. // Annex A. Arithmetic Integer Decoding Procedure
  11213. // A.2 Procedure for decoding values
  11214. function decodeInteger(contextCache, procedure, decoder) {
  11215. var contexts = contextCache.getContexts(procedure);
  11216. var prev = 1;
  11217. function readBits(length) {
  11218. var v = 0;
  11219. for (var i = 0; i < length; i++) {
  11220. var bit = decoder.readBit(contexts, prev);
  11221. prev = (prev < 256 ? (prev << 1) | bit :
  11222. (((prev << 1) | bit) & 511) | 256);
  11223. v = (v << 1) | bit;
  11224. }
  11225. return v >>> 0;
  11226. }
  11227. var sign = readBits(1);
  11228. var value = readBits(1) ?
  11229. (readBits(1) ?
  11230. (readBits(1) ?
  11231. (readBits(1) ?
  11232. (readBits(1) ?
  11233. (readBits(32) + 4436) :
  11234. readBits(12) + 340) :
  11235. readBits(8) + 84) :
  11236. readBits(6) + 20) :
  11237. readBits(4) + 4) :
  11238. readBits(2);
  11239. return (sign === 0 ? value : (value > 0 ? -value : null));
  11240. }
  11241. // A.3 The IAID decoding procedure
  11242. function decodeIAID(contextCache, decoder, codeLength) {
  11243. var contexts = contextCache.getContexts('IAID');
  11244. var prev = 1;
  11245. for (var i = 0; i < codeLength; i++) {
  11246. var bit = decoder.readBit(contexts, prev);
  11247. prev = (prev << 1) | bit;
  11248. }
  11249. if (codeLength < 31) {
  11250. return prev & ((1 << codeLength) - 1);
  11251. }
  11252. return prev & 0x7FFFFFFF;
  11253. }
  11254. // 7.3 Segment types
  11255. var SegmentTypes = [
  11256. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11257. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11258. null, null, null, null, null, 'patternDictionary', null, null, null,
  11259. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11260. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11261. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11262. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11263. 'IntermediateGenericRefinementRegion', null,
  11264. 'ImmediateGenericRefinementRegion',
  11265. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11266. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11267. 'Tables', null, null, null, null, null, null, null, null,
  11268. 'Extension'
  11269. ];
  11270. var CodingTemplates = [
  11271. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11272. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11273. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11274. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11275. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11276. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11277. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11278. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11279. {x: -1, y: 0}],
  11280. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11281. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11282. ];
  11283. var RefinementTemplates = [
  11284. {
  11285. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11286. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11287. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11288. },
  11289. {
  11290. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11291. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11292. {x: 0, y: 1}, {x: 1, y: 1}]
  11293. }
  11294. ];
  11295. // See 6.2.5.7 Decoding the bitmap.
  11296. var ReusedContexts = [
  11297. 0x9B25, // 10011 0110010 0101
  11298. 0x0795, // 0011 110010 101
  11299. 0x00E5, // 001 11001 01
  11300. 0x0195 // 011001 0101
  11301. ];
  11302. var RefinementReusedContexts = [
  11303. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11304. 0x0008 // '0000' + '001000'
  11305. ];
  11306. function decodeBitmapTemplate0(width, height, decodingContext) {
  11307. var decoder = decodingContext.decoder;
  11308. var contexts = decodingContext.contextCache.getContexts('GB');
  11309. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11310. // ...ooooo....
  11311. // ..ooooooo... Context template for current pixel (X)
  11312. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11313. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11314. for (i = 0; i < height; i++) {
  11315. row = bitmap[i] = new Uint8Array(width);
  11316. row1 = (i < 1) ? row : bitmap[i - 1];
  11317. row2 = (i < 2) ? row : bitmap[i - 2];
  11318. // At the beginning of each row:
  11319. // Fill contextLabel with pixels that are above/right of (X)
  11320. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11321. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11322. (row1[3] << 4);
  11323. for (j = 0; j < width; j++) {
  11324. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11325. // At each pixel: Clear contextLabel pixels that are shifted
  11326. // out of the context, then add new ones.
  11327. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11328. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11329. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11330. }
  11331. }
  11332. return bitmap;
  11333. }
  11334. // 6.2 Generic Region Decoding Procedure
  11335. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11336. decodingContext) {
  11337. if (mmr) {
  11338. error('JBIG2 error: MMR encoding is not supported');
  11339. }
  11340. // Use optimized version for the most common case
  11341. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11342. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11343. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11344. return decodeBitmapTemplate0(width, height, decodingContext);
  11345. }
  11346. var useskip = !!skip;
  11347. var template = CodingTemplates[templateIndex].concat(at);
  11348. // Sorting is non-standard, and it is not required. But sorting increases
  11349. // the number of template bits that can be reused from the previous
  11350. // contextLabel in the main loop.
  11351. template.sort(function (a, b) {
  11352. return (a.y - b.y) || (a.x - b.x);
  11353. });
  11354. var templateLength = template.length;
  11355. var templateX = new Int8Array(templateLength);
  11356. var templateY = new Int8Array(templateLength);
  11357. var changingTemplateEntries = [];
  11358. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11359. var c, k;
  11360. for (k = 0; k < templateLength; k++) {
  11361. templateX[k] = template[k].x;
  11362. templateY[k] = template[k].y;
  11363. minX = Math.min(minX, template[k].x);
  11364. maxX = Math.max(maxX, template[k].x);
  11365. minY = Math.min(minY, template[k].y);
  11366. // Check if the template pixel appears in two consecutive context labels,
  11367. // so it can be reused. Otherwise, we add it to the list of changing
  11368. // template entries.
  11369. if (k < templateLength - 1 &&
  11370. template[k].y === template[k + 1].y &&
  11371. template[k].x === template[k + 1].x - 1) {
  11372. reuseMask |= 1 << (templateLength - 1 - k);
  11373. } else {
  11374. changingTemplateEntries.push(k);
  11375. }
  11376. }
  11377. var changingEntriesLength = changingTemplateEntries.length;
  11378. var changingTemplateX = new Int8Array(changingEntriesLength);
  11379. var changingTemplateY = new Int8Array(changingEntriesLength);
  11380. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  11381. for (c = 0; c < changingEntriesLength; c++) {
  11382. k = changingTemplateEntries[c];
  11383. changingTemplateX[c] = template[k].x;
  11384. changingTemplateY[c] = template[k].y;
  11385. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  11386. }
  11387. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  11388. var sbb_left = -minX;
  11389. var sbb_top = -minY;
  11390. var sbb_right = width - maxX;
  11391. var pseudoPixelContext = ReusedContexts[templateIndex];
  11392. var row = new Uint8Array(width);
  11393. var bitmap = [];
  11394. var decoder = decodingContext.decoder;
  11395. var contexts = decodingContext.contextCache.getContexts('GB');
  11396. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  11397. for (var i = 0; i < height; i++) {
  11398. if (prediction) {
  11399. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11400. ltp ^= sltp;
  11401. if (ltp) {
  11402. bitmap.push(row); // duplicate previous row
  11403. continue;
  11404. }
  11405. }
  11406. row = new Uint8Array(row);
  11407. bitmap.push(row);
  11408. for (j = 0; j < width; j++) {
  11409. if (useskip && skip[i][j]) {
  11410. row[j] = 0;
  11411. continue;
  11412. }
  11413. // Are we in the middle of a scanline, so we can reuse contextLabel
  11414. // bits?
  11415. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  11416. // If yes, we can just shift the bits that are reusable and only
  11417. // fetch the remaining ones.
  11418. contextLabel = (contextLabel << 1) & reuseMask;
  11419. for (k = 0; k < changingEntriesLength; k++) {
  11420. i0 = i + changingTemplateY[k];
  11421. j0 = j + changingTemplateX[k];
  11422. bit = bitmap[i0][j0];
  11423. if (bit) {
  11424. bit = changingTemplateBit[k];
  11425. contextLabel |= bit;
  11426. }
  11427. }
  11428. } else {
  11429. // compute the contextLabel from scratch
  11430. contextLabel = 0;
  11431. shift = templateLength - 1;
  11432. for (k = 0; k < templateLength; k++, shift--) {
  11433. j0 = j + templateX[k];
  11434. if (j0 >= 0 && j0 < width) {
  11435. i0 = i + templateY[k];
  11436. if (i0 >= 0) {
  11437. bit = bitmap[i0][j0];
  11438. if (bit) {
  11439. contextLabel |= bit << shift;
  11440. }
  11441. }
  11442. }
  11443. }
  11444. }
  11445. var pixel = decoder.readBit(contexts, contextLabel);
  11446. row[j] = pixel;
  11447. }
  11448. }
  11449. return bitmap;
  11450. }
  11451. // 6.3.2 Generic Refinement Region Decoding Procedure
  11452. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  11453. offsetX, offsetY, prediction, at,
  11454. decodingContext) {
  11455. var codingTemplate = RefinementTemplates[templateIndex].coding;
  11456. if (templateIndex === 0) {
  11457. codingTemplate = codingTemplate.concat([at[0]]);
  11458. }
  11459. var codingTemplateLength = codingTemplate.length;
  11460. var codingTemplateX = new Int32Array(codingTemplateLength);
  11461. var codingTemplateY = new Int32Array(codingTemplateLength);
  11462. var k;
  11463. for (k = 0; k < codingTemplateLength; k++) {
  11464. codingTemplateX[k] = codingTemplate[k].x;
  11465. codingTemplateY[k] = codingTemplate[k].y;
  11466. }
  11467. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  11468. if (templateIndex === 0) {
  11469. referenceTemplate = referenceTemplate.concat([at[1]]);
  11470. }
  11471. var referenceTemplateLength = referenceTemplate.length;
  11472. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  11473. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  11474. for (k = 0; k < referenceTemplateLength; k++) {
  11475. referenceTemplateX[k] = referenceTemplate[k].x;
  11476. referenceTemplateY[k] = referenceTemplate[k].y;
  11477. }
  11478. var referenceWidth = referenceBitmap[0].length;
  11479. var referenceHeight = referenceBitmap.length;
  11480. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  11481. var bitmap = [];
  11482. var decoder = decodingContext.decoder;
  11483. var contexts = decodingContext.contextCache.getContexts('GR');
  11484. var ltp = 0;
  11485. for (var i = 0; i < height; i++) {
  11486. if (prediction) {
  11487. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11488. ltp ^= sltp;
  11489. if (ltp) {
  11490. error('JBIG2 error: prediction is not supported');
  11491. }
  11492. }
  11493. var row = new Uint8Array(width);
  11494. bitmap.push(row);
  11495. for (var j = 0; j < width; j++) {
  11496. var i0, j0;
  11497. var contextLabel = 0;
  11498. for (k = 0; k < codingTemplateLength; k++) {
  11499. i0 = i + codingTemplateY[k];
  11500. j0 = j + codingTemplateX[k];
  11501. if (i0 < 0 || j0 < 0 || j0 >= width) {
  11502. contextLabel <<= 1; // out of bound pixel
  11503. } else {
  11504. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  11505. }
  11506. }
  11507. for (k = 0; k < referenceTemplateLength; k++) {
  11508. i0 = i + referenceTemplateY[k] + offsetY;
  11509. j0 = j + referenceTemplateX[k] + offsetX;
  11510. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  11511. j0 >= referenceWidth) {
  11512. contextLabel <<= 1; // out of bound pixel
  11513. } else {
  11514. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  11515. }
  11516. }
  11517. var pixel = decoder.readBit(contexts, contextLabel);
  11518. row[j] = pixel;
  11519. }
  11520. }
  11521. return bitmap;
  11522. }
  11523. // 6.5.5 Decoding the symbol dictionary
  11524. function decodeSymbolDictionary(huffman, refinement, symbols,
  11525. numberOfNewSymbols, numberOfExportedSymbols,
  11526. huffmanTables, templateIndex, at,
  11527. refinementTemplateIndex, refinementAt,
  11528. decodingContext) {
  11529. if (huffman) {
  11530. error('JBIG2 error: huffman is not supported');
  11531. }
  11532. var newSymbols = [];
  11533. var currentHeight = 0;
  11534. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  11535. var decoder = decodingContext.decoder;
  11536. var contextCache = decodingContext.contextCache;
  11537. while (newSymbols.length < numberOfNewSymbols) {
  11538. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  11539. currentHeight += deltaHeight;
  11540. var currentWidth = 0;
  11541. var totalWidth = 0;
  11542. while (true) {
  11543. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  11544. if (deltaWidth === null) {
  11545. break; // OOB
  11546. }
  11547. currentWidth += deltaWidth;
  11548. totalWidth += currentWidth;
  11549. var bitmap;
  11550. if (refinement) {
  11551. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  11552. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  11553. if (numberOfInstances > 1) {
  11554. bitmap = decodeTextRegion(huffman, refinement,
  11555. currentWidth, currentHeight, 0,
  11556. numberOfInstances, 1, //strip size
  11557. symbols.concat(newSymbols),
  11558. symbolCodeLength,
  11559. 0, //transposed
  11560. 0, //ds offset
  11561. 1, //top left 7.4.3.1.1
  11562. 0, //OR operator
  11563. huffmanTables,
  11564. refinementTemplateIndex, refinementAt,
  11565. decodingContext);
  11566. } else {
  11567. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11568. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11569. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11570. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  11571. newSymbols[symbolId - symbols.length]);
  11572. bitmap = decodeRefinement(currentWidth, currentHeight,
  11573. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  11574. decodingContext);
  11575. }
  11576. } else {
  11577. // 6.5.8.1 Direct-coded symbol bitmap
  11578. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  11579. templateIndex, false, null, at, decodingContext);
  11580. }
  11581. newSymbols.push(bitmap);
  11582. }
  11583. }
  11584. // 6.5.10 Exported symbols
  11585. var exportedSymbols = [];
  11586. var flags = [], currentFlag = false;
  11587. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  11588. while (flags.length < totalSymbolsLength) {
  11589. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  11590. while (runLength--) {
  11591. flags.push(currentFlag);
  11592. }
  11593. currentFlag = !currentFlag;
  11594. }
  11595. for (var i = 0, ii = symbols.length; i < ii; i++) {
  11596. if (flags[i]) {
  11597. exportedSymbols.push(symbols[i]);
  11598. }
  11599. }
  11600. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  11601. if (flags[i]) {
  11602. exportedSymbols.push(newSymbols[j]);
  11603. }
  11604. }
  11605. return exportedSymbols;
  11606. }
  11607. function decodeTextRegion(huffman, refinement, width, height,
  11608. defaultPixelValue, numberOfSymbolInstances,
  11609. stripSize, inputSymbols, symbolCodeLength,
  11610. transposed, dsOffset, referenceCorner,
  11611. combinationOperator, huffmanTables,
  11612. refinementTemplateIndex, refinementAt,
  11613. decodingContext) {
  11614. if (huffman) {
  11615. error('JBIG2 error: huffman is not supported');
  11616. }
  11617. // Prepare bitmap
  11618. var bitmap = [];
  11619. var i, row;
  11620. for (i = 0; i < height; i++) {
  11621. row = new Uint8Array(width);
  11622. if (defaultPixelValue) {
  11623. for (var j = 0; j < width; j++) {
  11624. row[j] = defaultPixelValue;
  11625. }
  11626. }
  11627. bitmap.push(row);
  11628. }
  11629. var decoder = decodingContext.decoder;
  11630. var contextCache = decodingContext.contextCache;
  11631. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11632. var firstS = 0;
  11633. i = 0;
  11634. while (i < numberOfSymbolInstances) {
  11635. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11636. stripT += deltaT;
  11637. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  11638. firstS += deltaFirstS;
  11639. var currentS = firstS;
  11640. do {
  11641. var currentT = (stripSize === 1 ? 0 :
  11642. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  11643. var t = stripSize * stripT + currentT;
  11644. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11645. var applyRefinement = (refinement &&
  11646. decodeInteger(contextCache, 'IARI', decoder));
  11647. var symbolBitmap = inputSymbols[symbolId];
  11648. var symbolWidth = symbolBitmap[0].length;
  11649. var symbolHeight = symbolBitmap.length;
  11650. if (applyRefinement) {
  11651. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  11652. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  11653. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11654. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11655. symbolWidth += rdw;
  11656. symbolHeight += rdh;
  11657. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  11658. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  11659. (rdh >> 1) + rdy, false, refinementAt,
  11660. decodingContext);
  11661. }
  11662. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  11663. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  11664. var s2, t2, symbolRow;
  11665. if (transposed) {
  11666. // Place Symbol Bitmap from T1,S1
  11667. for (s2 = 0; s2 < symbolHeight; s2++) {
  11668. row = bitmap[offsetS + s2];
  11669. if (!row) {
  11670. continue;
  11671. }
  11672. symbolRow = symbolBitmap[s2];
  11673. // To ignore Parts of Symbol bitmap which goes
  11674. // outside bitmap region
  11675. var maxWidth = Math.min(width - offsetT, symbolWidth);
  11676. switch (combinationOperator) {
  11677. case 0: // OR
  11678. for (t2 = 0; t2 < maxWidth; t2++) {
  11679. row[offsetT + t2] |= symbolRow[t2];
  11680. }
  11681. break;
  11682. case 2: // XOR
  11683. for (t2 = 0; t2 < maxWidth; t2++) {
  11684. row[offsetT + t2] ^= symbolRow[t2];
  11685. }
  11686. break;
  11687. default:
  11688. error('JBIG2 error: operator ' + combinationOperator +
  11689. ' is not supported');
  11690. }
  11691. }
  11692. currentS += symbolHeight - 1;
  11693. } else {
  11694. for (t2 = 0; t2 < symbolHeight; t2++) {
  11695. row = bitmap[offsetT + t2];
  11696. if (!row) {
  11697. continue;
  11698. }
  11699. symbolRow = symbolBitmap[t2];
  11700. switch (combinationOperator) {
  11701. case 0: // OR
  11702. for (s2 = 0; s2 < symbolWidth; s2++) {
  11703. row[offsetS + s2] |= symbolRow[s2];
  11704. }
  11705. break;
  11706. case 2: // XOR
  11707. for (s2 = 0; s2 < symbolWidth; s2++) {
  11708. row[offsetS + s2] ^= symbolRow[s2];
  11709. }
  11710. break;
  11711. default:
  11712. error('JBIG2 error: operator ' + combinationOperator +
  11713. ' is not supported');
  11714. }
  11715. }
  11716. currentS += symbolWidth - 1;
  11717. }
  11718. i++;
  11719. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11720. if (deltaS === null) {
  11721. break; // OOB
  11722. }
  11723. currentS += deltaS + dsOffset;
  11724. } while (true);
  11725. }
  11726. return bitmap;
  11727. }
  11728. function readSegmentHeader(data, start) {
  11729. var segmentHeader = {};
  11730. segmentHeader.number = readUint32(data, start);
  11731. var flags = data[start + 4];
  11732. var segmentType = flags & 0x3F;
  11733. if (!SegmentTypes[segmentType]) {
  11734. error('JBIG2 error: invalid segment type: ' + segmentType);
  11735. }
  11736. segmentHeader.type = segmentType;
  11737. segmentHeader.typeName = SegmentTypes[segmentType];
  11738. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11739. var pageAssociationFieldSize = !!(flags & 0x40);
  11740. var referredFlags = data[start + 5];
  11741. var referredToCount = (referredFlags >> 5) & 7;
  11742. var retainBits = [referredFlags & 31];
  11743. var position = start + 6;
  11744. if (referredFlags === 7) {
  11745. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11746. position += 3;
  11747. var bytes = (referredToCount + 7) >> 3;
  11748. retainBits[0] = data[position++];
  11749. while (--bytes > 0) {
  11750. retainBits.push(data[position++]);
  11751. }
  11752. } else if (referredFlags === 5 || referredFlags === 6) {
  11753. error('JBIG2 error: invalid referred-to flags');
  11754. }
  11755. segmentHeader.retainBits = retainBits;
  11756. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11757. (segmentHeader.number <= 65536 ? 2 : 4));
  11758. var referredTo = [];
  11759. var i, ii;
  11760. for (i = 0; i < referredToCount; i++) {
  11761. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11762. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11763. readUint32(data, position)));
  11764. referredTo.push(number);
  11765. position += referredToSegmentNumberSize;
  11766. }
  11767. segmentHeader.referredTo = referredTo;
  11768. if (!pageAssociationFieldSize) {
  11769. segmentHeader.pageAssociation = data[position++];
  11770. } else {
  11771. segmentHeader.pageAssociation = readUint32(data, position);
  11772. position += 4;
  11773. }
  11774. segmentHeader.length = readUint32(data, position);
  11775. position += 4;
  11776. if (segmentHeader.length === 0xFFFFFFFF) {
  11777. // 7.2.7 Segment data length, unknown segment length
  11778. if (segmentType === 38) { // ImmediateGenericRegion
  11779. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11780. var genericRegionSegmentFlags = data[position +
  11781. RegionSegmentInformationFieldLength];
  11782. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11783. // searching for the segment end
  11784. var searchPatternLength = 6;
  11785. var searchPattern = new Uint8Array(searchPatternLength);
  11786. if (!genericRegionMmr) {
  11787. searchPattern[0] = 0xFF;
  11788. searchPattern[1] = 0xAC;
  11789. }
  11790. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11791. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11792. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11793. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11794. for (i = position, ii = data.length; i < ii; i++) {
  11795. var j = 0;
  11796. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11797. j++;
  11798. }
  11799. if (j === searchPatternLength) {
  11800. segmentHeader.length = i + searchPatternLength;
  11801. break;
  11802. }
  11803. }
  11804. if (segmentHeader.length === 0xFFFFFFFF) {
  11805. error('JBIG2 error: segment end was not found');
  11806. }
  11807. } else {
  11808. error('JBIG2 error: invalid unknown segment length');
  11809. }
  11810. }
  11811. segmentHeader.headerEnd = position;
  11812. return segmentHeader;
  11813. }
  11814. function readSegments(header, data, start, end) {
  11815. var segments = [];
  11816. var position = start;
  11817. while (position < end) {
  11818. var segmentHeader = readSegmentHeader(data, position);
  11819. position = segmentHeader.headerEnd;
  11820. var segment = {
  11821. header: segmentHeader,
  11822. data: data
  11823. };
  11824. if (!header.randomAccess) {
  11825. segment.start = position;
  11826. position += segmentHeader.length;
  11827. segment.end = position;
  11828. }
  11829. segments.push(segment);
  11830. if (segmentHeader.type === 51) {
  11831. break; // end of file is found
  11832. }
  11833. }
  11834. if (header.randomAccess) {
  11835. for (var i = 0, ii = segments.length; i < ii; i++) {
  11836. segments[i].start = position;
  11837. position += segments[i].header.length;
  11838. segments[i].end = position;
  11839. }
  11840. }
  11841. return segments;
  11842. }
  11843. // 7.4.1 Region segment information field
  11844. function readRegionSegmentInformation(data, start) {
  11845. return {
  11846. width: readUint32(data, start),
  11847. height: readUint32(data, start + 4),
  11848. x: readUint32(data, start + 8),
  11849. y: readUint32(data, start + 12),
  11850. combinationOperator: data[start + 16] & 7
  11851. };
  11852. }
  11853. var RegionSegmentInformationFieldLength = 17;
  11854. function processSegment(segment, visitor) {
  11855. var header = segment.header;
  11856. var data = segment.data, position = segment.start, end = segment.end;
  11857. var args, at, i, atLength;
  11858. switch (header.type) {
  11859. case 0: // SymbolDictionary
  11860. // 7.4.2 Symbol dictionary segment syntax
  11861. var dictionary = {};
  11862. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11863. dictionary.huffman = !!(dictionaryFlags & 1);
  11864. dictionary.refinement = !!(dictionaryFlags & 2);
  11865. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11866. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11867. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11868. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11869. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11870. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11871. dictionary.template = (dictionaryFlags >> 10) & 3;
  11872. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11873. position += 2;
  11874. if (!dictionary.huffman) {
  11875. atLength = dictionary.template === 0 ? 4 : 1;
  11876. at = [];
  11877. for (i = 0; i < atLength; i++) {
  11878. at.push({
  11879. x: readInt8(data, position),
  11880. y: readInt8(data, position + 1)
  11881. });
  11882. position += 2;
  11883. }
  11884. dictionary.at = at;
  11885. }
  11886. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11887. at = [];
  11888. for (i = 0; i < 2; i++) {
  11889. at.push({
  11890. x: readInt8(data, position),
  11891. y: readInt8(data, position + 1)
  11892. });
  11893. position += 2;
  11894. }
  11895. dictionary.refinementAt = at;
  11896. }
  11897. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11898. position += 4;
  11899. dictionary.numberOfNewSymbols = readUint32(data, position);
  11900. position += 4;
  11901. args = [dictionary, header.number, header.referredTo,
  11902. data, position, end];
  11903. break;
  11904. case 6: // ImmediateTextRegion
  11905. case 7: // ImmediateLosslessTextRegion
  11906. var textRegion = {};
  11907. textRegion.info = readRegionSegmentInformation(data, position);
  11908. position += RegionSegmentInformationFieldLength;
  11909. var textRegionSegmentFlags = readUint16(data, position);
  11910. position += 2;
  11911. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11912. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11913. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11914. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11915. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11916. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11917. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11918. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11919. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11920. if (textRegion.huffman) {
  11921. var textRegionHuffmanFlags = readUint16(data, position);
  11922. position += 2;
  11923. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11924. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11925. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11926. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11927. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11928. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11929. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11930. textRegion.huffmanRefinementSizeSelector =
  11931. !!(textRegionHuffmanFlags & 14);
  11932. }
  11933. if (textRegion.refinement && !textRegion.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. textRegion.refinementAt = at;
  11943. }
  11944. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11945. position += 4;
  11946. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11947. if (textRegion.huffman) {
  11948. error('JBIG2 error: huffman is not supported');
  11949. }
  11950. args = [textRegion, header.referredTo, data, position, end];
  11951. break;
  11952. case 38: // ImmediateGenericRegion
  11953. case 39: // ImmediateLosslessGenericRegion
  11954. var genericRegion = {};
  11955. genericRegion.info = readRegionSegmentInformation(data, position);
  11956. position += RegionSegmentInformationFieldLength;
  11957. var genericRegionSegmentFlags = data[position++];
  11958. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  11959. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  11960. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  11961. if (!genericRegion.mmr) {
  11962. atLength = genericRegion.template === 0 ? 4 : 1;
  11963. at = [];
  11964. for (i = 0; i < atLength; i++) {
  11965. at.push({
  11966. x: readInt8(data, position),
  11967. y: readInt8(data, position + 1)
  11968. });
  11969. position += 2;
  11970. }
  11971. genericRegion.at = at;
  11972. }
  11973. args = [genericRegion, data, position, end];
  11974. break;
  11975. case 48: // PageInformation
  11976. var pageInfo = {
  11977. width: readUint32(data, position),
  11978. height: readUint32(data, position + 4),
  11979. resolutionX: readUint32(data, position + 8),
  11980. resolutionY: readUint32(data, position + 12)
  11981. };
  11982. if (pageInfo.height === 0xFFFFFFFF) {
  11983. delete pageInfo.height;
  11984. }
  11985. var pageSegmentFlags = data[position + 16];
  11986. var pageStripingInformation = readUint16(data, position + 17);
  11987. pageInfo.lossless = !!(pageSegmentFlags & 1);
  11988. pageInfo.refinement = !!(pageSegmentFlags & 2);
  11989. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  11990. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  11991. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  11992. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  11993. args = [pageInfo];
  11994. break;
  11995. case 49: // EndOfPage
  11996. break;
  11997. case 50: // EndOfStripe
  11998. break;
  11999. case 51: // EndOfFile
  12000. break;
  12001. case 62: // 7.4.15 defines 2 extension types which
  12002. // are comments and can be ignored.
  12003. break;
  12004. default:
  12005. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12006. header.type + ') is not implemented');
  12007. }
  12008. var callbackName = 'on' + header.typeName;
  12009. if (callbackName in visitor) {
  12010. visitor[callbackName].apply(visitor, args);
  12011. }
  12012. }
  12013. function processSegments(segments, visitor) {
  12014. for (var i = 0, ii = segments.length; i < ii; i++) {
  12015. processSegment(segments[i], visitor);
  12016. }
  12017. }
  12018. function parseJbig2(data, start, end) {
  12019. var position = start;
  12020. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12021. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12022. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12023. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12024. error('JBIG2 error: invalid header');
  12025. }
  12026. var header = {};
  12027. position += 8;
  12028. var flags = data[position++];
  12029. header.randomAccess = !(flags & 1);
  12030. if (!(flags & 2)) {
  12031. header.numberOfPages = readUint32(data, position);
  12032. position += 4;
  12033. }
  12034. var segments = readSegments(header, data, position, end);
  12035. error('Not implemented');
  12036. // processSegments(segments, new SimpleSegmentVisitor());
  12037. }
  12038. function parseJbig2Chunks(chunks) {
  12039. var visitor = new SimpleSegmentVisitor();
  12040. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12041. var chunk = chunks[i];
  12042. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12043. processSegments(segments, visitor);
  12044. }
  12045. return visitor.buffer;
  12046. }
  12047. function SimpleSegmentVisitor() {}
  12048. SimpleSegmentVisitor.prototype = {
  12049. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12050. this.currentPageInfo = info;
  12051. var rowSize = (info.width + 7) >> 3;
  12052. var buffer = new Uint8Array(rowSize * info.height);
  12053. // The contents of ArrayBuffers are initialized to 0.
  12054. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12055. if (info.defaultPixelValue) {
  12056. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12057. buffer[i] = 0xFF;
  12058. }
  12059. }
  12060. this.buffer = buffer;
  12061. },
  12062. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12063. var pageInfo = this.currentPageInfo;
  12064. var width = regionInfo.width, height = regionInfo.height;
  12065. var rowSize = (pageInfo.width + 7) >> 3;
  12066. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12067. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12068. var buffer = this.buffer;
  12069. var mask0 = 128 >> (regionInfo.x & 7);
  12070. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12071. var i, j, mask, offset;
  12072. switch (combinationOperator) {
  12073. case 0: // OR
  12074. for (i = 0; i < height; i++) {
  12075. mask = mask0;
  12076. offset = offset0;
  12077. for (j = 0; j < width; j++) {
  12078. if (bitmap[i][j]) {
  12079. buffer[offset] |= mask;
  12080. }
  12081. mask >>= 1;
  12082. if (!mask) {
  12083. mask = 128;
  12084. offset++;
  12085. }
  12086. }
  12087. offset0 += rowSize;
  12088. }
  12089. break;
  12090. case 2: // XOR
  12091. for (i = 0; i < height; i++) {
  12092. mask = mask0;
  12093. offset = offset0;
  12094. for (j = 0; j < width; j++) {
  12095. if (bitmap[i][j]) {
  12096. buffer[offset] ^= mask;
  12097. }
  12098. mask >>= 1;
  12099. if (!mask) {
  12100. mask = 128;
  12101. offset++;
  12102. }
  12103. }
  12104. offset0 += rowSize;
  12105. }
  12106. break;
  12107. default:
  12108. error('JBIG2 error: operator ' + combinationOperator +
  12109. ' is not supported');
  12110. }
  12111. },
  12112. onImmediateGenericRegion:
  12113. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12114. start, end) {
  12115. var regionInfo = region.info;
  12116. var decodingContext = new DecodingContext(data, start, end);
  12117. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12118. region.template, region.prediction, null,
  12119. region.at, decodingContext);
  12120. this.drawBitmap(regionInfo, bitmap);
  12121. },
  12122. onImmediateLosslessGenericRegion:
  12123. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12124. this.onImmediateGenericRegion.apply(this, arguments);
  12125. },
  12126. onSymbolDictionary:
  12127. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12128. currentSegment,
  12129. referredSegments,
  12130. data, start, end) {
  12131. var huffmanTables;
  12132. if (dictionary.huffman) {
  12133. error('JBIG2 error: huffman is not supported');
  12134. }
  12135. // Combines exported symbols from all referred segments
  12136. var symbols = this.symbols;
  12137. if (!symbols) {
  12138. this.symbols = symbols = {};
  12139. }
  12140. var inputSymbols = [];
  12141. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12142. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12143. }
  12144. var decodingContext = new DecodingContext(data, start, end);
  12145. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12146. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12147. dictionary.numberOfExportedSymbols, huffmanTables,
  12148. dictionary.template, dictionary.at,
  12149. dictionary.refinementTemplate, dictionary.refinementAt,
  12150. decodingContext);
  12151. },
  12152. onImmediateTextRegion:
  12153. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12154. referredSegments,
  12155. data, start, end) {
  12156. var regionInfo = region.info;
  12157. var huffmanTables;
  12158. // Combines exported symbols from all referred segments
  12159. var symbols = this.symbols;
  12160. var inputSymbols = [];
  12161. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12162. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12163. }
  12164. var symbolCodeLength = log2(inputSymbols.length);
  12165. var decodingContext = new DecodingContext(data, start, end);
  12166. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12167. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12168. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12169. symbolCodeLength, region.transposed, region.dsOffset,
  12170. region.referenceCorner, region.combinationOperator, huffmanTables,
  12171. region.refinementTemplate, region.refinementAt, decodingContext);
  12172. this.drawBitmap(regionInfo, bitmap);
  12173. },
  12174. onImmediateLosslessTextRegion:
  12175. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12176. this.onImmediateTextRegion.apply(this, arguments);
  12177. }
  12178. };
  12179. function Jbig2Image() {}
  12180. Jbig2Image.prototype = {
  12181. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12182. return parseJbig2Chunks(chunks);
  12183. }
  12184. };
  12185. return Jbig2Image;
  12186. })();
  12187. exports.Jbig2Image = Jbig2Image;
  12188. }));
  12189. (function (root, factory) {
  12190. {
  12191. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12192. root.pdfjsCoreArithmeticDecoder);
  12193. }
  12194. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12195. var info = sharedUtil.info;
  12196. var log2 = sharedUtil.log2;
  12197. var readUint16 = sharedUtil.readUint16;
  12198. var readUint32 = sharedUtil.readUint32;
  12199. var warn = sharedUtil.warn;
  12200. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12201. var JpxImage = (function JpxImageClosure() {
  12202. // Table E.1
  12203. var SubbandsGainLog2 = {
  12204. 'LL': 0,
  12205. 'LH': 1,
  12206. 'HL': 1,
  12207. 'HH': 2
  12208. };
  12209. function JpxImage() {
  12210. this.failOnCorruptedImage = false;
  12211. }
  12212. JpxImage.prototype = {
  12213. parse: function JpxImage_parse(data) {
  12214. var head = readUint16(data, 0);
  12215. // No box header, immediate start of codestream (SOC)
  12216. if (head === 0xFF4F) {
  12217. this.parseCodestream(data, 0, data.length);
  12218. return;
  12219. }
  12220. var position = 0, length = data.length;
  12221. while (position < length) {
  12222. var headerSize = 8;
  12223. var lbox = readUint32(data, position);
  12224. var tbox = readUint32(data, position + 4);
  12225. position += headerSize;
  12226. if (lbox === 1) {
  12227. // XLBox: read UInt64 according to spec.
  12228. // JavaScript's int precision of 53 bit should be sufficient here.
  12229. lbox = readUint32(data, position) * 4294967296 +
  12230. readUint32(data, position + 4);
  12231. position += 8;
  12232. headerSize += 8;
  12233. }
  12234. if (lbox === 0) {
  12235. lbox = length - position + headerSize;
  12236. }
  12237. if (lbox < headerSize) {
  12238. throw new Error('JPX Error: Invalid box field size');
  12239. }
  12240. var dataLength = lbox - headerSize;
  12241. var jumpDataLength = true;
  12242. switch (tbox) {
  12243. case 0x6A703268: // 'jp2h'
  12244. jumpDataLength = false; // parsing child boxes
  12245. break;
  12246. case 0x636F6C72: // 'colr'
  12247. // Colorspaces are not used, the CS from the PDF is used.
  12248. var method = data[position];
  12249. if (method === 1) {
  12250. // enumerated colorspace
  12251. var colorspace = readUint32(data, position + 3);
  12252. switch (colorspace) {
  12253. case 16: // this indicates a sRGB colorspace
  12254. case 17: // this indicates a grayscale colorspace
  12255. case 18: // this indicates a YUV colorspace
  12256. break;
  12257. default:
  12258. warn('Unknown colorspace ' + colorspace);
  12259. break;
  12260. }
  12261. } else if (method === 2) {
  12262. info('ICC profile not supported');
  12263. }
  12264. break;
  12265. case 0x6A703263: // 'jp2c'
  12266. this.parseCodestream(data, position, position + dataLength);
  12267. break;
  12268. case 0x6A502020: // 'jP\024\024'
  12269. if (0x0d0a870a !== readUint32(data, position)) {
  12270. warn('Invalid JP2 signature');
  12271. }
  12272. break;
  12273. // The following header types are valid but currently not used:
  12274. case 0x6A501A1A: // 'jP\032\032'
  12275. case 0x66747970: // 'ftyp'
  12276. case 0x72726571: // 'rreq'
  12277. case 0x72657320: // 'res '
  12278. case 0x69686472: // 'ihdr'
  12279. break;
  12280. default:
  12281. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12282. (tbox >> 16) & 0xFF,
  12283. (tbox >> 8) & 0xFF,
  12284. tbox & 0xFF);
  12285. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12286. break;
  12287. }
  12288. if (jumpDataLength) {
  12289. position += dataLength;
  12290. }
  12291. }
  12292. },
  12293. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12294. var newByte = stream.getByte();
  12295. while (newByte >= 0) {
  12296. var oldByte = newByte;
  12297. newByte = stream.getByte();
  12298. var code = (oldByte << 8) | newByte;
  12299. // Image and tile size (SIZ)
  12300. if (code === 0xFF51) {
  12301. stream.skip(4);
  12302. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12303. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12304. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12305. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12306. stream.skip(16);
  12307. var Csiz = stream.getUint16(); // Byte 36
  12308. this.width = Xsiz - XOsiz;
  12309. this.height = Ysiz - YOsiz;
  12310. this.componentsCount = Csiz;
  12311. // Results are always returned as Uint8Arrays
  12312. this.bitsPerComponent = 8;
  12313. return;
  12314. }
  12315. }
  12316. throw new Error('JPX Error: No size marker found in JPX stream');
  12317. },
  12318. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12319. var context = {};
  12320. try {
  12321. var doNotRecover = false;
  12322. var position = start;
  12323. while (position + 1 < end) {
  12324. var code = readUint16(data, position);
  12325. position += 2;
  12326. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12327. switch (code) {
  12328. case 0xFF4F: // Start of codestream (SOC)
  12329. context.mainHeader = true;
  12330. break;
  12331. case 0xFFD9: // End of codestream (EOC)
  12332. break;
  12333. case 0xFF51: // Image and tile size (SIZ)
  12334. length = readUint16(data, position);
  12335. var siz = {};
  12336. siz.Xsiz = readUint32(data, position + 4);
  12337. siz.Ysiz = readUint32(data, position + 8);
  12338. siz.XOsiz = readUint32(data, position + 12);
  12339. siz.YOsiz = readUint32(data, position + 16);
  12340. siz.XTsiz = readUint32(data, position + 20);
  12341. siz.YTsiz = readUint32(data, position + 24);
  12342. siz.XTOsiz = readUint32(data, position + 28);
  12343. siz.YTOsiz = readUint32(data, position + 32);
  12344. var componentsCount = readUint16(data, position + 36);
  12345. siz.Csiz = componentsCount;
  12346. var components = [];
  12347. j = position + 38;
  12348. for (var i = 0; i < componentsCount; i++) {
  12349. var component = {
  12350. precision: (data[j] & 0x7F) + 1,
  12351. isSigned: !!(data[j] & 0x80),
  12352. XRsiz: data[j + 1],
  12353. YRsiz: data[j + 1]
  12354. };
  12355. calculateComponentDimensions(component, siz);
  12356. components.push(component);
  12357. }
  12358. context.SIZ = siz;
  12359. context.components = components;
  12360. calculateTileGrids(context, components);
  12361. context.QCC = [];
  12362. context.COC = [];
  12363. break;
  12364. case 0xFF5C: // Quantization default (QCD)
  12365. length = readUint16(data, position);
  12366. var qcd = {};
  12367. j = position + 2;
  12368. sqcd = data[j++];
  12369. switch (sqcd & 0x1F) {
  12370. case 0:
  12371. spqcdSize = 8;
  12372. scalarExpounded = true;
  12373. break;
  12374. case 1:
  12375. spqcdSize = 16;
  12376. scalarExpounded = false;
  12377. break;
  12378. case 2:
  12379. spqcdSize = 16;
  12380. scalarExpounded = true;
  12381. break;
  12382. default:
  12383. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12384. }
  12385. qcd.noQuantization = (spqcdSize === 8);
  12386. qcd.scalarExpounded = scalarExpounded;
  12387. qcd.guardBits = sqcd >> 5;
  12388. spqcds = [];
  12389. while (j < length + position) {
  12390. var spqcd = {};
  12391. if (spqcdSize === 8) {
  12392. spqcd.epsilon = data[j++] >> 3;
  12393. spqcd.mu = 0;
  12394. } else {
  12395. spqcd.epsilon = data[j] >> 3;
  12396. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12397. j += 2;
  12398. }
  12399. spqcds.push(spqcd);
  12400. }
  12401. qcd.SPqcds = spqcds;
  12402. if (context.mainHeader) {
  12403. context.QCD = qcd;
  12404. } else {
  12405. context.currentTile.QCD = qcd;
  12406. context.currentTile.QCC = [];
  12407. }
  12408. break;
  12409. case 0xFF5D: // Quantization component (QCC)
  12410. length = readUint16(data, position);
  12411. var qcc = {};
  12412. j = position + 2;
  12413. var cqcc;
  12414. if (context.SIZ.Csiz < 257) {
  12415. cqcc = data[j++];
  12416. } else {
  12417. cqcc = readUint16(data, j);
  12418. j += 2;
  12419. }
  12420. sqcd = data[j++];
  12421. switch (sqcd & 0x1F) {
  12422. case 0:
  12423. spqcdSize = 8;
  12424. scalarExpounded = true;
  12425. break;
  12426. case 1:
  12427. spqcdSize = 16;
  12428. scalarExpounded = false;
  12429. break;
  12430. case 2:
  12431. spqcdSize = 16;
  12432. scalarExpounded = true;
  12433. break;
  12434. default:
  12435. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12436. }
  12437. qcc.noQuantization = (spqcdSize === 8);
  12438. qcc.scalarExpounded = scalarExpounded;
  12439. qcc.guardBits = sqcd >> 5;
  12440. spqcds = [];
  12441. while (j < (length + position)) {
  12442. spqcd = {};
  12443. if (spqcdSize === 8) {
  12444. spqcd.epsilon = data[j++] >> 3;
  12445. spqcd.mu = 0;
  12446. } else {
  12447. spqcd.epsilon = data[j] >> 3;
  12448. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12449. j += 2;
  12450. }
  12451. spqcds.push(spqcd);
  12452. }
  12453. qcc.SPqcds = spqcds;
  12454. if (context.mainHeader) {
  12455. context.QCC[cqcc] = qcc;
  12456. } else {
  12457. context.currentTile.QCC[cqcc] = qcc;
  12458. }
  12459. break;
  12460. case 0xFF52: // Coding style default (COD)
  12461. length = readUint16(data, position);
  12462. var cod = {};
  12463. j = position + 2;
  12464. var scod = data[j++];
  12465. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  12466. cod.sopMarkerUsed = !!(scod & 2);
  12467. cod.ephMarkerUsed = !!(scod & 4);
  12468. cod.progressionOrder = data[j++];
  12469. cod.layersCount = readUint16(data, j);
  12470. j += 2;
  12471. cod.multipleComponentTransform = data[j++];
  12472. cod.decompositionLevelsCount = data[j++];
  12473. cod.xcb = (data[j++] & 0xF) + 2;
  12474. cod.ycb = (data[j++] & 0xF) + 2;
  12475. var blockStyle = data[j++];
  12476. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12477. cod.resetContextProbabilities = !!(blockStyle & 2);
  12478. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12479. cod.verticalyStripe = !!(blockStyle & 8);
  12480. cod.predictableTermination = !!(blockStyle & 16);
  12481. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12482. cod.reversibleTransformation = data[j++];
  12483. if (cod.entropyCoderWithCustomPrecincts) {
  12484. var precinctsSizes = [];
  12485. while (j < length + position) {
  12486. var precinctsSize = data[j++];
  12487. precinctsSizes.push({
  12488. PPx: precinctsSize & 0xF,
  12489. PPy: precinctsSize >> 4
  12490. });
  12491. }
  12492. cod.precinctsSizes = precinctsSizes;
  12493. }
  12494. var unsupported = [];
  12495. if (cod.selectiveArithmeticCodingBypass) {
  12496. unsupported.push('selectiveArithmeticCodingBypass');
  12497. }
  12498. if (cod.resetContextProbabilities) {
  12499. unsupported.push('resetContextProbabilities');
  12500. }
  12501. if (cod.terminationOnEachCodingPass) {
  12502. unsupported.push('terminationOnEachCodingPass');
  12503. }
  12504. if (cod.verticalyStripe) {
  12505. unsupported.push('verticalyStripe');
  12506. }
  12507. if (cod.predictableTermination) {
  12508. unsupported.push('predictableTermination');
  12509. }
  12510. if (unsupported.length > 0) {
  12511. doNotRecover = true;
  12512. throw new Error('JPX Error: Unsupported COD options (' +
  12513. unsupported.join(', ') + ')');
  12514. }
  12515. if (context.mainHeader) {
  12516. context.COD = cod;
  12517. } else {
  12518. context.currentTile.COD = cod;
  12519. context.currentTile.COC = [];
  12520. }
  12521. break;
  12522. case 0xFF90: // Start of tile-part (SOT)
  12523. length = readUint16(data, position);
  12524. tile = {};
  12525. tile.index = readUint16(data, position + 2);
  12526. tile.length = readUint32(data, position + 4);
  12527. tile.dataEnd = tile.length + position - 2;
  12528. tile.partIndex = data[position + 8];
  12529. tile.partsCount = data[position + 9];
  12530. context.mainHeader = false;
  12531. if (tile.partIndex === 0) {
  12532. // reset component specific settings
  12533. tile.COD = context.COD;
  12534. tile.COC = context.COC.slice(0); // clone of the global COC
  12535. tile.QCD = context.QCD;
  12536. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12537. }
  12538. context.currentTile = tile;
  12539. break;
  12540. case 0xFF93: // Start of data (SOD)
  12541. tile = context.currentTile;
  12542. if (tile.partIndex === 0) {
  12543. initializeTile(context, tile.index);
  12544. buildPackets(context);
  12545. }
  12546. // moving to the end of the data
  12547. length = tile.dataEnd - position;
  12548. parseTilePackets(context, data, position, length);
  12549. break;
  12550. case 0xFF55: // Tile-part lengths, main header (TLM)
  12551. case 0xFF57: // Packet length, main header (PLM)
  12552. case 0xFF58: // Packet length, tile-part header (PLT)
  12553. case 0xFF64: // Comment (COM)
  12554. length = readUint16(data, position);
  12555. // skipping content
  12556. break;
  12557. case 0xFF53: // Coding style component (COC)
  12558. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  12559. 'not implemented');
  12560. default:
  12561. throw new Error('JPX Error: Unknown codestream code: ' +
  12562. code.toString(16));
  12563. }
  12564. position += length;
  12565. }
  12566. } catch (e) {
  12567. if (doNotRecover || this.failOnCorruptedImage) {
  12568. throw e;
  12569. } else {
  12570. warn('Trying to recover from ' + e.message);
  12571. }
  12572. }
  12573. this.tiles = transformComponents(context);
  12574. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12575. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12576. this.componentsCount = context.SIZ.Csiz;
  12577. }
  12578. };
  12579. function calculateComponentDimensions(component, siz) {
  12580. // Section B.2 Component mapping
  12581. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12582. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12583. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12584. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12585. component.width = component.x1 - component.x0;
  12586. component.height = component.y1 - component.y0;
  12587. }
  12588. function calculateTileGrids(context, components) {
  12589. var siz = context.SIZ;
  12590. // Section B.3 Division into tile and tile-components
  12591. var tile, tiles = [];
  12592. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12593. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12594. for (var q = 0; q < numYtiles; q++) {
  12595. for (var p = 0; p < numXtiles; p++) {
  12596. tile = {};
  12597. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12598. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12599. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12600. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12601. tile.width = tile.tx1 - tile.tx0;
  12602. tile.height = tile.ty1 - tile.ty0;
  12603. tile.components = [];
  12604. tiles.push(tile);
  12605. }
  12606. }
  12607. context.tiles = tiles;
  12608. var componentsCount = siz.Csiz;
  12609. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12610. var component = components[i];
  12611. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12612. var tileComponent = {};
  12613. tile = tiles[j];
  12614. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12615. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12616. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12617. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12618. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12619. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12620. tile.components[i] = tileComponent;
  12621. }
  12622. }
  12623. }
  12624. function getBlocksDimensions(context, component, r) {
  12625. var codOrCoc = component.codingStyleParameters;
  12626. var result = {};
  12627. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12628. result.PPx = 15;
  12629. result.PPy = 15;
  12630. } else {
  12631. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12632. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12633. }
  12634. // calculate codeblock size as described in section B.7
  12635. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12636. Math.min(codOrCoc.xcb, result.PPx));
  12637. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12638. Math.min(codOrCoc.ycb, result.PPy));
  12639. return result;
  12640. }
  12641. function buildPrecincts(context, resolution, dimensions) {
  12642. // Section B.6 Division resolution to precincts
  12643. var precinctWidth = 1 << dimensions.PPx;
  12644. var precinctHeight = 1 << dimensions.PPy;
  12645. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12646. // to precincts. Precinct partition divides a resolution according to width
  12647. // and height parameters. The subband that belongs to the resolution level
  12648. // has a different size than the level, unless it is the zero resolution.
  12649. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12650. // The precinct partitioning for a particular subband is derived from a
  12651. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12652. // resolution level)... The LL band associated with each resolution level is
  12653. // divided into precincts... Each of the resulting precinct regions is then
  12654. // mapped into its child subbands (if any) at the next lower resolution
  12655. // level. This is accomplished by using the coordinate transformation
  12656. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12657. // coordinates of a point in the LL band and child subband, respectively.
  12658. var isZeroRes = resolution.resLevel === 0;
  12659. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12660. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12661. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12662. Math.ceil(resolution.trx1 / precinctWidth) -
  12663. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12664. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12665. Math.ceil(resolution.try1 / precinctHeight) -
  12666. Math.floor(resolution.try0 / precinctHeight) : 0);
  12667. var numprecincts = numprecinctswide * numprecinctshigh;
  12668. resolution.precinctParameters = {
  12669. precinctWidth: precinctWidth,
  12670. precinctHeight: precinctHeight,
  12671. numprecinctswide: numprecinctswide,
  12672. numprecinctshigh: numprecinctshigh,
  12673. numprecincts: numprecincts,
  12674. precinctWidthInSubband: precinctWidthInSubband,
  12675. precinctHeightInSubband: precinctHeightInSubband
  12676. };
  12677. }
  12678. function buildCodeblocks(context, subband, dimensions) {
  12679. // Section B.7 Division sub-band into code-blocks
  12680. var xcb_ = dimensions.xcb_;
  12681. var ycb_ = dimensions.ycb_;
  12682. var codeblockWidth = 1 << xcb_;
  12683. var codeblockHeight = 1 << ycb_;
  12684. var cbx0 = subband.tbx0 >> xcb_;
  12685. var cby0 = subband.tby0 >> ycb_;
  12686. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12687. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12688. var precinctParameters = subband.resolution.precinctParameters;
  12689. var codeblocks = [];
  12690. var precincts = [];
  12691. var i, j, codeblock, precinctNumber;
  12692. for (j = cby0; j < cby1; j++) {
  12693. for (i = cbx0; i < cbx1; i++) {
  12694. codeblock = {
  12695. cbx: i,
  12696. cby: j,
  12697. tbx0: codeblockWidth * i,
  12698. tby0: codeblockHeight * j,
  12699. tbx1: codeblockWidth * (i + 1),
  12700. tby1: codeblockHeight * (j + 1)
  12701. };
  12702. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12703. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12704. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12705. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12706. // Calculate precinct number for this codeblock, codeblock position
  12707. // should be relative to its subband, use actual dimension and position
  12708. // See comment about codeblock group width and height
  12709. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12710. precinctParameters.precinctWidthInSubband);
  12711. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12712. precinctParameters.precinctHeightInSubband);
  12713. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12714. codeblock.precinctNumber = precinctNumber;
  12715. codeblock.subbandType = subband.type;
  12716. codeblock.Lblock = 3;
  12717. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12718. codeblock.tby1_ <= codeblock.tby0_) {
  12719. continue;
  12720. }
  12721. codeblocks.push(codeblock);
  12722. // building precinct for the sub-band
  12723. var precinct = precincts[precinctNumber];
  12724. if (precinct !== undefined) {
  12725. if (i < precinct.cbxMin) {
  12726. precinct.cbxMin = i;
  12727. } else if (i > precinct.cbxMax) {
  12728. precinct.cbxMax = i;
  12729. }
  12730. if (j < precinct.cbyMin) {
  12731. precinct.cbxMin = j;
  12732. } else if (j > precinct.cbyMax) {
  12733. precinct.cbyMax = j;
  12734. }
  12735. } else {
  12736. precincts[precinctNumber] = precinct = {
  12737. cbxMin: i,
  12738. cbyMin: j,
  12739. cbxMax: i,
  12740. cbyMax: j
  12741. };
  12742. }
  12743. codeblock.precinct = precinct;
  12744. }
  12745. }
  12746. subband.codeblockParameters = {
  12747. codeblockWidth: xcb_,
  12748. codeblockHeight: ycb_,
  12749. numcodeblockwide: cbx1 - cbx0 + 1,
  12750. numcodeblockhigh: cby1 - cby0 + 1
  12751. };
  12752. subband.codeblocks = codeblocks;
  12753. subband.precincts = precincts;
  12754. }
  12755. function createPacket(resolution, precinctNumber, layerNumber) {
  12756. var precinctCodeblocks = [];
  12757. // Section B.10.8 Order of info in packet
  12758. var subbands = resolution.subbands;
  12759. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12760. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12761. var subband = subbands[i];
  12762. var codeblocks = subband.codeblocks;
  12763. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12764. var codeblock = codeblocks[j];
  12765. if (codeblock.precinctNumber !== precinctNumber) {
  12766. continue;
  12767. }
  12768. precinctCodeblocks.push(codeblock);
  12769. }
  12770. }
  12771. return {
  12772. layerNumber: layerNumber,
  12773. codeblocks: precinctCodeblocks
  12774. };
  12775. }
  12776. function LayerResolutionComponentPositionIterator(context) {
  12777. var siz = context.SIZ;
  12778. var tileIndex = context.currentTile.index;
  12779. var tile = context.tiles[tileIndex];
  12780. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12781. var componentsCount = siz.Csiz;
  12782. var maxDecompositionLevelsCount = 0;
  12783. for (var q = 0; q < componentsCount; q++) {
  12784. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12785. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12786. }
  12787. var l = 0, r = 0, i = 0, k = 0;
  12788. this.nextPacket = function JpxImage_nextPacket() {
  12789. // Section B.12.1.1 Layer-resolution-component-position
  12790. for (; l < layersCount; l++) {
  12791. for (; r <= maxDecompositionLevelsCount; r++) {
  12792. for (; i < componentsCount; i++) {
  12793. var component = tile.components[i];
  12794. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12795. continue;
  12796. }
  12797. var resolution = component.resolutions[r];
  12798. var numprecincts = resolution.precinctParameters.numprecincts;
  12799. for (; k < numprecincts;) {
  12800. var packet = createPacket(resolution, k, l);
  12801. k++;
  12802. return packet;
  12803. }
  12804. k = 0;
  12805. }
  12806. i = 0;
  12807. }
  12808. r = 0;
  12809. }
  12810. throw new Error('JPX Error: Out of packets');
  12811. };
  12812. }
  12813. function ResolutionLayerComponentPositionIterator(context) {
  12814. var siz = context.SIZ;
  12815. var tileIndex = context.currentTile.index;
  12816. var tile = context.tiles[tileIndex];
  12817. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12818. var componentsCount = siz.Csiz;
  12819. var maxDecompositionLevelsCount = 0;
  12820. for (var q = 0; q < componentsCount; q++) {
  12821. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12822. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12823. }
  12824. var r = 0, l = 0, i = 0, k = 0;
  12825. this.nextPacket = function JpxImage_nextPacket() {
  12826. // Section B.12.1.2 Resolution-layer-component-position
  12827. for (; r <= maxDecompositionLevelsCount; r++) {
  12828. for (; l < layersCount; l++) {
  12829. for (; i < componentsCount; i++) {
  12830. var component = tile.components[i];
  12831. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12832. continue;
  12833. }
  12834. var resolution = component.resolutions[r];
  12835. var numprecincts = resolution.precinctParameters.numprecincts;
  12836. for (; k < numprecincts;) {
  12837. var packet = createPacket(resolution, k, l);
  12838. k++;
  12839. return packet;
  12840. }
  12841. k = 0;
  12842. }
  12843. i = 0;
  12844. }
  12845. l = 0;
  12846. }
  12847. throw new Error('JPX Error: Out of packets');
  12848. };
  12849. }
  12850. function ResolutionPositionComponentLayerIterator(context) {
  12851. var siz = context.SIZ;
  12852. var tileIndex = context.currentTile.index;
  12853. var tile = context.tiles[tileIndex];
  12854. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12855. var componentsCount = siz.Csiz;
  12856. var l, r, c, p;
  12857. var maxDecompositionLevelsCount = 0;
  12858. for (c = 0; c < componentsCount; c++) {
  12859. var component = tile.components[c];
  12860. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12861. component.codingStyleParameters.decompositionLevelsCount);
  12862. }
  12863. var maxNumPrecinctsInLevel = new Int32Array(
  12864. maxDecompositionLevelsCount + 1);
  12865. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12866. var maxNumPrecincts = 0;
  12867. for (c = 0; c < componentsCount; ++c) {
  12868. var resolutions = tile.components[c].resolutions;
  12869. if (r < resolutions.length) {
  12870. maxNumPrecincts = Math.max(maxNumPrecincts,
  12871. resolutions[r].precinctParameters.numprecincts);
  12872. }
  12873. }
  12874. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12875. }
  12876. l = 0;
  12877. r = 0;
  12878. c = 0;
  12879. p = 0;
  12880. this.nextPacket = function JpxImage_nextPacket() {
  12881. // Section B.12.1.3 Resolution-position-component-layer
  12882. for (; r <= maxDecompositionLevelsCount; r++) {
  12883. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12884. for (; c < componentsCount; c++) {
  12885. var component = tile.components[c];
  12886. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12887. continue;
  12888. }
  12889. var resolution = component.resolutions[r];
  12890. var numprecincts = resolution.precinctParameters.numprecincts;
  12891. if (p >= numprecincts) {
  12892. continue;
  12893. }
  12894. for (; l < layersCount;) {
  12895. var packet = createPacket(resolution, p, l);
  12896. l++;
  12897. return packet;
  12898. }
  12899. l = 0;
  12900. }
  12901. c = 0;
  12902. }
  12903. p = 0;
  12904. }
  12905. throw new Error('JPX Error: Out of packets');
  12906. };
  12907. }
  12908. function PositionComponentResolutionLayerIterator(context) {
  12909. var siz = context.SIZ;
  12910. var tileIndex = context.currentTile.index;
  12911. var tile = context.tiles[tileIndex];
  12912. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12913. var componentsCount = siz.Csiz;
  12914. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12915. var precinctsIterationSizes = precinctsSizes;
  12916. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12917. this.nextPacket = function JpxImage_nextPacket() {
  12918. // Section B.12.1.4 Position-component-resolution-layer
  12919. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12920. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12921. for (; c < componentsCount; c++) {
  12922. var component = tile.components[c];
  12923. var decompositionLevelsCount =
  12924. component.codingStyleParameters.decompositionLevelsCount;
  12925. for (; r <= decompositionLevelsCount; r++) {
  12926. var resolution = component.resolutions[r];
  12927. var sizeInImageScale =
  12928. precinctsSizes.components[c].resolutions[r];
  12929. var k = getPrecinctIndexIfExist(
  12930. px,
  12931. py,
  12932. sizeInImageScale,
  12933. precinctsIterationSizes,
  12934. resolution);
  12935. if (k === null) {
  12936. continue;
  12937. }
  12938. for (; l < layersCount;) {
  12939. var packet = createPacket(resolution, k, l);
  12940. l++;
  12941. return packet;
  12942. }
  12943. l = 0;
  12944. }
  12945. r = 0;
  12946. }
  12947. c = 0;
  12948. }
  12949. px = 0;
  12950. }
  12951. throw new Error('JPX Error: Out of packets');
  12952. };
  12953. }
  12954. function ComponentPositionResolutionLayerIterator(context) {
  12955. var siz = context.SIZ;
  12956. var tileIndex = context.currentTile.index;
  12957. var tile = context.tiles[tileIndex];
  12958. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12959. var componentsCount = siz.Csiz;
  12960. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12961. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12962. this.nextPacket = function JpxImage_nextPacket() {
  12963. // Section B.12.1.5 Component-position-resolution-layer
  12964. for (; c < componentsCount; ++c) {
  12965. var component = tile.components[c];
  12966. var precinctsIterationSizes = precinctsSizes.components[c];
  12967. var decompositionLevelsCount =
  12968. component.codingStyleParameters.decompositionLevelsCount;
  12969. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12970. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12971. for (; r <= decompositionLevelsCount; r++) {
  12972. var resolution = component.resolutions[r];
  12973. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12974. var k = getPrecinctIndexIfExist(
  12975. px,
  12976. py,
  12977. sizeInImageScale,
  12978. precinctsIterationSizes,
  12979. resolution);
  12980. if (k === null) {
  12981. continue;
  12982. }
  12983. for (; l < layersCount;) {
  12984. var packet = createPacket(resolution, k, l);
  12985. l++;
  12986. return packet;
  12987. }
  12988. l = 0;
  12989. }
  12990. r = 0;
  12991. }
  12992. px = 0;
  12993. }
  12994. py = 0;
  12995. }
  12996. throw new Error('JPX Error: Out of packets');
  12997. };
  12998. }
  12999. function getPrecinctIndexIfExist(
  13000. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13001. var posX = pxIndex * precinctIterationSizes.minWidth;
  13002. var posY = pyIndex * precinctIterationSizes.minHeight;
  13003. if (posX % sizeInImageScale.width !== 0 ||
  13004. posY % sizeInImageScale.height !== 0) {
  13005. return null;
  13006. }
  13007. var startPrecinctRowIndex =
  13008. (posY / sizeInImageScale.width) *
  13009. resolution.precinctParameters.numprecinctswide;
  13010. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13011. }
  13012. function getPrecinctSizesInImageScale(tile) {
  13013. var componentsCount = tile.components.length;
  13014. var minWidth = Number.MAX_VALUE;
  13015. var minHeight = Number.MAX_VALUE;
  13016. var maxNumWide = 0;
  13017. var maxNumHigh = 0;
  13018. var sizePerComponent = new Array(componentsCount);
  13019. for (var c = 0; c < componentsCount; c++) {
  13020. var component = tile.components[c];
  13021. var decompositionLevelsCount =
  13022. component.codingStyleParameters.decompositionLevelsCount;
  13023. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13024. var minWidthCurrentComponent = Number.MAX_VALUE;
  13025. var minHeightCurrentComponent = Number.MAX_VALUE;
  13026. var maxNumWideCurrentComponent = 0;
  13027. var maxNumHighCurrentComponent = 0;
  13028. var scale = 1;
  13029. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13030. var resolution = component.resolutions[r];
  13031. var widthCurrentResolution =
  13032. scale * resolution.precinctParameters.precinctWidth;
  13033. var heightCurrentResolution =
  13034. scale * resolution.precinctParameters.precinctHeight;
  13035. minWidthCurrentComponent = Math.min(
  13036. minWidthCurrentComponent,
  13037. widthCurrentResolution);
  13038. minHeightCurrentComponent = Math.min(
  13039. minHeightCurrentComponent,
  13040. heightCurrentResolution);
  13041. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13042. resolution.precinctParameters.numprecinctswide);
  13043. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13044. resolution.precinctParameters.numprecinctshigh);
  13045. sizePerResolution[r] = {
  13046. width: widthCurrentResolution,
  13047. height: heightCurrentResolution
  13048. };
  13049. scale <<= 1;
  13050. }
  13051. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13052. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13053. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13054. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13055. sizePerComponent[c] = {
  13056. resolutions: sizePerResolution,
  13057. minWidth: minWidthCurrentComponent,
  13058. minHeight: minHeightCurrentComponent,
  13059. maxNumWide: maxNumWideCurrentComponent,
  13060. maxNumHigh: maxNumHighCurrentComponent
  13061. };
  13062. }
  13063. return {
  13064. components: sizePerComponent,
  13065. minWidth: minWidth,
  13066. minHeight: minHeight,
  13067. maxNumWide: maxNumWide,
  13068. maxNumHigh: maxNumHigh
  13069. };
  13070. }
  13071. function buildPackets(context) {
  13072. var siz = context.SIZ;
  13073. var tileIndex = context.currentTile.index;
  13074. var tile = context.tiles[tileIndex];
  13075. var componentsCount = siz.Csiz;
  13076. // Creating resolutions and sub-bands for each component
  13077. for (var c = 0; c < componentsCount; c++) {
  13078. var component = tile.components[c];
  13079. var decompositionLevelsCount =
  13080. component.codingStyleParameters.decompositionLevelsCount;
  13081. // Section B.5 Resolution levels and sub-bands
  13082. var resolutions = [];
  13083. var subbands = [];
  13084. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13085. var blocksDimensions = getBlocksDimensions(context, component, r);
  13086. var resolution = {};
  13087. var scale = 1 << (decompositionLevelsCount - r);
  13088. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13089. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13090. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13091. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13092. resolution.resLevel = r;
  13093. buildPrecincts(context, resolution, blocksDimensions);
  13094. resolutions.push(resolution);
  13095. var subband;
  13096. if (r === 0) {
  13097. // one sub-band (LL) with last decomposition
  13098. subband = {};
  13099. subband.type = 'LL';
  13100. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13101. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13102. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13103. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13104. subband.resolution = resolution;
  13105. buildCodeblocks(context, subband, blocksDimensions);
  13106. subbands.push(subband);
  13107. resolution.subbands = [subband];
  13108. } else {
  13109. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13110. var resolutionSubbands = [];
  13111. // three sub-bands (HL, LH and HH) with rest of decompositions
  13112. subband = {};
  13113. subband.type = 'HL';
  13114. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13115. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13116. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13117. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13118. subband.resolution = resolution;
  13119. buildCodeblocks(context, subband, blocksDimensions);
  13120. subbands.push(subband);
  13121. resolutionSubbands.push(subband);
  13122. subband = {};
  13123. subband.type = 'LH';
  13124. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13125. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13126. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13127. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13128. subband.resolution = resolution;
  13129. buildCodeblocks(context, subband, blocksDimensions);
  13130. subbands.push(subband);
  13131. resolutionSubbands.push(subband);
  13132. subband = {};
  13133. subband.type = 'HH';
  13134. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13135. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13136. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13137. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13138. subband.resolution = resolution;
  13139. buildCodeblocks(context, subband, blocksDimensions);
  13140. subbands.push(subband);
  13141. resolutionSubbands.push(subband);
  13142. resolution.subbands = resolutionSubbands;
  13143. }
  13144. }
  13145. component.resolutions = resolutions;
  13146. component.subbands = subbands;
  13147. }
  13148. // Generate the packets sequence
  13149. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13150. switch (progressionOrder) {
  13151. case 0:
  13152. tile.packetsIterator =
  13153. new LayerResolutionComponentPositionIterator(context);
  13154. break;
  13155. case 1:
  13156. tile.packetsIterator =
  13157. new ResolutionLayerComponentPositionIterator(context);
  13158. break;
  13159. case 2:
  13160. tile.packetsIterator =
  13161. new ResolutionPositionComponentLayerIterator(context);
  13162. break;
  13163. case 3:
  13164. tile.packetsIterator =
  13165. new PositionComponentResolutionLayerIterator(context);
  13166. break;
  13167. case 4:
  13168. tile.packetsIterator =
  13169. new ComponentPositionResolutionLayerIterator(context);
  13170. break;
  13171. default:
  13172. throw new Error('JPX Error: Unsupported progression order ' +
  13173. progressionOrder);
  13174. }
  13175. }
  13176. function parseTilePackets(context, data, offset, dataLength) {
  13177. var position = 0;
  13178. var buffer, bufferSize = 0, skipNextBit = false;
  13179. function readBits(count) {
  13180. while (bufferSize < count) {
  13181. var b = data[offset + position];
  13182. position++;
  13183. if (skipNextBit) {
  13184. buffer = (buffer << 7) | b;
  13185. bufferSize += 7;
  13186. skipNextBit = false;
  13187. } else {
  13188. buffer = (buffer << 8) | b;
  13189. bufferSize += 8;
  13190. }
  13191. if (b === 0xFF) {
  13192. skipNextBit = true;
  13193. }
  13194. }
  13195. bufferSize -= count;
  13196. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13197. }
  13198. function skipMarkerIfEqual(value) {
  13199. if (data[offset + position - 1] === 0xFF &&
  13200. data[offset + position] === value) {
  13201. skipBytes(1);
  13202. return true;
  13203. } else if (data[offset + position] === 0xFF &&
  13204. data[offset + position + 1] === value) {
  13205. skipBytes(2);
  13206. return true;
  13207. }
  13208. return false;
  13209. }
  13210. function skipBytes(count) {
  13211. position += count;
  13212. }
  13213. function alignToByte() {
  13214. bufferSize = 0;
  13215. if (skipNextBit) {
  13216. position++;
  13217. skipNextBit = false;
  13218. }
  13219. }
  13220. function readCodingpasses() {
  13221. if (readBits(1) === 0) {
  13222. return 1;
  13223. }
  13224. if (readBits(1) === 0) {
  13225. return 2;
  13226. }
  13227. var value = readBits(2);
  13228. if (value < 3) {
  13229. return value + 3;
  13230. }
  13231. value = readBits(5);
  13232. if (value < 31) {
  13233. return value + 6;
  13234. }
  13235. value = readBits(7);
  13236. return value + 37;
  13237. }
  13238. var tileIndex = context.currentTile.index;
  13239. var tile = context.tiles[tileIndex];
  13240. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13241. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13242. var packetsIterator = tile.packetsIterator;
  13243. while (position < dataLength) {
  13244. alignToByte();
  13245. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13246. // Skip also marker segment length and packet sequence ID
  13247. skipBytes(4);
  13248. }
  13249. var packet = packetsIterator.nextPacket();
  13250. if (!readBits(1)) {
  13251. continue;
  13252. }
  13253. var layerNumber = packet.layerNumber;
  13254. var queue = [], codeblock;
  13255. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13256. codeblock = packet.codeblocks[i];
  13257. var precinct = codeblock.precinct;
  13258. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13259. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13260. var codeblockIncluded = false;
  13261. var firstTimeInclusion = false;
  13262. var valueReady;
  13263. if (codeblock['included'] !== undefined) {
  13264. codeblockIncluded = !!readBits(1);
  13265. } else {
  13266. // reading inclusion tree
  13267. precinct = codeblock.precinct;
  13268. var inclusionTree, zeroBitPlanesTree;
  13269. if (precinct['inclusionTree'] !== undefined) {
  13270. inclusionTree = precinct.inclusionTree;
  13271. } else {
  13272. // building inclusion and zero bit-planes trees
  13273. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13274. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13275. inclusionTree = new InclusionTree(width, height, layerNumber);
  13276. zeroBitPlanesTree = new TagTree(width, height);
  13277. precinct.inclusionTree = inclusionTree;
  13278. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13279. }
  13280. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13281. while (true) {
  13282. if (readBits(1)) {
  13283. valueReady = !inclusionTree.nextLevel();
  13284. if (valueReady) {
  13285. codeblock.included = true;
  13286. codeblockIncluded = firstTimeInclusion = true;
  13287. break;
  13288. }
  13289. } else {
  13290. inclusionTree.incrementValue(layerNumber);
  13291. break;
  13292. }
  13293. }
  13294. }
  13295. }
  13296. if (!codeblockIncluded) {
  13297. continue;
  13298. }
  13299. if (firstTimeInclusion) {
  13300. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13301. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13302. while (true) {
  13303. if (readBits(1)) {
  13304. valueReady = !zeroBitPlanesTree.nextLevel();
  13305. if (valueReady) {
  13306. break;
  13307. }
  13308. } else {
  13309. zeroBitPlanesTree.incrementValue();
  13310. }
  13311. }
  13312. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13313. }
  13314. var codingpasses = readCodingpasses();
  13315. while (readBits(1)) {
  13316. codeblock.Lblock++;
  13317. }
  13318. var codingpassesLog2 = log2(codingpasses);
  13319. // rounding down log2
  13320. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13321. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13322. var codedDataLength = readBits(bits);
  13323. queue.push({
  13324. codeblock: codeblock,
  13325. codingpasses: codingpasses,
  13326. dataLength: codedDataLength
  13327. });
  13328. }
  13329. alignToByte();
  13330. if (ephMarkerUsed) {
  13331. skipMarkerIfEqual(0x92);
  13332. }
  13333. while (queue.length > 0) {
  13334. var packetItem = queue.shift();
  13335. codeblock = packetItem.codeblock;
  13336. if (codeblock['data'] === undefined) {
  13337. codeblock.data = [];
  13338. }
  13339. codeblock.data.push({
  13340. data: data,
  13341. start: offset + position,
  13342. end: offset + position + packetItem.dataLength,
  13343. codingpasses: packetItem.codingpasses
  13344. });
  13345. position += packetItem.dataLength;
  13346. }
  13347. }
  13348. return position;
  13349. }
  13350. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13351. delta, mb, reversible, segmentationSymbolUsed) {
  13352. var x0 = subband.tbx0;
  13353. var y0 = subband.tby0;
  13354. var width = subband.tbx1 - subband.tbx0;
  13355. var codeblocks = subband.codeblocks;
  13356. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13357. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13358. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13359. var codeblock = codeblocks[i];
  13360. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13361. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13362. if (blockWidth === 0 || blockHeight === 0) {
  13363. continue;
  13364. }
  13365. if (codeblock['data'] === undefined) {
  13366. continue;
  13367. }
  13368. var bitModel, currentCodingpassType;
  13369. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13370. codeblock.zeroBitPlanes, mb);
  13371. currentCodingpassType = 2; // first bit plane starts from cleanup
  13372. // collect data
  13373. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  13374. var j, jj, dataItem;
  13375. for (j = 0, jj = data.length; j < jj; j++) {
  13376. dataItem = data[j];
  13377. totalLength += dataItem.end - dataItem.start;
  13378. codingpasses += dataItem.codingpasses;
  13379. }
  13380. var encodedData = new Uint8Array(totalLength);
  13381. var position = 0;
  13382. for (j = 0, jj = data.length; j < jj; j++) {
  13383. dataItem = data[j];
  13384. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  13385. encodedData.set(chunk, position);
  13386. position += chunk.length;
  13387. }
  13388. // decoding the item
  13389. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  13390. bitModel.setDecoder(decoder);
  13391. for (j = 0; j < codingpasses; j++) {
  13392. switch (currentCodingpassType) {
  13393. case 0:
  13394. bitModel.runSignificancePropogationPass();
  13395. break;
  13396. case 1:
  13397. bitModel.runMagnitudeRefinementPass();
  13398. break;
  13399. case 2:
  13400. bitModel.runCleanupPass();
  13401. if (segmentationSymbolUsed) {
  13402. bitModel.checkSegmentationSymbol();
  13403. }
  13404. break;
  13405. }
  13406. currentCodingpassType = (currentCodingpassType + 1) % 3;
  13407. }
  13408. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  13409. var sign = bitModel.coefficentsSign;
  13410. var magnitude = bitModel.coefficentsMagnitude;
  13411. var bitsDecoded = bitModel.bitsDecoded;
  13412. var magnitudeCorrection = reversible ? 0 : 0.5;
  13413. var k, n, nb;
  13414. position = 0;
  13415. // Do the interleaving of Section F.3.3 here, so we do not need
  13416. // to copy later. LL level is not interleaved, just copied.
  13417. var interleave = (subband.type !== 'LL');
  13418. for (j = 0; j < blockHeight; j++) {
  13419. var row = (offset / width) | 0; // row in the non-interleaved subband
  13420. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  13421. for (k = 0; k < blockWidth; k++) {
  13422. n = magnitude[position];
  13423. if (n !== 0) {
  13424. n = (n + magnitudeCorrection) * delta;
  13425. if (sign[position] !== 0) {
  13426. n = -n;
  13427. }
  13428. nb = bitsDecoded[position];
  13429. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  13430. if (reversible && (nb >= mb)) {
  13431. coefficients[pos] = n;
  13432. } else {
  13433. coefficients[pos] = n * (1 << (mb - nb));
  13434. }
  13435. }
  13436. offset++;
  13437. position++;
  13438. }
  13439. offset += width - blockWidth;
  13440. }
  13441. }
  13442. }
  13443. function transformTile(context, tile, c) {
  13444. var component = tile.components[c];
  13445. var codingStyleParameters = component.codingStyleParameters;
  13446. var quantizationParameters = component.quantizationParameters;
  13447. var decompositionLevelsCount =
  13448. codingStyleParameters.decompositionLevelsCount;
  13449. var spqcds = quantizationParameters.SPqcds;
  13450. var scalarExpounded = quantizationParameters.scalarExpounded;
  13451. var guardBits = quantizationParameters.guardBits;
  13452. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  13453. var precision = context.components[c].precision;
  13454. var reversible = codingStyleParameters.reversibleTransformation;
  13455. var transform = (reversible ? new ReversibleTransform() :
  13456. new IrreversibleTransform());
  13457. var subbandCoefficients = [];
  13458. var b = 0;
  13459. for (var i = 0; i <= decompositionLevelsCount; i++) {
  13460. var resolution = component.resolutions[i];
  13461. var width = resolution.trx1 - resolution.trx0;
  13462. var height = resolution.try1 - resolution.try0;
  13463. // Allocate space for the whole sublevel.
  13464. var coefficients = new Float32Array(width * height);
  13465. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  13466. var mu, epsilon;
  13467. if (!scalarExpounded) {
  13468. // formula E-5
  13469. mu = spqcds[0].mu;
  13470. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  13471. } else {
  13472. mu = spqcds[b].mu;
  13473. epsilon = spqcds[b].epsilon;
  13474. b++;
  13475. }
  13476. var subband = resolution.subbands[j];
  13477. var gainLog2 = SubbandsGainLog2[subband.type];
  13478. // calulate quantization coefficient (Section E.1.1.1)
  13479. var delta = (reversible ? 1 :
  13480. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13481. var mb = (guardBits + epsilon - 1);
  13482. // In the first resolution level, copyCoefficients will fill the
  13483. // whole array with coefficients. In the succeding passes,
  13484. // copyCoefficients will consecutively fill in the values that belong
  13485. // to the interleaved positions of the HL, LH, and HH coefficients.
  13486. // The LL coefficients will then be interleaved in Transform.iterate().
  13487. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13488. reversible, segmentationSymbolUsed);
  13489. }
  13490. subbandCoefficients.push({
  13491. width: width,
  13492. height: height,
  13493. items: coefficients
  13494. });
  13495. }
  13496. var result = transform.calculate(subbandCoefficients,
  13497. component.tcx0, component.tcy0);
  13498. return {
  13499. left: component.tcx0,
  13500. top: component.tcy0,
  13501. width: result.width,
  13502. height: result.height,
  13503. items: result.items
  13504. };
  13505. }
  13506. function transformComponents(context) {
  13507. var siz = context.SIZ;
  13508. var components = context.components;
  13509. var componentsCount = siz.Csiz;
  13510. var resultImages = [];
  13511. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13512. var tile = context.tiles[i];
  13513. var transformedTiles = [];
  13514. var c;
  13515. for (c = 0; c < componentsCount; c++) {
  13516. transformedTiles[c] = transformTile(context, tile, c);
  13517. }
  13518. var tile0 = transformedTiles[0];
  13519. var out = new Uint8Array(tile0.items.length * componentsCount);
  13520. var result = {
  13521. left: tile0.left,
  13522. top: tile0.top,
  13523. width: tile0.width,
  13524. height: tile0.height,
  13525. items: out
  13526. };
  13527. // Section G.2.2 Inverse multi component transform
  13528. var shift, offset, max, min, maxK;
  13529. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13530. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13531. var fourComponents = componentsCount === 4;
  13532. var y0items = transformedTiles[0].items;
  13533. var y1items = transformedTiles[1].items;
  13534. var y2items = transformedTiles[2].items;
  13535. var y3items = fourComponents ? transformedTiles[3].items : null;
  13536. // HACK: The multiple component transform formulas below assume that
  13537. // all components have the same precision. With this in mind, we
  13538. // compute shift and offset only once.
  13539. shift = components[0].precision - 8;
  13540. offset = (128 << shift) + 0.5;
  13541. max = 255 * (1 << shift);
  13542. maxK = max * 0.5;
  13543. min = -maxK;
  13544. var component0 = tile.components[0];
  13545. var alpha01 = componentsCount - 3;
  13546. jj = y0items.length;
  13547. if (!component0.codingStyleParameters.reversibleTransformation) {
  13548. // inverse irreversible multiple component transform
  13549. for (j = 0; j < jj; j++, pos += alpha01) {
  13550. y0 = y0items[j] + offset;
  13551. y1 = y1items[j];
  13552. y2 = y2items[j];
  13553. r = y0 + 1.402 * y2;
  13554. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13555. b = y0 + 1.772 * y1;
  13556. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13557. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13558. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13559. }
  13560. } else {
  13561. // inverse reversible multiple component transform
  13562. for (j = 0; j < jj; j++, pos += alpha01) {
  13563. y0 = y0items[j] + offset;
  13564. y1 = y1items[j];
  13565. y2 = y2items[j];
  13566. g = y0 - ((y2 + y1) >> 2);
  13567. r = g + y2;
  13568. b = g + y1;
  13569. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13570. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13571. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13572. }
  13573. }
  13574. if (fourComponents) {
  13575. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13576. k = y3items[j];
  13577. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13578. }
  13579. }
  13580. } else { // no multi-component transform
  13581. for (c = 0; c < componentsCount; c++) {
  13582. var items = transformedTiles[c].items;
  13583. shift = components[c].precision - 8;
  13584. offset = (128 << shift) + 0.5;
  13585. max = (127.5 * (1 << shift));
  13586. min = -max;
  13587. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13588. val = items[j];
  13589. out[pos] = val <= min ? 0 :
  13590. val >= max ? 255 : (val + offset) >> shift;
  13591. pos += componentsCount;
  13592. }
  13593. }
  13594. }
  13595. resultImages.push(result);
  13596. }
  13597. return resultImages;
  13598. }
  13599. function initializeTile(context, tileIndex) {
  13600. var siz = context.SIZ;
  13601. var componentsCount = siz.Csiz;
  13602. var tile = context.tiles[tileIndex];
  13603. for (var c = 0; c < componentsCount; c++) {
  13604. var component = tile.components[c];
  13605. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13606. context.currentTile.QCC[c] : context.currentTile.QCD);
  13607. component.quantizationParameters = qcdOrQcc;
  13608. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13609. context.currentTile.COC[c] : context.currentTile.COD);
  13610. component.codingStyleParameters = codOrCoc;
  13611. }
  13612. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13613. }
  13614. // Section B.10.2 Tag trees
  13615. var TagTree = (function TagTreeClosure() {
  13616. function TagTree(width, height) {
  13617. var levelsLength = log2(Math.max(width, height)) + 1;
  13618. this.levels = [];
  13619. for (var i = 0; i < levelsLength; i++) {
  13620. var level = {
  13621. width: width,
  13622. height: height,
  13623. items: []
  13624. };
  13625. this.levels.push(level);
  13626. width = Math.ceil(width / 2);
  13627. height = Math.ceil(height / 2);
  13628. }
  13629. }
  13630. TagTree.prototype = {
  13631. reset: function TagTree_reset(i, j) {
  13632. var currentLevel = 0, value = 0, level;
  13633. while (currentLevel < this.levels.length) {
  13634. level = this.levels[currentLevel];
  13635. var index = i + j * level.width;
  13636. if (level.items[index] !== undefined) {
  13637. value = level.items[index];
  13638. break;
  13639. }
  13640. level.index = index;
  13641. i >>= 1;
  13642. j >>= 1;
  13643. currentLevel++;
  13644. }
  13645. currentLevel--;
  13646. level = this.levels[currentLevel];
  13647. level.items[level.index] = value;
  13648. this.currentLevel = currentLevel;
  13649. delete this.value;
  13650. },
  13651. incrementValue: function TagTree_incrementValue() {
  13652. var level = this.levels[this.currentLevel];
  13653. level.items[level.index]++;
  13654. },
  13655. nextLevel: function TagTree_nextLevel() {
  13656. var currentLevel = this.currentLevel;
  13657. var level = this.levels[currentLevel];
  13658. var value = level.items[level.index];
  13659. currentLevel--;
  13660. if (currentLevel < 0) {
  13661. this.value = value;
  13662. return false;
  13663. }
  13664. this.currentLevel = currentLevel;
  13665. level = this.levels[currentLevel];
  13666. level.items[level.index] = value;
  13667. return true;
  13668. }
  13669. };
  13670. return TagTree;
  13671. })();
  13672. var InclusionTree = (function InclusionTreeClosure() {
  13673. function InclusionTree(width, height, defaultValue) {
  13674. var levelsLength = log2(Math.max(width, height)) + 1;
  13675. this.levels = [];
  13676. for (var i = 0; i < levelsLength; i++) {
  13677. var items = new Uint8Array(width * height);
  13678. for (var j = 0, jj = items.length; j < jj; j++) {
  13679. items[j] = defaultValue;
  13680. }
  13681. var level = {
  13682. width: width,
  13683. height: height,
  13684. items: items
  13685. };
  13686. this.levels.push(level);
  13687. width = Math.ceil(width / 2);
  13688. height = Math.ceil(height / 2);
  13689. }
  13690. }
  13691. InclusionTree.prototype = {
  13692. reset: function InclusionTree_reset(i, j, stopValue) {
  13693. var currentLevel = 0;
  13694. while (currentLevel < this.levels.length) {
  13695. var level = this.levels[currentLevel];
  13696. var index = i + j * level.width;
  13697. level.index = index;
  13698. var value = level.items[index];
  13699. if (value === 0xFF) {
  13700. break;
  13701. }
  13702. if (value > stopValue) {
  13703. this.currentLevel = currentLevel;
  13704. // already know about this one, propagating the value to top levels
  13705. this.propagateValues();
  13706. return false;
  13707. }
  13708. i >>= 1;
  13709. j >>= 1;
  13710. currentLevel++;
  13711. }
  13712. this.currentLevel = currentLevel - 1;
  13713. return true;
  13714. },
  13715. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13716. var level = this.levels[this.currentLevel];
  13717. level.items[level.index] = stopValue + 1;
  13718. this.propagateValues();
  13719. },
  13720. propagateValues: function InclusionTree_propagateValues() {
  13721. var levelIndex = this.currentLevel;
  13722. var level = this.levels[levelIndex];
  13723. var currentValue = level.items[level.index];
  13724. while (--levelIndex >= 0) {
  13725. level = this.levels[levelIndex];
  13726. level.items[level.index] = currentValue;
  13727. }
  13728. },
  13729. nextLevel: function InclusionTree_nextLevel() {
  13730. var currentLevel = this.currentLevel;
  13731. var level = this.levels[currentLevel];
  13732. var value = level.items[level.index];
  13733. level.items[level.index] = 0xFF;
  13734. currentLevel--;
  13735. if (currentLevel < 0) {
  13736. return false;
  13737. }
  13738. this.currentLevel = currentLevel;
  13739. level = this.levels[currentLevel];
  13740. level.items[level.index] = value;
  13741. return true;
  13742. }
  13743. };
  13744. return InclusionTree;
  13745. })();
  13746. // Section D. Coefficient bit modeling
  13747. var BitModel = (function BitModelClosure() {
  13748. var UNIFORM_CONTEXT = 17;
  13749. var RUNLENGTH_CONTEXT = 18;
  13750. // Table D-1
  13751. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13752. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13753. var LLAndLHContextsLabel = new Uint8Array([
  13754. 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,
  13755. 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,
  13756. 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
  13757. ]);
  13758. var HLContextLabel = new Uint8Array([
  13759. 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,
  13760. 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,
  13761. 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
  13762. ]);
  13763. var HHContextLabel = new Uint8Array([
  13764. 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,
  13765. 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,
  13766. 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
  13767. ]);
  13768. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13769. this.width = width;
  13770. this.height = height;
  13771. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13772. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13773. var coefficientCount = width * height;
  13774. // coefficients outside the encoding region treated as insignificant
  13775. // add border state cells for significanceState
  13776. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13777. this.coefficentsSign = new Uint8Array(coefficientCount);
  13778. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13779. mb > 6 ? new Uint16Array(coefficientCount) :
  13780. new Uint8Array(coefficientCount);
  13781. this.processingFlags = new Uint8Array(coefficientCount);
  13782. var bitsDecoded = new Uint8Array(coefficientCount);
  13783. if (zeroBitPlanes !== 0) {
  13784. for (var i = 0; i < coefficientCount; i++) {
  13785. bitsDecoded[i] = zeroBitPlanes;
  13786. }
  13787. }
  13788. this.bitsDecoded = bitsDecoded;
  13789. this.reset();
  13790. }
  13791. BitModel.prototype = {
  13792. setDecoder: function BitModel_setDecoder(decoder) {
  13793. this.decoder = decoder;
  13794. },
  13795. reset: function BitModel_reset() {
  13796. // We have 17 contexts that are accessed via context labels,
  13797. // plus the uniform and runlength context.
  13798. this.contexts = new Int8Array(19);
  13799. // Contexts are packed into 1 byte:
  13800. // highest 7 bits carry the index, lowest bit carries mps
  13801. this.contexts[0] = (4 << 1) | 0;
  13802. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13803. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13804. },
  13805. setNeighborsSignificance:
  13806. function BitModel_setNeighborsSignificance(row, column, index) {
  13807. var neighborsSignificance = this.neighborsSignificance;
  13808. var width = this.width, height = this.height;
  13809. var left = (column > 0);
  13810. var right = (column + 1 < width);
  13811. var i;
  13812. if (row > 0) {
  13813. i = index - width;
  13814. if (left) {
  13815. neighborsSignificance[i - 1] += 0x10;
  13816. }
  13817. if (right) {
  13818. neighborsSignificance[i + 1] += 0x10;
  13819. }
  13820. neighborsSignificance[i] += 0x04;
  13821. }
  13822. if (row + 1 < height) {
  13823. i = index + width;
  13824. if (left) {
  13825. neighborsSignificance[i - 1] += 0x10;
  13826. }
  13827. if (right) {
  13828. neighborsSignificance[i + 1] += 0x10;
  13829. }
  13830. neighborsSignificance[i] += 0x04;
  13831. }
  13832. if (left) {
  13833. neighborsSignificance[index - 1] += 0x01;
  13834. }
  13835. if (right) {
  13836. neighborsSignificance[index + 1] += 0x01;
  13837. }
  13838. neighborsSignificance[index] |= 0x80;
  13839. },
  13840. runSignificancePropogationPass:
  13841. function BitModel_runSignificancePropogationPass() {
  13842. var decoder = this.decoder;
  13843. var width = this.width, height = this.height;
  13844. var coefficentsMagnitude = this.coefficentsMagnitude;
  13845. var coefficentsSign = this.coefficentsSign;
  13846. var neighborsSignificance = this.neighborsSignificance;
  13847. var processingFlags = this.processingFlags;
  13848. var contexts = this.contexts;
  13849. var labels = this.contextLabelTable;
  13850. var bitsDecoded = this.bitsDecoded;
  13851. var processedInverseMask = ~1;
  13852. var processedMask = 1;
  13853. var firstMagnitudeBitMask = 2;
  13854. for (var i0 = 0; i0 < height; i0 += 4) {
  13855. for (var j = 0; j < width; j++) {
  13856. var index = i0 * width + j;
  13857. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13858. var i = i0 + i1;
  13859. if (i >= height) {
  13860. break;
  13861. }
  13862. // clear processed flag first
  13863. processingFlags[index] &= processedInverseMask;
  13864. if (coefficentsMagnitude[index] ||
  13865. !neighborsSignificance[index]) {
  13866. continue;
  13867. }
  13868. var contextLabel = labels[neighborsSignificance[index]];
  13869. var decision = decoder.readBit(contexts, contextLabel);
  13870. if (decision) {
  13871. var sign = this.decodeSignBit(i, j, index);
  13872. coefficentsSign[index] = sign;
  13873. coefficentsMagnitude[index] = 1;
  13874. this.setNeighborsSignificance(i, j, index);
  13875. processingFlags[index] |= firstMagnitudeBitMask;
  13876. }
  13877. bitsDecoded[index]++;
  13878. processingFlags[index] |= processedMask;
  13879. }
  13880. }
  13881. }
  13882. },
  13883. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13884. var width = this.width, height = this.height;
  13885. var coefficentsMagnitude = this.coefficentsMagnitude;
  13886. var coefficentsSign = this.coefficentsSign;
  13887. var contribution, sign0, sign1, significance1;
  13888. var contextLabel, decoded;
  13889. // calculate horizontal contribution
  13890. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13891. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13892. sign1 = coefficentsSign[index + 1];
  13893. if (significance1) {
  13894. sign0 = coefficentsSign[index - 1];
  13895. contribution = 1 - sign1 - sign0;
  13896. } else {
  13897. contribution = 1 - sign1 - sign1;
  13898. }
  13899. } else if (significance1) {
  13900. sign0 = coefficentsSign[index - 1];
  13901. contribution = 1 - sign0 - sign0;
  13902. } else {
  13903. contribution = 0;
  13904. }
  13905. var horizontalContribution = 3 * contribution;
  13906. // calculate vertical contribution and combine with the horizontal
  13907. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13908. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13909. sign1 = coefficentsSign[index + width];
  13910. if (significance1) {
  13911. sign0 = coefficentsSign[index - width];
  13912. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13913. } else {
  13914. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13915. }
  13916. } else if (significance1) {
  13917. sign0 = coefficentsSign[index - width];
  13918. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13919. } else {
  13920. contribution = horizontalContribution;
  13921. }
  13922. if (contribution >= 0) {
  13923. contextLabel = 9 + contribution;
  13924. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13925. } else {
  13926. contextLabel = 9 - contribution;
  13927. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13928. }
  13929. return decoded;
  13930. },
  13931. runMagnitudeRefinementPass:
  13932. function BitModel_runMagnitudeRefinementPass() {
  13933. var decoder = this.decoder;
  13934. var width = this.width, height = this.height;
  13935. var coefficentsMagnitude = this.coefficentsMagnitude;
  13936. var neighborsSignificance = this.neighborsSignificance;
  13937. var contexts = this.contexts;
  13938. var bitsDecoded = this.bitsDecoded;
  13939. var processingFlags = this.processingFlags;
  13940. var processedMask = 1;
  13941. var firstMagnitudeBitMask = 2;
  13942. var length = width * height;
  13943. var width4 = width * 4;
  13944. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13945. indexNext = Math.min(length, index0 + width4);
  13946. for (var j = 0; j < width; j++) {
  13947. for (var index = index0 + j; index < indexNext; index += width) {
  13948. // significant but not those that have just become
  13949. if (!coefficentsMagnitude[index] ||
  13950. (processingFlags[index] & processedMask) !== 0) {
  13951. continue;
  13952. }
  13953. var contextLabel = 16;
  13954. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13955. processingFlags[index] ^= firstMagnitudeBitMask;
  13956. // first refinement
  13957. var significance = neighborsSignificance[index] & 127;
  13958. contextLabel = significance === 0 ? 15 : 14;
  13959. }
  13960. var bit = decoder.readBit(contexts, contextLabel);
  13961. coefficentsMagnitude[index] =
  13962. (coefficentsMagnitude[index] << 1) | bit;
  13963. bitsDecoded[index]++;
  13964. processingFlags[index] |= processedMask;
  13965. }
  13966. }
  13967. }
  13968. },
  13969. runCleanupPass: function BitModel_runCleanupPass() {
  13970. var decoder = this.decoder;
  13971. var width = this.width, height = this.height;
  13972. var neighborsSignificance = this.neighborsSignificance;
  13973. var coefficentsMagnitude = this.coefficentsMagnitude;
  13974. var coefficentsSign = this.coefficentsSign;
  13975. var contexts = this.contexts;
  13976. var labels = this.contextLabelTable;
  13977. var bitsDecoded = this.bitsDecoded;
  13978. var processingFlags = this.processingFlags;
  13979. var processedMask = 1;
  13980. var firstMagnitudeBitMask = 2;
  13981. var oneRowDown = width;
  13982. var twoRowsDown = width * 2;
  13983. var threeRowsDown = width * 3;
  13984. var iNext;
  13985. for (var i0 = 0; i0 < height; i0 = iNext) {
  13986. iNext = Math.min(i0 + 4, height);
  13987. var indexBase = i0 * width;
  13988. var checkAllEmpty = i0 + 3 < height;
  13989. for (var j = 0; j < width; j++) {
  13990. var index0 = indexBase + j;
  13991. // using the property: labels[neighborsSignificance[index]] === 0
  13992. // when neighborsSignificance[index] === 0
  13993. var allEmpty = (checkAllEmpty &&
  13994. processingFlags[index0] === 0 &&
  13995. processingFlags[index0 + oneRowDown] === 0 &&
  13996. processingFlags[index0 + twoRowsDown] === 0 &&
  13997. processingFlags[index0 + threeRowsDown] === 0 &&
  13998. neighborsSignificance[index0] === 0 &&
  13999. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14000. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14001. neighborsSignificance[index0 + threeRowsDown] === 0);
  14002. var i1 = 0, index = index0;
  14003. var i = i0, sign;
  14004. if (allEmpty) {
  14005. var hasSignificantCoefficent =
  14006. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14007. if (!hasSignificantCoefficent) {
  14008. bitsDecoded[index0]++;
  14009. bitsDecoded[index0 + oneRowDown]++;
  14010. bitsDecoded[index0 + twoRowsDown]++;
  14011. bitsDecoded[index0 + threeRowsDown]++;
  14012. continue; // next column
  14013. }
  14014. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14015. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14016. if (i1 !== 0) {
  14017. i = i0 + i1;
  14018. index += i1 * width;
  14019. }
  14020. sign = this.decodeSignBit(i, j, index);
  14021. coefficentsSign[index] = sign;
  14022. coefficentsMagnitude[index] = 1;
  14023. this.setNeighborsSignificance(i, j, index);
  14024. processingFlags[index] |= firstMagnitudeBitMask;
  14025. index = index0;
  14026. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14027. bitsDecoded[index]++;
  14028. }
  14029. i1++;
  14030. }
  14031. for (i = i0 + i1; i < iNext; i++, index += width) {
  14032. if (coefficentsMagnitude[index] ||
  14033. (processingFlags[index] & processedMask) !== 0) {
  14034. continue;
  14035. }
  14036. var contextLabel = labels[neighborsSignificance[index]];
  14037. var decision = decoder.readBit(contexts, contextLabel);
  14038. if (decision === 1) {
  14039. sign = this.decodeSignBit(i, j, index);
  14040. coefficentsSign[index] = sign;
  14041. coefficentsMagnitude[index] = 1;
  14042. this.setNeighborsSignificance(i, j, index);
  14043. processingFlags[index] |= firstMagnitudeBitMask;
  14044. }
  14045. bitsDecoded[index]++;
  14046. }
  14047. }
  14048. }
  14049. },
  14050. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14051. var decoder = this.decoder;
  14052. var contexts = this.contexts;
  14053. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14054. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14055. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14056. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14057. if (symbol !== 0xA) {
  14058. throw new Error('JPX Error: Invalid segmentation symbol');
  14059. }
  14060. }
  14061. };
  14062. return BitModel;
  14063. })();
  14064. // Section F, Discrete wavelet transformation
  14065. var Transform = (function TransformClosure() {
  14066. function Transform() {}
  14067. Transform.prototype.calculate =
  14068. function transformCalculate(subbands, u0, v0) {
  14069. var ll = subbands[0];
  14070. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14071. ll = this.iterate(ll, subbands[i], u0, v0);
  14072. }
  14073. return ll;
  14074. };
  14075. Transform.prototype.extend = function extend(buffer, offset, size) {
  14076. // Section F.3.7 extending... using max extension of 4
  14077. var i1 = offset - 1, j1 = offset + 1;
  14078. var i2 = offset + size - 2, j2 = offset + size;
  14079. buffer[i1--] = buffer[j1++];
  14080. buffer[j2++] = buffer[i2--];
  14081. buffer[i1--] = buffer[j1++];
  14082. buffer[j2++] = buffer[i2--];
  14083. buffer[i1--] = buffer[j1++];
  14084. buffer[j2++] = buffer[i2--];
  14085. buffer[i1] = buffer[j1];
  14086. buffer[j2] = buffer[i2];
  14087. };
  14088. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14089. u0, v0) {
  14090. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14091. var width = hl_lh_hh.width;
  14092. var height = hl_lh_hh.height;
  14093. var items = hl_lh_hh.items;
  14094. var i, j, k, l, u, v;
  14095. // Interleave LL according to Section F.3.3
  14096. for (k = 0, i = 0; i < llHeight; i++) {
  14097. l = i * 2 * width;
  14098. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14099. items[l] = llItems[k];
  14100. }
  14101. }
  14102. // The LL band is not needed anymore.
  14103. llItems = ll.items = null;
  14104. var bufferPadding = 4;
  14105. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14106. // Section F.3.4 HOR_SR
  14107. if (width === 1) {
  14108. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14109. if ((u0 & 1) !== 0) {
  14110. for (v = 0, k = 0; v < height; v++, k += width) {
  14111. items[k] *= 0.5;
  14112. }
  14113. }
  14114. } else {
  14115. for (v = 0, k = 0; v < height; v++, k += width) {
  14116. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14117. this.extend(rowBuffer, bufferPadding, width);
  14118. this.filter(rowBuffer, bufferPadding, width);
  14119. items.set(
  14120. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14121. k);
  14122. }
  14123. }
  14124. // Accesses to the items array can take long, because it may not fit into
  14125. // CPU cache and has to be fetched from main memory. Since subsequent
  14126. // accesses to the items array are not local when reading columns, we
  14127. // have a cache miss every time. To reduce cache misses, get up to
  14128. // 'numBuffers' items at a time and store them into the individual
  14129. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14130. var numBuffers = 16;
  14131. var colBuffers = [];
  14132. for (i = 0; i < numBuffers; i++) {
  14133. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14134. }
  14135. var b, currentBuffer = 0;
  14136. ll = bufferPadding + height;
  14137. // Section F.3.5 VER_SR
  14138. if (height === 1) {
  14139. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14140. if ((v0 & 1) !== 0) {
  14141. for (u = 0; u < width; u++) {
  14142. items[u] *= 0.5;
  14143. }
  14144. }
  14145. } else {
  14146. for (u = 0; u < width; u++) {
  14147. // if we ran out of buffers, copy several image columns at once
  14148. if (currentBuffer === 0) {
  14149. numBuffers = Math.min(width - u, numBuffers);
  14150. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14151. for (b = 0; b < numBuffers; b++) {
  14152. colBuffers[b][l] = items[k + b];
  14153. }
  14154. }
  14155. currentBuffer = numBuffers;
  14156. }
  14157. currentBuffer--;
  14158. var buffer = colBuffers[currentBuffer];
  14159. this.extend(buffer, bufferPadding, height);
  14160. this.filter(buffer, bufferPadding, height);
  14161. // If this is last buffer in this group of buffers, flush all buffers.
  14162. if (currentBuffer === 0) {
  14163. k = u - numBuffers + 1;
  14164. for (l = bufferPadding; l < ll; k += width, l++) {
  14165. for (b = 0; b < numBuffers; b++) {
  14166. items[k + b] = colBuffers[b][l];
  14167. }
  14168. }
  14169. }
  14170. }
  14171. }
  14172. return {
  14173. width: width,
  14174. height: height,
  14175. items: items
  14176. };
  14177. };
  14178. return Transform;
  14179. })();
  14180. // Section 3.8.2 Irreversible 9-7 filter
  14181. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14182. function IrreversibleTransform() {
  14183. Transform.call(this);
  14184. }
  14185. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14186. IrreversibleTransform.prototype.filter =
  14187. function irreversibleTransformFilter(x, offset, length) {
  14188. var len = length >> 1;
  14189. offset = offset | 0;
  14190. var j, n, current, next;
  14191. var alpha = -1.586134342059924;
  14192. var beta = -0.052980118572961;
  14193. var gamma = 0.882911075530934;
  14194. var delta = 0.443506852043971;
  14195. var K = 1.230174104914001;
  14196. var K_ = 1 / K;
  14197. // step 1 is combined with step 3
  14198. // step 2
  14199. j = offset - 3;
  14200. for (n = len + 4; n--; j += 2) {
  14201. x[j] *= K_;
  14202. }
  14203. // step 1 & 3
  14204. j = offset - 2;
  14205. current = delta * x[j -1];
  14206. for (n = len + 3; n--; j += 2) {
  14207. next = delta * x[j + 1];
  14208. x[j] = K * x[j] - current - next;
  14209. if (n--) {
  14210. j += 2;
  14211. current = delta * x[j + 1];
  14212. x[j] = K * x[j] - current - next;
  14213. } else {
  14214. break;
  14215. }
  14216. }
  14217. // step 4
  14218. j = offset - 1;
  14219. current = gamma * x[j - 1];
  14220. for (n = len + 2; n--; j += 2) {
  14221. next = gamma * x[j + 1];
  14222. x[j] -= current + next;
  14223. if (n--) {
  14224. j += 2;
  14225. current = gamma * x[j + 1];
  14226. x[j] -= current + next;
  14227. } else {
  14228. break;
  14229. }
  14230. }
  14231. // step 5
  14232. j = offset;
  14233. current = beta * x[j - 1];
  14234. for (n = len + 1; n--; j += 2) {
  14235. next = beta * x[j + 1];
  14236. x[j] -= current + next;
  14237. if (n--) {
  14238. j += 2;
  14239. current = beta * x[j + 1];
  14240. x[j] -= current + next;
  14241. } else {
  14242. break;
  14243. }
  14244. }
  14245. // step 6
  14246. if (len !== 0) {
  14247. j = offset + 1;
  14248. current = alpha * x[j - 1];
  14249. for (n = len; n--; j += 2) {
  14250. next = alpha * x[j + 1];
  14251. x[j] -= current + next;
  14252. if (n--) {
  14253. j += 2;
  14254. current = alpha * x[j + 1];
  14255. x[j] -= current + next;
  14256. } else {
  14257. break;
  14258. }
  14259. }
  14260. }
  14261. };
  14262. return IrreversibleTransform;
  14263. })();
  14264. // Section 3.8.1 Reversible 5-3 filter
  14265. var ReversibleTransform = (function ReversibleTransformClosure() {
  14266. function ReversibleTransform() {
  14267. Transform.call(this);
  14268. }
  14269. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14270. ReversibleTransform.prototype.filter =
  14271. function reversibleTransformFilter(x, offset, length) {
  14272. var len = length >> 1;
  14273. offset = offset | 0;
  14274. var j, n;
  14275. for (j = offset, n = len + 1; n--; j += 2) {
  14276. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14277. }
  14278. for (j = offset + 1, n = len; n--; j += 2) {
  14279. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14280. }
  14281. };
  14282. return ReversibleTransform;
  14283. })();
  14284. return JpxImage;
  14285. })();
  14286. exports.JpxImage = JpxImage;
  14287. }));
  14288. (function (root, factory) {
  14289. {
  14290. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14291. }
  14292. }(this, function (exports, sharedUtil) {
  14293. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14294. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14295. // Workaround for missing math precison in JS.
  14296. var MASK_HIGH = 0xffff0000;
  14297. var MASK_LOW = 0xffff;
  14298. function MurmurHash3_64 (seed) {
  14299. var SEED = 0xc3d2e1f0;
  14300. this.h1 = seed ? seed & 0xffffffff : SEED;
  14301. this.h2 = seed ? seed & 0xffffffff : SEED;
  14302. }
  14303. var alwaysUseUint32ArrayView = false;
  14304. // old webkits have issues with non-aligned arrays
  14305. try {
  14306. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14307. } catch (e) {
  14308. alwaysUseUint32ArrayView = true;
  14309. }
  14310. MurmurHash3_64.prototype = {
  14311. update: function MurmurHash3_64_update(input) {
  14312. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14313. var i;
  14314. if (typeof input === 'string') {
  14315. var data = new Uint8Array(input.length * 2);
  14316. var length = 0;
  14317. for (i = 0; i < input.length; i++) {
  14318. var code = input.charCodeAt(i);
  14319. if (code <= 0xff) {
  14320. data[length++] = code;
  14321. }
  14322. else {
  14323. data[length++] = code >>> 8;
  14324. data[length++] = code & 0xff;
  14325. }
  14326. }
  14327. } else if (input instanceof Uint8Array) {
  14328. data = input;
  14329. length = data.length;
  14330. } else if (typeof input === 'object' && ('length' in input)) {
  14331. // processing regular arrays as well, e.g. for IE9
  14332. data = input;
  14333. length = data.length;
  14334. useUint32ArrayView = true;
  14335. } else {
  14336. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14337. 'Input must be a string or array.');
  14338. }
  14339. var blockCounts = length >> 2;
  14340. var tailLength = length - blockCounts * 4;
  14341. // we don't care about endianness here
  14342. var dataUint32 = useUint32ArrayView ?
  14343. new Uint32ArrayView(data, blockCounts) :
  14344. new Uint32Array(data.buffer, 0, blockCounts);
  14345. var k1 = 0;
  14346. var k2 = 0;
  14347. var h1 = this.h1;
  14348. var h2 = this.h2;
  14349. var C1 = 0xcc9e2d51;
  14350. var C2 = 0x1b873593;
  14351. var C1_LOW = C1 & MASK_LOW;
  14352. var C2_LOW = C2 & MASK_LOW;
  14353. for (i = 0; i < blockCounts; i++) {
  14354. if (i & 1) {
  14355. k1 = dataUint32[i];
  14356. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14357. k1 = k1 << 15 | k1 >>> 17;
  14358. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14359. h1 ^= k1;
  14360. h1 = h1 << 13 | h1 >>> 19;
  14361. h1 = h1 * 5 + 0xe6546b64;
  14362. } else {
  14363. k2 = dataUint32[i];
  14364. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14365. k2 = k2 << 15 | k2 >>> 17;
  14366. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14367. h2 ^= k2;
  14368. h2 = h2 << 13 | h2 >>> 19;
  14369. h2 = h2 * 5 + 0xe6546b64;
  14370. }
  14371. }
  14372. k1 = 0;
  14373. switch (tailLength) {
  14374. case 3:
  14375. k1 ^= data[blockCounts * 4 + 2] << 16;
  14376. /* falls through */
  14377. case 2:
  14378. k1 ^= data[blockCounts * 4 + 1] << 8;
  14379. /* falls through */
  14380. case 1:
  14381. k1 ^= data[blockCounts * 4];
  14382. /* falls through */
  14383. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14384. k1 = k1 << 15 | k1 >>> 17;
  14385. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14386. if (blockCounts & 1) {
  14387. h1 ^= k1;
  14388. } else {
  14389. h2 ^= k1;
  14390. }
  14391. }
  14392. this.h1 = h1;
  14393. this.h2 = h2;
  14394. return this;
  14395. },
  14396. hexdigest: function MurmurHash3_64_hexdigest () {
  14397. var h1 = this.h1;
  14398. var h2 = this.h2;
  14399. h1 ^= h2 >>> 1;
  14400. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  14401. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  14402. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  14403. h1 ^= h2 >>> 1;
  14404. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  14405. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  14406. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  14407. h1 ^= h2 >>> 1;
  14408. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  14409. var hex = (arr[i] >>> 0).toString(16);
  14410. while (hex.length < 8) {
  14411. hex = '0' + hex;
  14412. }
  14413. str += hex;
  14414. }
  14415. return str;
  14416. }
  14417. };
  14418. return MurmurHash3_64;
  14419. })();
  14420. exports.MurmurHash3_64 = MurmurHash3_64;
  14421. }));
  14422. (function (root, factory) {
  14423. {
  14424. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  14425. }
  14426. }(this, function (exports, sharedUtil) {
  14427. var isArray = sharedUtil.isArray;
  14428. var Name = (function NameClosure() {
  14429. function Name(name) {
  14430. this.name = name;
  14431. }
  14432. Name.prototype = {};
  14433. var nameCache = {};
  14434. Name.get = function Name_get(name) {
  14435. var nameValue = nameCache[name];
  14436. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  14437. };
  14438. return Name;
  14439. })();
  14440. var Cmd = (function CmdClosure() {
  14441. function Cmd(cmd) {
  14442. this.cmd = cmd;
  14443. }
  14444. Cmd.prototype = {};
  14445. var cmdCache = {};
  14446. Cmd.get = function Cmd_get(cmd) {
  14447. var cmdValue = cmdCache[cmd];
  14448. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  14449. };
  14450. return Cmd;
  14451. })();
  14452. var Dict = (function DictClosure() {
  14453. var nonSerializable = function nonSerializableClosure() {
  14454. return nonSerializable; // creating closure on some variable
  14455. };
  14456. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  14457. 'Background': true,
  14458. 'ExtGState': true,
  14459. 'Halftone': true,
  14460. 'Layout': true,
  14461. 'Mask': true,
  14462. 'Pagination': true,
  14463. 'Printing': true
  14464. };
  14465. function isRecursionAllowedFor(dict) {
  14466. if (!isName(dict.Type)) {
  14467. return true;
  14468. }
  14469. var dictType = dict.Type.name;
  14470. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  14471. }
  14472. // xref is optional
  14473. function Dict(xref) {
  14474. // Map should only be used internally, use functions below to access.
  14475. this.map = Object.create(null);
  14476. this.xref = xref;
  14477. this.objId = null;
  14478. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  14479. }
  14480. Dict.prototype = {
  14481. assignXref: function Dict_assignXref(newXref) {
  14482. this.xref = newXref;
  14483. },
  14484. // automatically dereferences Ref objects
  14485. get: function Dict_get(key1, key2, key3) {
  14486. var value;
  14487. var xref = this.xref;
  14488. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14489. typeof key2 === 'undefined') {
  14490. return xref ? xref.fetchIfRef(value) : value;
  14491. }
  14492. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14493. typeof key3 === 'undefined') {
  14494. return xref ? xref.fetchIfRef(value) : value;
  14495. }
  14496. value = this.map[key3] || null;
  14497. return xref ? xref.fetchIfRef(value) : value;
  14498. },
  14499. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  14500. getAsync: function Dict_getAsync(key1, key2, key3) {
  14501. var value;
  14502. var xref = this.xref;
  14503. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14504. typeof key2 === 'undefined') {
  14505. if (xref) {
  14506. return xref.fetchIfRefAsync(value);
  14507. }
  14508. return Promise.resolve(value);
  14509. }
  14510. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14511. typeof key3 === 'undefined') {
  14512. if (xref) {
  14513. return xref.fetchIfRefAsync(value);
  14514. }
  14515. return Promise.resolve(value);
  14516. }
  14517. value = this.map[key3] || null;
  14518. if (xref) {
  14519. return xref.fetchIfRefAsync(value);
  14520. }
  14521. return Promise.resolve(value);
  14522. },
  14523. // Same as get(), but dereferences all elements if the result is an Array.
  14524. getArray: function Dict_getArray(key1, key2, key3) {
  14525. var value = this.get(key1, key2, key3);
  14526. var xref = this.xref;
  14527. if (!isArray(value) || !xref) {
  14528. return value;
  14529. }
  14530. value = value.slice(); // Ensure that we don't modify the Dict data.
  14531. for (var i = 0, ii = value.length; i < ii; i++) {
  14532. if (!isRef(value[i])) {
  14533. continue;
  14534. }
  14535. value[i] = xref.fetch(value[i]);
  14536. }
  14537. return value;
  14538. },
  14539. // no dereferencing
  14540. getRaw: function Dict_getRaw(key) {
  14541. return this.map[key];
  14542. },
  14543. // creates new map and dereferences all Refs
  14544. getAll: function Dict_getAll() {
  14545. var all = Object.create(null);
  14546. var queue = null;
  14547. var key, obj;
  14548. for (key in this.map) {
  14549. obj = this.get(key);
  14550. if (obj instanceof Dict) {
  14551. if (isRecursionAllowedFor(obj)) {
  14552. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  14553. } else {
  14554. all[key] = this.getRaw(key);
  14555. }
  14556. } else {
  14557. all[key] = obj;
  14558. }
  14559. }
  14560. if (!queue) {
  14561. return all;
  14562. }
  14563. // trying to take cyclic references into the account
  14564. var processed = Object.create(null);
  14565. while (queue.length > 0) {
  14566. var item = queue.shift();
  14567. var itemObj = item.obj;
  14568. var objId = itemObj.objId;
  14569. if (objId && objId in processed) {
  14570. item.target[item.key] = processed[objId];
  14571. continue;
  14572. }
  14573. var dereferenced = Object.create(null);
  14574. for (key in itemObj.map) {
  14575. obj = itemObj.get(key);
  14576. if (obj instanceof Dict) {
  14577. if (isRecursionAllowedFor(obj)) {
  14578. queue.push({target: dereferenced, key: key, obj: obj});
  14579. } else {
  14580. dereferenced[key] = itemObj.getRaw(key);
  14581. }
  14582. } else {
  14583. dereferenced[key] = obj;
  14584. }
  14585. }
  14586. if (objId) {
  14587. processed[objId] = dereferenced;
  14588. }
  14589. item.target[item.key] = dereferenced;
  14590. }
  14591. return all;
  14592. },
  14593. getKeys: function Dict_getKeys() {
  14594. return Object.keys(this.map);
  14595. },
  14596. set: function Dict_set(key, value) {
  14597. this.map[key] = value;
  14598. },
  14599. has: function Dict_has(key) {
  14600. return key in this.map;
  14601. },
  14602. forEach: function Dict_forEach(callback) {
  14603. for (var key in this.map) {
  14604. callback(key, this.get(key));
  14605. }
  14606. }
  14607. };
  14608. Dict.empty = new Dict(null);
  14609. Dict.merge = function Dict_merge(xref, dictArray) {
  14610. var mergedDict = new Dict(xref);
  14611. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  14612. var dict = dictArray[i];
  14613. if (!isDict(dict)) {
  14614. continue;
  14615. }
  14616. for (var keyName in dict.map) {
  14617. if (mergedDict.map[keyName]) {
  14618. continue;
  14619. }
  14620. mergedDict.map[keyName] = dict.map[keyName];
  14621. }
  14622. }
  14623. return mergedDict;
  14624. };
  14625. return Dict;
  14626. })();
  14627. var Ref = (function RefClosure() {
  14628. function Ref(num, gen) {
  14629. this.num = num;
  14630. this.gen = gen;
  14631. }
  14632. Ref.prototype = {
  14633. toString: function Ref_toString() {
  14634. // This function is hot, so we make the string as compact as possible.
  14635. // |this.gen| is almost always zero, so we treat that case specially.
  14636. var str = this.num + 'R';
  14637. if (this.gen !== 0) {
  14638. str += this.gen;
  14639. }
  14640. return str;
  14641. }
  14642. };
  14643. return Ref;
  14644. })();
  14645. // The reference is identified by number and generation.
  14646. // This structure stores only one instance of the reference.
  14647. var RefSet = (function RefSetClosure() {
  14648. function RefSet() {
  14649. this.dict = {};
  14650. }
  14651. RefSet.prototype = {
  14652. has: function RefSet_has(ref) {
  14653. return ref.toString() in this.dict;
  14654. },
  14655. put: function RefSet_put(ref) {
  14656. this.dict[ref.toString()] = true;
  14657. },
  14658. remove: function RefSet_remove(ref) {
  14659. delete this.dict[ref.toString()];
  14660. }
  14661. };
  14662. return RefSet;
  14663. })();
  14664. var RefSetCache = (function RefSetCacheClosure() {
  14665. function RefSetCache() {
  14666. this.dict = Object.create(null);
  14667. }
  14668. RefSetCache.prototype = {
  14669. get: function RefSetCache_get(ref) {
  14670. return this.dict[ref.toString()];
  14671. },
  14672. has: function RefSetCache_has(ref) {
  14673. return ref.toString() in this.dict;
  14674. },
  14675. put: function RefSetCache_put(ref, obj) {
  14676. this.dict[ref.toString()] = obj;
  14677. },
  14678. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  14679. this.dict[ref.toString()] = this.get(aliasRef);
  14680. },
  14681. forEach: function RefSetCache_forEach(fn, thisArg) {
  14682. for (var i in this.dict) {
  14683. fn.call(thisArg, this.dict[i]);
  14684. }
  14685. },
  14686. clear: function RefSetCache_clear() {
  14687. this.dict = Object.create(null);
  14688. }
  14689. };
  14690. return RefSetCache;
  14691. })();
  14692. function isName(v) {
  14693. return v instanceof Name;
  14694. }
  14695. function isCmd(v, cmd) {
  14696. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  14697. }
  14698. function isDict(v, type) {
  14699. if (!(v instanceof Dict)) {
  14700. return false;
  14701. }
  14702. if (!type) {
  14703. return true;
  14704. }
  14705. var dictType = v.get('Type');
  14706. return isName(dictType) && dictType.name === type;
  14707. }
  14708. function isRef(v) {
  14709. return v instanceof Ref;
  14710. }
  14711. function isStream(v) {
  14712. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  14713. }
  14714. exports.Cmd = Cmd;
  14715. exports.Dict = Dict;
  14716. exports.Name = Name;
  14717. exports.Ref = Ref;
  14718. exports.RefSet = RefSet;
  14719. exports.RefSetCache = RefSetCache;
  14720. exports.isCmd = isCmd;
  14721. exports.isDict = isDict;
  14722. exports.isName = isName;
  14723. exports.isRef = isRef;
  14724. exports.isStream = isStream;
  14725. }));
  14726. (function (root, factory) {
  14727. {
  14728. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  14729. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  14730. root.pdfjsCoreJpx);
  14731. }
  14732. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  14733. coreJpx) {
  14734. var Util = sharedUtil.Util;
  14735. var error = sharedUtil.error;
  14736. var info = sharedUtil.info;
  14737. var isArray = sharedUtil.isArray;
  14738. var shadow = sharedUtil.shadow;
  14739. var warn = sharedUtil.warn;
  14740. var Dict = corePrimitives.Dict;
  14741. var Jbig2Image = coreJbig2.Jbig2Image;
  14742. var JpegImage = coreJpg.JpegImage;
  14743. var JpxImage = coreJpx.JpxImage;
  14744. var coreParser; // see _setCoreParser below
  14745. var EOF; // = coreParser.EOF;
  14746. var Lexer; // = coreParser.Lexer;
  14747. var coreColorSpace; // see _setCoreColorSpace below
  14748. var ColorSpace; // = coreColorSpace.ColorSpace;
  14749. var Stream = (function StreamClosure() {
  14750. function Stream(arrayBuffer, start, length, dict) {
  14751. this.bytes = (arrayBuffer instanceof Uint8Array ?
  14752. arrayBuffer : new Uint8Array(arrayBuffer));
  14753. this.start = start || 0;
  14754. this.pos = this.start;
  14755. this.end = (start + length) || this.bytes.length;
  14756. this.dict = dict;
  14757. }
  14758. // required methods for a stream. if a particular stream does not
  14759. // implement these, an error should be thrown
  14760. Stream.prototype = {
  14761. get length() {
  14762. return this.end - this.start;
  14763. },
  14764. get isEmpty() {
  14765. return this.length === 0;
  14766. },
  14767. getByte: function Stream_getByte() {
  14768. if (this.pos >= this.end) {
  14769. return -1;
  14770. }
  14771. return this.bytes[this.pos++];
  14772. },
  14773. getUint16: function Stream_getUint16() {
  14774. var b0 = this.getByte();
  14775. var b1 = this.getByte();
  14776. if (b0 === -1 || b1 === -1) {
  14777. return -1;
  14778. }
  14779. return (b0 << 8) + b1;
  14780. },
  14781. getInt32: function Stream_getInt32() {
  14782. var b0 = this.getByte();
  14783. var b1 = this.getByte();
  14784. var b2 = this.getByte();
  14785. var b3 = this.getByte();
  14786. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14787. },
  14788. // returns subarray of original buffer
  14789. // should only be read
  14790. getBytes: function Stream_getBytes(length) {
  14791. var bytes = this.bytes;
  14792. var pos = this.pos;
  14793. var strEnd = this.end;
  14794. if (!length) {
  14795. return bytes.subarray(pos, strEnd);
  14796. }
  14797. var end = pos + length;
  14798. if (end > strEnd) {
  14799. end = strEnd;
  14800. }
  14801. this.pos = end;
  14802. return bytes.subarray(pos, end);
  14803. },
  14804. peekByte: function Stream_peekByte() {
  14805. var peekedByte = this.getByte();
  14806. this.pos--;
  14807. return peekedByte;
  14808. },
  14809. peekBytes: function Stream_peekBytes(length) {
  14810. var bytes = this.getBytes(length);
  14811. this.pos -= bytes.length;
  14812. return bytes;
  14813. },
  14814. skip: function Stream_skip(n) {
  14815. if (!n) {
  14816. n = 1;
  14817. }
  14818. this.pos += n;
  14819. },
  14820. reset: function Stream_reset() {
  14821. this.pos = this.start;
  14822. },
  14823. moveStart: function Stream_moveStart() {
  14824. this.start = this.pos;
  14825. },
  14826. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  14827. return new Stream(this.bytes.buffer, start, length, dict);
  14828. },
  14829. isStream: true
  14830. };
  14831. return Stream;
  14832. })();
  14833. var StringStream = (function StringStreamClosure() {
  14834. function StringStream(str) {
  14835. var length = str.length;
  14836. var bytes = new Uint8Array(length);
  14837. for (var n = 0; n < length; ++n) {
  14838. bytes[n] = str.charCodeAt(n);
  14839. }
  14840. Stream.call(this, bytes);
  14841. }
  14842. StringStream.prototype = Stream.prototype;
  14843. return StringStream;
  14844. })();
  14845. // super class for the decoding streams
  14846. var DecodeStream = (function DecodeStreamClosure() {
  14847. // Lots of DecodeStreams are created whose buffers are never used. For these
  14848. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  14849. // having special cases that would be required if we used |null| for an empty
  14850. // buffer.
  14851. var emptyBuffer = new Uint8Array(0);
  14852. function DecodeStream(maybeMinBufferLength) {
  14853. this.pos = 0;
  14854. this.bufferLength = 0;
  14855. this.eof = false;
  14856. this.buffer = emptyBuffer;
  14857. this.minBufferLength = 512;
  14858. if (maybeMinBufferLength) {
  14859. // Compute the first power of two that is as big as maybeMinBufferLength.
  14860. while (this.minBufferLength < maybeMinBufferLength) {
  14861. this.minBufferLength *= 2;
  14862. }
  14863. }
  14864. }
  14865. DecodeStream.prototype = {
  14866. get isEmpty() {
  14867. while (!this.eof && this.bufferLength === 0) {
  14868. this.readBlock();
  14869. }
  14870. return this.bufferLength === 0;
  14871. },
  14872. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  14873. var buffer = this.buffer;
  14874. if (requested <= buffer.byteLength) {
  14875. return buffer;
  14876. }
  14877. var size = this.minBufferLength;
  14878. while (size < requested) {
  14879. size *= 2;
  14880. }
  14881. var buffer2 = new Uint8Array(size);
  14882. buffer2.set(buffer);
  14883. return (this.buffer = buffer2);
  14884. },
  14885. getByte: function DecodeStream_getByte() {
  14886. var pos = this.pos;
  14887. while (this.bufferLength <= pos) {
  14888. if (this.eof) {
  14889. return -1;
  14890. }
  14891. this.readBlock();
  14892. }
  14893. return this.buffer[this.pos++];
  14894. },
  14895. getUint16: function DecodeStream_getUint16() {
  14896. var b0 = this.getByte();
  14897. var b1 = this.getByte();
  14898. if (b0 === -1 || b1 === -1) {
  14899. return -1;
  14900. }
  14901. return (b0 << 8) + b1;
  14902. },
  14903. getInt32: function DecodeStream_getInt32() {
  14904. var b0 = this.getByte();
  14905. var b1 = this.getByte();
  14906. var b2 = this.getByte();
  14907. var b3 = this.getByte();
  14908. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14909. },
  14910. getBytes: function DecodeStream_getBytes(length) {
  14911. var end, pos = this.pos;
  14912. if (length) {
  14913. this.ensureBuffer(pos + length);
  14914. end = pos + length;
  14915. while (!this.eof && this.bufferLength < end) {
  14916. this.readBlock();
  14917. }
  14918. var bufEnd = this.bufferLength;
  14919. if (end > bufEnd) {
  14920. end = bufEnd;
  14921. }
  14922. } else {
  14923. while (!this.eof) {
  14924. this.readBlock();
  14925. }
  14926. end = this.bufferLength;
  14927. }
  14928. this.pos = end;
  14929. return this.buffer.subarray(pos, end);
  14930. },
  14931. peekByte: function DecodeStream_peekByte() {
  14932. var peekedByte = this.getByte();
  14933. this.pos--;
  14934. return peekedByte;
  14935. },
  14936. peekBytes: function DecodeStream_peekBytes(length) {
  14937. var bytes = this.getBytes(length);
  14938. this.pos -= bytes.length;
  14939. return bytes;
  14940. },
  14941. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  14942. var end = start + length;
  14943. while (this.bufferLength <= end && !this.eof) {
  14944. this.readBlock();
  14945. }
  14946. return new Stream(this.buffer, start, length, dict);
  14947. },
  14948. skip: function DecodeStream_skip(n) {
  14949. if (!n) {
  14950. n = 1;
  14951. }
  14952. this.pos += n;
  14953. },
  14954. reset: function DecodeStream_reset() {
  14955. this.pos = 0;
  14956. },
  14957. getBaseStreams: function DecodeStream_getBaseStreams() {
  14958. if (this.str && this.str.getBaseStreams) {
  14959. return this.str.getBaseStreams();
  14960. }
  14961. return [];
  14962. }
  14963. };
  14964. return DecodeStream;
  14965. })();
  14966. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  14967. function StreamsSequenceStream(streams) {
  14968. this.streams = streams;
  14969. DecodeStream.call(this, /* maybeLength = */ null);
  14970. }
  14971. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  14972. StreamsSequenceStream.prototype.readBlock =
  14973. function streamSequenceStreamReadBlock() {
  14974. var streams = this.streams;
  14975. if (streams.length === 0) {
  14976. this.eof = true;
  14977. return;
  14978. }
  14979. var stream = streams.shift();
  14980. var chunk = stream.getBytes();
  14981. var bufferLength = this.bufferLength;
  14982. var newLength = bufferLength + chunk.length;
  14983. var buffer = this.ensureBuffer(newLength);
  14984. buffer.set(chunk, bufferLength);
  14985. this.bufferLength = newLength;
  14986. };
  14987. StreamsSequenceStream.prototype.getBaseStreams =
  14988. function StreamsSequenceStream_getBaseStreams() {
  14989. var baseStreams = [];
  14990. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  14991. var stream = this.streams[i];
  14992. if (stream.getBaseStreams) {
  14993. Util.appendToArray(baseStreams, stream.getBaseStreams());
  14994. }
  14995. }
  14996. return baseStreams;
  14997. };
  14998. return StreamsSequenceStream;
  14999. })();
  15000. var FlateStream = (function FlateStreamClosure() {
  15001. var codeLenCodeMap = new Int32Array([
  15002. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  15003. ]);
  15004. var lengthDecode = new Int32Array([
  15005. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  15006. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  15007. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  15008. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  15009. ]);
  15010. var distDecode = new Int32Array([
  15011. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  15012. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  15013. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  15014. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  15015. ]);
  15016. var fixedLitCodeTab = [new Int32Array([
  15017. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  15018. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  15019. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  15020. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  15021. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  15022. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  15023. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  15024. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  15025. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  15026. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  15027. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  15028. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  15029. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  15030. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  15031. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  15032. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  15033. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  15034. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  15035. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  15036. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  15037. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  15038. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  15039. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  15040. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  15041. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  15042. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  15043. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  15044. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  15045. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  15046. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  15047. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  15048. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  15049. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  15050. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  15051. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  15052. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  15053. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  15054. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  15055. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  15056. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  15057. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  15058. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  15059. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  15060. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  15061. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  15062. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  15063. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  15064. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  15065. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  15066. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  15067. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  15068. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  15069. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  15070. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  15071. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  15072. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  15073. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  15074. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  15075. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  15076. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  15077. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  15078. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  15079. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  15080. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  15081. ]), 9];
  15082. var fixedDistCodeTab = [new Int32Array([
  15083. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  15084. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  15085. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  15086. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  15087. ]), 5];
  15088. function FlateStream(str, maybeLength) {
  15089. this.str = str;
  15090. this.dict = str.dict;
  15091. var cmf = str.getByte();
  15092. var flg = str.getByte();
  15093. if (cmf === -1 || flg === -1) {
  15094. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  15095. }
  15096. if ((cmf & 0x0f) !== 0x08) {
  15097. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  15098. }
  15099. if ((((cmf << 8) + flg) % 31) !== 0) {
  15100. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  15101. }
  15102. if (flg & 0x20) {
  15103. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  15104. }
  15105. this.codeSize = 0;
  15106. this.codeBuf = 0;
  15107. DecodeStream.call(this, maybeLength);
  15108. }
  15109. FlateStream.prototype = Object.create(DecodeStream.prototype);
  15110. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  15111. var str = this.str;
  15112. var codeSize = this.codeSize;
  15113. var codeBuf = this.codeBuf;
  15114. var b;
  15115. while (codeSize < bits) {
  15116. if ((b = str.getByte()) === -1) {
  15117. error('Bad encoding in flate stream');
  15118. }
  15119. codeBuf |= b << codeSize;
  15120. codeSize += 8;
  15121. }
  15122. b = codeBuf & ((1 << bits) - 1);
  15123. this.codeBuf = codeBuf >> bits;
  15124. this.codeSize = codeSize -= bits;
  15125. return b;
  15126. };
  15127. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  15128. var str = this.str;
  15129. var codes = table[0];
  15130. var maxLen = table[1];
  15131. var codeSize = this.codeSize;
  15132. var codeBuf = this.codeBuf;
  15133. var b;
  15134. while (codeSize < maxLen) {
  15135. if ((b = str.getByte()) === -1) {
  15136. // premature end of stream. code might however still be valid.
  15137. // codeSize < codeLen check below guards against incomplete codeVal.
  15138. break;
  15139. }
  15140. codeBuf |= (b << codeSize);
  15141. codeSize += 8;
  15142. }
  15143. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  15144. var codeLen = code >> 16;
  15145. var codeVal = code & 0xffff;
  15146. if (codeLen < 1 || codeSize < codeLen) {
  15147. error('Bad encoding in flate stream');
  15148. }
  15149. this.codeBuf = (codeBuf >> codeLen);
  15150. this.codeSize = (codeSize - codeLen);
  15151. return codeVal;
  15152. };
  15153. FlateStream.prototype.generateHuffmanTable =
  15154. function flateStreamGenerateHuffmanTable(lengths) {
  15155. var n = lengths.length;
  15156. // find max code length
  15157. var maxLen = 0;
  15158. var i;
  15159. for (i = 0; i < n; ++i) {
  15160. if (lengths[i] > maxLen) {
  15161. maxLen = lengths[i];
  15162. }
  15163. }
  15164. // build the table
  15165. var size = 1 << maxLen;
  15166. var codes = new Int32Array(size);
  15167. for (var len = 1, code = 0, skip = 2;
  15168. len <= maxLen;
  15169. ++len, code <<= 1, skip <<= 1) {
  15170. for (var val = 0; val < n; ++val) {
  15171. if (lengths[val] === len) {
  15172. // bit-reverse the code
  15173. var code2 = 0;
  15174. var t = code;
  15175. for (i = 0; i < len; ++i) {
  15176. code2 = (code2 << 1) | (t & 1);
  15177. t >>= 1;
  15178. }
  15179. // fill the table entries
  15180. for (i = code2; i < size; i += skip) {
  15181. codes[i] = (len << 16) | val;
  15182. }
  15183. ++code;
  15184. }
  15185. }
  15186. }
  15187. return [codes, maxLen];
  15188. };
  15189. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  15190. var buffer, len;
  15191. var str = this.str;
  15192. // read block header
  15193. var hdr = this.getBits(3);
  15194. if (hdr & 1) {
  15195. this.eof = true;
  15196. }
  15197. hdr >>= 1;
  15198. if (hdr === 0) { // uncompressed block
  15199. var b;
  15200. if ((b = str.getByte()) === -1) {
  15201. error('Bad block header in flate stream');
  15202. }
  15203. var blockLen = b;
  15204. if ((b = str.getByte()) === -1) {
  15205. error('Bad block header in flate stream');
  15206. }
  15207. blockLen |= (b << 8);
  15208. if ((b = str.getByte()) === -1) {
  15209. error('Bad block header in flate stream');
  15210. }
  15211. var check = b;
  15212. if ((b = str.getByte()) === -1) {
  15213. error('Bad block header in flate stream');
  15214. }
  15215. check |= (b << 8);
  15216. if (check !== (~blockLen & 0xffff) &&
  15217. (blockLen !== 0 || check !== 0)) {
  15218. // Ignoring error for bad "empty" block (see issue 1277)
  15219. error('Bad uncompressed block length in flate stream');
  15220. }
  15221. this.codeBuf = 0;
  15222. this.codeSize = 0;
  15223. var bufferLength = this.bufferLength;
  15224. buffer = this.ensureBuffer(bufferLength + blockLen);
  15225. var end = bufferLength + blockLen;
  15226. this.bufferLength = end;
  15227. if (blockLen === 0) {
  15228. if (str.peekByte() === -1) {
  15229. this.eof = true;
  15230. }
  15231. } else {
  15232. for (var n = bufferLength; n < end; ++n) {
  15233. if ((b = str.getByte()) === -1) {
  15234. this.eof = true;
  15235. break;
  15236. }
  15237. buffer[n] = b;
  15238. }
  15239. }
  15240. return;
  15241. }
  15242. var litCodeTable;
  15243. var distCodeTable;
  15244. if (hdr === 1) { // compressed block, fixed codes
  15245. litCodeTable = fixedLitCodeTab;
  15246. distCodeTable = fixedDistCodeTab;
  15247. } else if (hdr === 2) { // compressed block, dynamic codes
  15248. var numLitCodes = this.getBits(5) + 257;
  15249. var numDistCodes = this.getBits(5) + 1;
  15250. var numCodeLenCodes = this.getBits(4) + 4;
  15251. // build the code lengths code table
  15252. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  15253. var i;
  15254. for (i = 0; i < numCodeLenCodes; ++i) {
  15255. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  15256. }
  15257. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  15258. // build the literal and distance code tables
  15259. len = 0;
  15260. i = 0;
  15261. var codes = numLitCodes + numDistCodes;
  15262. var codeLengths = new Uint8Array(codes);
  15263. var bitsLength, bitsOffset, what;
  15264. while (i < codes) {
  15265. var code = this.getCode(codeLenCodeTab);
  15266. if (code === 16) {
  15267. bitsLength = 2; bitsOffset = 3; what = len;
  15268. } else if (code === 17) {
  15269. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  15270. } else if (code === 18) {
  15271. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  15272. } else {
  15273. codeLengths[i++] = len = code;
  15274. continue;
  15275. }
  15276. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  15277. while (repeatLength-- > 0) {
  15278. codeLengths[i++] = what;
  15279. }
  15280. }
  15281. litCodeTable =
  15282. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  15283. distCodeTable =
  15284. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  15285. } else {
  15286. error('Unknown block type in flate stream');
  15287. }
  15288. buffer = this.buffer;
  15289. var limit = buffer ? buffer.length : 0;
  15290. var pos = this.bufferLength;
  15291. while (true) {
  15292. var code1 = this.getCode(litCodeTable);
  15293. if (code1 < 256) {
  15294. if (pos + 1 >= limit) {
  15295. buffer = this.ensureBuffer(pos + 1);
  15296. limit = buffer.length;
  15297. }
  15298. buffer[pos++] = code1;
  15299. continue;
  15300. }
  15301. if (code1 === 256) {
  15302. this.bufferLength = pos;
  15303. return;
  15304. }
  15305. code1 -= 257;
  15306. code1 = lengthDecode[code1];
  15307. var code2 = code1 >> 16;
  15308. if (code2 > 0) {
  15309. code2 = this.getBits(code2);
  15310. }
  15311. len = (code1 & 0xffff) + code2;
  15312. code1 = this.getCode(distCodeTable);
  15313. code1 = distDecode[code1];
  15314. code2 = code1 >> 16;
  15315. if (code2 > 0) {
  15316. code2 = this.getBits(code2);
  15317. }
  15318. var dist = (code1 & 0xffff) + code2;
  15319. if (pos + len >= limit) {
  15320. buffer = this.ensureBuffer(pos + len);
  15321. limit = buffer.length;
  15322. }
  15323. for (var k = 0; k < len; ++k, ++pos) {
  15324. buffer[pos] = buffer[pos - dist];
  15325. }
  15326. }
  15327. };
  15328. return FlateStream;
  15329. })();
  15330. var PredictorStream = (function PredictorStreamClosure() {
  15331. function PredictorStream(str, maybeLength, params) {
  15332. var predictor = this.predictor = params.get('Predictor') || 1;
  15333. if (predictor <= 1) {
  15334. return str; // no prediction
  15335. }
  15336. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  15337. error('Unsupported predictor: ' + predictor);
  15338. }
  15339. if (predictor === 2) {
  15340. this.readBlock = this.readBlockTiff;
  15341. } else {
  15342. this.readBlock = this.readBlockPng;
  15343. }
  15344. this.str = str;
  15345. this.dict = str.dict;
  15346. var colors = this.colors = params.get('Colors') || 1;
  15347. var bits = this.bits = params.get('BitsPerComponent') || 8;
  15348. var columns = this.columns = params.get('Columns') || 1;
  15349. this.pixBytes = (colors * bits + 7) >> 3;
  15350. this.rowBytes = (columns * colors * bits + 7) >> 3;
  15351. DecodeStream.call(this, maybeLength);
  15352. return this;
  15353. }
  15354. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  15355. PredictorStream.prototype.readBlockTiff =
  15356. function predictorStreamReadBlockTiff() {
  15357. var rowBytes = this.rowBytes;
  15358. var bufferLength = this.bufferLength;
  15359. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15360. var bits = this.bits;
  15361. var colors = this.colors;
  15362. var rawBytes = this.str.getBytes(rowBytes);
  15363. this.eof = !rawBytes.length;
  15364. if (this.eof) {
  15365. return;
  15366. }
  15367. var inbuf = 0, outbuf = 0;
  15368. var inbits = 0, outbits = 0;
  15369. var pos = bufferLength;
  15370. var i;
  15371. if (bits === 1) {
  15372. for (i = 0; i < rowBytes; ++i) {
  15373. var c = rawBytes[i];
  15374. inbuf = (inbuf << 8) | c;
  15375. // bitwise addition is exclusive or
  15376. // first shift inbuf and then add
  15377. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  15378. // truncate inbuf (assumes colors < 16)
  15379. inbuf &= 0xFFFF;
  15380. }
  15381. } else if (bits === 8) {
  15382. for (i = 0; i < colors; ++i) {
  15383. buffer[pos++] = rawBytes[i];
  15384. }
  15385. for (; i < rowBytes; ++i) {
  15386. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  15387. pos++;
  15388. }
  15389. } else {
  15390. var compArray = new Uint8Array(colors + 1);
  15391. var bitMask = (1 << bits) - 1;
  15392. var j = 0, k = bufferLength;
  15393. var columns = this.columns;
  15394. for (i = 0; i < columns; ++i) {
  15395. for (var kk = 0; kk < colors; ++kk) {
  15396. if (inbits < bits) {
  15397. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  15398. inbits += 8;
  15399. }
  15400. compArray[kk] = (compArray[kk] +
  15401. (inbuf >> (inbits - bits))) & bitMask;
  15402. inbits -= bits;
  15403. outbuf = (outbuf << bits) | compArray[kk];
  15404. outbits += bits;
  15405. if (outbits >= 8) {
  15406. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  15407. outbits -= 8;
  15408. }
  15409. }
  15410. }
  15411. if (outbits > 0) {
  15412. buffer[k++] = (outbuf << (8 - outbits)) +
  15413. (inbuf & ((1 << (8 - outbits)) - 1));
  15414. }
  15415. }
  15416. this.bufferLength += rowBytes;
  15417. };
  15418. PredictorStream.prototype.readBlockPng =
  15419. function predictorStreamReadBlockPng() {
  15420. var rowBytes = this.rowBytes;
  15421. var pixBytes = this.pixBytes;
  15422. var predictor = this.str.getByte();
  15423. var rawBytes = this.str.getBytes(rowBytes);
  15424. this.eof = !rawBytes.length;
  15425. if (this.eof) {
  15426. return;
  15427. }
  15428. var bufferLength = this.bufferLength;
  15429. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15430. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  15431. if (prevRow.length === 0) {
  15432. prevRow = new Uint8Array(rowBytes);
  15433. }
  15434. var i, j = bufferLength, up, c;
  15435. switch (predictor) {
  15436. case 0:
  15437. for (i = 0; i < rowBytes; ++i) {
  15438. buffer[j++] = rawBytes[i];
  15439. }
  15440. break;
  15441. case 1:
  15442. for (i = 0; i < pixBytes; ++i) {
  15443. buffer[j++] = rawBytes[i];
  15444. }
  15445. for (; i < rowBytes; ++i) {
  15446. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  15447. j++;
  15448. }
  15449. break;
  15450. case 2:
  15451. for (i = 0; i < rowBytes; ++i) {
  15452. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  15453. }
  15454. break;
  15455. case 3:
  15456. for (i = 0; i < pixBytes; ++i) {
  15457. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  15458. }
  15459. for (; i < rowBytes; ++i) {
  15460. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  15461. rawBytes[i]) & 0xFF;
  15462. j++;
  15463. }
  15464. break;
  15465. case 4:
  15466. // we need to save the up left pixels values. the simplest way
  15467. // is to create a new buffer
  15468. for (i = 0; i < pixBytes; ++i) {
  15469. up = prevRow[i];
  15470. c = rawBytes[i];
  15471. buffer[j++] = up + c;
  15472. }
  15473. for (; i < rowBytes; ++i) {
  15474. up = prevRow[i];
  15475. var upLeft = prevRow[i - pixBytes];
  15476. var left = buffer[j - pixBytes];
  15477. var p = left + up - upLeft;
  15478. var pa = p - left;
  15479. if (pa < 0) {
  15480. pa = -pa;
  15481. }
  15482. var pb = p - up;
  15483. if (pb < 0) {
  15484. pb = -pb;
  15485. }
  15486. var pc = p - upLeft;
  15487. if (pc < 0) {
  15488. pc = -pc;
  15489. }
  15490. c = rawBytes[i];
  15491. if (pa <= pb && pa <= pc) {
  15492. buffer[j++] = left + c;
  15493. } else if (pb <= pc) {
  15494. buffer[j++] = up + c;
  15495. } else {
  15496. buffer[j++] = upLeft + c;
  15497. }
  15498. }
  15499. break;
  15500. default:
  15501. error('Unsupported predictor: ' + predictor);
  15502. }
  15503. this.bufferLength += rowBytes;
  15504. };
  15505. return PredictorStream;
  15506. })();
  15507. /**
  15508. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  15509. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  15510. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  15511. * a library to decode these images and the stream behaves like all the other
  15512. * DecodeStreams.
  15513. */
  15514. var JpegStream = (function JpegStreamClosure() {
  15515. function JpegStream(stream, maybeLength, dict, xref) {
  15516. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  15517. // Note: this seems to mainly affect inline images.
  15518. var ch;
  15519. while ((ch = stream.getByte()) !== -1) {
  15520. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  15521. stream.skip(-1); // Reset the stream position to the SOI.
  15522. break;
  15523. }
  15524. }
  15525. this.stream = stream;
  15526. this.maybeLength = maybeLength;
  15527. this.dict = dict;
  15528. DecodeStream.call(this, maybeLength);
  15529. }
  15530. JpegStream.prototype = Object.create(DecodeStream.prototype);
  15531. Object.defineProperty(JpegStream.prototype, 'bytes', {
  15532. get: function JpegStream_bytes() {
  15533. // If this.maybeLength is null, we'll get the entire stream.
  15534. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15535. },
  15536. configurable: true
  15537. });
  15538. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  15539. if (this.bufferLength) {
  15540. return;
  15541. }
  15542. try {
  15543. var jpegImage = new JpegImage();
  15544. // checking if values needs to be transformed before conversion
  15545. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  15546. var decodeArr = this.dict.get('Decode');
  15547. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  15548. var decodeArrLength = decodeArr.length;
  15549. var transform = new Int32Array(decodeArrLength);
  15550. var transformNeeded = false;
  15551. var maxValue = (1 << bitsPerComponent) - 1;
  15552. for (var i = 0; i < decodeArrLength; i += 2) {
  15553. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  15554. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  15555. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  15556. transformNeeded = true;
  15557. }
  15558. }
  15559. if (transformNeeded) {
  15560. jpegImage.decodeTransform = transform;
  15561. }
  15562. }
  15563. jpegImage.parse(this.bytes);
  15564. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  15565. this.forceRGB);
  15566. this.buffer = data;
  15567. this.bufferLength = data.length;
  15568. this.eof = true;
  15569. } catch (e) {
  15570. error('JPEG error: ' + e);
  15571. }
  15572. };
  15573. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  15574. this.ensureBuffer();
  15575. return this.buffer;
  15576. };
  15577. JpegStream.prototype.getIR = function JpegStream_getIR() {
  15578. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  15579. };
  15580. /**
  15581. * Checks if the image can be decoded and displayed by the browser without any
  15582. * further processing such as color space conversions.
  15583. */
  15584. JpegStream.prototype.isNativelySupported =
  15585. function JpegStream_isNativelySupported(xref, res) {
  15586. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15587. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  15588. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15589. };
  15590. /**
  15591. * Checks if the image can be decoded by the browser.
  15592. */
  15593. JpegStream.prototype.isNativelyDecodable =
  15594. function JpegStream_isNativelyDecodable(xref, res) {
  15595. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15596. return (cs.numComps === 1 || cs.numComps === 3) &&
  15597. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15598. };
  15599. return JpegStream;
  15600. })();
  15601. /**
  15602. * For JPEG 2000's we use a library to decode these images and
  15603. * the stream behaves like all the other DecodeStreams.
  15604. */
  15605. var JpxStream = (function JpxStreamClosure() {
  15606. function JpxStream(stream, maybeLength, dict) {
  15607. this.stream = stream;
  15608. this.maybeLength = maybeLength;
  15609. this.dict = dict;
  15610. DecodeStream.call(this, maybeLength);
  15611. }
  15612. JpxStream.prototype = Object.create(DecodeStream.prototype);
  15613. Object.defineProperty(JpxStream.prototype, 'bytes', {
  15614. get: function JpxStream_bytes() {
  15615. // If this.maybeLength is null, we'll get the entire stream.
  15616. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15617. },
  15618. configurable: true
  15619. });
  15620. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  15621. if (this.bufferLength) {
  15622. return;
  15623. }
  15624. var jpxImage = new JpxImage();
  15625. jpxImage.parse(this.bytes);
  15626. var width = jpxImage.width;
  15627. var height = jpxImage.height;
  15628. var componentsCount = jpxImage.componentsCount;
  15629. var tileCount = jpxImage.tiles.length;
  15630. if (tileCount === 1) {
  15631. this.buffer = jpxImage.tiles[0].items;
  15632. } else {
  15633. var data = new Uint8Array(width * height * componentsCount);
  15634. for (var k = 0; k < tileCount; k++) {
  15635. var tileComponents = jpxImage.tiles[k];
  15636. var tileWidth = tileComponents.width;
  15637. var tileHeight = tileComponents.height;
  15638. var tileLeft = tileComponents.left;
  15639. var tileTop = tileComponents.top;
  15640. var src = tileComponents.items;
  15641. var srcPosition = 0;
  15642. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  15643. var imgRowSize = width * componentsCount;
  15644. var tileRowSize = tileWidth * componentsCount;
  15645. for (var j = 0; j < tileHeight; j++) {
  15646. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  15647. data.set(rowBytes, dataPosition);
  15648. srcPosition += tileRowSize;
  15649. dataPosition += imgRowSize;
  15650. }
  15651. }
  15652. this.buffer = data;
  15653. }
  15654. this.bufferLength = this.buffer.length;
  15655. this.eof = true;
  15656. };
  15657. return JpxStream;
  15658. })();
  15659. /**
  15660. * For JBIG2's we use a library to decode these images and
  15661. * the stream behaves like all the other DecodeStreams.
  15662. */
  15663. var Jbig2Stream = (function Jbig2StreamClosure() {
  15664. function Jbig2Stream(stream, maybeLength, dict) {
  15665. this.stream = stream;
  15666. this.maybeLength = maybeLength;
  15667. this.dict = dict;
  15668. DecodeStream.call(this, maybeLength);
  15669. }
  15670. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  15671. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  15672. get: function Jbig2Stream_bytes() {
  15673. // If this.maybeLength is null, we'll get the entire stream.
  15674. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15675. },
  15676. configurable: true
  15677. });
  15678. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  15679. if (this.bufferLength) {
  15680. return;
  15681. }
  15682. var jbig2Image = new Jbig2Image();
  15683. var chunks = [], xref = this.dict.xref;
  15684. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  15685. // According to the PDF specification, DecodeParms can be either
  15686. // a dictionary, or an array whose elements are dictionaries.
  15687. if (isArray(decodeParams)) {
  15688. if (decodeParams.length > 1) {
  15689. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  15690. 'not supported.');
  15691. }
  15692. decodeParams = xref.fetchIfRef(decodeParams[0]);
  15693. }
  15694. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  15695. var globalsStream = decodeParams.get('JBIG2Globals');
  15696. var globals = globalsStream.getBytes();
  15697. chunks.push({data: globals, start: 0, end: globals.length});
  15698. }
  15699. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  15700. var data = jbig2Image.parseChunks(chunks);
  15701. var dataLength = data.length;
  15702. // JBIG2 had black as 1 and white as 0, inverting the colors
  15703. for (var i = 0; i < dataLength; i++) {
  15704. data[i] ^= 0xFF;
  15705. }
  15706. this.buffer = data;
  15707. this.bufferLength = dataLength;
  15708. this.eof = true;
  15709. };
  15710. return Jbig2Stream;
  15711. })();
  15712. var DecryptStream = (function DecryptStreamClosure() {
  15713. function DecryptStream(str, maybeLength, decrypt) {
  15714. this.str = str;
  15715. this.dict = str.dict;
  15716. this.decrypt = decrypt;
  15717. this.nextChunk = null;
  15718. this.initialized = false;
  15719. DecodeStream.call(this, maybeLength);
  15720. }
  15721. var chunkSize = 512;
  15722. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  15723. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  15724. var chunk;
  15725. if (this.initialized) {
  15726. chunk = this.nextChunk;
  15727. } else {
  15728. chunk = this.str.getBytes(chunkSize);
  15729. this.initialized = true;
  15730. }
  15731. if (!chunk || chunk.length === 0) {
  15732. this.eof = true;
  15733. return;
  15734. }
  15735. this.nextChunk = this.str.getBytes(chunkSize);
  15736. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  15737. var decrypt = this.decrypt;
  15738. chunk = decrypt(chunk, !hasMoreData);
  15739. var bufferLength = this.bufferLength;
  15740. var i, n = chunk.length;
  15741. var buffer = this.ensureBuffer(bufferLength + n);
  15742. for (i = 0; i < n; i++) {
  15743. buffer[bufferLength++] = chunk[i];
  15744. }
  15745. this.bufferLength = bufferLength;
  15746. };
  15747. return DecryptStream;
  15748. })();
  15749. var Ascii85Stream = (function Ascii85StreamClosure() {
  15750. function Ascii85Stream(str, maybeLength) {
  15751. this.str = str;
  15752. this.dict = str.dict;
  15753. this.input = new Uint8Array(5);
  15754. // Most streams increase in size when decoded, but Ascii85 streams
  15755. // typically shrink by ~20%.
  15756. if (maybeLength) {
  15757. maybeLength = 0.8 * maybeLength;
  15758. }
  15759. DecodeStream.call(this, maybeLength);
  15760. }
  15761. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  15762. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  15763. var TILDA_CHAR = 0x7E; // '~'
  15764. var Z_LOWER_CHAR = 0x7A; // 'z'
  15765. var EOF = -1;
  15766. var str = this.str;
  15767. var c = str.getByte();
  15768. while (Lexer.isSpace(c)) {
  15769. c = str.getByte();
  15770. }
  15771. if (c === EOF || c === TILDA_CHAR) {
  15772. this.eof = true;
  15773. return;
  15774. }
  15775. var bufferLength = this.bufferLength, buffer;
  15776. var i;
  15777. // special code for z
  15778. if (c === Z_LOWER_CHAR) {
  15779. buffer = this.ensureBuffer(bufferLength + 4);
  15780. for (i = 0; i < 4; ++i) {
  15781. buffer[bufferLength + i] = 0;
  15782. }
  15783. this.bufferLength += 4;
  15784. } else {
  15785. var input = this.input;
  15786. input[0] = c;
  15787. for (i = 1; i < 5; ++i) {
  15788. c = str.getByte();
  15789. while (Lexer.isSpace(c)) {
  15790. c = str.getByte();
  15791. }
  15792. input[i] = c;
  15793. if (c === EOF || c === TILDA_CHAR) {
  15794. break;
  15795. }
  15796. }
  15797. buffer = this.ensureBuffer(bufferLength + i - 1);
  15798. this.bufferLength += i - 1;
  15799. // partial ending;
  15800. if (i < 5) {
  15801. for (; i < 5; ++i) {
  15802. input[i] = 0x21 + 84;
  15803. }
  15804. this.eof = true;
  15805. }
  15806. var t = 0;
  15807. for (i = 0; i < 5; ++i) {
  15808. t = t * 85 + (input[i] - 0x21);
  15809. }
  15810. for (i = 3; i >= 0; --i) {
  15811. buffer[bufferLength + i] = t & 0xFF;
  15812. t >>= 8;
  15813. }
  15814. }
  15815. };
  15816. return Ascii85Stream;
  15817. })();
  15818. var AsciiHexStream = (function AsciiHexStreamClosure() {
  15819. function AsciiHexStream(str, maybeLength) {
  15820. this.str = str;
  15821. this.dict = str.dict;
  15822. this.firstDigit = -1;
  15823. // Most streams increase in size when decoded, but AsciiHex streams shrink
  15824. // by 50%.
  15825. if (maybeLength) {
  15826. maybeLength = 0.5 * maybeLength;
  15827. }
  15828. DecodeStream.call(this, maybeLength);
  15829. }
  15830. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  15831. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  15832. var UPSTREAM_BLOCK_SIZE = 8000;
  15833. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  15834. if (!bytes.length) {
  15835. this.eof = true;
  15836. return;
  15837. }
  15838. var maxDecodeLength = (bytes.length + 1) >> 1;
  15839. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  15840. var bufferLength = this.bufferLength;
  15841. var firstDigit = this.firstDigit;
  15842. for (var i = 0, ii = bytes.length; i < ii; i++) {
  15843. var ch = bytes[i], digit;
  15844. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  15845. digit = ch & 0x0F;
  15846. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  15847. // 'A'-'Z', 'a'-'z'
  15848. digit = (ch & 0x0F) + 9;
  15849. } else if (ch === 0x3E) { // '>'
  15850. this.eof = true;
  15851. break;
  15852. } else { // probably whitespace
  15853. continue; // ignoring
  15854. }
  15855. if (firstDigit < 0) {
  15856. firstDigit = digit;
  15857. } else {
  15858. buffer[bufferLength++] = (firstDigit << 4) | digit;
  15859. firstDigit = -1;
  15860. }
  15861. }
  15862. if (firstDigit >= 0 && this.eof) {
  15863. // incomplete byte
  15864. buffer[bufferLength++] = (firstDigit << 4);
  15865. firstDigit = -1;
  15866. }
  15867. this.firstDigit = firstDigit;
  15868. this.bufferLength = bufferLength;
  15869. };
  15870. return AsciiHexStream;
  15871. })();
  15872. var RunLengthStream = (function RunLengthStreamClosure() {
  15873. function RunLengthStream(str, maybeLength) {
  15874. this.str = str;
  15875. this.dict = str.dict;
  15876. DecodeStream.call(this, maybeLength);
  15877. }
  15878. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  15879. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  15880. // The repeatHeader has following format. The first byte defines type of run
  15881. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  15882. // (in addition to the second byte from the header), n = 129 through 255 -
  15883. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  15884. var repeatHeader = this.str.getBytes(2);
  15885. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  15886. this.eof = true;
  15887. return;
  15888. }
  15889. var buffer;
  15890. var bufferLength = this.bufferLength;
  15891. var n = repeatHeader[0];
  15892. if (n < 128) {
  15893. // copy n bytes
  15894. buffer = this.ensureBuffer(bufferLength + n + 1);
  15895. buffer[bufferLength++] = repeatHeader[1];
  15896. if (n > 0) {
  15897. var source = this.str.getBytes(n);
  15898. buffer.set(source, bufferLength);
  15899. bufferLength += n;
  15900. }
  15901. } else {
  15902. n = 257 - n;
  15903. var b = repeatHeader[1];
  15904. buffer = this.ensureBuffer(bufferLength + n + 1);
  15905. for (var i = 0; i < n; i++) {
  15906. buffer[bufferLength++] = b;
  15907. }
  15908. }
  15909. this.bufferLength = bufferLength;
  15910. };
  15911. return RunLengthStream;
  15912. })();
  15913. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  15914. var ccittEOL = -2;
  15915. var twoDimPass = 0;
  15916. var twoDimHoriz = 1;
  15917. var twoDimVert0 = 2;
  15918. var twoDimVertR1 = 3;
  15919. var twoDimVertL1 = 4;
  15920. var twoDimVertR2 = 5;
  15921. var twoDimVertL2 = 6;
  15922. var twoDimVertR3 = 7;
  15923. var twoDimVertL3 = 8;
  15924. var twoDimTable = [
  15925. [-1, -1], [-1, -1], // 000000x
  15926. [7, twoDimVertL3], // 0000010
  15927. [7, twoDimVertR3], // 0000011
  15928. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  15929. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  15930. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  15931. [4, twoDimPass], [4, twoDimPass],
  15932. [4, twoDimPass], [4, twoDimPass],
  15933. [4, twoDimPass], [4, twoDimPass],
  15934. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  15935. [3, twoDimHoriz], [3, twoDimHoriz],
  15936. [3, twoDimHoriz], [3, twoDimHoriz],
  15937. [3, twoDimHoriz], [3, twoDimHoriz],
  15938. [3, twoDimHoriz], [3, twoDimHoriz],
  15939. [3, twoDimHoriz], [3, twoDimHoriz],
  15940. [3, twoDimHoriz], [3, twoDimHoriz],
  15941. [3, twoDimHoriz], [3, twoDimHoriz],
  15942. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  15943. [3, twoDimVertL1], [3, twoDimVertL1],
  15944. [3, twoDimVertL1], [3, twoDimVertL1],
  15945. [3, twoDimVertL1], [3, twoDimVertL1],
  15946. [3, twoDimVertL1], [3, twoDimVertL1],
  15947. [3, twoDimVertL1], [3, twoDimVertL1],
  15948. [3, twoDimVertL1], [3, twoDimVertL1],
  15949. [3, twoDimVertL1], [3, twoDimVertL1],
  15950. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  15951. [3, twoDimVertR1], [3, twoDimVertR1],
  15952. [3, twoDimVertR1], [3, twoDimVertR1],
  15953. [3, twoDimVertR1], [3, twoDimVertR1],
  15954. [3, twoDimVertR1], [3, twoDimVertR1],
  15955. [3, twoDimVertR1], [3, twoDimVertR1],
  15956. [3, twoDimVertR1], [3, twoDimVertR1],
  15957. [3, twoDimVertR1], [3, twoDimVertR1],
  15958. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  15959. [1, twoDimVert0], [1, twoDimVert0],
  15960. [1, twoDimVert0], [1, twoDimVert0],
  15961. [1, twoDimVert0], [1, twoDimVert0],
  15962. [1, twoDimVert0], [1, twoDimVert0],
  15963. [1, twoDimVert0], [1, twoDimVert0],
  15964. [1, twoDimVert0], [1, twoDimVert0],
  15965. [1, twoDimVert0], [1, twoDimVert0],
  15966. [1, twoDimVert0], [1, twoDimVert0],
  15967. [1, twoDimVert0], [1, twoDimVert0],
  15968. [1, twoDimVert0], [1, twoDimVert0],
  15969. [1, twoDimVert0], [1, twoDimVert0],
  15970. [1, twoDimVert0], [1, twoDimVert0],
  15971. [1, twoDimVert0], [1, twoDimVert0],
  15972. [1, twoDimVert0], [1, twoDimVert0],
  15973. [1, twoDimVert0], [1, twoDimVert0],
  15974. [1, twoDimVert0], [1, twoDimVert0],
  15975. [1, twoDimVert0], [1, twoDimVert0],
  15976. [1, twoDimVert0], [1, twoDimVert0],
  15977. [1, twoDimVert0], [1, twoDimVert0],
  15978. [1, twoDimVert0], [1, twoDimVert0],
  15979. [1, twoDimVert0], [1, twoDimVert0],
  15980. [1, twoDimVert0], [1, twoDimVert0],
  15981. [1, twoDimVert0], [1, twoDimVert0],
  15982. [1, twoDimVert0], [1, twoDimVert0],
  15983. [1, twoDimVert0], [1, twoDimVert0],
  15984. [1, twoDimVert0], [1, twoDimVert0],
  15985. [1, twoDimVert0], [1, twoDimVert0],
  15986. [1, twoDimVert0], [1, twoDimVert0],
  15987. [1, twoDimVert0], [1, twoDimVert0],
  15988. [1, twoDimVert0], [1, twoDimVert0],
  15989. [1, twoDimVert0], [1, twoDimVert0]
  15990. ];
  15991. var whiteTable1 = [
  15992. [-1, -1], // 00000
  15993. [12, ccittEOL], // 00001
  15994. [-1, -1], [-1, -1], // 0001x
  15995. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  15996. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  15997. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  15998. [11, 1792], [11, 1792], // 1000x
  15999. [12, 1984], // 10010
  16000. [12, 2048], // 10011
  16001. [12, 2112], // 10100
  16002. [12, 2176], // 10101
  16003. [12, 2240], // 10110
  16004. [12, 2304], // 10111
  16005. [11, 1856], [11, 1856], // 1100x
  16006. [11, 1920], [11, 1920], // 1101x
  16007. [12, 2368], // 11100
  16008. [12, 2432], // 11101
  16009. [12, 2496], // 11110
  16010. [12, 2560] // 11111
  16011. ];
  16012. var whiteTable2 = [
  16013. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  16014. [8, 29], [8, 29], // 00000010x
  16015. [8, 30], [8, 30], // 00000011x
  16016. [8, 45], [8, 45], // 00000100x
  16017. [8, 46], [8, 46], // 00000101x
  16018. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  16019. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  16020. [8, 47], [8, 47], // 00001010x
  16021. [8, 48], [8, 48], // 00001011x
  16022. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  16023. [6, 13], [6, 13], [6, 13], [6, 13],
  16024. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  16025. [8, 33], [8, 33], // 00010010x
  16026. [8, 34], [8, 34], // 00010011x
  16027. [8, 35], [8, 35], // 00010100x
  16028. [8, 36], [8, 36], // 00010101x
  16029. [8, 37], [8, 37], // 00010110x
  16030. [8, 38], [8, 38], // 00010111x
  16031. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  16032. [8, 31], [8, 31], // 00011010x
  16033. [8, 32], [8, 32], // 00011011x
  16034. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  16035. [6, 1], [6, 1], [6, 1], [6, 1],
  16036. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  16037. [6, 12], [6, 12], [6, 12], [6, 12],
  16038. [8, 53], [8, 53], // 00100100x
  16039. [8, 54], [8, 54], // 00100101x
  16040. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  16041. [8, 39], [8, 39], // 00101000x
  16042. [8, 40], [8, 40], // 00101001x
  16043. [8, 41], [8, 41], // 00101010x
  16044. [8, 42], [8, 42], // 00101011x
  16045. [8, 43], [8, 43], // 00101100x
  16046. [8, 44], [8, 44], // 00101101x
  16047. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  16048. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  16049. [8, 61], [8, 61], // 00110010x
  16050. [8, 62], [8, 62], // 00110011x
  16051. [8, 63], [8, 63], // 00110100x
  16052. [8, 0], [8, 0], // 00110101x
  16053. [8, 320], [8, 320], // 00110110x
  16054. [8, 384], [8, 384], // 00110111x
  16055. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  16056. [5, 10], [5, 10], [5, 10], [5, 10],
  16057. [5, 10], [5, 10], [5, 10], [5, 10],
  16058. [5, 10], [5, 10], [5, 10], [5, 10],
  16059. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  16060. [5, 11], [5, 11], [5, 11], [5, 11],
  16061. [5, 11], [5, 11], [5, 11], [5, 11],
  16062. [5, 11], [5, 11], [5, 11], [5, 11],
  16063. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  16064. [8, 59], [8, 59], // 01001010x
  16065. [8, 60], [8, 60], // 01001011x
  16066. [9, 1472], // 010011000
  16067. [9, 1536], // 010011001
  16068. [9, 1600], // 010011010
  16069. [9, 1728], // 010011011
  16070. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  16071. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  16072. [8, 49], [8, 49], // 01010010x
  16073. [8, 50], [8, 50], // 01010011x
  16074. [8, 51], [8, 51], // 01010100x
  16075. [8, 52], [8, 52], // 01010101x
  16076. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  16077. [8, 55], [8, 55], // 01011000x
  16078. [8, 56], [8, 56], // 01011001x
  16079. [8, 57], [8, 57], // 01011010x
  16080. [8, 58], [8, 58], // 01011011x
  16081. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  16082. [6, 192], [6, 192], [6, 192], [6, 192],
  16083. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  16084. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  16085. [8, 448], [8, 448], // 01100100x
  16086. [8, 512], [8, 512], // 01100101x
  16087. [9, 704], // 011001100
  16088. [9, 768], // 011001101
  16089. [8, 640], [8, 640], // 01100111x
  16090. [8, 576], [8, 576], // 01101000x
  16091. [9, 832], // 011010010
  16092. [9, 896], // 011010011
  16093. [9, 960], // 011010100
  16094. [9, 1024], // 011010101
  16095. [9, 1088], // 011010110
  16096. [9, 1152], // 011010111
  16097. [9, 1216], // 011011000
  16098. [9, 1280], // 011011001
  16099. [9, 1344], // 011011010
  16100. [9, 1408], // 011011011
  16101. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  16102. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  16103. [4, 2], [4, 2], [4, 2], [4, 2],
  16104. [4, 2], [4, 2], [4, 2], [4, 2],
  16105. [4, 2], [4, 2], [4, 2], [4, 2],
  16106. [4, 2], [4, 2], [4, 2], [4, 2],
  16107. [4, 2], [4, 2], [4, 2], [4, 2],
  16108. [4, 2], [4, 2], [4, 2], [4, 2],
  16109. [4, 2], [4, 2], [4, 2], [4, 2],
  16110. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  16111. [4, 3], [4, 3], [4, 3], [4, 3],
  16112. [4, 3], [4, 3], [4, 3], [4, 3],
  16113. [4, 3], [4, 3], [4, 3], [4, 3],
  16114. [4, 3], [4, 3], [4, 3], [4, 3],
  16115. [4, 3], [4, 3], [4, 3], [4, 3],
  16116. [4, 3], [4, 3], [4, 3], [4, 3],
  16117. [4, 3], [4, 3], [4, 3], [4, 3],
  16118. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  16119. [5, 128], [5, 128], [5, 128], [5, 128],
  16120. [5, 128], [5, 128], [5, 128], [5, 128],
  16121. [5, 128], [5, 128], [5, 128], [5, 128],
  16122. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  16123. [5, 8], [5, 8], [5, 8], [5, 8],
  16124. [5, 8], [5, 8], [5, 8], [5, 8],
  16125. [5, 8], [5, 8], [5, 8], [5, 8],
  16126. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  16127. [5, 9], [5, 9], [5, 9], [5, 9],
  16128. [5, 9], [5, 9], [5, 9], [5, 9],
  16129. [5, 9], [5, 9], [5, 9], [5, 9],
  16130. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  16131. [6, 16], [6, 16], [6, 16], [6, 16],
  16132. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  16133. [6, 17], [6, 17], [6, 17], [6, 17],
  16134. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  16135. [4, 4], [4, 4], [4, 4], [4, 4],
  16136. [4, 4], [4, 4], [4, 4], [4, 4],
  16137. [4, 4], [4, 4], [4, 4], [4, 4],
  16138. [4, 4], [4, 4], [4, 4], [4, 4],
  16139. [4, 4], [4, 4], [4, 4], [4, 4],
  16140. [4, 4], [4, 4], [4, 4], [4, 4],
  16141. [4, 4], [4, 4], [4, 4], [4, 4],
  16142. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  16143. [4, 5], [4, 5], [4, 5], [4, 5],
  16144. [4, 5], [4, 5], [4, 5], [4, 5],
  16145. [4, 5], [4, 5], [4, 5], [4, 5],
  16146. [4, 5], [4, 5], [4, 5], [4, 5],
  16147. [4, 5], [4, 5], [4, 5], [4, 5],
  16148. [4, 5], [4, 5], [4, 5], [4, 5],
  16149. [4, 5], [4, 5], [4, 5], [4, 5],
  16150. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  16151. [6, 14], [6, 14], [6, 14], [6, 14],
  16152. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  16153. [6, 15], [6, 15], [6, 15], [6, 15],
  16154. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  16155. [5, 64], [5, 64], [5, 64], [5, 64],
  16156. [5, 64], [5, 64], [5, 64], [5, 64],
  16157. [5, 64], [5, 64], [5, 64], [5, 64],
  16158. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  16159. [4, 6], [4, 6], [4, 6], [4, 6],
  16160. [4, 6], [4, 6], [4, 6], [4, 6],
  16161. [4, 6], [4, 6], [4, 6], [4, 6],
  16162. [4, 6], [4, 6], [4, 6], [4, 6],
  16163. [4, 6], [4, 6], [4, 6], [4, 6],
  16164. [4, 6], [4, 6], [4, 6], [4, 6],
  16165. [4, 6], [4, 6], [4, 6], [4, 6],
  16166. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  16167. [4, 7], [4, 7], [4, 7], [4, 7],
  16168. [4, 7], [4, 7], [4, 7], [4, 7],
  16169. [4, 7], [4, 7], [4, 7], [4, 7],
  16170. [4, 7], [4, 7], [4, 7], [4, 7],
  16171. [4, 7], [4, 7], [4, 7], [4, 7],
  16172. [4, 7], [4, 7], [4, 7], [4, 7],
  16173. [4, 7], [4, 7], [4, 7], [4, 7]
  16174. ];
  16175. var blackTable1 = [
  16176. [-1, -1], [-1, -1], // 000000000000x
  16177. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  16178. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  16179. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  16180. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  16181. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  16182. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  16183. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  16184. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  16185. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  16186. [12, 1984], [12, 1984], // 000000010010x
  16187. [12, 2048], [12, 2048], // 000000010011x
  16188. [12, 2112], [12, 2112], // 000000010100x
  16189. [12, 2176], [12, 2176], // 000000010101x
  16190. [12, 2240], [12, 2240], // 000000010110x
  16191. [12, 2304], [12, 2304], // 000000010111x
  16192. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  16193. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  16194. [12, 2368], [12, 2368], // 000000011100x
  16195. [12, 2432], [12, 2432], // 000000011101x
  16196. [12, 2496], [12, 2496], // 000000011110x
  16197. [12, 2560], [12, 2560], // 000000011111x
  16198. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  16199. [10, 18], [10, 18], [10, 18], [10, 18],
  16200. [12, 52], [12, 52], // 000000100100x
  16201. [13, 640], // 0000001001010
  16202. [13, 704], // 0000001001011
  16203. [13, 768], // 0000001001100
  16204. [13, 832], // 0000001001101
  16205. [12, 55], [12, 55], // 000000100111x
  16206. [12, 56], [12, 56], // 000000101000x
  16207. [13, 1280], // 0000001010010
  16208. [13, 1344], // 0000001010011
  16209. [13, 1408], // 0000001010100
  16210. [13, 1472], // 0000001010101
  16211. [12, 59], [12, 59], // 000000101011x
  16212. [12, 60], [12, 60], // 000000101100x
  16213. [13, 1536], // 0000001011010
  16214. [13, 1600], // 0000001011011
  16215. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  16216. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  16217. [13, 1664], // 0000001100100
  16218. [13, 1728], // 0000001100101
  16219. [12, 320], [12, 320], // 000000110011x
  16220. [12, 384], [12, 384], // 000000110100x
  16221. [12, 448], [12, 448], // 000000110101x
  16222. [13, 512], // 0000001101100
  16223. [13, 576], // 0000001101101
  16224. [12, 53], [12, 53], // 000000110111x
  16225. [12, 54], [12, 54], // 000000111000x
  16226. [13, 896], // 0000001110010
  16227. [13, 960], // 0000001110011
  16228. [13, 1024], // 0000001110100
  16229. [13, 1088], // 0000001110101
  16230. [13, 1152], // 0000001110110
  16231. [13, 1216], // 0000001110111
  16232. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  16233. [10, 64], [10, 64], [10, 64], [10, 64]
  16234. ];
  16235. var blackTable2 = [
  16236. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  16237. [8, 13], [8, 13], [8, 13], [8, 13],
  16238. [8, 13], [8, 13], [8, 13], [8, 13],
  16239. [8, 13], [8, 13], [8, 13], [8, 13],
  16240. [11, 23], [11, 23], // 00000101000x
  16241. [12, 50], // 000001010010
  16242. [12, 51], // 000001010011
  16243. [12, 44], // 000001010100
  16244. [12, 45], // 000001010101
  16245. [12, 46], // 000001010110
  16246. [12, 47], // 000001010111
  16247. [12, 57], // 000001011000
  16248. [12, 58], // 000001011001
  16249. [12, 61], // 000001011010
  16250. [12, 256], // 000001011011
  16251. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  16252. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  16253. [12, 48], // 000001100100
  16254. [12, 49], // 000001100101
  16255. [12, 62], // 000001100110
  16256. [12, 63], // 000001100111
  16257. [12, 30], // 000001101000
  16258. [12, 31], // 000001101001
  16259. [12, 32], // 000001101010
  16260. [12, 33], // 000001101011
  16261. [12, 40], // 000001101100
  16262. [12, 41], // 000001101101
  16263. [11, 22], [11, 22], // 00000110111x
  16264. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  16265. [8, 14], [8, 14], [8, 14], [8, 14],
  16266. [8, 14], [8, 14], [8, 14], [8, 14],
  16267. [8, 14], [8, 14], [8, 14], [8, 14],
  16268. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  16269. [7, 10], [7, 10], [7, 10], [7, 10],
  16270. [7, 10], [7, 10], [7, 10], [7, 10],
  16271. [7, 10], [7, 10], [7, 10], [7, 10],
  16272. [7, 10], [7, 10], [7, 10], [7, 10],
  16273. [7, 10], [7, 10], [7, 10], [7, 10],
  16274. [7, 10], [7, 10], [7, 10], [7, 10],
  16275. [7, 10], [7, 10], [7, 10], [7, 10],
  16276. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  16277. [7, 11], [7, 11], [7, 11], [7, 11],
  16278. [7, 11], [7, 11], [7, 11], [7, 11],
  16279. [7, 11], [7, 11], [7, 11], [7, 11],
  16280. [7, 11], [7, 11], [7, 11], [7, 11],
  16281. [7, 11], [7, 11], [7, 11], [7, 11],
  16282. [7, 11], [7, 11], [7, 11], [7, 11],
  16283. [7, 11], [7, 11], [7, 11], [7, 11],
  16284. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  16285. [9, 15], [9, 15], [9, 15], [9, 15],
  16286. [12, 128], // 000011001000
  16287. [12, 192], // 000011001001
  16288. [12, 26], // 000011001010
  16289. [12, 27], // 000011001011
  16290. [12, 28], // 000011001100
  16291. [12, 29], // 000011001101
  16292. [11, 19], [11, 19], // 00001100111x
  16293. [11, 20], [11, 20], // 00001101000x
  16294. [12, 34], // 000011010010
  16295. [12, 35], // 000011010011
  16296. [12, 36], // 000011010100
  16297. [12, 37], // 000011010101
  16298. [12, 38], // 000011010110
  16299. [12, 39], // 000011010111
  16300. [11, 21], [11, 21], // 00001101100x
  16301. [12, 42], // 000011011010
  16302. [12, 43], // 000011011011
  16303. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  16304. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  16305. [7, 12], [7, 12], [7, 12], [7, 12],
  16306. [7, 12], [7, 12], [7, 12], [7, 12],
  16307. [7, 12], [7, 12], [7, 12], [7, 12],
  16308. [7, 12], [7, 12], [7, 12], [7, 12],
  16309. [7, 12], [7, 12], [7, 12], [7, 12],
  16310. [7, 12], [7, 12], [7, 12], [7, 12],
  16311. [7, 12], [7, 12], [7, 12], [7, 12]
  16312. ];
  16313. var blackTable3 = [
  16314. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  16315. [6, 9], // 000100
  16316. [6, 8], // 000101
  16317. [5, 7], [5, 7], // 00011x
  16318. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  16319. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  16320. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  16321. [3, 1], [3, 1], [3, 1], [3, 1],
  16322. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  16323. [3, 4], [3, 4], [3, 4], [3, 4],
  16324. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  16325. [2, 3], [2, 3], [2, 3], [2, 3],
  16326. [2, 3], [2, 3], [2, 3], [2, 3],
  16327. [2, 3], [2, 3], [2, 3], [2, 3],
  16328. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  16329. [2, 2], [2, 2], [2, 2], [2, 2],
  16330. [2, 2], [2, 2], [2, 2], [2, 2],
  16331. [2, 2], [2, 2], [2, 2], [2, 2]
  16332. ];
  16333. function CCITTFaxStream(str, maybeLength, params) {
  16334. this.str = str;
  16335. this.dict = str.dict;
  16336. params = params || Dict.empty;
  16337. this.encoding = params.get('K') || 0;
  16338. this.eoline = params.get('EndOfLine') || false;
  16339. this.byteAlign = params.get('EncodedByteAlign') || false;
  16340. this.columns = params.get('Columns') || 1728;
  16341. this.rows = params.get('Rows') || 0;
  16342. var eoblock = params.get('EndOfBlock');
  16343. if (eoblock === null || eoblock === undefined) {
  16344. eoblock = true;
  16345. }
  16346. this.eoblock = eoblock;
  16347. this.black = params.get('BlackIs1') || false;
  16348. this.codingLine = new Uint32Array(this.columns + 1);
  16349. this.refLine = new Uint32Array(this.columns + 2);
  16350. this.codingLine[0] = this.columns;
  16351. this.codingPos = 0;
  16352. this.row = 0;
  16353. this.nextLine2D = this.encoding < 0;
  16354. this.inputBits = 0;
  16355. this.inputBuf = 0;
  16356. this.outputBits = 0;
  16357. var code1;
  16358. while ((code1 = this.lookBits(12)) === 0) {
  16359. this.eatBits(1);
  16360. }
  16361. if (code1 === 1) {
  16362. this.eatBits(12);
  16363. }
  16364. if (this.encoding > 0) {
  16365. this.nextLine2D = !this.lookBits(1);
  16366. this.eatBits(1);
  16367. }
  16368. DecodeStream.call(this, maybeLength);
  16369. }
  16370. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  16371. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  16372. while (!this.eof) {
  16373. var c = this.lookChar();
  16374. this.ensureBuffer(this.bufferLength + 1);
  16375. this.buffer[this.bufferLength++] = c;
  16376. }
  16377. };
  16378. CCITTFaxStream.prototype.addPixels =
  16379. function ccittFaxStreamAddPixels(a1, blackPixels) {
  16380. var codingLine = this.codingLine;
  16381. var codingPos = this.codingPos;
  16382. if (a1 > codingLine[codingPos]) {
  16383. if (a1 > this.columns) {
  16384. info('row is wrong length');
  16385. this.err = true;
  16386. a1 = this.columns;
  16387. }
  16388. if ((codingPos & 1) ^ blackPixels) {
  16389. ++codingPos;
  16390. }
  16391. codingLine[codingPos] = a1;
  16392. }
  16393. this.codingPos = codingPos;
  16394. };
  16395. CCITTFaxStream.prototype.addPixelsNeg =
  16396. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  16397. var codingLine = this.codingLine;
  16398. var codingPos = this.codingPos;
  16399. if (a1 > codingLine[codingPos]) {
  16400. if (a1 > this.columns) {
  16401. info('row is wrong length');
  16402. this.err = true;
  16403. a1 = this.columns;
  16404. }
  16405. if ((codingPos & 1) ^ blackPixels) {
  16406. ++codingPos;
  16407. }
  16408. codingLine[codingPos] = a1;
  16409. } else if (a1 < codingLine[codingPos]) {
  16410. if (a1 < 0) {
  16411. info('invalid code');
  16412. this.err = true;
  16413. a1 = 0;
  16414. }
  16415. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  16416. --codingPos;
  16417. }
  16418. codingLine[codingPos] = a1;
  16419. }
  16420. this.codingPos = codingPos;
  16421. };
  16422. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  16423. var refLine = this.refLine;
  16424. var codingLine = this.codingLine;
  16425. var columns = this.columns;
  16426. var refPos, blackPixels, bits, i;
  16427. if (this.outputBits === 0) {
  16428. if (this.eof) {
  16429. return null;
  16430. }
  16431. this.err = false;
  16432. var code1, code2, code3;
  16433. if (this.nextLine2D) {
  16434. for (i = 0; codingLine[i] < columns; ++i) {
  16435. refLine[i] = codingLine[i];
  16436. }
  16437. refLine[i++] = columns;
  16438. refLine[i] = columns;
  16439. codingLine[0] = 0;
  16440. this.codingPos = 0;
  16441. refPos = 0;
  16442. blackPixels = 0;
  16443. while (codingLine[this.codingPos] < columns) {
  16444. code1 = this.getTwoDimCode();
  16445. switch (code1) {
  16446. case twoDimPass:
  16447. this.addPixels(refLine[refPos + 1], blackPixels);
  16448. if (refLine[refPos + 1] < columns) {
  16449. refPos += 2;
  16450. }
  16451. break;
  16452. case twoDimHoriz:
  16453. code1 = code2 = 0;
  16454. if (blackPixels) {
  16455. do {
  16456. code1 += (code3 = this.getBlackCode());
  16457. } while (code3 >= 64);
  16458. do {
  16459. code2 += (code3 = this.getWhiteCode());
  16460. } while (code3 >= 64);
  16461. } else {
  16462. do {
  16463. code1 += (code3 = this.getWhiteCode());
  16464. } while (code3 >= 64);
  16465. do {
  16466. code2 += (code3 = this.getBlackCode());
  16467. } while (code3 >= 64);
  16468. }
  16469. this.addPixels(codingLine[this.codingPos] +
  16470. code1, blackPixels);
  16471. if (codingLine[this.codingPos] < columns) {
  16472. this.addPixels(codingLine[this.codingPos] + code2,
  16473. blackPixels ^ 1);
  16474. }
  16475. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16476. refLine[refPos] < columns) {
  16477. refPos += 2;
  16478. }
  16479. break;
  16480. case twoDimVertR3:
  16481. this.addPixels(refLine[refPos] + 3, blackPixels);
  16482. blackPixels ^= 1;
  16483. if (codingLine[this.codingPos] < columns) {
  16484. ++refPos;
  16485. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16486. refLine[refPos] < columns) {
  16487. refPos += 2;
  16488. }
  16489. }
  16490. break;
  16491. case twoDimVertR2:
  16492. this.addPixels(refLine[refPos] + 2, blackPixels);
  16493. blackPixels ^= 1;
  16494. if (codingLine[this.codingPos] < columns) {
  16495. ++refPos;
  16496. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16497. refLine[refPos] < columns) {
  16498. refPos += 2;
  16499. }
  16500. }
  16501. break;
  16502. case twoDimVertR1:
  16503. this.addPixels(refLine[refPos] + 1, blackPixels);
  16504. blackPixels ^= 1;
  16505. if (codingLine[this.codingPos] < columns) {
  16506. ++refPos;
  16507. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16508. refLine[refPos] < columns) {
  16509. refPos += 2;
  16510. }
  16511. }
  16512. break;
  16513. case twoDimVert0:
  16514. this.addPixels(refLine[refPos], blackPixels);
  16515. blackPixels ^= 1;
  16516. if (codingLine[this.codingPos] < columns) {
  16517. ++refPos;
  16518. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16519. refLine[refPos] < columns) {
  16520. refPos += 2;
  16521. }
  16522. }
  16523. break;
  16524. case twoDimVertL3:
  16525. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  16526. blackPixels ^= 1;
  16527. if (codingLine[this.codingPos] < columns) {
  16528. if (refPos > 0) {
  16529. --refPos;
  16530. } else {
  16531. ++refPos;
  16532. }
  16533. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16534. refLine[refPos] < columns) {
  16535. refPos += 2;
  16536. }
  16537. }
  16538. break;
  16539. case twoDimVertL2:
  16540. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  16541. blackPixels ^= 1;
  16542. if (codingLine[this.codingPos] < columns) {
  16543. if (refPos > 0) {
  16544. --refPos;
  16545. } else {
  16546. ++refPos;
  16547. }
  16548. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16549. refLine[refPos] < columns) {
  16550. refPos += 2;
  16551. }
  16552. }
  16553. break;
  16554. case twoDimVertL1:
  16555. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  16556. blackPixels ^= 1;
  16557. if (codingLine[this.codingPos] < columns) {
  16558. if (refPos > 0) {
  16559. --refPos;
  16560. } else {
  16561. ++refPos;
  16562. }
  16563. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16564. refLine[refPos] < columns) {
  16565. refPos += 2;
  16566. }
  16567. }
  16568. break;
  16569. case EOF:
  16570. this.addPixels(columns, 0);
  16571. this.eof = true;
  16572. break;
  16573. default:
  16574. info('bad 2d code');
  16575. this.addPixels(columns, 0);
  16576. this.err = true;
  16577. }
  16578. }
  16579. } else {
  16580. codingLine[0] = 0;
  16581. this.codingPos = 0;
  16582. blackPixels = 0;
  16583. while (codingLine[this.codingPos] < columns) {
  16584. code1 = 0;
  16585. if (blackPixels) {
  16586. do {
  16587. code1 += (code3 = this.getBlackCode());
  16588. } while (code3 >= 64);
  16589. } else {
  16590. do {
  16591. code1 += (code3 = this.getWhiteCode());
  16592. } while (code3 >= 64);
  16593. }
  16594. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  16595. blackPixels ^= 1;
  16596. }
  16597. }
  16598. var gotEOL = false;
  16599. if (this.byteAlign) {
  16600. this.inputBits &= ~7;
  16601. }
  16602. if (!this.eoblock && this.row === this.rows - 1) {
  16603. this.eof = true;
  16604. } else {
  16605. code1 = this.lookBits(12);
  16606. if (this.eoline) {
  16607. while (code1 !== EOF && code1 !== 1) {
  16608. this.eatBits(1);
  16609. code1 = this.lookBits(12);
  16610. }
  16611. } else {
  16612. while (code1 === 0) {
  16613. this.eatBits(1);
  16614. code1 = this.lookBits(12);
  16615. }
  16616. }
  16617. if (code1 === 1) {
  16618. this.eatBits(12);
  16619. gotEOL = true;
  16620. } else if (code1 === EOF) {
  16621. this.eof = true;
  16622. }
  16623. }
  16624. if (!this.eof && this.encoding > 0) {
  16625. this.nextLine2D = !this.lookBits(1);
  16626. this.eatBits(1);
  16627. }
  16628. if (this.eoblock && gotEOL && this.byteAlign) {
  16629. code1 = this.lookBits(12);
  16630. if (code1 === 1) {
  16631. this.eatBits(12);
  16632. if (this.encoding > 0) {
  16633. this.lookBits(1);
  16634. this.eatBits(1);
  16635. }
  16636. if (this.encoding >= 0) {
  16637. for (i = 0; i < 4; ++i) {
  16638. code1 = this.lookBits(12);
  16639. if (code1 !== 1) {
  16640. info('bad rtc code: ' + code1);
  16641. }
  16642. this.eatBits(12);
  16643. if (this.encoding > 0) {
  16644. this.lookBits(1);
  16645. this.eatBits(1);
  16646. }
  16647. }
  16648. }
  16649. this.eof = true;
  16650. }
  16651. } else if (this.err && this.eoline) {
  16652. while (true) {
  16653. code1 = this.lookBits(13);
  16654. if (code1 === EOF) {
  16655. this.eof = true;
  16656. return null;
  16657. }
  16658. if ((code1 >> 1) === 1) {
  16659. break;
  16660. }
  16661. this.eatBits(1);
  16662. }
  16663. this.eatBits(12);
  16664. if (this.encoding > 0) {
  16665. this.eatBits(1);
  16666. this.nextLine2D = !(code1 & 1);
  16667. }
  16668. }
  16669. if (codingLine[0] > 0) {
  16670. this.outputBits = codingLine[this.codingPos = 0];
  16671. } else {
  16672. this.outputBits = codingLine[this.codingPos = 1];
  16673. }
  16674. this.row++;
  16675. }
  16676. var c;
  16677. if (this.outputBits >= 8) {
  16678. c = (this.codingPos & 1) ? 0 : 0xFF;
  16679. this.outputBits -= 8;
  16680. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  16681. this.codingPos++;
  16682. this.outputBits = (codingLine[this.codingPos] -
  16683. codingLine[this.codingPos - 1]);
  16684. }
  16685. } else {
  16686. bits = 8;
  16687. c = 0;
  16688. do {
  16689. if (this.outputBits > bits) {
  16690. c <<= bits;
  16691. if (!(this.codingPos & 1)) {
  16692. c |= 0xFF >> (8 - bits);
  16693. }
  16694. this.outputBits -= bits;
  16695. bits = 0;
  16696. } else {
  16697. c <<= this.outputBits;
  16698. if (!(this.codingPos & 1)) {
  16699. c |= 0xFF >> (8 - this.outputBits);
  16700. }
  16701. bits -= this.outputBits;
  16702. this.outputBits = 0;
  16703. if (codingLine[this.codingPos] < columns) {
  16704. this.codingPos++;
  16705. this.outputBits = (codingLine[this.codingPos] -
  16706. codingLine[this.codingPos - 1]);
  16707. } else if (bits > 0) {
  16708. c <<= bits;
  16709. bits = 0;
  16710. }
  16711. }
  16712. } while (bits);
  16713. }
  16714. if (this.black) {
  16715. c ^= 0xFF;
  16716. }
  16717. return c;
  16718. };
  16719. // This functions returns the code found from the table.
  16720. // The start and end parameters set the boundaries for searching the table.
  16721. // The limit parameter is optional. Function returns an array with three
  16722. // values. The first array element indicates whether a valid code is being
  16723. // returned. The second array element is the actual code. The third array
  16724. // element indicates whether EOF was reached.
  16725. CCITTFaxStream.prototype.findTableCode =
  16726. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  16727. var limitValue = limit || 0;
  16728. for (var i = start; i <= end; ++i) {
  16729. var code = this.lookBits(i);
  16730. if (code === EOF) {
  16731. return [true, 1, false];
  16732. }
  16733. if (i < end) {
  16734. code <<= end - i;
  16735. }
  16736. if (!limitValue || code >= limitValue) {
  16737. var p = table[code - limitValue];
  16738. if (p[0] === i) {
  16739. this.eatBits(i);
  16740. return [true, p[1], true];
  16741. }
  16742. }
  16743. }
  16744. return [false, 0, false];
  16745. };
  16746. CCITTFaxStream.prototype.getTwoDimCode =
  16747. function ccittFaxStreamGetTwoDimCode() {
  16748. var code = 0;
  16749. var p;
  16750. if (this.eoblock) {
  16751. code = this.lookBits(7);
  16752. p = twoDimTable[code];
  16753. if (p && p[0] > 0) {
  16754. this.eatBits(p[0]);
  16755. return p[1];
  16756. }
  16757. } else {
  16758. var result = this.findTableCode(1, 7, twoDimTable);
  16759. if (result[0] && result[2]) {
  16760. return result[1];
  16761. }
  16762. }
  16763. info('Bad two dim code');
  16764. return EOF;
  16765. };
  16766. CCITTFaxStream.prototype.getWhiteCode =
  16767. function ccittFaxStreamGetWhiteCode() {
  16768. var code = 0;
  16769. var p;
  16770. if (this.eoblock) {
  16771. code = this.lookBits(12);
  16772. if (code === EOF) {
  16773. return 1;
  16774. }
  16775. if ((code >> 5) === 0) {
  16776. p = whiteTable1[code];
  16777. } else {
  16778. p = whiteTable2[code >> 3];
  16779. }
  16780. if (p[0] > 0) {
  16781. this.eatBits(p[0]);
  16782. return p[1];
  16783. }
  16784. } else {
  16785. var result = this.findTableCode(1, 9, whiteTable2);
  16786. if (result[0]) {
  16787. return result[1];
  16788. }
  16789. result = this.findTableCode(11, 12, whiteTable1);
  16790. if (result[0]) {
  16791. return result[1];
  16792. }
  16793. }
  16794. info('bad white code');
  16795. this.eatBits(1);
  16796. return 1;
  16797. };
  16798. CCITTFaxStream.prototype.getBlackCode =
  16799. function ccittFaxStreamGetBlackCode() {
  16800. var code, p;
  16801. if (this.eoblock) {
  16802. code = this.lookBits(13);
  16803. if (code === EOF) {
  16804. return 1;
  16805. }
  16806. if ((code >> 7) === 0) {
  16807. p = blackTable1[code];
  16808. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  16809. p = blackTable2[(code >> 1) - 64];
  16810. } else {
  16811. p = blackTable3[code >> 7];
  16812. }
  16813. if (p[0] > 0) {
  16814. this.eatBits(p[0]);
  16815. return p[1];
  16816. }
  16817. } else {
  16818. var result = this.findTableCode(2, 6, blackTable3);
  16819. if (result[0]) {
  16820. return result[1];
  16821. }
  16822. result = this.findTableCode(7, 12, blackTable2, 64);
  16823. if (result[0]) {
  16824. return result[1];
  16825. }
  16826. result = this.findTableCode(10, 13, blackTable1);
  16827. if (result[0]) {
  16828. return result[1];
  16829. }
  16830. }
  16831. info('bad black code');
  16832. this.eatBits(1);
  16833. return 1;
  16834. };
  16835. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  16836. var c;
  16837. while (this.inputBits < n) {
  16838. if ((c = this.str.getByte()) === -1) {
  16839. if (this.inputBits === 0) {
  16840. return EOF;
  16841. }
  16842. return ((this.inputBuf << (n - this.inputBits)) &
  16843. (0xFFFF >> (16 - n)));
  16844. }
  16845. this.inputBuf = (this.inputBuf << 8) + c;
  16846. this.inputBits += 8;
  16847. }
  16848. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  16849. };
  16850. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  16851. if ((this.inputBits -= n) < 0) {
  16852. this.inputBits = 0;
  16853. }
  16854. };
  16855. return CCITTFaxStream;
  16856. })();
  16857. var LZWStream = (function LZWStreamClosure() {
  16858. function LZWStream(str, maybeLength, earlyChange) {
  16859. this.str = str;
  16860. this.dict = str.dict;
  16861. this.cachedData = 0;
  16862. this.bitsCached = 0;
  16863. var maxLzwDictionarySize = 4096;
  16864. var lzwState = {
  16865. earlyChange: earlyChange,
  16866. codeLength: 9,
  16867. nextCode: 258,
  16868. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  16869. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  16870. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  16871. currentSequence: new Uint8Array(maxLzwDictionarySize),
  16872. currentSequenceLength: 0
  16873. };
  16874. for (var i = 0; i < 256; ++i) {
  16875. lzwState.dictionaryValues[i] = i;
  16876. lzwState.dictionaryLengths[i] = 1;
  16877. }
  16878. this.lzwState = lzwState;
  16879. DecodeStream.call(this, maybeLength);
  16880. }
  16881. LZWStream.prototype = Object.create(DecodeStream.prototype);
  16882. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  16883. var bitsCached = this.bitsCached;
  16884. var cachedData = this.cachedData;
  16885. while (bitsCached < n) {
  16886. var c = this.str.getByte();
  16887. if (c === -1) {
  16888. this.eof = true;
  16889. return null;
  16890. }
  16891. cachedData = (cachedData << 8) | c;
  16892. bitsCached += 8;
  16893. }
  16894. this.bitsCached = (bitsCached -= n);
  16895. this.cachedData = cachedData;
  16896. this.lastCode = null;
  16897. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  16898. };
  16899. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  16900. var blockSize = 512;
  16901. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  16902. var i, j, q;
  16903. var lzwState = this.lzwState;
  16904. if (!lzwState) {
  16905. return; // eof was found
  16906. }
  16907. var earlyChange = lzwState.earlyChange;
  16908. var nextCode = lzwState.nextCode;
  16909. var dictionaryValues = lzwState.dictionaryValues;
  16910. var dictionaryLengths = lzwState.dictionaryLengths;
  16911. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  16912. var codeLength = lzwState.codeLength;
  16913. var prevCode = lzwState.prevCode;
  16914. var currentSequence = lzwState.currentSequence;
  16915. var currentSequenceLength = lzwState.currentSequenceLength;
  16916. var decodedLength = 0;
  16917. var currentBufferLength = this.bufferLength;
  16918. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16919. for (i = 0; i < blockSize; i++) {
  16920. var code = this.readBits(codeLength);
  16921. var hasPrev = currentSequenceLength > 0;
  16922. if (code < 256) {
  16923. currentSequence[0] = code;
  16924. currentSequenceLength = 1;
  16925. } else if (code >= 258) {
  16926. if (code < nextCode) {
  16927. currentSequenceLength = dictionaryLengths[code];
  16928. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  16929. currentSequence[j] = dictionaryValues[q];
  16930. q = dictionaryPrevCodes[q];
  16931. }
  16932. } else {
  16933. currentSequence[currentSequenceLength++] = currentSequence[0];
  16934. }
  16935. } else if (code === 256) {
  16936. codeLength = 9;
  16937. nextCode = 258;
  16938. currentSequenceLength = 0;
  16939. continue;
  16940. } else {
  16941. this.eof = true;
  16942. delete this.lzwState;
  16943. break;
  16944. }
  16945. if (hasPrev) {
  16946. dictionaryPrevCodes[nextCode] = prevCode;
  16947. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  16948. dictionaryValues[nextCode] = currentSequence[0];
  16949. nextCode++;
  16950. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  16951. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  16952. 0.6931471805599453 + 1, 12) | 0;
  16953. }
  16954. prevCode = code;
  16955. decodedLength += currentSequenceLength;
  16956. if (estimatedDecodedSize < decodedLength) {
  16957. do {
  16958. estimatedDecodedSize += decodedSizeDelta;
  16959. } while (estimatedDecodedSize < decodedLength);
  16960. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16961. }
  16962. for (j = 0; j < currentSequenceLength; j++) {
  16963. buffer[currentBufferLength++] = currentSequence[j];
  16964. }
  16965. }
  16966. lzwState.nextCode = nextCode;
  16967. lzwState.codeLength = codeLength;
  16968. lzwState.prevCode = prevCode;
  16969. lzwState.currentSequenceLength = currentSequenceLength;
  16970. this.bufferLength = currentBufferLength;
  16971. };
  16972. return LZWStream;
  16973. })();
  16974. var NullStream = (function NullStreamClosure() {
  16975. function NullStream() {
  16976. Stream.call(this, new Uint8Array(0));
  16977. }
  16978. NullStream.prototype = Stream.prototype;
  16979. return NullStream;
  16980. })();
  16981. // TODO refactor to remove dependency on parser.js
  16982. function _setCoreParser(coreParser_) {
  16983. coreParser = coreParser_;
  16984. EOF = coreParser_.EOF;
  16985. Lexer = coreParser_.Lexer;
  16986. }
  16987. exports._setCoreParser = _setCoreParser;
  16988. // TODO refactor to remove dependency on colorspace.js
  16989. function _setCoreColorSpace(coreColorSpace_) {
  16990. coreColorSpace = coreColorSpace_;
  16991. ColorSpace = coreColorSpace_.ColorSpace;
  16992. }
  16993. exports._setCoreColorSpace = _setCoreColorSpace;
  16994. exports.Ascii85Stream = Ascii85Stream;
  16995. exports.AsciiHexStream = AsciiHexStream;
  16996. exports.CCITTFaxStream = CCITTFaxStream;
  16997. exports.DecryptStream = DecryptStream;
  16998. exports.DecodeStream = DecodeStream;
  16999. exports.FlateStream = FlateStream;
  17000. exports.Jbig2Stream = Jbig2Stream;
  17001. exports.JpegStream = JpegStream;
  17002. exports.JpxStream = JpxStream;
  17003. exports.NullStream = NullStream;
  17004. exports.PredictorStream = PredictorStream;
  17005. exports.RunLengthStream = RunLengthStream;
  17006. exports.Stream = Stream;
  17007. exports.StreamsSequenceStream = StreamsSequenceStream;
  17008. exports.StringStream = StringStream;
  17009. exports.LZWStream = LZWStream;
  17010. }));
  17011. (function (root, factory) {
  17012. {
  17013. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  17014. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  17015. }
  17016. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  17017. var PasswordException = sharedUtil.PasswordException;
  17018. var PasswordResponses = sharedUtil.PasswordResponses;
  17019. var bytesToString = sharedUtil.bytesToString;
  17020. var error = sharedUtil.error;
  17021. var isInt = sharedUtil.isInt;
  17022. var stringToBytes = sharedUtil.stringToBytes;
  17023. var utf8StringToString = sharedUtil.utf8StringToString;
  17024. var warn = sharedUtil.warn;
  17025. var Name = corePrimitives.Name;
  17026. var isName = corePrimitives.isName;
  17027. var DecryptStream = coreStream.DecryptStream;
  17028. var ARCFourCipher = (function ARCFourCipherClosure() {
  17029. function ARCFourCipher(key) {
  17030. this.a = 0;
  17031. this.b = 0;
  17032. var s = new Uint8Array(256);
  17033. var i, j = 0, tmp, keyLength = key.length;
  17034. for (i = 0; i < 256; ++i) {
  17035. s[i] = i;
  17036. }
  17037. for (i = 0; i < 256; ++i) {
  17038. tmp = s[i];
  17039. j = (j + tmp + key[i % keyLength]) & 0xFF;
  17040. s[i] = s[j];
  17041. s[j] = tmp;
  17042. }
  17043. this.s = s;
  17044. }
  17045. ARCFourCipher.prototype = {
  17046. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  17047. var i, n = data.length, tmp, tmp2;
  17048. var a = this.a, b = this.b, s = this.s;
  17049. var output = new Uint8Array(n);
  17050. for (i = 0; i < n; ++i) {
  17051. a = (a + 1) & 0xFF;
  17052. tmp = s[a];
  17053. b = (b + tmp) & 0xFF;
  17054. tmp2 = s[b];
  17055. s[a] = tmp2;
  17056. s[b] = tmp;
  17057. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  17058. }
  17059. this.a = a;
  17060. this.b = b;
  17061. return output;
  17062. }
  17063. };
  17064. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  17065. return ARCFourCipher;
  17066. })();
  17067. var calculateMD5 = (function calculateMD5Closure() {
  17068. var r = new Uint8Array([
  17069. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  17070. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  17071. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  17072. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  17073. var k = new Int32Array([
  17074. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  17075. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  17076. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  17077. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  17078. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  17079. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  17080. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  17081. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  17082. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  17083. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  17084. -145523070, -1120210379, 718787259, -343485551]);
  17085. function hash(data, offset, length) {
  17086. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  17087. // pre-processing
  17088. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  17089. var padded = new Uint8Array(paddedLength);
  17090. var i, j, n;
  17091. for (i = 0; i < length; ++i) {
  17092. padded[i] = data[offset++];
  17093. }
  17094. padded[i++] = 0x80;
  17095. n = paddedLength - 8;
  17096. while (i < n) {
  17097. padded[i++] = 0;
  17098. }
  17099. padded[i++] = (length << 3) & 0xFF;
  17100. padded[i++] = (length >> 5) & 0xFF;
  17101. padded[i++] = (length >> 13) & 0xFF;
  17102. padded[i++] = (length >> 21) & 0xFF;
  17103. padded[i++] = (length >>> 29) & 0xFF;
  17104. padded[i++] = 0;
  17105. padded[i++] = 0;
  17106. padded[i++] = 0;
  17107. var w = new Int32Array(16);
  17108. for (i = 0; i < paddedLength;) {
  17109. for (j = 0; j < 16; ++j, i += 4) {
  17110. w[j] = (padded[i] | (padded[i + 1] << 8) |
  17111. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  17112. }
  17113. var a = h0, b = h1, c = h2, d = h3, f, g;
  17114. for (j = 0; j < 64; ++j) {
  17115. if (j < 16) {
  17116. f = (b & c) | ((~b) & d);
  17117. g = j;
  17118. } else if (j < 32) {
  17119. f = (d & b) | ((~d) & c);
  17120. g = (5 * j + 1) & 15;
  17121. } else if (j < 48) {
  17122. f = b ^ c ^ d;
  17123. g = (3 * j + 5) & 15;
  17124. } else {
  17125. f = c ^ (b | (~d));
  17126. g = (7 * j) & 15;
  17127. }
  17128. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  17129. d = c;
  17130. c = b;
  17131. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  17132. a = tmp;
  17133. }
  17134. h0 = (h0 + a) | 0;
  17135. h1 = (h1 + b) | 0;
  17136. h2 = (h2 + c) | 0;
  17137. h3 = (h3 + d) | 0;
  17138. }
  17139. return new Uint8Array([
  17140. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  17141. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  17142. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  17143. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  17144. ]);
  17145. }
  17146. return hash;
  17147. })();
  17148. var Word64 = (function Word64Closure() {
  17149. function Word64(highInteger, lowInteger) {
  17150. this.high = highInteger | 0;
  17151. this.low = lowInteger | 0;
  17152. }
  17153. Word64.prototype = {
  17154. and: function Word64_and(word) {
  17155. this.high &= word.high;
  17156. this.low &= word.low;
  17157. },
  17158. xor: function Word64_xor(word) {
  17159. this.high ^= word.high;
  17160. this.low ^= word.low;
  17161. },
  17162. or: function Word64_or(word) {
  17163. this.high |= word.high;
  17164. this.low |= word.low;
  17165. },
  17166. shiftRight: function Word64_shiftRight(places) {
  17167. if (places >= 32) {
  17168. this.low = (this.high >>> (places - 32)) | 0;
  17169. this.high = 0;
  17170. } else {
  17171. this.low = (this.low >>> places) | (this.high << (32 - places));
  17172. this.high = (this.high >>> places) | 0;
  17173. }
  17174. },
  17175. shiftLeft: function Word64_shiftLeft(places) {
  17176. if (places >= 32) {
  17177. this.high = this.low << (places - 32);
  17178. this.low = 0;
  17179. } else {
  17180. this.high = (this.high << places) | (this.low >>> (32 - places));
  17181. this.low = this.low << places;
  17182. }
  17183. },
  17184. rotateRight: function Word64_rotateRight(places) {
  17185. var low, high;
  17186. if (places & 32) {
  17187. high = this.low;
  17188. low = this.high;
  17189. } else {
  17190. low = this.low;
  17191. high = this.high;
  17192. }
  17193. places &= 31;
  17194. this.low = (low >>> places) | (high << (32 - places));
  17195. this.high = (high >>> places) | (low << (32 - places));
  17196. },
  17197. not: function Word64_not() {
  17198. this.high = ~this.high;
  17199. this.low = ~this.low;
  17200. },
  17201. add: function Word64_add(word) {
  17202. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  17203. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  17204. if (lowAdd > 0xFFFFFFFF) {
  17205. highAdd += 1;
  17206. }
  17207. this.low = lowAdd | 0;
  17208. this.high = highAdd | 0;
  17209. },
  17210. copyTo: function Word64_copyTo(bytes, offset) {
  17211. bytes[offset] = (this.high >>> 24) & 0xFF;
  17212. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  17213. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  17214. bytes[offset + 3] = this.high & 0xFF;
  17215. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  17216. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  17217. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  17218. bytes[offset + 7] = this.low & 0xFF;
  17219. },
  17220. assign: function Word64_assign(word) {
  17221. this.high = word.high;
  17222. this.low = word.low;
  17223. }
  17224. };
  17225. return Word64;
  17226. })();
  17227. var calculateSHA256 = (function calculateSHA256Closure() {
  17228. function rotr(x, n) {
  17229. return (x >>> n) | (x << 32 - n);
  17230. }
  17231. function ch(x, y, z) {
  17232. return (x & y) ^ (~x & z);
  17233. }
  17234. function maj(x, y, z) {
  17235. return (x & y) ^ (x & z) ^ (y & z);
  17236. }
  17237. function sigma(x) {
  17238. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  17239. }
  17240. function sigmaPrime(x) {
  17241. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  17242. }
  17243. function littleSigma(x) {
  17244. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  17245. }
  17246. function littleSigmaPrime(x) {
  17247. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  17248. }
  17249. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  17250. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  17251. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  17252. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  17253. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  17254. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  17255. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  17256. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  17257. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  17258. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  17259. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  17260. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  17261. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17262. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  17263. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  17264. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  17265. function hash(data, offset, length) {
  17266. // initial hash values
  17267. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  17268. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  17269. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  17270. // pre-processing
  17271. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  17272. var padded = new Uint8Array(paddedLength);
  17273. var i, j, n;
  17274. for (i = 0; i < length; ++i) {
  17275. padded[i] = data[offset++];
  17276. }
  17277. padded[i++] = 0x80;
  17278. n = paddedLength - 8;
  17279. while (i < n) {
  17280. padded[i++] = 0;
  17281. }
  17282. padded[i++] = 0;
  17283. padded[i++] = 0;
  17284. padded[i++] = 0;
  17285. padded[i++] = (length >>> 29) & 0xFF;
  17286. padded[i++] = (length >> 21) & 0xFF;
  17287. padded[i++] = (length >> 13) & 0xFF;
  17288. padded[i++] = (length >> 5) & 0xFF;
  17289. padded[i++] = (length << 3) & 0xFF;
  17290. var w = new Uint32Array(64);
  17291. // for each 512 bit block
  17292. for (i = 0; i < paddedLength;) {
  17293. for (j = 0; j < 16; ++j) {
  17294. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  17295. (padded[i + 2] << 8) | (padded[i + 3]));
  17296. i += 4;
  17297. }
  17298. for (j = 16; j < 64; ++j) {
  17299. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  17300. littleSigma(w[j - 15]) + w[j - 16] | 0;
  17301. }
  17302. var a = h0, b = h1, c = h2, d = h3, e = h4,
  17303. f = h5, g = h6, h = h7, t1, t2;
  17304. for (j = 0; j < 64; ++j) {
  17305. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  17306. t2 = sigma(a) + maj(a, b, c);
  17307. h = g;
  17308. g = f;
  17309. f = e;
  17310. e = (d + t1) | 0;
  17311. d = c;
  17312. c = b;
  17313. b = a;
  17314. a = (t1 + t2) | 0;
  17315. }
  17316. h0 = (h0 + a) | 0;
  17317. h1 = (h1 + b) | 0;
  17318. h2 = (h2 + c) | 0;
  17319. h3 = (h3 + d) | 0;
  17320. h4 = (h4 + e) | 0;
  17321. h5 = (h5 + f) | 0;
  17322. h6 = (h6 + g) | 0;
  17323. h7 = (h7 + h) | 0;
  17324. }
  17325. return new Uint8Array([
  17326. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  17327. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  17328. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  17329. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  17330. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  17331. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  17332. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  17333. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  17334. ]);
  17335. }
  17336. return hash;
  17337. })();
  17338. var calculateSHA512 = (function calculateSHA512Closure() {
  17339. function ch(result, x, y, z, tmp) {
  17340. result.assign(x);
  17341. result.and(y);
  17342. tmp.assign(x);
  17343. tmp.not();
  17344. tmp.and(z);
  17345. result.xor(tmp);
  17346. }
  17347. function maj(result, x, y, z, tmp) {
  17348. result.assign(x);
  17349. result.and(y);
  17350. tmp.assign(x);
  17351. tmp.and(z);
  17352. result.xor(tmp);
  17353. tmp.assign(y);
  17354. tmp.and(z);
  17355. result.xor(tmp);
  17356. }
  17357. function sigma(result, x, tmp) {
  17358. result.assign(x);
  17359. result.rotateRight(28);
  17360. tmp.assign(x);
  17361. tmp.rotateRight(34);
  17362. result.xor(tmp);
  17363. tmp.assign(x);
  17364. tmp.rotateRight(39);
  17365. result.xor(tmp);
  17366. }
  17367. function sigmaPrime(result, x, tmp) {
  17368. result.assign(x);
  17369. result.rotateRight(14);
  17370. tmp.assign(x);
  17371. tmp.rotateRight(18);
  17372. result.xor(tmp);
  17373. tmp.assign(x);
  17374. tmp.rotateRight(41);
  17375. result.xor(tmp);
  17376. }
  17377. function littleSigma(result, x, tmp) {
  17378. result.assign(x);
  17379. result.rotateRight(1);
  17380. tmp.assign(x);
  17381. tmp.rotateRight(8);
  17382. result.xor(tmp);
  17383. tmp.assign(x);
  17384. tmp.shiftRight(7);
  17385. result.xor(tmp);
  17386. }
  17387. function littleSigmaPrime(result, x, tmp) {
  17388. result.assign(x);
  17389. result.rotateRight(19);
  17390. tmp.assign(x);
  17391. tmp.rotateRight(61);
  17392. result.xor(tmp);
  17393. tmp.assign(x);
  17394. tmp.shiftRight(6);
  17395. result.xor(tmp);
  17396. }
  17397. var k = [
  17398. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  17399. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  17400. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  17401. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  17402. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  17403. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  17404. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  17405. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  17406. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  17407. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  17408. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  17409. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  17410. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  17411. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  17412. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  17413. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  17414. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  17415. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  17416. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  17417. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  17418. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  17419. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  17420. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  17421. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  17422. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  17423. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  17424. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  17425. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  17426. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  17427. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  17428. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  17429. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  17430. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  17431. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  17432. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  17433. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  17434. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  17435. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  17436. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  17437. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  17438. function hash(data, offset, length, mode384) {
  17439. mode384 = !!mode384;
  17440. // initial hash values
  17441. var h0, h1, h2, h3, h4, h5, h6, h7;
  17442. if (!mode384) {
  17443. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  17444. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  17445. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  17446. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  17447. h4 = new Word64(0x510e527f, 0xade682d1);
  17448. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  17449. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  17450. h7 = new Word64(0x5be0cd19, 0x137e2179);
  17451. }
  17452. else {
  17453. // SHA384 is exactly the same
  17454. // except with different starting values and a trimmed result
  17455. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  17456. h1 = new Word64(0x629a292a, 0x367cd507);
  17457. h2 = new Word64(0x9159015a, 0x3070dd17);
  17458. h3 = new Word64(0x152fecd8, 0xf70e5939);
  17459. h4 = new Word64(0x67332667, 0xffc00b31);
  17460. h5 = new Word64(0x8eb44a87, 0x68581511);
  17461. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  17462. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  17463. }
  17464. // pre-processing
  17465. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  17466. var padded = new Uint8Array(paddedLength);
  17467. var i, j, n;
  17468. for (i = 0; i < length; ++i) {
  17469. padded[i] = data[offset++];
  17470. }
  17471. padded[i++] = 0x80;
  17472. n = paddedLength - 16;
  17473. while (i < n) {
  17474. padded[i++] = 0;
  17475. }
  17476. padded[i++] = 0;
  17477. padded[i++] = 0;
  17478. padded[i++] = 0;
  17479. padded[i++] = 0;
  17480. padded[i++] = 0;
  17481. padded[i++] = 0;
  17482. padded[i++] = 0;
  17483. padded[i++] = 0;
  17484. padded[i++] = 0;
  17485. padded[i++] = 0;
  17486. padded[i++] = 0;
  17487. padded[i++] = (length >>> 29) & 0xFF;
  17488. padded[i++] = (length >> 21) & 0xFF;
  17489. padded[i++] = (length >> 13) & 0xFF;
  17490. padded[i++] = (length >> 5) & 0xFF;
  17491. padded[i++] = (length << 3) & 0xFF;
  17492. var w = new Array(80);
  17493. for (i = 0; i < 80; i++) {
  17494. w[i] = new Word64(0, 0);
  17495. }
  17496. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  17497. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  17498. var g = new Word64(0, 0), h = new Word64(0, 0);
  17499. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  17500. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  17501. // for each 1024 bit block
  17502. for (i = 0; i < paddedLength;) {
  17503. for (j = 0; j < 16; ++j) {
  17504. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  17505. (padded[i + 2] << 8) | (padded[i + 3]);
  17506. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  17507. (padded[i + 6]) << 8 | (padded[i + 7]);
  17508. i += 8;
  17509. }
  17510. for (j = 16; j < 80; ++j) {
  17511. tmp3 = w[j];
  17512. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  17513. tmp3.add(w[j - 7]);
  17514. littleSigma(tmp1, w[j - 15], tmp2);
  17515. tmp3.add(tmp1);
  17516. tmp3.add(w[j - 16]);
  17517. }
  17518. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  17519. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  17520. for (j = 0; j < 80; ++j) {
  17521. t1.assign(h);
  17522. sigmaPrime(tmp1, e, tmp2);
  17523. t1.add(tmp1);
  17524. ch(tmp1, e, f, g, tmp2);
  17525. t1.add(tmp1);
  17526. t1.add(k[j]);
  17527. t1.add(w[j]);
  17528. sigma(t2, a, tmp2);
  17529. maj(tmp1, a, b, c, tmp2);
  17530. t2.add(tmp1);
  17531. tmp3 = h;
  17532. h = g;
  17533. g = f;
  17534. f = e;
  17535. d.add(t1);
  17536. e = d;
  17537. d = c;
  17538. c = b;
  17539. b = a;
  17540. tmp3.assign(t1);
  17541. tmp3.add(t2);
  17542. a = tmp3;
  17543. }
  17544. h0.add(a);
  17545. h1.add(b);
  17546. h2.add(c);
  17547. h3.add(d);
  17548. h4.add(e);
  17549. h5.add(f);
  17550. h6.add(g);
  17551. h7.add(h);
  17552. }
  17553. var result;
  17554. if (!mode384) {
  17555. result = new Uint8Array(64);
  17556. h0.copyTo(result,0);
  17557. h1.copyTo(result,8);
  17558. h2.copyTo(result,16);
  17559. h3.copyTo(result,24);
  17560. h4.copyTo(result,32);
  17561. h5.copyTo(result,40);
  17562. h6.copyTo(result,48);
  17563. h7.copyTo(result,56);
  17564. }
  17565. else {
  17566. result = new Uint8Array(48);
  17567. h0.copyTo(result,0);
  17568. h1.copyTo(result,8);
  17569. h2.copyTo(result,16);
  17570. h3.copyTo(result,24);
  17571. h4.copyTo(result,32);
  17572. h5.copyTo(result,40);
  17573. }
  17574. return result;
  17575. }
  17576. return hash;
  17577. })();
  17578. var calculateSHA384 = (function calculateSHA384Closure() {
  17579. function hash(data, offset, length) {
  17580. return calculateSHA512(data, offset, length, true);
  17581. }
  17582. return hash;
  17583. })();
  17584. var NullCipher = (function NullCipherClosure() {
  17585. function NullCipher() {
  17586. }
  17587. NullCipher.prototype = {
  17588. decryptBlock: function NullCipher_decryptBlock(data) {
  17589. return data;
  17590. }
  17591. };
  17592. return NullCipher;
  17593. })();
  17594. var AES128Cipher = (function AES128CipherClosure() {
  17595. var rcon = new Uint8Array([
  17596. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17597. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17598. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17599. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17600. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  17601. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  17602. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  17603. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  17604. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  17605. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  17606. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  17607. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  17608. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  17609. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  17610. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  17611. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  17612. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  17613. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17614. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17615. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17616. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17617. 0x74, 0xe8, 0xcb, 0x8d]);
  17618. var s = new Uint8Array([
  17619. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  17620. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  17621. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  17622. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  17623. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  17624. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  17625. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  17626. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  17627. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  17628. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  17629. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  17630. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  17631. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  17632. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  17633. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  17634. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  17635. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  17636. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  17637. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  17638. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  17639. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  17640. 0xb0, 0x54, 0xbb, 0x16]);
  17641. var inv_s = new Uint8Array([
  17642. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  17643. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  17644. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  17645. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  17646. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  17647. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  17648. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  17649. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  17650. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  17651. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  17652. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  17653. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  17654. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  17655. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  17656. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  17657. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  17658. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  17659. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  17660. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  17661. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  17662. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  17663. 0x55, 0x21, 0x0c, 0x7d]);
  17664. var mixCol = new Uint8Array(256);
  17665. for (var i = 0; i < 256; i++) {
  17666. if (i < 128) {
  17667. mixCol[i] = i << 1;
  17668. } else {
  17669. mixCol[i] = (i << 1) ^ 0x1b;
  17670. }
  17671. }
  17672. var mix = new Uint32Array([
  17673. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  17674. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  17675. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  17676. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  17677. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  17678. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  17679. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  17680. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  17681. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  17682. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  17683. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  17684. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  17685. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  17686. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  17687. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  17688. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  17689. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  17690. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  17691. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  17692. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  17693. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  17694. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  17695. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  17696. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  17697. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  17698. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  17699. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  17700. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  17701. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  17702. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  17703. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  17704. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  17705. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  17706. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  17707. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  17708. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  17709. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  17710. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  17711. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  17712. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  17713. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  17714. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  17715. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  17716. function expandKey128(cipherKey) {
  17717. var b = 176, result = new Uint8Array(b);
  17718. result.set(cipherKey);
  17719. for (var j = 16, i = 1; j < b; ++i) {
  17720. // RotWord
  17721. var t1 = result[j - 3], t2 = result[j - 2],
  17722. t3 = result[j - 1], t4 = result[j - 4];
  17723. // SubWord
  17724. t1 = s[t1];
  17725. t2 = s[t2];
  17726. t3 = s[t3];
  17727. t4 = s[t4];
  17728. // Rcon
  17729. t1 = t1 ^ rcon[i];
  17730. for (var n = 0; n < 4; ++n) {
  17731. result[j] = (t1 ^= result[j - 16]);
  17732. j++;
  17733. result[j] = (t2 ^= result[j - 16]);
  17734. j++;
  17735. result[j] = (t3 ^= result[j - 16]);
  17736. j++;
  17737. result[j] = (t4 ^= result[j - 16]);
  17738. j++;
  17739. }
  17740. }
  17741. return result;
  17742. }
  17743. function decrypt128(input, key) {
  17744. var state = new Uint8Array(16);
  17745. state.set(input);
  17746. var i, j, k;
  17747. var t, u, v;
  17748. // AddRoundKey
  17749. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17750. state[j] ^= key[k];
  17751. }
  17752. for (i = 9; i >= 1; --i) {
  17753. // InvShiftRows
  17754. t = state[13];
  17755. state[13] = state[9];
  17756. state[9] = state[5];
  17757. state[5] = state[1];
  17758. state[1] = t;
  17759. t = state[14];
  17760. u = state[10];
  17761. state[14] = state[6];
  17762. state[10] = state[2];
  17763. state[6] = t;
  17764. state[2] = u;
  17765. t = state[15];
  17766. u = state[11];
  17767. v = state[7];
  17768. state[15] = state[3];
  17769. state[11] = t;
  17770. state[7] = u;
  17771. state[3] = v;
  17772. // InvSubBytes
  17773. for (j = 0; j < 16; ++j) {
  17774. state[j] = inv_s[state[j]];
  17775. }
  17776. // AddRoundKey
  17777. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17778. state[j] ^= key[k];
  17779. }
  17780. // InvMixColumns
  17781. for (j = 0; j < 16; j += 4) {
  17782. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  17783. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  17784. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  17785. (s3 >>> 24) ^ (s3 << 8));
  17786. state[j] = (t >>> 24) & 0xFF;
  17787. state[j + 1] = (t >> 16) & 0xFF;
  17788. state[j + 2] = (t >> 8) & 0xFF;
  17789. state[j + 3] = t & 0xFF;
  17790. }
  17791. }
  17792. // InvShiftRows
  17793. t = state[13];
  17794. state[13] = state[9];
  17795. state[9] = state[5];
  17796. state[5] = state[1];
  17797. state[1] = t;
  17798. t = state[14];
  17799. u = state[10];
  17800. state[14] = state[6];
  17801. state[10] = state[2];
  17802. state[6] = t;
  17803. state[2] = u;
  17804. t = state[15];
  17805. u = state[11];
  17806. v = state[7];
  17807. state[15] = state[3];
  17808. state[11] = t;
  17809. state[7] = u;
  17810. state[3] = v;
  17811. for (j = 0; j < 16; ++j) {
  17812. // InvSubBytes
  17813. state[j] = inv_s[state[j]];
  17814. // AddRoundKey
  17815. state[j] ^= key[j];
  17816. }
  17817. return state;
  17818. }
  17819. function encrypt128(input, key) {
  17820. var t, u, v, k;
  17821. var state = new Uint8Array(16);
  17822. state.set(input);
  17823. for (j = 0; j < 16; ++j) {
  17824. // AddRoundKey
  17825. state[j] ^= key[j];
  17826. }
  17827. for (i = 1; i < 10; i++) {
  17828. //SubBytes
  17829. for (j = 0; j < 16; ++j) {
  17830. state[j] = s[state[j]];
  17831. }
  17832. //ShiftRows
  17833. v = state[1];
  17834. state[1] = state[5];
  17835. state[5] = state[9];
  17836. state[9] = state[13];
  17837. state[13] = v;
  17838. v = state[2];
  17839. u = state[6];
  17840. state[2] = state[10];
  17841. state[6] = state[14];
  17842. state[10] = v;
  17843. state[14] = u;
  17844. v = state[3];
  17845. u = state[7];
  17846. t = state[11];
  17847. state[3] = state[15];
  17848. state[7] = v;
  17849. state[11] = u;
  17850. state[15] = t;
  17851. //MixColumns
  17852. for (var j = 0; j < 16; j += 4) {
  17853. var s0 = state[j + 0], s1 = state[j + 1];
  17854. var s2 = state[j + 2], s3 = state[j + 3];
  17855. t = s0 ^ s1 ^ s2 ^ s3;
  17856. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  17857. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  17858. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  17859. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  17860. }
  17861. //AddRoundKey
  17862. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17863. state[j] ^= key[k];
  17864. }
  17865. }
  17866. //SubBytes
  17867. for (j = 0; j < 16; ++j) {
  17868. state[j] = s[state[j]];
  17869. }
  17870. //ShiftRows
  17871. v = state[1];
  17872. state[1] = state[5];
  17873. state[5] = state[9];
  17874. state[9] = state[13];
  17875. state[13] = v;
  17876. v = state[2];
  17877. u = state[6];
  17878. state[2] = state[10];
  17879. state[6] = state[14];
  17880. state[10] = v;
  17881. state[14] = u;
  17882. v = state[3];
  17883. u = state[7];
  17884. t = state[11];
  17885. state[3] = state[15];
  17886. state[7] = v;
  17887. state[11] = u;
  17888. state[15] = t;
  17889. //AddRoundKey
  17890. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17891. state[j] ^= key[k];
  17892. }
  17893. return state;
  17894. }
  17895. function AES128Cipher(key) {
  17896. this.key = expandKey128(key);
  17897. this.buffer = new Uint8Array(16);
  17898. this.bufferPosition = 0;
  17899. }
  17900. function decryptBlock2(data, finalize) {
  17901. var i, j, ii, sourceLength = data.length,
  17902. buffer = this.buffer, bufferLength = this.bufferPosition,
  17903. result = [], iv = this.iv;
  17904. for (i = 0; i < sourceLength; ++i) {
  17905. buffer[bufferLength] = data[i];
  17906. ++bufferLength;
  17907. if (bufferLength < 16) {
  17908. continue;
  17909. }
  17910. // buffer is full, decrypting
  17911. var plain = decrypt128(buffer, this.key);
  17912. // xor-ing the IV vector to get plain text
  17913. for (j = 0; j < 16; ++j) {
  17914. plain[j] ^= iv[j];
  17915. }
  17916. iv = buffer;
  17917. result.push(plain);
  17918. buffer = new Uint8Array(16);
  17919. bufferLength = 0;
  17920. }
  17921. // saving incomplete buffer
  17922. this.buffer = buffer;
  17923. this.bufferLength = bufferLength;
  17924. this.iv = iv;
  17925. if (result.length === 0) {
  17926. return new Uint8Array([]);
  17927. }
  17928. // combining plain text blocks into one
  17929. var outputLength = 16 * result.length;
  17930. if (finalize) {
  17931. // undo a padding that is described in RFC 2898
  17932. var lastBlock = result[result.length - 1];
  17933. var psLen = lastBlock[15];
  17934. if (psLen <= 16) {
  17935. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  17936. if (lastBlock[i] !== psLen) {
  17937. // Invalid padding, assume that the block has no padding.
  17938. psLen = 0;
  17939. break;
  17940. }
  17941. }
  17942. outputLength -= psLen;
  17943. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  17944. }
  17945. }
  17946. var output = new Uint8Array(outputLength);
  17947. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  17948. output.set(result[i], j);
  17949. }
  17950. return output;
  17951. }
  17952. AES128Cipher.prototype = {
  17953. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  17954. var i, sourceLength = data.length;
  17955. var buffer = this.buffer, bufferLength = this.bufferPosition;
  17956. // waiting for IV values -- they are at the start of the stream
  17957. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  17958. buffer[bufferLength] = data[i];
  17959. }
  17960. if (bufferLength < 16) {
  17961. // need more data
  17962. this.bufferLength = bufferLength;
  17963. return new Uint8Array([]);
  17964. }
  17965. this.iv = buffer;
  17966. this.buffer = new Uint8Array(16);
  17967. this.bufferLength = 0;
  17968. // starting decryption
  17969. this.decryptBlock = decryptBlock2;
  17970. return this.decryptBlock(data.subarray(16), finalize);
  17971. },
  17972. encrypt: function AES128Cipher_encrypt(data, iv) {
  17973. var i, j, ii, sourceLength = data.length,
  17974. buffer = this.buffer, bufferLength = this.bufferPosition,
  17975. result = [];
  17976. if (!iv) {
  17977. iv = new Uint8Array(16);
  17978. }
  17979. for (i = 0; i < sourceLength; ++i) {
  17980. buffer[bufferLength] = data[i];
  17981. ++bufferLength;
  17982. if (bufferLength < 16) {
  17983. continue;
  17984. }
  17985. for (j = 0; j < 16; ++j) {
  17986. buffer[j] ^= iv[j];
  17987. }
  17988. // buffer is full, encrypting
  17989. var cipher = encrypt128(buffer, this.key);
  17990. iv = cipher;
  17991. result.push(cipher);
  17992. buffer = new Uint8Array(16);
  17993. bufferLength = 0;
  17994. }
  17995. // saving incomplete buffer
  17996. this.buffer = buffer;
  17997. this.bufferLength = bufferLength;
  17998. this.iv = iv;
  17999. if (result.length === 0) {
  18000. return new Uint8Array([]);
  18001. }
  18002. // combining plain text blocks into one
  18003. var outputLength = 16 * result.length;
  18004. var output = new Uint8Array(outputLength);
  18005. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18006. output.set(result[i], j);
  18007. }
  18008. return output;
  18009. }
  18010. };
  18011. return AES128Cipher;
  18012. })();
  18013. var AES256Cipher = (function AES256CipherClosure() {
  18014. var rcon = new Uint8Array([
  18015. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18016. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18017. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18018. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18019. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18020. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18021. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18022. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18023. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18024. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18025. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18026. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18027. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18028. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18029. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18030. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18031. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18032. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18033. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18034. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18035. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18036. 0x74, 0xe8, 0xcb, 0x8d]);
  18037. var s = new Uint8Array([
  18038. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18039. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18040. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18041. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18042. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18043. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18044. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18045. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18046. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18047. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18048. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18049. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18050. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18051. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18052. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18053. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18054. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18055. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18056. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18057. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18058. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18059. 0xb0, 0x54, 0xbb, 0x16]);
  18060. var inv_s = new Uint8Array([
  18061. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18062. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18063. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18064. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18065. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18066. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18067. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18068. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18069. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18070. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18071. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18072. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18073. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18074. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18075. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18076. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18077. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18078. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18079. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18080. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18081. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18082. 0x55, 0x21, 0x0c, 0x7d]);
  18083. var mixCol = new Uint8Array(256);
  18084. for (var i = 0; i < 256; i++) {
  18085. if (i < 128) {
  18086. mixCol[i] = i << 1;
  18087. } else {
  18088. mixCol[i] = (i << 1) ^ 0x1b;
  18089. }
  18090. }
  18091. var mix = new Uint32Array([
  18092. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18093. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18094. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18095. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18096. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18097. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18098. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18099. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18100. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18101. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18102. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18103. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18104. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18105. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18106. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18107. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18108. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18109. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18110. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18111. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18112. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18113. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18114. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18115. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18116. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18117. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18118. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18119. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18120. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18121. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18122. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18123. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18124. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18125. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18126. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18127. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18128. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18129. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18130. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18131. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18132. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18133. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18134. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18135. function expandKey256(cipherKey) {
  18136. var b = 240, result = new Uint8Array(b);
  18137. var r = 1;
  18138. result.set(cipherKey);
  18139. for (var j = 32, i = 1; j < b; ++i) {
  18140. if (j % 32 === 16) {
  18141. t1 = s[t1];
  18142. t2 = s[t2];
  18143. t3 = s[t3];
  18144. t4 = s[t4];
  18145. } else if (j % 32 === 0) {
  18146. // RotWord
  18147. var t1 = result[j - 3], t2 = result[j - 2],
  18148. t3 = result[j - 1], t4 = result[j - 4];
  18149. // SubWord
  18150. t1 = s[t1];
  18151. t2 = s[t2];
  18152. t3 = s[t3];
  18153. t4 = s[t4];
  18154. // Rcon
  18155. t1 = t1 ^ r;
  18156. if ((r <<= 1) >= 256) {
  18157. r = (r ^ 0x1b) & 0xFF;
  18158. }
  18159. }
  18160. for (var n = 0; n < 4; ++n) {
  18161. result[j] = (t1 ^= result[j - 32]);
  18162. j++;
  18163. result[j] = (t2 ^= result[j - 32]);
  18164. j++;
  18165. result[j] = (t3 ^= result[j - 32]);
  18166. j++;
  18167. result[j] = (t4 ^= result[j - 32]);
  18168. j++;
  18169. }
  18170. }
  18171. return result;
  18172. }
  18173. function decrypt256(input, key) {
  18174. var state = new Uint8Array(16);
  18175. state.set(input);
  18176. var i, j, k;
  18177. var t, u, v;
  18178. // AddRoundKey
  18179. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18180. state[j] ^= key[k];
  18181. }
  18182. for (i = 13; i >= 1; --i) {
  18183. // InvShiftRows
  18184. t = state[13];
  18185. state[13] = state[9];
  18186. state[9] = state[5];
  18187. state[5] = state[1];
  18188. state[1] = t;
  18189. t = state[14];
  18190. u = state[10];
  18191. state[14] = state[6];
  18192. state[10] = state[2];
  18193. state[6] = t;
  18194. state[2] = u;
  18195. t = state[15];
  18196. u = state[11];
  18197. v = state[7];
  18198. state[15] = state[3];
  18199. state[11] = t;
  18200. state[7] = u;
  18201. state[3] = v;
  18202. // InvSubBytes
  18203. for (j = 0; j < 16; ++j) {
  18204. state[j] = inv_s[state[j]];
  18205. }
  18206. // AddRoundKey
  18207. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18208. state[j] ^= key[k];
  18209. }
  18210. // InvMixColumns
  18211. for (j = 0; j < 16; j += 4) {
  18212. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18213. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18214. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18215. (s3 >>> 24) ^ (s3 << 8));
  18216. state[j] = (t >>> 24) & 0xFF;
  18217. state[j + 1] = (t >> 16) & 0xFF;
  18218. state[j + 2] = (t >> 8) & 0xFF;
  18219. state[j + 3] = t & 0xFF;
  18220. }
  18221. }
  18222. // InvShiftRows
  18223. t = state[13];
  18224. state[13] = state[9];
  18225. state[9] = state[5];
  18226. state[5] = state[1];
  18227. state[1] = t;
  18228. t = state[14];
  18229. u = state[10];
  18230. state[14] = state[6];
  18231. state[10] = state[2];
  18232. state[6] = t;
  18233. state[2] = u;
  18234. t = state[15];
  18235. u = state[11];
  18236. v = state[7];
  18237. state[15] = state[3];
  18238. state[11] = t;
  18239. state[7] = u;
  18240. state[3] = v;
  18241. for (j = 0; j < 16; ++j) {
  18242. // InvSubBytes
  18243. state[j] = inv_s[state[j]];
  18244. // AddRoundKey
  18245. state[j] ^= key[j];
  18246. }
  18247. return state;
  18248. }
  18249. function encrypt256(input, key) {
  18250. var t, u, v, k;
  18251. var state = new Uint8Array(16);
  18252. state.set(input);
  18253. for (j = 0; j < 16; ++j) {
  18254. // AddRoundKey
  18255. state[j] ^= key[j];
  18256. }
  18257. for (i = 1; i < 14; i++) {
  18258. //SubBytes
  18259. for (j = 0; j < 16; ++j) {
  18260. state[j] = s[state[j]];
  18261. }
  18262. //ShiftRows
  18263. v = state[1];
  18264. state[1] = state[5];
  18265. state[5] = state[9];
  18266. state[9] = state[13];
  18267. state[13] = v;
  18268. v = state[2];
  18269. u = state[6];
  18270. state[2] = state[10];
  18271. state[6] = state[14];
  18272. state[10] = v;
  18273. state[14] = u;
  18274. v = state[3];
  18275. u = state[7];
  18276. t = state[11];
  18277. state[3] = state[15];
  18278. state[7] = v;
  18279. state[11] = u;
  18280. state[15] = t;
  18281. //MixColumns
  18282. for (var j = 0; j < 16; j += 4) {
  18283. var s0 = state[j + 0], s1 = state[j + 1];
  18284. var s2 = state[j + 2], s3 = state[j + 3];
  18285. t = s0 ^ s1 ^ s2 ^ s3;
  18286. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18287. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18288. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18289. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18290. }
  18291. //AddRoundKey
  18292. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18293. state[j] ^= key[k];
  18294. }
  18295. }
  18296. //SubBytes
  18297. for (j = 0; j < 16; ++j) {
  18298. state[j] = s[state[j]];
  18299. }
  18300. //ShiftRows
  18301. v = state[1];
  18302. state[1] = state[5];
  18303. state[5] = state[9];
  18304. state[9] = state[13];
  18305. state[13] = v;
  18306. v = state[2];
  18307. u = state[6];
  18308. state[2] = state[10];
  18309. state[6] = state[14];
  18310. state[10] = v;
  18311. state[14] = u;
  18312. v = state[3];
  18313. u = state[7];
  18314. t = state[11];
  18315. state[3] = state[15];
  18316. state[7] = v;
  18317. state[11] = u;
  18318. state[15] = t;
  18319. //AddRoundKey
  18320. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18321. state[j] ^= key[k];
  18322. }
  18323. return state;
  18324. }
  18325. function AES256Cipher(key) {
  18326. this.key = expandKey256(key);
  18327. this.buffer = new Uint8Array(16);
  18328. this.bufferPosition = 0;
  18329. }
  18330. function decryptBlock2(data, finalize) {
  18331. var i, j, ii, sourceLength = data.length,
  18332. buffer = this.buffer, bufferLength = this.bufferPosition,
  18333. result = [], iv = this.iv;
  18334. for (i = 0; i < sourceLength; ++i) {
  18335. buffer[bufferLength] = data[i];
  18336. ++bufferLength;
  18337. if (bufferLength < 16) {
  18338. continue;
  18339. }
  18340. // buffer is full, decrypting
  18341. var plain = decrypt256(buffer, this.key);
  18342. // xor-ing the IV vector to get plain text
  18343. for (j = 0; j < 16; ++j) {
  18344. plain[j] ^= iv[j];
  18345. }
  18346. iv = buffer;
  18347. result.push(plain);
  18348. buffer = new Uint8Array(16);
  18349. bufferLength = 0;
  18350. }
  18351. // saving incomplete buffer
  18352. this.buffer = buffer;
  18353. this.bufferLength = bufferLength;
  18354. this.iv = iv;
  18355. if (result.length === 0) {
  18356. return new Uint8Array([]);
  18357. }
  18358. // combining plain text blocks into one
  18359. var outputLength = 16 * result.length;
  18360. if (finalize) {
  18361. // undo a padding that is described in RFC 2898
  18362. var lastBlock = result[result.length - 1];
  18363. var psLen = lastBlock[15];
  18364. if (psLen <= 16) {
  18365. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18366. if (lastBlock[i] !== psLen) {
  18367. // Invalid padding, assume that the block has no padding.
  18368. psLen = 0;
  18369. break;
  18370. }
  18371. }
  18372. outputLength -= psLen;
  18373. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18374. }
  18375. }
  18376. var output = new Uint8Array(outputLength);
  18377. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18378. output.set(result[i], j);
  18379. }
  18380. return output;
  18381. }
  18382. AES256Cipher.prototype = {
  18383. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  18384. var i, sourceLength = data.length;
  18385. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18386. // if not supplied an IV wait for IV values
  18387. // they are at the start of the stream
  18388. if (iv) {
  18389. this.iv = iv;
  18390. } else {
  18391. for (i = 0; bufferLength < 16 &&
  18392. i < sourceLength; ++i, ++bufferLength) {
  18393. buffer[bufferLength] = data[i];
  18394. }
  18395. if (bufferLength < 16) {
  18396. //need more data
  18397. this.bufferLength = bufferLength;
  18398. return new Uint8Array([]);
  18399. }
  18400. this.iv = buffer;
  18401. data = data.subarray(16);
  18402. }
  18403. this.buffer = new Uint8Array(16);
  18404. this.bufferLength = 0;
  18405. // starting decryption
  18406. this.decryptBlock = decryptBlock2;
  18407. return this.decryptBlock(data, finalize);
  18408. },
  18409. encrypt: function AES256Cipher_encrypt(data, iv) {
  18410. var i, j, ii, sourceLength = data.length,
  18411. buffer = this.buffer, bufferLength = this.bufferPosition,
  18412. result = [];
  18413. if (!iv) {
  18414. iv = new Uint8Array(16);
  18415. }
  18416. for (i = 0; i < sourceLength; ++i) {
  18417. buffer[bufferLength] = data[i];
  18418. ++bufferLength;
  18419. if (bufferLength < 16) {
  18420. continue;
  18421. }
  18422. for (j = 0; j < 16; ++j) {
  18423. buffer[j] ^= iv[j];
  18424. }
  18425. // buffer is full, encrypting
  18426. var cipher = encrypt256(buffer, this.key);
  18427. this.iv = cipher;
  18428. result.push(cipher);
  18429. buffer = new Uint8Array(16);
  18430. bufferLength = 0;
  18431. }
  18432. // saving incomplete buffer
  18433. this.buffer = buffer;
  18434. this.bufferLength = bufferLength;
  18435. this.iv = iv;
  18436. if (result.length === 0) {
  18437. return new Uint8Array([]);
  18438. }
  18439. // combining plain text blocks into one
  18440. var outputLength = 16 * result.length;
  18441. var output = new Uint8Array(outputLength);
  18442. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18443. output.set(result[i], j);
  18444. }
  18445. return output;
  18446. }
  18447. };
  18448. return AES256Cipher;
  18449. })();
  18450. var PDF17 = (function PDF17Closure() {
  18451. function compareByteArrays(array1, array2) {
  18452. if (array1.length !== array2.length) {
  18453. return false;
  18454. }
  18455. for (var i = 0; i < array1.length; i++) {
  18456. if (array1[i] !== array2[i]) {
  18457. return false;
  18458. }
  18459. }
  18460. return true;
  18461. }
  18462. function PDF17() {
  18463. }
  18464. PDF17.prototype = {
  18465. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  18466. ownerValidationSalt,
  18467. userBytes,
  18468. ownerPassword) {
  18469. var hashData = new Uint8Array(password.length + 56);
  18470. hashData.set(password, 0);
  18471. hashData.set(ownerValidationSalt, password.length);
  18472. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18473. var result = calculateSHA256(hashData, 0, hashData.length);
  18474. return compareByteArrays(result, ownerPassword);
  18475. },
  18476. checkUserPassword: function PDF17_checkUserPassword(password,
  18477. userValidationSalt,
  18478. userPassword) {
  18479. var hashData = new Uint8Array(password.length + 8);
  18480. hashData.set(password, 0);
  18481. hashData.set(userValidationSalt, password.length);
  18482. var result = calculateSHA256(hashData, 0, hashData.length);
  18483. return compareByteArrays(result, userPassword);
  18484. },
  18485. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  18486. ownerEncryption) {
  18487. var hashData = new Uint8Array(password.length + 56);
  18488. hashData.set(password, 0);
  18489. hashData.set(ownerKeySalt, password.length);
  18490. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18491. var key = calculateSHA256(hashData, 0, hashData.length);
  18492. var cipher = new AES256Cipher(key);
  18493. return cipher.decryptBlock(ownerEncryption,
  18494. false,
  18495. new Uint8Array(16));
  18496. },
  18497. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  18498. userEncryption) {
  18499. var hashData = new Uint8Array(password.length + 8);
  18500. hashData.set(password, 0);
  18501. hashData.set(userKeySalt, password.length);
  18502. //key is the decryption key for the UE string
  18503. var key = calculateSHA256(hashData, 0, hashData.length);
  18504. var cipher = new AES256Cipher(key);
  18505. return cipher.decryptBlock(userEncryption,
  18506. false,
  18507. new Uint8Array(16));
  18508. }
  18509. };
  18510. return PDF17;
  18511. })();
  18512. var PDF20 = (function PDF20Closure() {
  18513. function concatArrays(array1, array2) {
  18514. var t = new Uint8Array(array1.length + array2.length);
  18515. t.set(array1, 0);
  18516. t.set(array2, array1.length);
  18517. return t;
  18518. }
  18519. function calculatePDF20Hash(password, input, userBytes) {
  18520. //This refers to Algorithm 2.B as defined in ISO 32000-2
  18521. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  18522. var e = [0];
  18523. var i = 0;
  18524. while (i < 64 || e[e.length - 1] > i - 32) {
  18525. var arrayLength = password.length + k.length + userBytes.length;
  18526. var k1 = new Uint8Array(arrayLength * 64);
  18527. var array = concatArrays(password, k);
  18528. array = concatArrays(array, userBytes);
  18529. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  18530. k1.set(array, pos);
  18531. }
  18532. //AES128 CBC NO PADDING with
  18533. //first 16 bytes of k as the key and the second 16 as the iv.
  18534. var cipher = new AES128Cipher(k.subarray(0, 16));
  18535. e = cipher.encrypt(k1, k.subarray(16, 32));
  18536. //Now we have to take the first 16 bytes of an unsigned
  18537. //big endian integer... and compute the remainder
  18538. //modulo 3.... That is a fairly large number and
  18539. //JavaScript isn't going to handle that well...
  18540. //So we're using a trick that allows us to perform
  18541. //modulo math byte by byte
  18542. var remainder = 0;
  18543. for (var z = 0; z < 16; z++) {
  18544. remainder *= (256 % 3);
  18545. remainder %= 3;
  18546. remainder += ((e[z] >>> 0) % 3);
  18547. remainder %= 3;
  18548. }
  18549. if (remainder === 0) {
  18550. k = calculateSHA256(e, 0, e.length);
  18551. }
  18552. else if (remainder === 1) {
  18553. k = calculateSHA384(e, 0, e.length);
  18554. }
  18555. else if (remainder === 2) {
  18556. k = calculateSHA512(e, 0, e.length);
  18557. }
  18558. i++;
  18559. }
  18560. return k.subarray(0, 32);
  18561. }
  18562. function PDF20() {
  18563. }
  18564. function compareByteArrays(array1, array2) {
  18565. if (array1.length !== array2.length) {
  18566. return false;
  18567. }
  18568. for (var i = 0; i < array1.length; i++) {
  18569. if (array1[i] !== array2[i]) {
  18570. return false;
  18571. }
  18572. }
  18573. return true;
  18574. }
  18575. PDF20.prototype = {
  18576. hash: function PDF20_hash(password, concatBytes, userBytes) {
  18577. return calculatePDF20Hash(password, concatBytes, userBytes);
  18578. },
  18579. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  18580. ownerValidationSalt,
  18581. userBytes,
  18582. ownerPassword) {
  18583. var hashData = new Uint8Array(password.length + 56);
  18584. hashData.set(password, 0);
  18585. hashData.set(ownerValidationSalt, password.length);
  18586. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18587. var result = calculatePDF20Hash(password, hashData, userBytes);
  18588. return compareByteArrays(result, ownerPassword);
  18589. },
  18590. checkUserPassword: function PDF20_checkUserPassword(password,
  18591. userValidationSalt,
  18592. userPassword) {
  18593. var hashData = new Uint8Array(password.length + 8);
  18594. hashData.set(password, 0);
  18595. hashData.set(userValidationSalt, password.length);
  18596. var result = calculatePDF20Hash(password, hashData, []);
  18597. return compareByteArrays(result, userPassword);
  18598. },
  18599. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  18600. ownerEncryption) {
  18601. var hashData = new Uint8Array(password.length + 56);
  18602. hashData.set(password, 0);
  18603. hashData.set(ownerKeySalt, password.length);
  18604. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18605. var key = calculatePDF20Hash(password, hashData, userBytes);
  18606. var cipher = new AES256Cipher(key);
  18607. return cipher.decryptBlock(ownerEncryption,
  18608. false,
  18609. new Uint8Array(16));
  18610. },
  18611. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  18612. userEncryption) {
  18613. var hashData = new Uint8Array(password.length + 8);
  18614. hashData.set(password, 0);
  18615. hashData.set(userKeySalt, password.length);
  18616. //key is the decryption key for the UE string
  18617. var key = calculatePDF20Hash(password, hashData, []);
  18618. var cipher = new AES256Cipher(key);
  18619. return cipher.decryptBlock(userEncryption,
  18620. false,
  18621. new Uint8Array(16));
  18622. }
  18623. };
  18624. return PDF20;
  18625. })();
  18626. var CipherTransform = (function CipherTransformClosure() {
  18627. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  18628. this.stringCipherConstructor = stringCipherConstructor;
  18629. this.streamCipherConstructor = streamCipherConstructor;
  18630. }
  18631. CipherTransform.prototype = {
  18632. createStream: function CipherTransform_createStream(stream, length) {
  18633. var cipher = new this.streamCipherConstructor();
  18634. return new DecryptStream(stream, length,
  18635. function cipherTransformDecryptStream(data, finalize) {
  18636. return cipher.decryptBlock(data, finalize);
  18637. }
  18638. );
  18639. },
  18640. decryptString: function CipherTransform_decryptString(s) {
  18641. var cipher = new this.stringCipherConstructor();
  18642. var data = stringToBytes(s);
  18643. data = cipher.decryptBlock(data, true);
  18644. return bytesToString(data);
  18645. }
  18646. };
  18647. return CipherTransform;
  18648. })();
  18649. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  18650. var defaultPasswordBytes = new Uint8Array([
  18651. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  18652. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  18653. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  18654. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  18655. function createEncryptionKey20(revision, password, ownerPassword,
  18656. ownerValidationSalt, ownerKeySalt, uBytes,
  18657. userPassword, userValidationSalt, userKeySalt,
  18658. ownerEncryption, userEncryption, perms) {
  18659. if (password) {
  18660. var passwordLength = Math.min(127, password.length);
  18661. password = password.subarray(0, passwordLength);
  18662. } else {
  18663. password = [];
  18664. }
  18665. var pdfAlgorithm;
  18666. if (revision === 6) {
  18667. pdfAlgorithm = new PDF20();
  18668. } else {
  18669. pdfAlgorithm = new PDF17();
  18670. }
  18671. if (pdfAlgorithm) {
  18672. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  18673. userPassword)) {
  18674. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  18675. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  18676. ownerValidationSalt,
  18677. uBytes,
  18678. ownerPassword)) {
  18679. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  18680. ownerEncryption);
  18681. }
  18682. }
  18683. return null;
  18684. }
  18685. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  18686. flags, revision, keyLength, encryptMetadata) {
  18687. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  18688. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  18689. if (password) {
  18690. n = Math.min(32, password.length);
  18691. for (; i < n; ++i) {
  18692. hashData[i] = password[i];
  18693. }
  18694. }
  18695. j = 0;
  18696. while (i < 32) {
  18697. hashData[i++] = defaultPasswordBytes[j++];
  18698. }
  18699. // as now the padded password in the hashData[0..i]
  18700. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  18701. hashData[i++] = ownerPassword[j];
  18702. }
  18703. hashData[i++] = flags & 0xFF;
  18704. hashData[i++] = (flags >> 8) & 0xFF;
  18705. hashData[i++] = (flags >> 16) & 0xFF;
  18706. hashData[i++] = (flags >>> 24) & 0xFF;
  18707. for (j = 0, n = fileId.length; j < n; ++j) {
  18708. hashData[i++] = fileId[j];
  18709. }
  18710. if (revision >= 4 && !encryptMetadata) {
  18711. hashData[i++] = 0xFF;
  18712. hashData[i++] = 0xFF;
  18713. hashData[i++] = 0xFF;
  18714. hashData[i++] = 0xFF;
  18715. }
  18716. var hash = calculateMD5(hashData, 0, i);
  18717. var keyLengthInBytes = keyLength >> 3;
  18718. if (revision >= 3) {
  18719. for (j = 0; j < 50; ++j) {
  18720. hash = calculateMD5(hash, 0, keyLengthInBytes);
  18721. }
  18722. }
  18723. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  18724. var cipher, checkData;
  18725. if (revision >= 3) {
  18726. for (i = 0; i < 32; ++i) {
  18727. hashData[i] = defaultPasswordBytes[i];
  18728. }
  18729. for (j = 0, n = fileId.length; j < n; ++j) {
  18730. hashData[i++] = fileId[j];
  18731. }
  18732. cipher = new ARCFourCipher(encryptionKey);
  18733. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  18734. n = encryptionKey.length;
  18735. var derivedKey = new Uint8Array(n), k;
  18736. for (j = 1; j <= 19; ++j) {
  18737. for (k = 0; k < n; ++k) {
  18738. derivedKey[k] = encryptionKey[k] ^ j;
  18739. }
  18740. cipher = new ARCFourCipher(derivedKey);
  18741. checkData = cipher.encryptBlock(checkData);
  18742. }
  18743. for (j = 0, n = checkData.length; j < n; ++j) {
  18744. if (userPassword[j] !== checkData[j]) {
  18745. return null;
  18746. }
  18747. }
  18748. } else {
  18749. cipher = new ARCFourCipher(encryptionKey);
  18750. checkData = cipher.encryptBlock(defaultPasswordBytes);
  18751. for (j = 0, n = checkData.length; j < n; ++j) {
  18752. if (userPassword[j] !== checkData[j]) {
  18753. return null;
  18754. }
  18755. }
  18756. }
  18757. return encryptionKey;
  18758. }
  18759. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  18760. var hashData = new Uint8Array(32), i = 0, j, n;
  18761. n = Math.min(32, password.length);
  18762. for (; i < n; ++i) {
  18763. hashData[i] = password[i];
  18764. }
  18765. j = 0;
  18766. while (i < 32) {
  18767. hashData[i++] = defaultPasswordBytes[j++];
  18768. }
  18769. var hash = calculateMD5(hashData, 0, i);
  18770. var keyLengthInBytes = keyLength >> 3;
  18771. if (revision >= 3) {
  18772. for (j = 0; j < 50; ++j) {
  18773. hash = calculateMD5(hash, 0, hash.length);
  18774. }
  18775. }
  18776. var cipher, userPassword;
  18777. if (revision >= 3) {
  18778. userPassword = ownerPassword;
  18779. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  18780. for (j = 19; j >= 0; j--) {
  18781. for (k = 0; k < keyLengthInBytes; ++k) {
  18782. derivedKey[k] = hash[k] ^ j;
  18783. }
  18784. cipher = new ARCFourCipher(derivedKey);
  18785. userPassword = cipher.encryptBlock(userPassword);
  18786. }
  18787. } else {
  18788. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  18789. userPassword = cipher.encryptBlock(ownerPassword);
  18790. }
  18791. return userPassword;
  18792. }
  18793. var identityName = Name.get('Identity');
  18794. function CipherTransformFactory(dict, fileId, password) {
  18795. var filter = dict.get('Filter');
  18796. if (!isName(filter) || filter.name !== 'Standard') {
  18797. error('unknown encryption method');
  18798. }
  18799. this.dict = dict;
  18800. var algorithm = dict.get('V');
  18801. if (!isInt(algorithm) ||
  18802. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  18803. algorithm !== 5)) {
  18804. error('unsupported encryption algorithm');
  18805. }
  18806. this.algorithm = algorithm;
  18807. var keyLength = dict.get('Length') || 40;
  18808. if (!isInt(keyLength) ||
  18809. keyLength < 40 || (keyLength % 8) !== 0) {
  18810. error('invalid key length');
  18811. }
  18812. // prepare keys
  18813. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  18814. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  18815. var flags = dict.get('P');
  18816. var revision = dict.get('R');
  18817. // meaningful when V is 4 or 5
  18818. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  18819. dict.get('EncryptMetadata') !== false);
  18820. this.encryptMetadata = encryptMetadata;
  18821. var fileIdBytes = stringToBytes(fileId);
  18822. var passwordBytes;
  18823. if (password) {
  18824. if (revision === 6) {
  18825. try {
  18826. password = utf8StringToString(password);
  18827. } catch (ex) {
  18828. warn('CipherTransformFactory: ' +
  18829. 'Unable to convert UTF8 encoded password.');
  18830. }
  18831. }
  18832. passwordBytes = stringToBytes(password);
  18833. }
  18834. var encryptionKey;
  18835. if (algorithm !== 5) {
  18836. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  18837. ownerPassword, userPassword, flags,
  18838. revision, keyLength, encryptMetadata);
  18839. }
  18840. else {
  18841. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  18842. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  18843. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  18844. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  18845. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  18846. var ownerEncryption = stringToBytes(dict.get('OE'));
  18847. var userEncryption = stringToBytes(dict.get('UE'));
  18848. var perms = stringToBytes(dict.get('Perms'));
  18849. encryptionKey =
  18850. createEncryptionKey20(revision, passwordBytes,
  18851. ownerPassword, ownerValidationSalt,
  18852. ownerKeySalt, uBytes,
  18853. userPassword, userValidationSalt,
  18854. userKeySalt, ownerEncryption,
  18855. userEncryption, perms);
  18856. }
  18857. if (!encryptionKey && !password) {
  18858. throw new PasswordException('No password given',
  18859. PasswordResponses.NEED_PASSWORD);
  18860. } else if (!encryptionKey && password) {
  18861. // Attempting use the password as an owner password
  18862. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  18863. revision, keyLength);
  18864. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  18865. ownerPassword, userPassword, flags,
  18866. revision, keyLength, encryptMetadata);
  18867. }
  18868. if (!encryptionKey) {
  18869. throw new PasswordException('Incorrect Password',
  18870. PasswordResponses.INCORRECT_PASSWORD);
  18871. }
  18872. this.encryptionKey = encryptionKey;
  18873. if (algorithm >= 4) {
  18874. this.cf = dict.get('CF');
  18875. this.stmf = dict.get('StmF') || identityName;
  18876. this.strf = dict.get('StrF') || identityName;
  18877. this.eff = dict.get('EFF') || this.stmf;
  18878. }
  18879. }
  18880. function buildObjectKey(num, gen, encryptionKey, isAes) {
  18881. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  18882. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  18883. key[i] = encryptionKey[i];
  18884. }
  18885. key[i++] = num & 0xFF;
  18886. key[i++] = (num >> 8) & 0xFF;
  18887. key[i++] = (num >> 16) & 0xFF;
  18888. key[i++] = gen & 0xFF;
  18889. key[i++] = (gen >> 8) & 0xFF;
  18890. if (isAes) {
  18891. key[i++] = 0x73;
  18892. key[i++] = 0x41;
  18893. key[i++] = 0x6C;
  18894. key[i++] = 0x54;
  18895. }
  18896. var hash = calculateMD5(key, 0, i);
  18897. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  18898. }
  18899. function buildCipherConstructor(cf, name, num, gen, key) {
  18900. var cryptFilter = cf.get(name.name);
  18901. var cfm;
  18902. if (cryptFilter !== null && cryptFilter !== undefined) {
  18903. cfm = cryptFilter.get('CFM');
  18904. }
  18905. if (!cfm || cfm.name === 'None') {
  18906. return function cipherTransformFactoryBuildCipherConstructorNone() {
  18907. return new NullCipher();
  18908. };
  18909. }
  18910. if ('V2' === cfm.name) {
  18911. return function cipherTransformFactoryBuildCipherConstructorV2() {
  18912. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  18913. };
  18914. }
  18915. if ('AESV2' === cfm.name) {
  18916. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  18917. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  18918. };
  18919. }
  18920. if ('AESV3' === cfm.name) {
  18921. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  18922. return new AES256Cipher(key);
  18923. };
  18924. }
  18925. error('Unknown crypto method');
  18926. }
  18927. CipherTransformFactory.prototype = {
  18928. createCipherTransform:
  18929. function CipherTransformFactory_createCipherTransform(num, gen) {
  18930. if (this.algorithm === 4 || this.algorithm === 5) {
  18931. return new CipherTransform(
  18932. buildCipherConstructor(this.cf, this.stmf,
  18933. num, gen, this.encryptionKey),
  18934. buildCipherConstructor(this.cf, this.strf,
  18935. num, gen, this.encryptionKey));
  18936. }
  18937. // algorithms 1 and 2
  18938. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  18939. var cipherConstructor = function buildCipherCipherConstructor() {
  18940. return new ARCFourCipher(key);
  18941. };
  18942. return new CipherTransform(cipherConstructor, cipherConstructor);
  18943. }
  18944. };
  18945. return CipherTransformFactory;
  18946. })();
  18947. exports.AES128Cipher = AES128Cipher;
  18948. exports.AES256Cipher = AES256Cipher;
  18949. exports.ARCFourCipher = ARCFourCipher;
  18950. exports.CipherTransformFactory = CipherTransformFactory;
  18951. exports.PDF17 = PDF17;
  18952. exports.PDF20 = PDF20;
  18953. exports.calculateMD5 = calculateMD5;
  18954. exports.calculateSHA256 = calculateSHA256;
  18955. exports.calculateSHA384 = calculateSHA384;
  18956. exports.calculateSHA512 = calculateSHA512;
  18957. }));
  18958. (function (root, factory) {
  18959. {
  18960. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  18961. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  18962. }
  18963. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  18964. var Util = sharedUtil.Util;
  18965. var bytesToString = sharedUtil.bytesToString;
  18966. var error = sharedUtil.error;
  18967. var Stream = coreStream.Stream;
  18968. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  18969. var coreFonts; // see _setCoreFonts below
  18970. var CFFParser; // = coreFonts.CFFParser;
  18971. var Encodings; // = coreFonts.Encodings;
  18972. var FontRendererFactory = (function FontRendererFactoryClosure() {
  18973. function getLong(data, offset) {
  18974. return (data[offset] << 24) | (data[offset + 1] << 16) |
  18975. (data[offset + 2] << 8) | data[offset + 3];
  18976. }
  18977. function getUshort(data, offset) {
  18978. return (data[offset] << 8) | data[offset + 1];
  18979. }
  18980. function parseCmap(data, start, end) {
  18981. var offset = (getUshort(data, start + 2) === 1 ?
  18982. getLong(data, start + 8) : getLong(data, start + 16));
  18983. var format = getUshort(data, start + offset);
  18984. var length, ranges, p, i;
  18985. if (format === 4) {
  18986. length = getUshort(data, start + offset + 2);
  18987. var segCount = getUshort(data, start + offset + 6) >> 1;
  18988. p = start + offset + 14;
  18989. ranges = [];
  18990. for (i = 0; i < segCount; i++, p += 2) {
  18991. ranges[i] = {end: getUshort(data, p)};
  18992. }
  18993. p += 2;
  18994. for (i = 0; i < segCount; i++, p += 2) {
  18995. ranges[i].start = getUshort(data, p);
  18996. }
  18997. for (i = 0; i < segCount; i++, p += 2) {
  18998. ranges[i].idDelta = getUshort(data, p);
  18999. }
  19000. for (i = 0; i < segCount; i++, p += 2) {
  19001. var idOffset = getUshort(data, p);
  19002. if (idOffset === 0) {
  19003. continue;
  19004. }
  19005. ranges[i].ids = [];
  19006. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19007. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19008. idOffset += 2;
  19009. }
  19010. }
  19011. return ranges;
  19012. } else if (format === 12) {
  19013. length = getLong(data, start + offset + 4);
  19014. var groups = getLong(data, start + offset + 12);
  19015. p = start + offset + 16;
  19016. ranges = [];
  19017. for (i = 0; i < groups; i++) {
  19018. ranges.push({
  19019. start: getLong(data, p),
  19020. end: getLong(data, p + 4),
  19021. idDelta: getLong(data, p + 8) - getLong(data, p)
  19022. });
  19023. p += 12;
  19024. }
  19025. return ranges;
  19026. }
  19027. error('not supported cmap: ' + format);
  19028. }
  19029. function parseCff(data, start, end) {
  19030. var properties = {};
  19031. var parser = new CFFParser(new Stream(data, start, end - start),
  19032. properties);
  19033. var cff = parser.parse();
  19034. return {
  19035. glyphs: cff.charStrings.objects,
  19036. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19037. cff.topDict.privateDict.subrsIndex.objects),
  19038. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19039. };
  19040. }
  19041. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19042. var itemSize, itemDecode;
  19043. if (isGlyphLocationsLong) {
  19044. itemSize = 4;
  19045. itemDecode = function fontItemDecodeLong(data, offset) {
  19046. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19047. (data[offset + 2] << 8) | data[offset + 3];
  19048. };
  19049. } else {
  19050. itemSize = 2;
  19051. itemDecode = function fontItemDecode(data, offset) {
  19052. return (data[offset] << 9) | (data[offset + 1] << 1);
  19053. };
  19054. }
  19055. var glyphs = [];
  19056. var startOffset = itemDecode(loca, 0);
  19057. for (var j = itemSize; j < loca.length; j += itemSize) {
  19058. var endOffset = itemDecode(loca, j);
  19059. glyphs.push(glyf.subarray(startOffset, endOffset));
  19060. startOffset = endOffset;
  19061. }
  19062. return glyphs;
  19063. }
  19064. function lookupCmap(ranges, unicode) {
  19065. var code = unicode.charCodeAt(0);
  19066. var l = 0, r = ranges.length - 1;
  19067. while (l < r) {
  19068. var c = (l + r + 1) >> 1;
  19069. if (code < ranges[c].start) {
  19070. r = c - 1;
  19071. } else {
  19072. l = c;
  19073. }
  19074. }
  19075. if (ranges[l].start <= code && code <= ranges[l].end) {
  19076. return (ranges[l].idDelta + (ranges[l].ids ?
  19077. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19078. }
  19079. return 0;
  19080. }
  19081. function compileGlyf(code, cmds, font) {
  19082. function moveTo(x, y) {
  19083. cmds.push({cmd: 'moveTo', args: [x, y]});
  19084. }
  19085. function lineTo(x, y) {
  19086. cmds.push({cmd: 'lineTo', args: [x, y]});
  19087. }
  19088. function quadraticCurveTo(xa, ya, x, y) {
  19089. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  19090. }
  19091. var i = 0;
  19092. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19093. var flags;
  19094. var x = 0, y = 0;
  19095. i += 10;
  19096. if (numberOfContours < 0) {
  19097. // composite glyph
  19098. do {
  19099. flags = (code[i] << 8) | code[i + 1];
  19100. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19101. i += 4;
  19102. var arg1, arg2;
  19103. if ((flags & 0x01)) {
  19104. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19105. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19106. i += 4;
  19107. } else {
  19108. arg1 = code[i++]; arg2 = code[i++];
  19109. }
  19110. if ((flags & 0x02)) {
  19111. x = arg1;
  19112. y = arg2;
  19113. } else {
  19114. x = 0; y = 0; // TODO "they are points" ?
  19115. }
  19116. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19117. if ((flags & 0x08)) {
  19118. scaleX =
  19119. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19120. i += 2;
  19121. } else if ((flags & 0x40)) {
  19122. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19123. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19124. i += 4;
  19125. } else if ((flags & 0x80)) {
  19126. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19127. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19128. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19129. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19130. i += 8;
  19131. }
  19132. var subglyph = font.glyphs[glyphIndex];
  19133. if (subglyph) {
  19134. cmds.push({cmd: 'save'});
  19135. cmds.push({cmd: 'transform',
  19136. args: [scaleX, scale01, scale10, scaleY, x, y]});
  19137. compileGlyf(subglyph, cmds, font);
  19138. cmds.push({cmd: 'restore'});
  19139. }
  19140. } while ((flags & 0x20));
  19141. } else {
  19142. // simple glyph
  19143. var endPtsOfContours = [];
  19144. var j, jj;
  19145. for (j = 0; j < numberOfContours; j++) {
  19146. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19147. i += 2;
  19148. }
  19149. var instructionLength = (code[i] << 8) | code[i + 1];
  19150. i += 2 + instructionLength; // skipping the instructions
  19151. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19152. var points = [];
  19153. while (points.length < numberOfPoints) {
  19154. flags = code[i++];
  19155. var repeat = 1;
  19156. if ((flags & 0x08)) {
  19157. repeat += code[i++];
  19158. }
  19159. while (repeat-- > 0) {
  19160. points.push({flags: flags});
  19161. }
  19162. }
  19163. for (j = 0; j < numberOfPoints; j++) {
  19164. switch (points[j].flags & 0x12) {
  19165. case 0x00:
  19166. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19167. i += 2;
  19168. break;
  19169. case 0x02:
  19170. x -= code[i++];
  19171. break;
  19172. case 0x12:
  19173. x += code[i++];
  19174. break;
  19175. }
  19176. points[j].x = x;
  19177. }
  19178. for (j = 0; j < numberOfPoints; j++) {
  19179. switch (points[j].flags & 0x24) {
  19180. case 0x00:
  19181. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19182. i += 2;
  19183. break;
  19184. case 0x04:
  19185. y -= code[i++];
  19186. break;
  19187. case 0x24:
  19188. y += code[i++];
  19189. break;
  19190. }
  19191. points[j].y = y;
  19192. }
  19193. var startPoint = 0;
  19194. for (i = 0; i < numberOfContours; i++) {
  19195. var endPoint = endPtsOfContours[i];
  19196. // contours might have implicit points, which is located in the middle
  19197. // between two neighboring off-curve points
  19198. var contour = points.slice(startPoint, endPoint + 1);
  19199. if ((contour[0].flags & 1)) {
  19200. contour.push(contour[0]); // using start point at the contour end
  19201. } else if ((contour[contour.length - 1].flags & 1)) {
  19202. // first is off-curve point, trying to use one from the end
  19203. contour.unshift(contour[contour.length - 1]);
  19204. } else {
  19205. // start and end are off-curve points, creating implicit one
  19206. var p = {
  19207. flags: 1,
  19208. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19209. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19210. };
  19211. contour.unshift(p);
  19212. contour.push(p);
  19213. }
  19214. moveTo(contour[0].x, contour[0].y);
  19215. for (j = 1, jj = contour.length; j < jj; j++) {
  19216. if ((contour[j].flags & 1)) {
  19217. lineTo(contour[j].x, contour[j].y);
  19218. } else if ((contour[j + 1].flags & 1)){
  19219. quadraticCurveTo(contour[j].x, contour[j].y,
  19220. contour[j + 1].x, contour[j + 1].y);
  19221. j++;
  19222. } else {
  19223. quadraticCurveTo(contour[j].x, contour[j].y,
  19224. (contour[j].x + contour[j + 1].x) / 2,
  19225. (contour[j].y + contour[j + 1].y) / 2);
  19226. }
  19227. }
  19228. startPoint = endPoint + 1;
  19229. }
  19230. }
  19231. }
  19232. function compileCharString(code, cmds, font) {
  19233. var stack = [];
  19234. var x = 0, y = 0;
  19235. var stems = 0;
  19236. function moveTo(x, y) {
  19237. cmds.push({cmd: 'moveTo', args: [x, y]});
  19238. }
  19239. function lineTo(x, y) {
  19240. cmds.push({cmd: 'lineTo', args: [x, y]});
  19241. }
  19242. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19243. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  19244. }
  19245. function parse(code) {
  19246. var i = 0;
  19247. while (i < code.length) {
  19248. var stackClean = false;
  19249. var v = code[i++];
  19250. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19251. switch (v) {
  19252. case 1: // hstem
  19253. stems += stack.length >> 1;
  19254. stackClean = true;
  19255. break;
  19256. case 3: // vstem
  19257. stems += stack.length >> 1;
  19258. stackClean = true;
  19259. break;
  19260. case 4: // vmoveto
  19261. y += stack.pop();
  19262. moveTo(x, y);
  19263. stackClean = true;
  19264. break;
  19265. case 5: // rlineto
  19266. while (stack.length > 0) {
  19267. x += stack.shift();
  19268. y += stack.shift();
  19269. lineTo(x, y);
  19270. }
  19271. break;
  19272. case 6: // hlineto
  19273. while (stack.length > 0) {
  19274. x += stack.shift();
  19275. lineTo(x, y);
  19276. if (stack.length === 0) {
  19277. break;
  19278. }
  19279. y += stack.shift();
  19280. lineTo(x, y);
  19281. }
  19282. break;
  19283. case 7: // vlineto
  19284. while (stack.length > 0) {
  19285. y += stack.shift();
  19286. lineTo(x, y);
  19287. if (stack.length === 0) {
  19288. break;
  19289. }
  19290. x += stack.shift();
  19291. lineTo(x, y);
  19292. }
  19293. break;
  19294. case 8: // rrcurveto
  19295. while (stack.length > 0) {
  19296. xa = x + stack.shift(); ya = y + stack.shift();
  19297. xb = xa + stack.shift(); yb = ya + stack.shift();
  19298. x = xb + stack.shift(); y = yb + stack.shift();
  19299. bezierCurveTo(xa, ya, xb, yb, x, y);
  19300. }
  19301. break;
  19302. case 10: // callsubr
  19303. n = stack.pop() + font.subrsBias;
  19304. subrCode = font.subrs[n];
  19305. if (subrCode) {
  19306. parse(subrCode);
  19307. }
  19308. break;
  19309. case 11: // return
  19310. return;
  19311. case 12:
  19312. v = code[i++];
  19313. switch (v) {
  19314. case 34: // flex
  19315. xa = x + stack.shift();
  19316. xb = xa + stack.shift(); y1 = y + stack.shift();
  19317. x = xb + stack.shift();
  19318. bezierCurveTo(xa, y, xb, y1, x, y1);
  19319. xa = x + stack.shift();
  19320. xb = xa + stack.shift();
  19321. x = xb + stack.shift();
  19322. bezierCurveTo(xa, y1, xb, y, x, y);
  19323. break;
  19324. case 35: // flex
  19325. xa = x + stack.shift(); ya = y + stack.shift();
  19326. xb = xa + stack.shift(); yb = ya + stack.shift();
  19327. x = xb + stack.shift(); y = yb + stack.shift();
  19328. bezierCurveTo(xa, ya, xb, yb, x, y);
  19329. xa = x + stack.shift(); ya = y + stack.shift();
  19330. xb = xa + stack.shift(); yb = ya + stack.shift();
  19331. x = xb + stack.shift(); y = yb + stack.shift();
  19332. bezierCurveTo(xa, ya, xb, yb, x, y);
  19333. stack.pop(); // fd
  19334. break;
  19335. case 36: // hflex1
  19336. xa = x + stack.shift(); y1 = y + stack.shift();
  19337. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19338. x = xb + stack.shift();
  19339. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19340. xa = x + stack.shift();
  19341. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19342. x = xb + stack.shift();
  19343. bezierCurveTo(xa, y2, xb, y3, x, y);
  19344. break;
  19345. case 37: // flex1
  19346. var x0 = x, y0 = y;
  19347. xa = x + stack.shift(); ya = y + stack.shift();
  19348. xb = xa + stack.shift(); yb = ya + stack.shift();
  19349. x = xb + stack.shift(); y = yb + stack.shift();
  19350. bezierCurveTo(xa, ya, xb, yb, x, y);
  19351. xa = x + stack.shift(); ya = y + stack.shift();
  19352. xb = xa + stack.shift(); yb = ya + stack.shift();
  19353. x = xb; y = yb;
  19354. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19355. x += stack.shift();
  19356. } else {
  19357. y += stack.shift();
  19358. }
  19359. bezierCurveTo(xa, ya, xb, yb, x, y);
  19360. break;
  19361. default:
  19362. error('unknown operator: 12 ' + v);
  19363. }
  19364. break;
  19365. case 14: // endchar
  19366. if (stack.length >= 4) {
  19367. var achar = stack.pop();
  19368. var bchar = stack.pop();
  19369. y = stack.pop();
  19370. x = stack.pop();
  19371. cmds.push({cmd: 'save'});
  19372. cmds.push({cmd: 'translate', args: [x, y]});
  19373. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19374. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19375. compileCharString(font.glyphs[gid], cmds, font);
  19376. cmds.push({cmd: 'restore'});
  19377. gid = lookupCmap(font.cmap, String.fromCharCode(
  19378. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19379. compileCharString(font.glyphs[gid], cmds, font);
  19380. }
  19381. return;
  19382. case 18: // hstemhm
  19383. stems += stack.length >> 1;
  19384. stackClean = true;
  19385. break;
  19386. case 19: // hintmask
  19387. stems += stack.length >> 1;
  19388. i += (stems + 7) >> 3;
  19389. stackClean = true;
  19390. break;
  19391. case 20: // cntrmask
  19392. stems += stack.length >> 1;
  19393. i += (stems + 7) >> 3;
  19394. stackClean = true;
  19395. break;
  19396. case 21: // rmoveto
  19397. y += stack.pop();
  19398. x += stack.pop();
  19399. moveTo(x, y);
  19400. stackClean = true;
  19401. break;
  19402. case 22: // hmoveto
  19403. x += stack.pop();
  19404. moveTo(x, y);
  19405. stackClean = true;
  19406. break;
  19407. case 23: // vstemhm
  19408. stems += stack.length >> 1;
  19409. stackClean = true;
  19410. break;
  19411. case 24: // rcurveline
  19412. while (stack.length > 2) {
  19413. xa = x + stack.shift(); ya = y + stack.shift();
  19414. xb = xa + stack.shift(); yb = ya + stack.shift();
  19415. x = xb + stack.shift(); y = yb + stack.shift();
  19416. bezierCurveTo(xa, ya, xb, yb, x, y);
  19417. }
  19418. x += stack.shift();
  19419. y += stack.shift();
  19420. lineTo(x, y);
  19421. break;
  19422. case 25: // rlinecurve
  19423. while (stack.length > 6) {
  19424. x += stack.shift();
  19425. y += stack.shift();
  19426. lineTo(x, y);
  19427. }
  19428. xa = x + stack.shift(); ya = y + stack.shift();
  19429. xb = xa + stack.shift(); yb = ya + stack.shift();
  19430. x = xb + stack.shift(); y = yb + stack.shift();
  19431. bezierCurveTo(xa, ya, xb, yb, x, y);
  19432. break;
  19433. case 26: // vvcurveto
  19434. if (stack.length % 2) {
  19435. x += stack.shift();
  19436. }
  19437. while (stack.length > 0) {
  19438. xa = x; ya = y + stack.shift();
  19439. xb = xa + stack.shift(); yb = ya + stack.shift();
  19440. x = xb; y = yb + stack.shift();
  19441. bezierCurveTo(xa, ya, xb, yb, x, y);
  19442. }
  19443. break;
  19444. case 27: // hhcurveto
  19445. if (stack.length % 2) {
  19446. y += stack.shift();
  19447. }
  19448. while (stack.length > 0) {
  19449. xa = x + stack.shift(); ya = y;
  19450. xb = xa + stack.shift(); yb = ya + stack.shift();
  19451. x = xb + stack.shift(); y = yb;
  19452. bezierCurveTo(xa, ya, xb, yb, x, y);
  19453. }
  19454. break;
  19455. case 28:
  19456. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19457. i += 2;
  19458. break;
  19459. case 29: // callgsubr
  19460. n = stack.pop() + font.gsubrsBias;
  19461. subrCode = font.gsubrs[n];
  19462. if (subrCode) {
  19463. parse(subrCode);
  19464. }
  19465. break;
  19466. case 30: // vhcurveto
  19467. while (stack.length > 0) {
  19468. xa = x; ya = y + stack.shift();
  19469. xb = xa + stack.shift(); yb = ya + stack.shift();
  19470. x = xb + stack.shift();
  19471. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19472. bezierCurveTo(xa, ya, xb, yb, x, y);
  19473. if (stack.length === 0) {
  19474. break;
  19475. }
  19476. xa = x + stack.shift(); ya = y;
  19477. xb = xa + stack.shift(); yb = ya + stack.shift();
  19478. y = yb + stack.shift();
  19479. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19480. bezierCurveTo(xa, ya, xb, yb, x, y);
  19481. }
  19482. break;
  19483. case 31: // hvcurveto
  19484. while (stack.length > 0) {
  19485. xa = x + stack.shift(); ya = y;
  19486. xb = xa + stack.shift(); yb = ya + stack.shift();
  19487. y = yb + stack.shift();
  19488. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19489. bezierCurveTo(xa, ya, xb, yb, x, y);
  19490. if (stack.length === 0) {
  19491. break;
  19492. }
  19493. xa = x; ya = y + stack.shift();
  19494. xb = xa + stack.shift(); yb = ya + stack.shift();
  19495. x = xb + stack.shift();
  19496. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19497. bezierCurveTo(xa, ya, xb, yb, x, y);
  19498. }
  19499. break;
  19500. default:
  19501. if (v < 32) {
  19502. error('unknown operator: ' + v);
  19503. }
  19504. if (v < 247) {
  19505. stack.push(v - 139);
  19506. } else if (v < 251) {
  19507. stack.push((v - 247) * 256 + code[i++] + 108);
  19508. } else if (v < 255) {
  19509. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19510. } else {
  19511. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19512. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19513. i += 4;
  19514. }
  19515. break;
  19516. }
  19517. if (stackClean) {
  19518. stack.length = 0;
  19519. }
  19520. }
  19521. }
  19522. parse(code);
  19523. }
  19524. var noop = '';
  19525. function CompiledFont(fontMatrix) {
  19526. this.compiledGlyphs = {};
  19527. this.fontMatrix = fontMatrix;
  19528. }
  19529. CompiledFont.prototype = {
  19530. getPathJs: function (unicode) {
  19531. var gid = lookupCmap(this.cmap, unicode);
  19532. var fn = this.compiledGlyphs[gid];
  19533. if (!fn) {
  19534. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19535. }
  19536. return fn;
  19537. },
  19538. compileGlyph: function (code) {
  19539. if (!code || code.length === 0 || code[0] === 14) {
  19540. return noop;
  19541. }
  19542. var cmds = [];
  19543. cmds.push({cmd: 'save'});
  19544. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  19545. cmds.push({cmd: 'scale', args: ['size', '-size']});
  19546. this.compileGlyphImpl(code, cmds);
  19547. cmds.push({cmd: 'restore'});
  19548. return cmds;
  19549. },
  19550. compileGlyphImpl: function () {
  19551. error('Children classes should implement this.');
  19552. },
  19553. hasBuiltPath: function (unicode) {
  19554. var gid = lookupCmap(this.cmap, unicode);
  19555. return gid in this.compiledGlyphs;
  19556. }
  19557. };
  19558. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19559. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19560. CompiledFont.call(this, fontMatrix);
  19561. this.glyphs = glyphs;
  19562. this.cmap = cmap;
  19563. this.compiledGlyphs = [];
  19564. }
  19565. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19566. compileGlyphImpl: function (code, cmds) {
  19567. compileGlyf(code, cmds, this);
  19568. }
  19569. });
  19570. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19571. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19572. CompiledFont.call(this, fontMatrix);
  19573. this.glyphs = cffInfo.glyphs;
  19574. this.gsubrs = cffInfo.gsubrs || [];
  19575. this.subrs = cffInfo.subrs || [];
  19576. this.cmap = cmap;
  19577. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19578. this.compiledGlyphs = [];
  19579. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19580. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19581. this.subrsBias = (this.subrs.length < 1240 ?
  19582. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19583. }
  19584. Util.inherit(Type2Compiled, CompiledFont, {
  19585. compileGlyphImpl: function (code, cmds) {
  19586. compileCharString(code, cmds, this);
  19587. }
  19588. });
  19589. return {
  19590. create: function FontRendererFactory_create(font) {
  19591. var data = new Uint8Array(font.data);
  19592. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19593. var numTables = getUshort(data, 4);
  19594. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19595. var tag = bytesToString(data.subarray(p, p + 4));
  19596. var offset = getLong(data, p + 8);
  19597. var length = getLong(data, p + 12);
  19598. switch (tag) {
  19599. case 'cmap':
  19600. cmap = parseCmap(data, offset, offset + length);
  19601. break;
  19602. case 'glyf':
  19603. glyf = data.subarray(offset, offset + length);
  19604. break;
  19605. case 'loca':
  19606. loca = data.subarray(offset, offset + length);
  19607. break;
  19608. case 'head':
  19609. unitsPerEm = getUshort(data, offset + 18);
  19610. indexToLocFormat = getUshort(data, offset + 50);
  19611. break;
  19612. case 'CFF ':
  19613. cff = parseCff(data, offset, offset + length);
  19614. break;
  19615. }
  19616. }
  19617. if (glyf) {
  19618. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19619. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19620. return new TrueTypeCompiled(
  19621. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19622. } else {
  19623. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19624. }
  19625. }
  19626. };
  19627. })();
  19628. // TODO refactor to remove cyclic dependency on fonts.js
  19629. function _setCoreFonts(coreFonts_) {
  19630. coreFonts = coreFonts_;
  19631. Encodings = coreFonts_.Encodings;
  19632. CFFParser = coreFonts_.CFFParser;
  19633. }
  19634. exports._setCoreFonts = _setCoreFonts;
  19635. exports.FontRendererFactory = FontRendererFactory;
  19636. }));
  19637. (function (root, factory) {
  19638. {
  19639. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  19640. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19641. }
  19642. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19643. var MissingDataException = sharedUtil.MissingDataException;
  19644. var StreamType = sharedUtil.StreamType;
  19645. var assert = sharedUtil.assert;
  19646. var error = sharedUtil.error;
  19647. var info = sharedUtil.info;
  19648. var isArray = sharedUtil.isArray;
  19649. var isInt = sharedUtil.isInt;
  19650. var isNum = sharedUtil.isNum;
  19651. var isString = sharedUtil.isString;
  19652. var warn = sharedUtil.warn;
  19653. var Cmd = corePrimitives.Cmd;
  19654. var Dict = corePrimitives.Dict;
  19655. var Name = corePrimitives.Name;
  19656. var Ref = corePrimitives.Ref;
  19657. var isCmd = corePrimitives.isCmd;
  19658. var isDict = corePrimitives.isDict;
  19659. var isName = corePrimitives.isName;
  19660. var Ascii85Stream = coreStream.Ascii85Stream;
  19661. var AsciiHexStream = coreStream.AsciiHexStream;
  19662. var CCITTFaxStream = coreStream.CCITTFaxStream;
  19663. var FlateStream = coreStream.FlateStream;
  19664. var Jbig2Stream = coreStream.Jbig2Stream;
  19665. var JpegStream = coreStream.JpegStream;
  19666. var JpxStream = coreStream.JpxStream;
  19667. var LZWStream = coreStream.LZWStream;
  19668. var NullStream = coreStream.NullStream;
  19669. var PredictorStream = coreStream.PredictorStream;
  19670. var RunLengthStream = coreStream.RunLengthStream;
  19671. var EOF = {};
  19672. function isEOF(v) {
  19673. return (v === EOF);
  19674. }
  19675. var MAX_LENGTH_TO_CACHE = 1000;
  19676. var Parser = (function ParserClosure() {
  19677. function Parser(lexer, allowStreams, xref) {
  19678. this.lexer = lexer;
  19679. this.allowStreams = allowStreams;
  19680. this.xref = xref;
  19681. this.imageCache = {};
  19682. this.refill();
  19683. }
  19684. Parser.prototype = {
  19685. refill: function Parser_refill() {
  19686. this.buf1 = this.lexer.getObj();
  19687. this.buf2 = this.lexer.getObj();
  19688. },
  19689. shift: function Parser_shift() {
  19690. if (isCmd(this.buf2, 'ID')) {
  19691. this.buf1 = this.buf2;
  19692. this.buf2 = null;
  19693. } else {
  19694. this.buf1 = this.buf2;
  19695. this.buf2 = this.lexer.getObj();
  19696. }
  19697. },
  19698. tryShift: function Parser_tryShift() {
  19699. try {
  19700. this.shift();
  19701. return true;
  19702. } catch (e) {
  19703. if (e instanceof MissingDataException) {
  19704. throw e;
  19705. }
  19706. // Upon failure, the caller should reset this.lexer.pos to a known good
  19707. // state and call this.shift() twice to reset the buffers.
  19708. return false;
  19709. }
  19710. },
  19711. getObj: function Parser_getObj(cipherTransform) {
  19712. var buf1 = this.buf1;
  19713. this.shift();
  19714. if (buf1 instanceof Cmd) {
  19715. switch (buf1.cmd) {
  19716. case 'BI': // inline image
  19717. return this.makeInlineImage(cipherTransform);
  19718. case '[': // array
  19719. var array = [];
  19720. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  19721. array.push(this.getObj(cipherTransform));
  19722. }
  19723. if (isEOF(this.buf1)) {
  19724. error('End of file inside array');
  19725. }
  19726. this.shift();
  19727. return array;
  19728. case '<<': // dictionary or stream
  19729. var dict = new Dict(this.xref);
  19730. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  19731. if (!isName(this.buf1)) {
  19732. info('Malformed dictionary: key must be a name object');
  19733. this.shift();
  19734. continue;
  19735. }
  19736. var key = this.buf1.name;
  19737. this.shift();
  19738. if (isEOF(this.buf1)) {
  19739. break;
  19740. }
  19741. dict.set(key, this.getObj(cipherTransform));
  19742. }
  19743. if (isEOF(this.buf1)) {
  19744. error('End of file inside dictionary');
  19745. }
  19746. // Stream objects are not allowed inside content streams or
  19747. // object streams.
  19748. if (isCmd(this.buf2, 'stream')) {
  19749. return (this.allowStreams ?
  19750. this.makeStream(dict, cipherTransform) : dict);
  19751. }
  19752. this.shift();
  19753. return dict;
  19754. default: // simple object
  19755. return buf1;
  19756. }
  19757. }
  19758. if (isInt(buf1)) { // indirect reference or integer
  19759. var num = buf1;
  19760. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  19761. var ref = new Ref(num, this.buf1);
  19762. this.shift();
  19763. this.shift();
  19764. return ref;
  19765. }
  19766. return num;
  19767. }
  19768. if (isString(buf1)) { // string
  19769. var str = buf1;
  19770. if (cipherTransform) {
  19771. str = cipherTransform.decryptString(str);
  19772. }
  19773. return str;
  19774. }
  19775. // simple object
  19776. return buf1;
  19777. },
  19778. /**
  19779. * Find the end of the stream by searching for the /EI\s/.
  19780. * @returns {number} The inline stream length.
  19781. */
  19782. findDefaultInlineStreamEnd:
  19783. function Parser_findDefaultInlineStreamEnd(stream) {
  19784. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  19785. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  19786. while ((ch = stream.getByte()) !== -1) {
  19787. if (state === 0) {
  19788. state = (ch === E) ? 1 : 0;
  19789. } else if (state === 1) {
  19790. state = (ch === I) ? 2 : 0;
  19791. } else {
  19792. assert(state === 2);
  19793. if (ch === SPACE || ch === LF || ch === CR) {
  19794. // Let's check the next five bytes are ASCII... just be sure.
  19795. n = 5;
  19796. followingBytes = stream.peekBytes(n);
  19797. for (i = 0; i < n; i++) {
  19798. ch = followingBytes[i];
  19799. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  19800. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  19801. // it's binary stuff. Resetting the state.
  19802. state = 0;
  19803. break;
  19804. }
  19805. }
  19806. if (state === 2) {
  19807. break; // Finished!
  19808. }
  19809. } else {
  19810. state = 0;
  19811. }
  19812. }
  19813. }
  19814. return ((stream.pos - 4) - startPos);
  19815. },
  19816. /**
  19817. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  19818. * @returns {number} The inline stream length.
  19819. */
  19820. findDCTDecodeInlineStreamEnd:
  19821. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  19822. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  19823. while ((b = stream.getByte()) !== -1) {
  19824. if (b !== 0xFF) { // Not a valid marker.
  19825. continue;
  19826. }
  19827. switch (stream.getByte()) {
  19828. case 0x00: // Byte stuffing.
  19829. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  19830. break;
  19831. case 0xFF: // Fill byte.
  19832. // Avoid skipping a valid marker, resetting the stream position.
  19833. stream.skip(-1);
  19834. break;
  19835. case 0xD9: // EOI
  19836. foundEOI = true;
  19837. break;
  19838. case 0xC0: // SOF0
  19839. case 0xC1: // SOF1
  19840. case 0xC2: // SOF2
  19841. case 0xC3: // SOF3
  19842. case 0xC5: // SOF5
  19843. case 0xC6: // SOF6
  19844. case 0xC7: // SOF7
  19845. case 0xC9: // SOF9
  19846. case 0xCA: // SOF10
  19847. case 0xCB: // SOF11
  19848. case 0xCD: // SOF13
  19849. case 0xCE: // SOF14
  19850. case 0xCF: // SOF15
  19851. case 0xC4: // DHT
  19852. case 0xCC: // DAC
  19853. case 0xDA: // SOS
  19854. case 0xDB: // DQT
  19855. case 0xDC: // DNL
  19856. case 0xDD: // DRI
  19857. case 0xDE: // DHP
  19858. case 0xDF: // EXP
  19859. case 0xE0: // APP0
  19860. case 0xE1: // APP1
  19861. case 0xE2: // APP2
  19862. case 0xE3: // APP3
  19863. case 0xE4: // APP4
  19864. case 0xE5: // APP5
  19865. case 0xE6: // APP6
  19866. case 0xE7: // APP7
  19867. case 0xE8: // APP8
  19868. case 0xE9: // APP9
  19869. case 0xEA: // APP10
  19870. case 0xEB: // APP11
  19871. case 0xEC: // APP12
  19872. case 0xED: // APP13
  19873. case 0xEE: // APP14
  19874. case 0xEF: // APP15
  19875. case 0xFE: // COM
  19876. // The marker should be followed by the length of the segment.
  19877. markerLength = stream.getUint16();
  19878. if (markerLength > 2) {
  19879. // |markerLength| contains the byte length of the marker segment,
  19880. // including its own length (2 bytes) and excluding the marker.
  19881. stream.skip(markerLength - 2); // Jump to the next marker.
  19882. } else {
  19883. // The marker length is invalid, resetting the stream position.
  19884. stream.skip(-2);
  19885. }
  19886. break;
  19887. }
  19888. if (foundEOI) {
  19889. break;
  19890. }
  19891. }
  19892. length = stream.pos - startPos;
  19893. if (b === -1) {
  19894. warn('Inline DCTDecode image stream: ' +
  19895. 'EOI marker not found, searching for /EI/ instead.');
  19896. stream.skip(-length); // Reset the stream position.
  19897. return this.findDefaultInlineStreamEnd(stream);
  19898. }
  19899. this.inlineStreamSkipEI(stream);
  19900. return length;
  19901. },
  19902. /**
  19903. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  19904. * @returns {number} The inline stream length.
  19905. */
  19906. findASCII85DecodeInlineStreamEnd:
  19907. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  19908. var TILDE = 0x7E, GT = 0x3E;
  19909. var startPos = stream.pos, ch, length;
  19910. while ((ch = stream.getByte()) !== -1) {
  19911. if (ch === TILDE && stream.peekByte() === GT) {
  19912. stream.skip();
  19913. break;
  19914. }
  19915. }
  19916. length = stream.pos - startPos;
  19917. if (ch === -1) {
  19918. warn('Inline ASCII85Decode image stream: ' +
  19919. 'EOD marker not found, searching for /EI/ instead.');
  19920. stream.skip(-length); // Reset the stream position.
  19921. return this.findDefaultInlineStreamEnd(stream);
  19922. }
  19923. this.inlineStreamSkipEI(stream);
  19924. return length;
  19925. },
  19926. /**
  19927. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  19928. * @returns {number} The inline stream length.
  19929. */
  19930. findASCIIHexDecodeInlineStreamEnd:
  19931. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  19932. var GT = 0x3E;
  19933. var startPos = stream.pos, ch, length;
  19934. while ((ch = stream.getByte()) !== -1) {
  19935. if (ch === GT) {
  19936. break;
  19937. }
  19938. }
  19939. length = stream.pos - startPos;
  19940. if (ch === -1) {
  19941. warn('Inline ASCIIHexDecode image stream: ' +
  19942. 'EOD marker not found, searching for /EI/ instead.');
  19943. stream.skip(-length); // Reset the stream position.
  19944. return this.findDefaultInlineStreamEnd(stream);
  19945. }
  19946. this.inlineStreamSkipEI(stream);
  19947. return length;
  19948. },
  19949. /**
  19950. * Skip over the /EI/ for streams where we search for an EOD marker.
  19951. */
  19952. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  19953. var E = 0x45, I = 0x49;
  19954. var state = 0, ch;
  19955. while ((ch = stream.getByte()) !== -1) {
  19956. if (state === 0) {
  19957. state = (ch === E) ? 1 : 0;
  19958. } else if (state === 1) {
  19959. state = (ch === I) ? 2 : 0;
  19960. } else if (state === 2) {
  19961. break;
  19962. }
  19963. }
  19964. },
  19965. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  19966. var lexer = this.lexer;
  19967. var stream = lexer.stream;
  19968. // Parse dictionary.
  19969. var dict = new Dict(this.xref);
  19970. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  19971. if (!isName(this.buf1)) {
  19972. error('Dictionary key must be a name object');
  19973. }
  19974. var key = this.buf1.name;
  19975. this.shift();
  19976. if (isEOF(this.buf1)) {
  19977. break;
  19978. }
  19979. dict.set(key, this.getObj(cipherTransform));
  19980. }
  19981. // Extract the name of the first (i.e. the current) image filter.
  19982. var filter = dict.get('Filter', 'F'), filterName;
  19983. if (isName(filter)) {
  19984. filterName = filter.name;
  19985. } else if (isArray(filter) && isName(filter[0])) {
  19986. filterName = filter[0].name;
  19987. }
  19988. // Parse image stream.
  19989. var startPos = stream.pos, length, i, ii;
  19990. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  19991. length = this.findDCTDecodeInlineStreamEnd(stream);
  19992. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  19993. length = this.findASCII85DecodeInlineStreamEnd(stream);
  19994. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  19995. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  19996. } else {
  19997. length = this.findDefaultInlineStreamEnd(stream);
  19998. }
  19999. var imageStream = stream.makeSubStream(startPos, length, dict);
  20000. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  20001. // adler32 checksum.
  20002. var adler32;
  20003. if (length < MAX_LENGTH_TO_CACHE) {
  20004. var imageBytes = imageStream.getBytes();
  20005. imageStream.reset();
  20006. var a = 1;
  20007. var b = 0;
  20008. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  20009. // No modulo required in the loop if imageBytes.length < 5552.
  20010. a += imageBytes[i] & 0xff;
  20011. b += a;
  20012. }
  20013. adler32 = ((b % 65521) << 16) | (a % 65521);
  20014. if (this.imageCache.adler32 === adler32) {
  20015. this.buf2 = Cmd.get('EI');
  20016. this.shift();
  20017. this.imageCache[adler32].reset();
  20018. return this.imageCache[adler32];
  20019. }
  20020. }
  20021. if (cipherTransform) {
  20022. imageStream = cipherTransform.createStream(imageStream, length);
  20023. }
  20024. imageStream = this.filter(imageStream, dict, length);
  20025. imageStream.dict = dict;
  20026. if (adler32 !== undefined) {
  20027. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  20028. this.imageCache[adler32] = imageStream;
  20029. }
  20030. this.buf2 = Cmd.get('EI');
  20031. this.shift();
  20032. return imageStream;
  20033. },
  20034. makeStream: function Parser_makeStream(dict, cipherTransform) {
  20035. var lexer = this.lexer;
  20036. var stream = lexer.stream;
  20037. // get stream start position
  20038. lexer.skipToNextLine();
  20039. var pos = stream.pos - 1;
  20040. // get length
  20041. var length = dict.get('Length');
  20042. if (!isInt(length)) {
  20043. info('Bad ' + length + ' attribute in stream');
  20044. length = 0;
  20045. }
  20046. // skip over the stream data
  20047. stream.pos = pos + length;
  20048. lexer.nextChar();
  20049. // Shift '>>' and check whether the new object marks the end of the stream
  20050. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  20051. this.shift(); // 'stream'
  20052. } else {
  20053. // bad stream length, scanning for endstream
  20054. stream.pos = pos;
  20055. var SCAN_BLOCK_SIZE = 2048;
  20056. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  20057. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  20058. 0x61, 0x6D];
  20059. var skipped = 0, found = false, i, j;
  20060. while (stream.pos < stream.end) {
  20061. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  20062. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  20063. if (scanLength <= 0) {
  20064. break;
  20065. }
  20066. found = false;
  20067. for (i = 0, j = 0; i < scanLength; i++) {
  20068. var b = scanBytes[i];
  20069. if (b !== ENDSTREAM_SIGNATURE[j]) {
  20070. i -= j;
  20071. j = 0;
  20072. } else {
  20073. j++;
  20074. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  20075. i++;
  20076. found = true;
  20077. break;
  20078. }
  20079. }
  20080. }
  20081. if (found) {
  20082. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  20083. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  20084. break;
  20085. }
  20086. skipped += scanLength;
  20087. stream.pos += scanLength;
  20088. }
  20089. if (!found) {
  20090. error('Missing endstream');
  20091. }
  20092. length = skipped;
  20093. lexer.nextChar();
  20094. this.shift();
  20095. this.shift();
  20096. }
  20097. this.shift(); // 'endstream'
  20098. stream = stream.makeSubStream(pos, length, dict);
  20099. if (cipherTransform) {
  20100. stream = cipherTransform.createStream(stream, length);
  20101. }
  20102. stream = this.filter(stream, dict, length);
  20103. stream.dict = dict;
  20104. return stream;
  20105. },
  20106. filter: function Parser_filter(stream, dict, length) {
  20107. var filter = dict.get('Filter', 'F');
  20108. var params = dict.get('DecodeParms', 'DP');
  20109. if (isName(filter)) {
  20110. return this.makeFilter(stream, filter.name, length, params);
  20111. }
  20112. var maybeLength = length;
  20113. if (isArray(filter)) {
  20114. var filterArray = filter;
  20115. var paramsArray = params;
  20116. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  20117. filter = filterArray[i];
  20118. if (!isName(filter)) {
  20119. error('Bad filter name: ' + filter);
  20120. }
  20121. params = null;
  20122. if (isArray(paramsArray) && (i in paramsArray)) {
  20123. params = paramsArray[i];
  20124. }
  20125. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  20126. // after the first stream the length variable is invalid
  20127. maybeLength = null;
  20128. }
  20129. }
  20130. return stream;
  20131. },
  20132. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  20133. if (stream.dict.get('Length') === 0 && !maybeLength) {
  20134. warn('Empty "' + name + '" stream.');
  20135. return new NullStream(stream);
  20136. }
  20137. try {
  20138. if (params && this.xref) {
  20139. params = this.xref.fetchIfRef(params);
  20140. }
  20141. var xrefStreamStats = this.xref.stats.streamTypes;
  20142. if (name === 'FlateDecode' || name === 'Fl') {
  20143. xrefStreamStats[StreamType.FLATE] = true;
  20144. if (params) {
  20145. return new PredictorStream(new FlateStream(stream, maybeLength),
  20146. maybeLength, params);
  20147. }
  20148. return new FlateStream(stream, maybeLength);
  20149. }
  20150. if (name === 'LZWDecode' || name === 'LZW') {
  20151. xrefStreamStats[StreamType.LZW] = true;
  20152. var earlyChange = 1;
  20153. if (params) {
  20154. if (params.has('EarlyChange')) {
  20155. earlyChange = params.get('EarlyChange');
  20156. }
  20157. return new PredictorStream(
  20158. new LZWStream(stream, maybeLength, earlyChange),
  20159. maybeLength, params);
  20160. }
  20161. return new LZWStream(stream, maybeLength, earlyChange);
  20162. }
  20163. if (name === 'DCTDecode' || name === 'DCT') {
  20164. xrefStreamStats[StreamType.DCT] = true;
  20165. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  20166. }
  20167. if (name === 'JPXDecode' || name === 'JPX') {
  20168. xrefStreamStats[StreamType.JPX] = true;
  20169. return new JpxStream(stream, maybeLength, stream.dict);
  20170. }
  20171. if (name === 'ASCII85Decode' || name === 'A85') {
  20172. xrefStreamStats[StreamType.A85] = true;
  20173. return new Ascii85Stream(stream, maybeLength);
  20174. }
  20175. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  20176. xrefStreamStats[StreamType.AHX] = true;
  20177. return new AsciiHexStream(stream, maybeLength);
  20178. }
  20179. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  20180. xrefStreamStats[StreamType.CCF] = true;
  20181. return new CCITTFaxStream(stream, maybeLength, params);
  20182. }
  20183. if (name === 'RunLengthDecode' || name === 'RL') {
  20184. xrefStreamStats[StreamType.RL] = true;
  20185. return new RunLengthStream(stream, maybeLength);
  20186. }
  20187. if (name === 'JBIG2Decode') {
  20188. xrefStreamStats[StreamType.JBIG] = true;
  20189. return new Jbig2Stream(stream, maybeLength, stream.dict);
  20190. }
  20191. warn('filter "' + name + '" not supported yet');
  20192. return stream;
  20193. } catch (ex) {
  20194. if (ex instanceof MissingDataException) {
  20195. throw ex;
  20196. }
  20197. warn('Invalid stream: \"' + ex + '\"');
  20198. return new NullStream(stream);
  20199. }
  20200. }
  20201. };
  20202. return Parser;
  20203. })();
  20204. var Lexer = (function LexerClosure() {
  20205. function Lexer(stream, knownCommands) {
  20206. this.stream = stream;
  20207. this.nextChar();
  20208. // While lexing, we build up many strings one char at a time. Using += for
  20209. // this can result in lots of garbage strings. It's better to build an
  20210. // array of single-char strings and then join() them together at the end.
  20211. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  20212. // purpose uses less memory than using a new array for each string.
  20213. this.strBuf = [];
  20214. // The PDFs might have "glued" commands with other commands, operands or
  20215. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  20216. // commands and their prefixes. The prefixes are built the following way:
  20217. // if there a command that is a prefix of the other valid command or
  20218. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  20219. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  20220. // other commands or literals as a prefix. The knowCommands is optional.
  20221. this.knownCommands = knownCommands;
  20222. }
  20223. Lexer.isSpace = function Lexer_isSpace(ch) {
  20224. // Space is one of the following characters: SPACE, TAB, CR or LF.
  20225. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  20226. };
  20227. // A '1' in this array means the character is white space. A '1' or
  20228. // '2' means the character ends a name or command.
  20229. var specialChars = [
  20230. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  20231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  20232. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  20233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  20234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  20235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  20236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  20237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  20238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  20239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  20240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  20241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  20242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  20243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  20244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  20245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  20246. ];
  20247. function toHexDigit(ch) {
  20248. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20249. return ch & 0x0F;
  20250. }
  20251. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20252. // 'A'-'F', 'a'-'f'
  20253. return (ch & 0x0F) + 9;
  20254. }
  20255. return -1;
  20256. }
  20257. Lexer.prototype = {
  20258. nextChar: function Lexer_nextChar() {
  20259. return (this.currentChar = this.stream.getByte());
  20260. },
  20261. peekChar: function Lexer_peekChar() {
  20262. return this.stream.peekByte();
  20263. },
  20264. getNumber: function Lexer_getNumber() {
  20265. var ch = this.currentChar;
  20266. var eNotation = false;
  20267. var divideBy = 0; // different from 0 if it's a floating point value
  20268. var sign = 1;
  20269. if (ch === 0x2D) { // '-'
  20270. sign = -1;
  20271. ch = this.nextChar();
  20272. if (ch === 0x2D) { // '-'
  20273. // Ignore double negative (this is consistent with Adobe Reader).
  20274. ch = this.nextChar();
  20275. }
  20276. } else if (ch === 0x2B) { // '+'
  20277. ch = this.nextChar();
  20278. }
  20279. if (ch === 0x2E) { // '.'
  20280. divideBy = 10;
  20281. ch = this.nextChar();
  20282. }
  20283. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20284. error('Invalid number: ' + String.fromCharCode(ch));
  20285. return 0;
  20286. }
  20287. var baseValue = ch - 0x30; // '0'
  20288. var powerValue = 0;
  20289. var powerValueSign = 1;
  20290. while ((ch = this.nextChar()) >= 0) {
  20291. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  20292. var currentDigit = ch - 0x30; // '0'
  20293. if (eNotation) { // We are after an 'e' or 'E'
  20294. powerValue = powerValue * 10 + currentDigit;
  20295. } else {
  20296. if (divideBy !== 0) { // We are after a point
  20297. divideBy *= 10;
  20298. }
  20299. baseValue = baseValue * 10 + currentDigit;
  20300. }
  20301. } else if (ch === 0x2E) { // '.'
  20302. if (divideBy === 0) {
  20303. divideBy = 1;
  20304. } else {
  20305. // A number can have only one '.'
  20306. break;
  20307. }
  20308. } else if (ch === 0x2D) { // '-'
  20309. // ignore minus signs in the middle of numbers to match
  20310. // Adobe's behavior
  20311. warn('Badly formated number');
  20312. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  20313. // 'E' can be either a scientific notation or the beginning of a new
  20314. // operator
  20315. ch = this.peekChar();
  20316. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  20317. powerValueSign = (ch === 0x2D) ? -1 : 1;
  20318. this.nextChar(); // Consume the sign character
  20319. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20320. // The 'E' must be the beginning of a new operator
  20321. break;
  20322. }
  20323. eNotation = true;
  20324. } else {
  20325. // the last character doesn't belong to us
  20326. break;
  20327. }
  20328. }
  20329. if (divideBy !== 0) {
  20330. baseValue /= divideBy;
  20331. }
  20332. if (eNotation) {
  20333. baseValue *= Math.pow(10, powerValueSign * powerValue);
  20334. }
  20335. return sign * baseValue;
  20336. },
  20337. getString: function Lexer_getString() {
  20338. var numParen = 1;
  20339. var done = false;
  20340. var strBuf = this.strBuf;
  20341. strBuf.length = 0;
  20342. var ch = this.nextChar();
  20343. while (true) {
  20344. var charBuffered = false;
  20345. switch (ch | 0) {
  20346. case -1:
  20347. warn('Unterminated string');
  20348. done = true;
  20349. break;
  20350. case 0x28: // '('
  20351. ++numParen;
  20352. strBuf.push('(');
  20353. break;
  20354. case 0x29: // ')'
  20355. if (--numParen === 0) {
  20356. this.nextChar(); // consume strings ')'
  20357. done = true;
  20358. } else {
  20359. strBuf.push(')');
  20360. }
  20361. break;
  20362. case 0x5C: // '\\'
  20363. ch = this.nextChar();
  20364. switch (ch) {
  20365. case -1:
  20366. warn('Unterminated string');
  20367. done = true;
  20368. break;
  20369. case 0x6E: // 'n'
  20370. strBuf.push('\n');
  20371. break;
  20372. case 0x72: // 'r'
  20373. strBuf.push('\r');
  20374. break;
  20375. case 0x74: // 't'
  20376. strBuf.push('\t');
  20377. break;
  20378. case 0x62: // 'b'
  20379. strBuf.push('\b');
  20380. break;
  20381. case 0x66: // 'f'
  20382. strBuf.push('\f');
  20383. break;
  20384. case 0x5C: // '\'
  20385. case 0x28: // '('
  20386. case 0x29: // ')'
  20387. strBuf.push(String.fromCharCode(ch));
  20388. break;
  20389. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  20390. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  20391. var x = ch & 0x0F;
  20392. ch = this.nextChar();
  20393. charBuffered = true;
  20394. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20395. x = (x << 3) + (ch & 0x0F);
  20396. ch = this.nextChar();
  20397. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20398. charBuffered = false;
  20399. x = (x << 3) + (ch & 0x0F);
  20400. }
  20401. }
  20402. strBuf.push(String.fromCharCode(x));
  20403. break;
  20404. case 0x0D: // CR
  20405. if (this.peekChar() === 0x0A) { // LF
  20406. this.nextChar();
  20407. }
  20408. break;
  20409. case 0x0A: // LF
  20410. break;
  20411. default:
  20412. strBuf.push(String.fromCharCode(ch));
  20413. break;
  20414. }
  20415. break;
  20416. default:
  20417. strBuf.push(String.fromCharCode(ch));
  20418. break;
  20419. }
  20420. if (done) {
  20421. break;
  20422. }
  20423. if (!charBuffered) {
  20424. ch = this.nextChar();
  20425. }
  20426. }
  20427. return strBuf.join('');
  20428. },
  20429. getName: function Lexer_getName() {
  20430. var ch, previousCh;
  20431. var strBuf = this.strBuf;
  20432. strBuf.length = 0;
  20433. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20434. if (ch === 0x23) { // '#'
  20435. ch = this.nextChar();
  20436. if (specialChars[ch]) {
  20437. warn('Lexer_getName: ' +
  20438. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  20439. strBuf.push('#');
  20440. break;
  20441. }
  20442. var x = toHexDigit(ch);
  20443. if (x !== -1) {
  20444. previousCh = ch;
  20445. ch = this.nextChar();
  20446. var x2 = toHexDigit(ch);
  20447. if (x2 === -1) {
  20448. warn('Lexer_getName: Illegal digit (' +
  20449. String.fromCharCode(ch) +') in hexadecimal number.');
  20450. strBuf.push('#', String.fromCharCode(previousCh));
  20451. if (specialChars[ch]) {
  20452. break;
  20453. }
  20454. strBuf.push(String.fromCharCode(ch));
  20455. continue;
  20456. }
  20457. strBuf.push(String.fromCharCode((x << 4) | x2));
  20458. } else {
  20459. strBuf.push('#', String.fromCharCode(ch));
  20460. }
  20461. } else {
  20462. strBuf.push(String.fromCharCode(ch));
  20463. }
  20464. }
  20465. if (strBuf.length > 127) {
  20466. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  20467. }
  20468. return Name.get(strBuf.join(''));
  20469. },
  20470. getHexString: function Lexer_getHexString() {
  20471. var strBuf = this.strBuf;
  20472. strBuf.length = 0;
  20473. var ch = this.currentChar;
  20474. var isFirstHex = true;
  20475. var firstDigit;
  20476. var secondDigit;
  20477. while (true) {
  20478. if (ch < 0) {
  20479. warn('Unterminated hex string');
  20480. break;
  20481. } else if (ch === 0x3E) { // '>'
  20482. this.nextChar();
  20483. break;
  20484. } else if (specialChars[ch] === 1) {
  20485. ch = this.nextChar();
  20486. continue;
  20487. } else {
  20488. if (isFirstHex) {
  20489. firstDigit = toHexDigit(ch);
  20490. if (firstDigit === -1) {
  20491. warn('Ignoring invalid character "' + ch + '" in hex string');
  20492. ch = this.nextChar();
  20493. continue;
  20494. }
  20495. } else {
  20496. secondDigit = toHexDigit(ch);
  20497. if (secondDigit === -1) {
  20498. warn('Ignoring invalid character "' + ch + '" in hex string');
  20499. ch = this.nextChar();
  20500. continue;
  20501. }
  20502. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  20503. }
  20504. isFirstHex = !isFirstHex;
  20505. ch = this.nextChar();
  20506. }
  20507. }
  20508. return strBuf.join('');
  20509. },
  20510. getObj: function Lexer_getObj() {
  20511. // skip whitespace and comments
  20512. var comment = false;
  20513. var ch = this.currentChar;
  20514. while (true) {
  20515. if (ch < 0) {
  20516. return EOF;
  20517. }
  20518. if (comment) {
  20519. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  20520. comment = false;
  20521. }
  20522. } else if (ch === 0x25) { // '%'
  20523. comment = true;
  20524. } else if (specialChars[ch] !== 1) {
  20525. break;
  20526. }
  20527. ch = this.nextChar();
  20528. }
  20529. // start reading token
  20530. switch (ch | 0) {
  20531. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  20532. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  20533. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  20534. return this.getNumber();
  20535. case 0x28: // '('
  20536. return this.getString();
  20537. case 0x2F: // '/'
  20538. return this.getName();
  20539. // array punctuation
  20540. case 0x5B: // '['
  20541. this.nextChar();
  20542. return Cmd.get('[');
  20543. case 0x5D: // ']'
  20544. this.nextChar();
  20545. return Cmd.get(']');
  20546. // hex string or dict punctuation
  20547. case 0x3C: // '<'
  20548. ch = this.nextChar();
  20549. if (ch === 0x3C) {
  20550. // dict punctuation
  20551. this.nextChar();
  20552. return Cmd.get('<<');
  20553. }
  20554. return this.getHexString();
  20555. // dict punctuation
  20556. case 0x3E: // '>'
  20557. ch = this.nextChar();
  20558. if (ch === 0x3E) {
  20559. this.nextChar();
  20560. return Cmd.get('>>');
  20561. }
  20562. return Cmd.get('>');
  20563. case 0x7B: // '{'
  20564. this.nextChar();
  20565. return Cmd.get('{');
  20566. case 0x7D: // '}'
  20567. this.nextChar();
  20568. return Cmd.get('}');
  20569. case 0x29: // ')'
  20570. error('Illegal character: ' + ch);
  20571. break;
  20572. }
  20573. // command
  20574. var str = String.fromCharCode(ch);
  20575. var knownCommands = this.knownCommands;
  20576. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20577. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20578. // stop if known command is found and next character does not make
  20579. // the str a command
  20580. var possibleCommand = str + String.fromCharCode(ch);
  20581. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  20582. break;
  20583. }
  20584. if (str.length === 128) {
  20585. error('Command token too long: ' + str.length);
  20586. }
  20587. str = possibleCommand;
  20588. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20589. }
  20590. if (str === 'true') {
  20591. return true;
  20592. }
  20593. if (str === 'false') {
  20594. return false;
  20595. }
  20596. if (str === 'null') {
  20597. return null;
  20598. }
  20599. return Cmd.get(str);
  20600. },
  20601. skipToNextLine: function Lexer_skipToNextLine() {
  20602. var ch = this.currentChar;
  20603. while (ch >= 0) {
  20604. if (ch === 0x0D) { // CR
  20605. ch = this.nextChar();
  20606. if (ch === 0x0A) { // LF
  20607. this.nextChar();
  20608. }
  20609. break;
  20610. } else if (ch === 0x0A) { // LF
  20611. this.nextChar();
  20612. break;
  20613. }
  20614. ch = this.nextChar();
  20615. }
  20616. }
  20617. };
  20618. return Lexer;
  20619. })();
  20620. var Linearization = {
  20621. create: function LinearizationCreate(stream) {
  20622. function getInt(name, allowZeroValue) {
  20623. var obj = linDict.get(name);
  20624. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  20625. return obj;
  20626. }
  20627. throw new Error('The "' + name + '" parameter in the linearization ' +
  20628. 'dictionary is invalid.');
  20629. }
  20630. function getHints() {
  20631. var hints = linDict.get('H'), hintsLength, item;
  20632. if (isArray(hints) &&
  20633. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  20634. for (var index = 0; index < hintsLength; index++) {
  20635. if (!(isInt(item = hints[index]) && item > 0)) {
  20636. throw new Error('Hint (' + index +
  20637. ') in the linearization dictionary is invalid.');
  20638. }
  20639. }
  20640. return hints;
  20641. }
  20642. throw new Error('Hint array in the linearization dictionary is invalid.');
  20643. }
  20644. var parser = new Parser(new Lexer(stream), false, null);
  20645. var obj1 = parser.getObj();
  20646. var obj2 = parser.getObj();
  20647. var obj3 = parser.getObj();
  20648. var linDict = parser.getObj();
  20649. var obj, length;
  20650. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  20651. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  20652. return null; // No valid linearization dictionary found.
  20653. } else if ((length = getInt('L')) !== stream.length) {
  20654. throw new Error('The "L" parameter in the linearization dictionary ' +
  20655. 'does not equal the stream length.');
  20656. }
  20657. return {
  20658. length: length,
  20659. hints: getHints(),
  20660. objectNumberFirst: getInt('O'),
  20661. endFirst: getInt('E'),
  20662. numPages: getInt('N'),
  20663. mainXRefEntriesOffset: getInt('T'),
  20664. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  20665. };
  20666. }
  20667. };
  20668. exports.EOF = EOF;
  20669. exports.Lexer = Lexer;
  20670. exports.Linearization = Linearization;
  20671. exports.Parser = Parser;
  20672. exports.isEOF = isEOF;
  20673. // TODO refactor to remove dependency on stream.js
  20674. coreStream._setCoreParser(exports);
  20675. }));
  20676. (function (root, factory) {
  20677. {
  20678. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  20679. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  20680. }
  20681. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  20682. var Util = sharedUtil.Util;
  20683. var assert = sharedUtil.assert;
  20684. var error = sharedUtil.error;
  20685. var isInt = sharedUtil.isInt;
  20686. var isString = sharedUtil.isString;
  20687. var warn = sharedUtil.warn;
  20688. var isName = corePrimitives.isName;
  20689. var isCmd = corePrimitives.isCmd;
  20690. var isStream = corePrimitives.isStream;
  20691. var StringStream = coreStream.StringStream;
  20692. var Lexer = coreParser.Lexer;
  20693. var isEOF = coreParser.isEOF;
  20694. var BUILT_IN_CMAPS = [
  20695. // << Start unicode maps.
  20696. 'Adobe-GB1-UCS2',
  20697. 'Adobe-CNS1-UCS2',
  20698. 'Adobe-Japan1-UCS2',
  20699. 'Adobe-Korea1-UCS2',
  20700. // >> End unicode maps.
  20701. '78-EUC-H',
  20702. '78-EUC-V',
  20703. '78-H',
  20704. '78-RKSJ-H',
  20705. '78-RKSJ-V',
  20706. '78-V',
  20707. '78ms-RKSJ-H',
  20708. '78ms-RKSJ-V',
  20709. '83pv-RKSJ-H',
  20710. '90ms-RKSJ-H',
  20711. '90ms-RKSJ-V',
  20712. '90msp-RKSJ-H',
  20713. '90msp-RKSJ-V',
  20714. '90pv-RKSJ-H',
  20715. '90pv-RKSJ-V',
  20716. 'Add-H',
  20717. 'Add-RKSJ-H',
  20718. 'Add-RKSJ-V',
  20719. 'Add-V',
  20720. 'Adobe-CNS1-0',
  20721. 'Adobe-CNS1-1',
  20722. 'Adobe-CNS1-2',
  20723. 'Adobe-CNS1-3',
  20724. 'Adobe-CNS1-4',
  20725. 'Adobe-CNS1-5',
  20726. 'Adobe-CNS1-6',
  20727. 'Adobe-GB1-0',
  20728. 'Adobe-GB1-1',
  20729. 'Adobe-GB1-2',
  20730. 'Adobe-GB1-3',
  20731. 'Adobe-GB1-4',
  20732. 'Adobe-GB1-5',
  20733. 'Adobe-Japan1-0',
  20734. 'Adobe-Japan1-1',
  20735. 'Adobe-Japan1-2',
  20736. 'Adobe-Japan1-3',
  20737. 'Adobe-Japan1-4',
  20738. 'Adobe-Japan1-5',
  20739. 'Adobe-Japan1-6',
  20740. 'Adobe-Korea1-0',
  20741. 'Adobe-Korea1-1',
  20742. 'Adobe-Korea1-2',
  20743. 'B5-H',
  20744. 'B5-V',
  20745. 'B5pc-H',
  20746. 'B5pc-V',
  20747. 'CNS-EUC-H',
  20748. 'CNS-EUC-V',
  20749. 'CNS1-H',
  20750. 'CNS1-V',
  20751. 'CNS2-H',
  20752. 'CNS2-V',
  20753. 'ETHK-B5-H',
  20754. 'ETHK-B5-V',
  20755. 'ETen-B5-H',
  20756. 'ETen-B5-V',
  20757. 'ETenms-B5-H',
  20758. 'ETenms-B5-V',
  20759. 'EUC-H',
  20760. 'EUC-V',
  20761. 'Ext-H',
  20762. 'Ext-RKSJ-H',
  20763. 'Ext-RKSJ-V',
  20764. 'Ext-V',
  20765. 'GB-EUC-H',
  20766. 'GB-EUC-V',
  20767. 'GB-H',
  20768. 'GB-V',
  20769. 'GBK-EUC-H',
  20770. 'GBK-EUC-V',
  20771. 'GBK2K-H',
  20772. 'GBK2K-V',
  20773. 'GBKp-EUC-H',
  20774. 'GBKp-EUC-V',
  20775. 'GBT-EUC-H',
  20776. 'GBT-EUC-V',
  20777. 'GBT-H',
  20778. 'GBT-V',
  20779. 'GBTpc-EUC-H',
  20780. 'GBTpc-EUC-V',
  20781. 'GBpc-EUC-H',
  20782. 'GBpc-EUC-V',
  20783. 'H',
  20784. 'HKdla-B5-H',
  20785. 'HKdla-B5-V',
  20786. 'HKdlb-B5-H',
  20787. 'HKdlb-B5-V',
  20788. 'HKgccs-B5-H',
  20789. 'HKgccs-B5-V',
  20790. 'HKm314-B5-H',
  20791. 'HKm314-B5-V',
  20792. 'HKm471-B5-H',
  20793. 'HKm471-B5-V',
  20794. 'HKscs-B5-H',
  20795. 'HKscs-B5-V',
  20796. 'Hankaku',
  20797. 'Hiragana',
  20798. 'KSC-EUC-H',
  20799. 'KSC-EUC-V',
  20800. 'KSC-H',
  20801. 'KSC-Johab-H',
  20802. 'KSC-Johab-V',
  20803. 'KSC-V',
  20804. 'KSCms-UHC-H',
  20805. 'KSCms-UHC-HW-H',
  20806. 'KSCms-UHC-HW-V',
  20807. 'KSCms-UHC-V',
  20808. 'KSCpc-EUC-H',
  20809. 'KSCpc-EUC-V',
  20810. 'Katakana',
  20811. 'NWP-H',
  20812. 'NWP-V',
  20813. 'RKSJ-H',
  20814. 'RKSJ-V',
  20815. 'Roman',
  20816. 'UniCNS-UCS2-H',
  20817. 'UniCNS-UCS2-V',
  20818. 'UniCNS-UTF16-H',
  20819. 'UniCNS-UTF16-V',
  20820. 'UniCNS-UTF32-H',
  20821. 'UniCNS-UTF32-V',
  20822. 'UniCNS-UTF8-H',
  20823. 'UniCNS-UTF8-V',
  20824. 'UniGB-UCS2-H',
  20825. 'UniGB-UCS2-V',
  20826. 'UniGB-UTF16-H',
  20827. 'UniGB-UTF16-V',
  20828. 'UniGB-UTF32-H',
  20829. 'UniGB-UTF32-V',
  20830. 'UniGB-UTF8-H',
  20831. 'UniGB-UTF8-V',
  20832. 'UniJIS-UCS2-H',
  20833. 'UniJIS-UCS2-HW-H',
  20834. 'UniJIS-UCS2-HW-V',
  20835. 'UniJIS-UCS2-V',
  20836. 'UniJIS-UTF16-H',
  20837. 'UniJIS-UTF16-V',
  20838. 'UniJIS-UTF32-H',
  20839. 'UniJIS-UTF32-V',
  20840. 'UniJIS-UTF8-H',
  20841. 'UniJIS-UTF8-V',
  20842. 'UniJIS2004-UTF16-H',
  20843. 'UniJIS2004-UTF16-V',
  20844. 'UniJIS2004-UTF32-H',
  20845. 'UniJIS2004-UTF32-V',
  20846. 'UniJIS2004-UTF8-H',
  20847. 'UniJIS2004-UTF8-V',
  20848. 'UniJISPro-UCS2-HW-V',
  20849. 'UniJISPro-UCS2-V',
  20850. 'UniJISPro-UTF8-V',
  20851. 'UniJISX0213-UTF32-H',
  20852. 'UniJISX0213-UTF32-V',
  20853. 'UniJISX02132004-UTF32-H',
  20854. 'UniJISX02132004-UTF32-V',
  20855. 'UniKS-UCS2-H',
  20856. 'UniKS-UCS2-V',
  20857. 'UniKS-UTF16-H',
  20858. 'UniKS-UTF16-V',
  20859. 'UniKS-UTF32-H',
  20860. 'UniKS-UTF32-V',
  20861. 'UniKS-UTF8-H',
  20862. 'UniKS-UTF8-V',
  20863. 'V',
  20864. 'WP-Symbol'];
  20865. // CMap, not to be confused with TrueType's cmap.
  20866. var CMap = (function CMapClosure() {
  20867. function CMap(builtInCMap) {
  20868. // Codespace ranges are stored as follows:
  20869. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  20870. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  20871. this.codespaceRanges = [[], [], [], []];
  20872. this.numCodespaceRanges = 0;
  20873. // Map entries have one of two forms.
  20874. // - cid chars are 16-bit unsigned integers, stored as integers.
  20875. // - bf chars are variable-length byte sequences, stored as strings, with
  20876. // one byte per character.
  20877. this._map = [];
  20878. this.name = '';
  20879. this.vertical = false;
  20880. this.useCMap = null;
  20881. this.builtInCMap = builtInCMap;
  20882. }
  20883. CMap.prototype = {
  20884. addCodespaceRange: function(n, low, high) {
  20885. this.codespaceRanges[n - 1].push(low, high);
  20886. this.numCodespaceRanges++;
  20887. },
  20888. mapCidRange: function(low, high, dstLow) {
  20889. while (low <= high) {
  20890. this._map[low++] = dstLow++;
  20891. }
  20892. },
  20893. mapBfRange: function(low, high, dstLow) {
  20894. var lastByte = dstLow.length - 1;
  20895. while (low <= high) {
  20896. this._map[low++] = dstLow;
  20897. // Only the last byte has to be incremented.
  20898. dstLow = dstLow.substr(0, lastByte) +
  20899. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  20900. }
  20901. },
  20902. mapBfRangeToArray: function(low, high, array) {
  20903. var i = 0, ii = array.length;
  20904. while (low <= high && i < ii) {
  20905. this._map[low] = array[i++];
  20906. ++low;
  20907. }
  20908. },
  20909. // This is used for both bf and cid chars.
  20910. mapOne: function(src, dst) {
  20911. this._map[src] = dst;
  20912. },
  20913. lookup: function(code) {
  20914. return this._map[code];
  20915. },
  20916. contains: function(code) {
  20917. return this._map[code] !== undefined;
  20918. },
  20919. forEach: function(callback) {
  20920. // Most maps have fewer than 65536 entries, and for those we use normal
  20921. // array iteration. But really sparse tables are possible -- e.g. with
  20922. // indices in the *billions*. For such tables we use for..in, which isn't
  20923. // ideal because it stringifies the indices for all present elements, but
  20924. // it does avoid iterating over every undefined entry.
  20925. var map = this._map;
  20926. var length = map.length;
  20927. var i;
  20928. if (length <= 0x10000) {
  20929. for (i = 0; i < length; i++) {
  20930. if (map[i] !== undefined) {
  20931. callback(i, map[i]);
  20932. }
  20933. }
  20934. } else {
  20935. for (i in this._map) {
  20936. callback(i, map[i]);
  20937. }
  20938. }
  20939. },
  20940. charCodeOf: function(value) {
  20941. return this._map.indexOf(value);
  20942. },
  20943. getMap: function() {
  20944. return this._map;
  20945. },
  20946. readCharCode: function(str, offset, out) {
  20947. var c = 0;
  20948. var codespaceRanges = this.codespaceRanges;
  20949. var codespaceRangesLen = this.codespaceRanges.length;
  20950. // 9.7.6.2 CMap Mapping
  20951. // The code length is at most 4.
  20952. for (var n = 0; n < codespaceRangesLen; n++) {
  20953. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  20954. // Check each codespace range to see if it falls within.
  20955. var codespaceRange = codespaceRanges[n];
  20956. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  20957. var low = codespaceRange[k++];
  20958. var high = codespaceRange[k++];
  20959. if (c >= low && c <= high) {
  20960. out.charcode = c;
  20961. out.length = n + 1;
  20962. return;
  20963. }
  20964. }
  20965. }
  20966. out.charcode = 0;
  20967. out.length = 1;
  20968. },
  20969. get length() {
  20970. return this._map.length;
  20971. },
  20972. get isIdentityCMap() {
  20973. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  20974. return false;
  20975. }
  20976. if (this._map.length !== 0x10000) {
  20977. return false;
  20978. }
  20979. for (var i = 0; i < 0x10000; i++) {
  20980. if (this._map[i] !== i) {
  20981. return false;
  20982. }
  20983. }
  20984. return true;
  20985. }
  20986. };
  20987. return CMap;
  20988. })();
  20989. // A special case of CMap, where the _map array implicitly has a length of
  20990. // 65536 and each element is equal to its index.
  20991. var IdentityCMap = (function IdentityCMapClosure() {
  20992. function IdentityCMap(vertical, n) {
  20993. CMap.call(this);
  20994. this.vertical = vertical;
  20995. this.addCodespaceRange(n, 0, 0xffff);
  20996. }
  20997. Util.inherit(IdentityCMap, CMap, {});
  20998. IdentityCMap.prototype = {
  20999. addCodespaceRange: CMap.prototype.addCodespaceRange,
  21000. mapCidRange: function(low, high, dstLow) {
  21001. error('should not call mapCidRange');
  21002. },
  21003. mapBfRange: function(low, high, dstLow) {
  21004. error('should not call mapBfRange');
  21005. },
  21006. mapBfRangeToArray: function(low, high, array) {
  21007. error('should not call mapBfRangeToArray');
  21008. },
  21009. mapOne: function(src, dst) {
  21010. error('should not call mapCidOne');
  21011. },
  21012. lookup: function(code) {
  21013. return (isInt(code) && code <= 0xffff) ? code : undefined;
  21014. },
  21015. contains: function(code) {
  21016. return isInt(code) && code <= 0xffff;
  21017. },
  21018. forEach: function(callback) {
  21019. for (var i = 0; i <= 0xffff; i++) {
  21020. callback(i, i);
  21021. }
  21022. },
  21023. charCodeOf: function(value) {
  21024. return (isInt(value) && value <= 0xffff) ? value : -1;
  21025. },
  21026. getMap: function() {
  21027. // Sometimes identity maps must be instantiated, but it's rare.
  21028. var map = new Array(0x10000);
  21029. for (var i = 0; i <= 0xffff; i++) {
  21030. map[i] = i;
  21031. }
  21032. return map;
  21033. },
  21034. readCharCode: CMap.prototype.readCharCode,
  21035. get length() {
  21036. return 0x10000;
  21037. },
  21038. get isIdentityCMap() {
  21039. error('should not access .isIdentityCMap');
  21040. }
  21041. };
  21042. return IdentityCMap;
  21043. })();
  21044. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  21045. function fetchBinaryData(url) {
  21046. var nonBinaryRequest = PDFJS.disableWorker;
  21047. var request = new XMLHttpRequest();
  21048. request.open('GET', url, false);
  21049. if (!nonBinaryRequest) {
  21050. try {
  21051. request.responseType = 'arraybuffer';
  21052. nonBinaryRequest = request.responseType !== 'arraybuffer';
  21053. } catch (e) {
  21054. nonBinaryRequest = true;
  21055. }
  21056. }
  21057. if (nonBinaryRequest && request.overrideMimeType) {
  21058. request.overrideMimeType('text/plain; charset=x-user-defined');
  21059. }
  21060. request.send(null);
  21061. if (nonBinaryRequest ? !request.responseText : !request.response) {
  21062. error('Unable to get binary cMap at: ' + url);
  21063. }
  21064. if (nonBinaryRequest) {
  21065. var data = Array.prototype.map.call(request.responseText, function (ch) {
  21066. return ch.charCodeAt(0) & 255;
  21067. });
  21068. return new Uint8Array(data);
  21069. }
  21070. return new Uint8Array(request.response);
  21071. }
  21072. function hexToInt(a, size) {
  21073. var n = 0;
  21074. for (var i = 0; i <= size; i++) {
  21075. n = (n << 8) | a[i];
  21076. }
  21077. return n >>> 0;
  21078. }
  21079. function hexToStr(a, size) {
  21080. // This code is hot. Special-case some common values to avoid creating an
  21081. // object with subarray().
  21082. if (size === 1) {
  21083. return String.fromCharCode(a[0], a[1]);
  21084. }
  21085. if (size === 3) {
  21086. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  21087. }
  21088. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  21089. }
  21090. function addHex(a, b, size) {
  21091. var c = 0;
  21092. for (var i = size; i >= 0; i--) {
  21093. c += a[i] + b[i];
  21094. a[i] = c & 255;
  21095. c >>= 8;
  21096. }
  21097. }
  21098. function incHex(a, size) {
  21099. var c = 1;
  21100. for (var i = size; i >= 0 && c > 0; i--) {
  21101. c += a[i];
  21102. a[i] = c & 255;
  21103. c >>= 8;
  21104. }
  21105. }
  21106. var MAX_NUM_SIZE = 16;
  21107. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  21108. function BinaryCMapStream(data) {
  21109. this.buffer = data;
  21110. this.pos = 0;
  21111. this.end = data.length;
  21112. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  21113. }
  21114. BinaryCMapStream.prototype = {
  21115. readByte: function () {
  21116. if (this.pos >= this.end) {
  21117. return -1;
  21118. }
  21119. return this.buffer[this.pos++];
  21120. },
  21121. readNumber: function () {
  21122. var n = 0;
  21123. var last;
  21124. do {
  21125. var b = this.readByte();
  21126. if (b < 0) {
  21127. error('unexpected EOF in bcmap');
  21128. }
  21129. last = !(b & 0x80);
  21130. n = (n << 7) | (b & 0x7F);
  21131. } while (!last);
  21132. return n;
  21133. },
  21134. readSigned: function () {
  21135. var n = this.readNumber();
  21136. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  21137. },
  21138. readHex: function (num, size) {
  21139. num.set(this.buffer.subarray(this.pos,
  21140. this.pos + size + 1));
  21141. this.pos += size + 1;
  21142. },
  21143. readHexNumber: function (num, size) {
  21144. var last;
  21145. var stack = this.tmpBuf, sp = 0;
  21146. do {
  21147. var b = this.readByte();
  21148. if (b < 0) {
  21149. error('unexpected EOF in bcmap');
  21150. }
  21151. last = !(b & 0x80);
  21152. stack[sp++] = b & 0x7F;
  21153. } while (!last);
  21154. var i = size, buffer = 0, bufferSize = 0;
  21155. while (i >= 0) {
  21156. while (bufferSize < 8 && stack.length > 0) {
  21157. buffer = (stack[--sp] << bufferSize) | buffer;
  21158. bufferSize += 7;
  21159. }
  21160. num[i] = buffer & 255;
  21161. i--;
  21162. buffer >>= 8;
  21163. bufferSize -= 8;
  21164. }
  21165. },
  21166. readHexSigned: function (num, size) {
  21167. this.readHexNumber(num, size);
  21168. var sign = num[size] & 1 ? 255 : 0;
  21169. var c = 0;
  21170. for (var i = 0; i <= size; i++) {
  21171. c = ((c & 1) << 8) | num[i];
  21172. num[i] = (c >> 1) ^ sign;
  21173. }
  21174. },
  21175. readString: function () {
  21176. var len = this.readNumber();
  21177. var s = '';
  21178. for (var i = 0; i < len; i++) {
  21179. s += String.fromCharCode(this.readNumber());
  21180. }
  21181. return s;
  21182. }
  21183. };
  21184. function processBinaryCMap(url, cMap, extend) {
  21185. var data = fetchBinaryData(url);
  21186. var stream = new BinaryCMapStream(data);
  21187. var header = stream.readByte();
  21188. cMap.vertical = !!(header & 1);
  21189. var useCMap = null;
  21190. var start = new Uint8Array(MAX_NUM_SIZE);
  21191. var end = new Uint8Array(MAX_NUM_SIZE);
  21192. var char = new Uint8Array(MAX_NUM_SIZE);
  21193. var charCode = new Uint8Array(MAX_NUM_SIZE);
  21194. var tmp = new Uint8Array(MAX_NUM_SIZE);
  21195. var code;
  21196. var b;
  21197. while ((b = stream.readByte()) >= 0) {
  21198. var type = b >> 5;
  21199. if (type === 7) { // metadata, e.g. comment or usecmap
  21200. switch (b & 0x1F) {
  21201. case 0:
  21202. stream.readString(); // skipping comment
  21203. break;
  21204. case 1:
  21205. useCMap = stream.readString();
  21206. break;
  21207. }
  21208. continue;
  21209. }
  21210. var sequence = !!(b & 0x10);
  21211. var dataSize = b & 15;
  21212. assert(dataSize + 1 <= MAX_NUM_SIZE);
  21213. var ucs2DataSize = 1;
  21214. var subitemsCount = stream.readNumber();
  21215. var i;
  21216. switch (type) {
  21217. case 0: // codespacerange
  21218. stream.readHex(start, dataSize);
  21219. stream.readHexNumber(end, dataSize);
  21220. addHex(end, start, dataSize);
  21221. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21222. hexToInt(end, dataSize));
  21223. for (i = 1; i < subitemsCount; i++) {
  21224. incHex(end, dataSize);
  21225. stream.readHexNumber(start, dataSize);
  21226. addHex(start, end, dataSize);
  21227. stream.readHexNumber(end, dataSize);
  21228. addHex(end, start, dataSize);
  21229. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21230. hexToInt(end, dataSize));
  21231. }
  21232. break;
  21233. case 1: // notdefrange
  21234. stream.readHex(start, dataSize);
  21235. stream.readHexNumber(end, dataSize);
  21236. addHex(end, start, dataSize);
  21237. code = stream.readNumber();
  21238. // undefined range, skipping
  21239. for (i = 1; i < subitemsCount; i++) {
  21240. incHex(end, dataSize);
  21241. stream.readHexNumber(start, dataSize);
  21242. addHex(start, end, dataSize);
  21243. stream.readHexNumber(end, dataSize);
  21244. addHex(end, start, dataSize);
  21245. code = stream.readNumber();
  21246. // nop
  21247. }
  21248. break;
  21249. case 2: // cidchar
  21250. stream.readHex(char, dataSize);
  21251. code = stream.readNumber();
  21252. cMap.mapOne(hexToInt(char, dataSize), code);
  21253. for (i = 1; i < subitemsCount; i++) {
  21254. incHex(char, dataSize);
  21255. if (!sequence) {
  21256. stream.readHexNumber(tmp, dataSize);
  21257. addHex(char, tmp, dataSize);
  21258. }
  21259. code = stream.readSigned() + (code + 1);
  21260. cMap.mapOne(hexToInt(char, dataSize), code);
  21261. }
  21262. break;
  21263. case 3: // cidrange
  21264. stream.readHex(start, dataSize);
  21265. stream.readHexNumber(end, dataSize);
  21266. addHex(end, start, dataSize);
  21267. code = stream.readNumber();
  21268. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21269. code);
  21270. for (i = 1; i < subitemsCount; i++) {
  21271. incHex(end, dataSize);
  21272. if (!sequence) {
  21273. stream.readHexNumber(start, dataSize);
  21274. addHex(start, end, dataSize);
  21275. } else {
  21276. start.set(end);
  21277. }
  21278. stream.readHexNumber(end, dataSize);
  21279. addHex(end, start, dataSize);
  21280. code = stream.readNumber();
  21281. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21282. code);
  21283. }
  21284. break;
  21285. case 4: // bfchar
  21286. stream.readHex(char, ucs2DataSize);
  21287. stream.readHex(charCode, dataSize);
  21288. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21289. hexToStr(charCode, dataSize));
  21290. for (i = 1; i < subitemsCount; i++) {
  21291. incHex(char, ucs2DataSize);
  21292. if (!sequence) {
  21293. stream.readHexNumber(tmp, ucs2DataSize);
  21294. addHex(char, tmp, ucs2DataSize);
  21295. }
  21296. incHex(charCode, dataSize);
  21297. stream.readHexSigned(tmp, dataSize);
  21298. addHex(charCode, tmp, dataSize);
  21299. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21300. hexToStr(charCode, dataSize));
  21301. }
  21302. break;
  21303. case 5: // bfrange
  21304. stream.readHex(start, ucs2DataSize);
  21305. stream.readHexNumber(end, ucs2DataSize);
  21306. addHex(end, start, ucs2DataSize);
  21307. stream.readHex(charCode, dataSize);
  21308. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21309. hexToInt(end, ucs2DataSize),
  21310. hexToStr(charCode, dataSize));
  21311. for (i = 1; i < subitemsCount; i++) {
  21312. incHex(end, ucs2DataSize);
  21313. if (!sequence) {
  21314. stream.readHexNumber(start, ucs2DataSize);
  21315. addHex(start, end, ucs2DataSize);
  21316. } else {
  21317. start.set(end);
  21318. }
  21319. stream.readHexNumber(end, ucs2DataSize);
  21320. addHex(end, start, ucs2DataSize);
  21321. stream.readHex(charCode, dataSize);
  21322. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21323. hexToInt(end, ucs2DataSize),
  21324. hexToStr(charCode, dataSize));
  21325. }
  21326. break;
  21327. default:
  21328. error('Unknown type: ' + type);
  21329. break;
  21330. }
  21331. }
  21332. if (useCMap) {
  21333. extend(useCMap);
  21334. }
  21335. return cMap;
  21336. }
  21337. function BinaryCMapReader() {}
  21338. BinaryCMapReader.prototype = {
  21339. read: processBinaryCMap
  21340. };
  21341. return BinaryCMapReader;
  21342. })();
  21343. var CMapFactory = (function CMapFactoryClosure() {
  21344. function strToInt(str) {
  21345. var a = 0;
  21346. for (var i = 0; i < str.length; i++) {
  21347. a = (a << 8) | str.charCodeAt(i);
  21348. }
  21349. return a >>> 0;
  21350. }
  21351. function expectString(obj) {
  21352. if (!isString(obj)) {
  21353. error('Malformed CMap: expected string.');
  21354. }
  21355. }
  21356. function expectInt(obj) {
  21357. if (!isInt(obj)) {
  21358. error('Malformed CMap: expected int.');
  21359. }
  21360. }
  21361. function parseBfChar(cMap, lexer) {
  21362. while (true) {
  21363. var obj = lexer.getObj();
  21364. if (isEOF(obj)) {
  21365. break;
  21366. }
  21367. if (isCmd(obj, 'endbfchar')) {
  21368. return;
  21369. }
  21370. expectString(obj);
  21371. var src = strToInt(obj);
  21372. obj = lexer.getObj();
  21373. // TODO are /dstName used?
  21374. expectString(obj);
  21375. var dst = obj;
  21376. cMap.mapOne(src, dst);
  21377. }
  21378. }
  21379. function parseBfRange(cMap, lexer) {
  21380. while (true) {
  21381. var obj = lexer.getObj();
  21382. if (isEOF(obj)) {
  21383. break;
  21384. }
  21385. if (isCmd(obj, 'endbfrange')) {
  21386. return;
  21387. }
  21388. expectString(obj);
  21389. var low = strToInt(obj);
  21390. obj = lexer.getObj();
  21391. expectString(obj);
  21392. var high = strToInt(obj);
  21393. obj = lexer.getObj();
  21394. if (isInt(obj) || isString(obj)) {
  21395. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  21396. cMap.mapBfRange(low, high, dstLow);
  21397. } else if (isCmd(obj, '[')) {
  21398. obj = lexer.getObj();
  21399. var array = [];
  21400. while (!isCmd(obj, ']') && !isEOF(obj)) {
  21401. array.push(obj);
  21402. obj = lexer.getObj();
  21403. }
  21404. cMap.mapBfRangeToArray(low, high, array);
  21405. } else {
  21406. break;
  21407. }
  21408. }
  21409. error('Invalid bf range.');
  21410. }
  21411. function parseCidChar(cMap, lexer) {
  21412. while (true) {
  21413. var obj = lexer.getObj();
  21414. if (isEOF(obj)) {
  21415. break;
  21416. }
  21417. if (isCmd(obj, 'endcidchar')) {
  21418. return;
  21419. }
  21420. expectString(obj);
  21421. var src = strToInt(obj);
  21422. obj = lexer.getObj();
  21423. expectInt(obj);
  21424. var dst = obj;
  21425. cMap.mapOne(src, dst);
  21426. }
  21427. }
  21428. function parseCidRange(cMap, lexer) {
  21429. while (true) {
  21430. var obj = lexer.getObj();
  21431. if (isEOF(obj)) {
  21432. break;
  21433. }
  21434. if (isCmd(obj, 'endcidrange')) {
  21435. return;
  21436. }
  21437. expectString(obj);
  21438. var low = strToInt(obj);
  21439. obj = lexer.getObj();
  21440. expectString(obj);
  21441. var high = strToInt(obj);
  21442. obj = lexer.getObj();
  21443. expectInt(obj);
  21444. var dstLow = obj;
  21445. cMap.mapCidRange(low, high, dstLow);
  21446. }
  21447. }
  21448. function parseCodespaceRange(cMap, lexer) {
  21449. while (true) {
  21450. var obj = lexer.getObj();
  21451. if (isEOF(obj)) {
  21452. break;
  21453. }
  21454. if (isCmd(obj, 'endcodespacerange')) {
  21455. return;
  21456. }
  21457. if (!isString(obj)) {
  21458. break;
  21459. }
  21460. var low = strToInt(obj);
  21461. obj = lexer.getObj();
  21462. if (!isString(obj)) {
  21463. break;
  21464. }
  21465. var high = strToInt(obj);
  21466. cMap.addCodespaceRange(obj.length, low, high);
  21467. }
  21468. error('Invalid codespace range.');
  21469. }
  21470. function parseWMode(cMap, lexer) {
  21471. var obj = lexer.getObj();
  21472. if (isInt(obj)) {
  21473. cMap.vertical = !!obj;
  21474. }
  21475. }
  21476. function parseCMapName(cMap, lexer) {
  21477. var obj = lexer.getObj();
  21478. if (isName(obj) && isString(obj.name)) {
  21479. cMap.name = obj.name;
  21480. }
  21481. }
  21482. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  21483. var previous;
  21484. var embededUseCMap;
  21485. objLoop: while (true) {
  21486. var obj = lexer.getObj();
  21487. if (isEOF(obj)) {
  21488. break;
  21489. } else if (isName(obj)) {
  21490. if (obj.name === 'WMode') {
  21491. parseWMode(cMap, lexer);
  21492. } else if (obj.name === 'CMapName') {
  21493. parseCMapName(cMap, lexer);
  21494. }
  21495. previous = obj;
  21496. } else if (isCmd(obj)) {
  21497. switch (obj.cmd) {
  21498. case 'endcmap':
  21499. break objLoop;
  21500. case 'usecmap':
  21501. if (isName(previous)) {
  21502. embededUseCMap = previous.name;
  21503. }
  21504. break;
  21505. case 'begincodespacerange':
  21506. parseCodespaceRange(cMap, lexer);
  21507. break;
  21508. case 'beginbfchar':
  21509. parseBfChar(cMap, lexer);
  21510. break;
  21511. case 'begincidchar':
  21512. parseCidChar(cMap, lexer);
  21513. break;
  21514. case 'beginbfrange':
  21515. parseBfRange(cMap, lexer);
  21516. break;
  21517. case 'begincidrange':
  21518. parseCidRange(cMap, lexer);
  21519. break;
  21520. }
  21521. }
  21522. }
  21523. if (!useCMap && embededUseCMap) {
  21524. // Load the usecmap definition from the file only if there wasn't one
  21525. // specified.
  21526. useCMap = embededUseCMap;
  21527. }
  21528. if (useCMap) {
  21529. extendCMap(cMap, builtInCMapParams, useCMap);
  21530. }
  21531. }
  21532. function extendCMap(cMap, builtInCMapParams, useCMap) {
  21533. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  21534. // If there aren't any code space ranges defined clone all the parent ones
  21535. // into this cMap.
  21536. if (cMap.numCodespaceRanges === 0) {
  21537. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  21538. for (var i = 0; i < useCodespaceRanges.length; i++) {
  21539. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  21540. }
  21541. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  21542. }
  21543. // Merge the map into the current one, making sure not to override
  21544. // any previously defined entries.
  21545. cMap.useCMap.forEach(function(key, value) {
  21546. if (!cMap.contains(key)) {
  21547. cMap.mapOne(key, cMap.useCMap.lookup(key));
  21548. }
  21549. });
  21550. }
  21551. function parseBinaryCMap(name, builtInCMapParams) {
  21552. var url = builtInCMapParams.url + name + '.bcmap';
  21553. var cMap = new CMap(true);
  21554. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  21555. extendCMap(cMap, builtInCMapParams, useCMap);
  21556. });
  21557. return cMap;
  21558. }
  21559. function createBuiltInCMap(name, builtInCMapParams) {
  21560. if (name === 'Identity-H') {
  21561. return new IdentityCMap(false, 2);
  21562. } else if (name === 'Identity-V') {
  21563. return new IdentityCMap(true, 2);
  21564. }
  21565. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  21566. error('Unknown cMap name: ' + name);
  21567. }
  21568. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  21569. if (builtInCMapParams.packed) {
  21570. return parseBinaryCMap(name, builtInCMapParams);
  21571. }
  21572. var request = new XMLHttpRequest();
  21573. var url = builtInCMapParams.url + name;
  21574. request.open('GET', url, false);
  21575. request.send(null);
  21576. if (!request.responseText) {
  21577. error('Unable to get cMap at: ' + url);
  21578. }
  21579. var cMap = new CMap(true);
  21580. var lexer = new Lexer(new StringStream(request.responseText));
  21581. parseCMap(cMap, lexer, builtInCMapParams, null);
  21582. return cMap;
  21583. }
  21584. return {
  21585. create: function (encoding, builtInCMapParams, useCMap) {
  21586. if (isName(encoding)) {
  21587. return createBuiltInCMap(encoding.name, builtInCMapParams);
  21588. } else if (isStream(encoding)) {
  21589. var cMap = new CMap();
  21590. var lexer = new Lexer(encoding);
  21591. try {
  21592. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  21593. } catch (e) {
  21594. warn('Invalid CMap data. ' + e);
  21595. }
  21596. if (cMap.isIdentityCMap) {
  21597. return createBuiltInCMap(cMap.name, builtInCMapParams);
  21598. }
  21599. return cMap;
  21600. }
  21601. error('Encoding required.');
  21602. }
  21603. };
  21604. })();
  21605. exports.CMap = CMap;
  21606. exports.CMapFactory = CMapFactory;
  21607. exports.IdentityCMap = IdentityCMap;
  21608. }));
  21609. (function (root, factory) {
  21610. {
  21611. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  21612. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  21613. root.pdfjsCoreChunkedStream);
  21614. }
  21615. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  21616. coreChunkedStream) {
  21617. var InvalidPDFException = sharedUtil.InvalidPDFException;
  21618. var MissingDataException = sharedUtil.MissingDataException;
  21619. var XRefParseException = sharedUtil.XRefParseException;
  21620. var assert = sharedUtil.assert;
  21621. var bytesToString = sharedUtil.bytesToString;
  21622. var createPromiseCapability = sharedUtil.createPromiseCapability;
  21623. var error = sharedUtil.error;
  21624. var info = sharedUtil.info;
  21625. var isArray = sharedUtil.isArray;
  21626. var isInt = sharedUtil.isInt;
  21627. var isString = sharedUtil.isString;
  21628. var shadow = sharedUtil.shadow;
  21629. var stringToPDFString = sharedUtil.stringToPDFString;
  21630. var stringToUTF8String = sharedUtil.stringToUTF8String;
  21631. var warn = sharedUtil.warn;
  21632. var Ref = corePrimitives.Ref;
  21633. var RefSet = corePrimitives.RefSet;
  21634. var RefSetCache = corePrimitives.RefSetCache;
  21635. var isName = corePrimitives.isName;
  21636. var isCmd = corePrimitives.isCmd;
  21637. var isDict = corePrimitives.isDict;
  21638. var isRef = corePrimitives.isRef;
  21639. var isStream = corePrimitives.isStream;
  21640. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  21641. var Lexer = coreParser.Lexer;
  21642. var Parser = coreParser.Parser;
  21643. var ChunkedStream = coreChunkedStream.ChunkedStream;
  21644. var Catalog = (function CatalogClosure() {
  21645. function Catalog(pdfManager, xref, pageFactory) {
  21646. this.pdfManager = pdfManager;
  21647. this.xref = xref;
  21648. this.catDict = xref.getCatalogObj();
  21649. this.fontCache = new RefSetCache();
  21650. assert(isDict(this.catDict),
  21651. 'catalog object is not a dictionary');
  21652. // TODO refactor to move getPage() to the PDFDocument.
  21653. this.pageFactory = pageFactory;
  21654. this.pagePromises = [];
  21655. }
  21656. Catalog.prototype = {
  21657. get metadata() {
  21658. var streamRef = this.catDict.getRaw('Metadata');
  21659. if (!isRef(streamRef)) {
  21660. return shadow(this, 'metadata', null);
  21661. }
  21662. var encryptMetadata = (!this.xref.encrypt ? false :
  21663. this.xref.encrypt.encryptMetadata);
  21664. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  21665. var metadata;
  21666. if (stream && isDict(stream.dict)) {
  21667. var type = stream.dict.get('Type');
  21668. var subtype = stream.dict.get('Subtype');
  21669. if (isName(type) && isName(subtype) &&
  21670. type.name === 'Metadata' && subtype.name === 'XML') {
  21671. // XXX: This should examine the charset the XML document defines,
  21672. // however since there are currently no real means to decode
  21673. // arbitrary charsets, let's just hope that the author of the PDF
  21674. // was reasonable enough to stick with the XML default charset,
  21675. // which is UTF-8.
  21676. try {
  21677. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  21678. } catch (e) {
  21679. info('Skipping invalid metadata.');
  21680. }
  21681. }
  21682. }
  21683. return shadow(this, 'metadata', metadata);
  21684. },
  21685. get toplevelPagesDict() {
  21686. var pagesObj = this.catDict.get('Pages');
  21687. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  21688. // shadow the prototype getter
  21689. return shadow(this, 'toplevelPagesDict', pagesObj);
  21690. },
  21691. get documentOutline() {
  21692. var obj = null;
  21693. try {
  21694. obj = this.readDocumentOutline();
  21695. } catch (ex) {
  21696. if (ex instanceof MissingDataException) {
  21697. throw ex;
  21698. }
  21699. warn('Unable to read document outline');
  21700. }
  21701. return shadow(this, 'documentOutline', obj);
  21702. },
  21703. readDocumentOutline: function Catalog_readDocumentOutline() {
  21704. var xref = this.xref;
  21705. var obj = this.catDict.get('Outlines');
  21706. var root = { items: [] };
  21707. if (isDict(obj)) {
  21708. obj = obj.getRaw('First');
  21709. var processed = new RefSet();
  21710. if (isRef(obj)) {
  21711. var queue = [{obj: obj, parent: root}];
  21712. // to avoid recursion keeping track of the items
  21713. // in the processed dictionary
  21714. processed.put(obj);
  21715. while (queue.length > 0) {
  21716. var i = queue.shift();
  21717. var outlineDict = xref.fetchIfRef(i.obj);
  21718. if (outlineDict === null) {
  21719. continue;
  21720. }
  21721. if (!outlineDict.has('Title')) {
  21722. error('Invalid outline item');
  21723. }
  21724. var dest = outlineDict.get('A');
  21725. if (dest) {
  21726. dest = dest.get('D');
  21727. } else if (outlineDict.has('Dest')) {
  21728. dest = outlineDict.getRaw('Dest');
  21729. if (isName(dest)) {
  21730. dest = dest.name;
  21731. }
  21732. }
  21733. var title = outlineDict.get('Title');
  21734. var outlineItem = {
  21735. dest: dest,
  21736. title: stringToPDFString(title),
  21737. color: outlineDict.get('C') || [0, 0, 0],
  21738. count: outlineDict.get('Count'),
  21739. bold: !!(outlineDict.get('F') & 2),
  21740. italic: !!(outlineDict.get('F') & 1),
  21741. items: []
  21742. };
  21743. i.parent.items.push(outlineItem);
  21744. obj = outlineDict.getRaw('First');
  21745. if (isRef(obj) && !processed.has(obj)) {
  21746. queue.push({obj: obj, parent: outlineItem});
  21747. processed.put(obj);
  21748. }
  21749. obj = outlineDict.getRaw('Next');
  21750. if (isRef(obj) && !processed.has(obj)) {
  21751. queue.push({obj: obj, parent: i.parent});
  21752. processed.put(obj);
  21753. }
  21754. }
  21755. }
  21756. }
  21757. return (root.items.length > 0 ? root.items : null);
  21758. },
  21759. get numPages() {
  21760. var obj = this.toplevelPagesDict.get('Count');
  21761. assert(
  21762. isInt(obj),
  21763. 'page count in top level pages object is not an integer'
  21764. );
  21765. // shadow the prototype getter
  21766. return shadow(this, 'num', obj);
  21767. },
  21768. get destinations() {
  21769. function fetchDestination(dest) {
  21770. return isDict(dest) ? dest.get('D') : dest;
  21771. }
  21772. var xref = this.xref;
  21773. var dests = {}, nameTreeRef, nameDictionaryRef;
  21774. var obj = this.catDict.get('Names');
  21775. if (obj && obj.has('Dests')) {
  21776. nameTreeRef = obj.getRaw('Dests');
  21777. } else if (this.catDict.has('Dests')) {
  21778. nameDictionaryRef = this.catDict.get('Dests');
  21779. }
  21780. if (nameDictionaryRef) {
  21781. // reading simple destination dictionary
  21782. obj = nameDictionaryRef;
  21783. obj.forEach(function catalogForEach(key, value) {
  21784. if (!value) {
  21785. return;
  21786. }
  21787. dests[key] = fetchDestination(value);
  21788. });
  21789. }
  21790. if (nameTreeRef) {
  21791. var nameTree = new NameTree(nameTreeRef, xref);
  21792. var names = nameTree.getAll();
  21793. for (var name in names) {
  21794. if (!names.hasOwnProperty(name)) {
  21795. continue;
  21796. }
  21797. dests[name] = fetchDestination(names[name]);
  21798. }
  21799. }
  21800. return shadow(this, 'destinations', dests);
  21801. },
  21802. getDestination: function Catalog_getDestination(destinationId) {
  21803. function fetchDestination(dest) {
  21804. return isDict(dest) ? dest.get('D') : dest;
  21805. }
  21806. var xref = this.xref;
  21807. var dest = null, nameTreeRef, nameDictionaryRef;
  21808. var obj = this.catDict.get('Names');
  21809. if (obj && obj.has('Dests')) {
  21810. nameTreeRef = obj.getRaw('Dests');
  21811. } else if (this.catDict.has('Dests')) {
  21812. nameDictionaryRef = this.catDict.get('Dests');
  21813. }
  21814. if (nameDictionaryRef) { // Simple destination dictionary.
  21815. var value = nameDictionaryRef.get(destinationId);
  21816. if (value) {
  21817. dest = fetchDestination(value);
  21818. }
  21819. }
  21820. if (nameTreeRef) {
  21821. var nameTree = new NameTree(nameTreeRef, xref);
  21822. dest = fetchDestination(nameTree.get(destinationId));
  21823. }
  21824. return dest;
  21825. },
  21826. get attachments() {
  21827. var xref = this.xref;
  21828. var attachments = null, nameTreeRef;
  21829. var obj = this.catDict.get('Names');
  21830. if (obj) {
  21831. nameTreeRef = obj.getRaw('EmbeddedFiles');
  21832. }
  21833. if (nameTreeRef) {
  21834. var nameTree = new NameTree(nameTreeRef, xref);
  21835. var names = nameTree.getAll();
  21836. for (var name in names) {
  21837. if (!names.hasOwnProperty(name)) {
  21838. continue;
  21839. }
  21840. var fs = new FileSpec(names[name], xref);
  21841. if (!attachments) {
  21842. attachments = {};
  21843. }
  21844. attachments[stringToPDFString(name)] = fs.serializable;
  21845. }
  21846. }
  21847. return shadow(this, 'attachments', attachments);
  21848. },
  21849. get javaScript() {
  21850. var xref = this.xref;
  21851. var obj = this.catDict.get('Names');
  21852. var javaScript = [];
  21853. function appendIfJavaScriptDict(jsDict) {
  21854. var type = jsDict.get('S');
  21855. if (!isName(type) || type.name !== 'JavaScript') {
  21856. return;
  21857. }
  21858. var js = jsDict.get('JS');
  21859. if (isStream(js)) {
  21860. js = bytesToString(js.getBytes());
  21861. } else if (!isString(js)) {
  21862. return;
  21863. }
  21864. javaScript.push(stringToPDFString(js));
  21865. }
  21866. if (obj && obj.has('JavaScript')) {
  21867. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  21868. var names = nameTree.getAll();
  21869. for (var name in names) {
  21870. if (!names.hasOwnProperty(name)) {
  21871. continue;
  21872. }
  21873. // We don't really use the JavaScript right now. This code is
  21874. // defensive so we don't cause errors on document load.
  21875. var jsDict = names[name];
  21876. if (isDict(jsDict)) {
  21877. appendIfJavaScriptDict(jsDict);
  21878. }
  21879. }
  21880. }
  21881. // Append OpenAction actions to javaScript array
  21882. var openactionDict = this.catDict.get('OpenAction');
  21883. if (isDict(openactionDict, 'Action')) {
  21884. var actionType = openactionDict.get('S');
  21885. if (isName(actionType) && actionType.name === 'Named') {
  21886. // The named Print action is not a part of the PDF 1.7 specification,
  21887. // but is supported by many PDF readers/writers (including Adobe's).
  21888. var action = openactionDict.get('N');
  21889. if (isName(action) && action.name === 'Print') {
  21890. javaScript.push('print({});');
  21891. }
  21892. } else {
  21893. appendIfJavaScriptDict(openactionDict);
  21894. }
  21895. }
  21896. return shadow(this, 'javaScript', javaScript);
  21897. },
  21898. cleanup: function Catalog_cleanup() {
  21899. var promises = [];
  21900. this.fontCache.forEach(function (promise) {
  21901. promises.push(promise);
  21902. });
  21903. return Promise.all(promises).then(function (translatedFonts) {
  21904. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  21905. var font = translatedFonts[i].dict;
  21906. delete font.translated;
  21907. }
  21908. this.fontCache.clear();
  21909. }.bind(this));
  21910. },
  21911. getPage: function Catalog_getPage(pageIndex) {
  21912. if (!(pageIndex in this.pagePromises)) {
  21913. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  21914. function (a) {
  21915. var dict = a[0];
  21916. var ref = a[1];
  21917. return this.pageFactory.createPage(pageIndex, dict, ref,
  21918. this.fontCache);
  21919. }.bind(this)
  21920. );
  21921. }
  21922. return this.pagePromises[pageIndex];
  21923. },
  21924. getPageDict: function Catalog_getPageDict(pageIndex) {
  21925. var capability = createPromiseCapability();
  21926. var nodesToVisit = [this.catDict.getRaw('Pages')];
  21927. var currentPageIndex = 0;
  21928. var xref = this.xref;
  21929. var checkAllKids = false;
  21930. function next() {
  21931. while (nodesToVisit.length) {
  21932. var currentNode = nodesToVisit.pop();
  21933. if (isRef(currentNode)) {
  21934. xref.fetchAsync(currentNode).then(function (obj) {
  21935. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  21936. if (pageIndex === currentPageIndex) {
  21937. capability.resolve([obj, currentNode]);
  21938. } else {
  21939. currentPageIndex++;
  21940. next();
  21941. }
  21942. return;
  21943. }
  21944. nodesToVisit.push(obj);
  21945. next();
  21946. }, capability.reject);
  21947. return;
  21948. }
  21949. // Must be a child page dictionary.
  21950. assert(
  21951. isDict(currentNode),
  21952. 'page dictionary kid reference points to wrong type of object'
  21953. );
  21954. var count = currentNode.get('Count');
  21955. // If the current node doesn't have any children, avoid getting stuck
  21956. // in an empty node further down in the tree (see issue5644.pdf).
  21957. if (count === 0) {
  21958. checkAllKids = true;
  21959. }
  21960. // Skip nodes where the page can't be.
  21961. if (currentPageIndex + count <= pageIndex) {
  21962. currentPageIndex += count;
  21963. continue;
  21964. }
  21965. var kids = currentNode.get('Kids');
  21966. assert(isArray(kids), 'page dictionary kids object is not an array');
  21967. if (!checkAllKids && count === kids.length) {
  21968. // Nodes that don't have the page have been skipped and this is the
  21969. // bottom of the tree which means the page requested must be a
  21970. // descendant of this pages node. Ideally we would just resolve the
  21971. // promise with the page ref here, but there is the case where more
  21972. // pages nodes could link to single a page (see issue 3666 pdf). To
  21973. // handle this push it back on the queue so if it is a pages node it
  21974. // will be descended into.
  21975. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  21976. currentPageIndex = pageIndex;
  21977. continue;
  21978. } else {
  21979. for (var last = kids.length - 1; last >= 0; last--) {
  21980. nodesToVisit.push(kids[last]);
  21981. }
  21982. }
  21983. }
  21984. capability.reject('Page index ' + pageIndex + ' not found.');
  21985. }
  21986. next();
  21987. return capability.promise;
  21988. },
  21989. getPageIndex: function Catalog_getPageIndex(ref) {
  21990. // The page tree nodes have the count of all the leaves below them. To get
  21991. // how many pages are before we just have to walk up the tree and keep
  21992. // adding the count of siblings to the left of the node.
  21993. var xref = this.xref;
  21994. function pagesBeforeRef(kidRef) {
  21995. var total = 0;
  21996. var parentRef;
  21997. return xref.fetchAsync(kidRef).then(function (node) {
  21998. if (!node) {
  21999. return null;
  22000. }
  22001. parentRef = node.getRaw('Parent');
  22002. return node.getAsync('Parent');
  22003. }).then(function (parent) {
  22004. if (!parent) {
  22005. return null;
  22006. }
  22007. return parent.getAsync('Kids');
  22008. }).then(function (kids) {
  22009. if (!kids) {
  22010. return null;
  22011. }
  22012. var kidPromises = [];
  22013. var found = false;
  22014. for (var i = 0; i < kids.length; i++) {
  22015. var kid = kids[i];
  22016. assert(isRef(kid), 'kids must be a ref');
  22017. if (kid.num === kidRef.num) {
  22018. found = true;
  22019. break;
  22020. }
  22021. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  22022. if (kid.has('Count')) {
  22023. var count = kid.get('Count');
  22024. total += count;
  22025. } else { // page leaf node
  22026. total++;
  22027. }
  22028. }));
  22029. }
  22030. if (!found) {
  22031. error('kid ref not found in parents kids');
  22032. }
  22033. return Promise.all(kidPromises).then(function () {
  22034. return [total, parentRef];
  22035. });
  22036. });
  22037. }
  22038. var total = 0;
  22039. function next(ref) {
  22040. return pagesBeforeRef(ref).then(function (args) {
  22041. if (!args) {
  22042. return total;
  22043. }
  22044. var count = args[0];
  22045. var parentRef = args[1];
  22046. total += count;
  22047. return next(parentRef);
  22048. });
  22049. }
  22050. return next(ref);
  22051. }
  22052. };
  22053. return Catalog;
  22054. })();
  22055. var XRef = (function XRefClosure() {
  22056. function XRef(stream, password) {
  22057. this.stream = stream;
  22058. this.entries = [];
  22059. this.xrefstms = {};
  22060. // prepare the XRef cache
  22061. this.cache = [];
  22062. this.password = password;
  22063. this.stats = {
  22064. streamTypes: [],
  22065. fontTypes: []
  22066. };
  22067. }
  22068. XRef.prototype = {
  22069. setStartXRef: function XRef_setStartXRef(startXRef) {
  22070. // Store the starting positions of xref tables as we process them
  22071. // so we can recover from missing data errors
  22072. this.startXRefQueue = [startXRef];
  22073. },
  22074. parse: function XRef_parse(recoveryMode) {
  22075. var trailerDict;
  22076. if (!recoveryMode) {
  22077. trailerDict = this.readXRef();
  22078. } else {
  22079. warn('Indexing all PDF objects');
  22080. trailerDict = this.indexObjects();
  22081. }
  22082. trailerDict.assignXref(this);
  22083. this.trailer = trailerDict;
  22084. var encrypt = trailerDict.get('Encrypt');
  22085. if (encrypt) {
  22086. var ids = trailerDict.get('ID');
  22087. var fileId = (ids && ids.length) ? ids[0] : '';
  22088. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  22089. this.password);
  22090. }
  22091. // get the root dictionary (catalog) object
  22092. if (!(this.root = trailerDict.get('Root'))) {
  22093. error('Invalid root reference');
  22094. }
  22095. },
  22096. processXRefTable: function XRef_processXRefTable(parser) {
  22097. if (!('tableState' in this)) {
  22098. // Stores state of the table as we process it so we can resume
  22099. // from middle of table in case of missing data error
  22100. this.tableState = {
  22101. entryNum: 0,
  22102. streamPos: parser.lexer.stream.pos,
  22103. parserBuf1: parser.buf1,
  22104. parserBuf2: parser.buf2
  22105. };
  22106. }
  22107. var obj = this.readXRefTable(parser);
  22108. // Sanity check
  22109. if (!isCmd(obj, 'trailer')) {
  22110. error('Invalid XRef table: could not find trailer dictionary');
  22111. }
  22112. // Read trailer dictionary, e.g.
  22113. // trailer
  22114. // << /Size 22
  22115. // /Root 20R
  22116. // /Info 10R
  22117. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  22118. // >>
  22119. // The parser goes through the entire stream << ... >> and provides
  22120. // a getter interface for the key-value table
  22121. var dict = parser.getObj();
  22122. // The pdflib PDF generator can generate a nested trailer dictionary
  22123. if (!isDict(dict) && dict.dict) {
  22124. dict = dict.dict;
  22125. }
  22126. if (!isDict(dict)) {
  22127. error('Invalid XRef table: could not parse trailer dictionary');
  22128. }
  22129. delete this.tableState;
  22130. return dict;
  22131. },
  22132. readXRefTable: function XRef_readXRefTable(parser) {
  22133. // Example of cross-reference table:
  22134. // xref
  22135. // 0 1 <-- subsection header (first obj #, obj count)
  22136. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  22137. // 23 2 <-- subsection header ... and so on ...
  22138. // 0000025518 00002 n
  22139. // 0000025635 00000 n
  22140. // trailer
  22141. // ...
  22142. var stream = parser.lexer.stream;
  22143. var tableState = this.tableState;
  22144. stream.pos = tableState.streamPos;
  22145. parser.buf1 = tableState.parserBuf1;
  22146. parser.buf2 = tableState.parserBuf2;
  22147. // Outer loop is over subsection headers
  22148. var obj;
  22149. while (true) {
  22150. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  22151. if (isCmd(obj = parser.getObj(), 'trailer')) {
  22152. break;
  22153. }
  22154. tableState.firstEntryNum = obj;
  22155. tableState.entryCount = parser.getObj();
  22156. }
  22157. var first = tableState.firstEntryNum;
  22158. var count = tableState.entryCount;
  22159. if (!isInt(first) || !isInt(count)) {
  22160. error('Invalid XRef table: wrong types in subsection header');
  22161. }
  22162. // Inner loop is over objects themselves
  22163. for (var i = tableState.entryNum; i < count; i++) {
  22164. tableState.streamPos = stream.pos;
  22165. tableState.entryNum = i;
  22166. tableState.parserBuf1 = parser.buf1;
  22167. tableState.parserBuf2 = parser.buf2;
  22168. var entry = {};
  22169. entry.offset = parser.getObj();
  22170. entry.gen = parser.getObj();
  22171. var type = parser.getObj();
  22172. if (isCmd(type, 'f')) {
  22173. entry.free = true;
  22174. } else if (isCmd(type, 'n')) {
  22175. entry.uncompressed = true;
  22176. }
  22177. // Validate entry obj
  22178. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  22179. !(entry.free || entry.uncompressed)) {
  22180. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  22181. }
  22182. if (!this.entries[i + first]) {
  22183. this.entries[i + first] = entry;
  22184. }
  22185. }
  22186. tableState.entryNum = 0;
  22187. tableState.streamPos = stream.pos;
  22188. tableState.parserBuf1 = parser.buf1;
  22189. tableState.parserBuf2 = parser.buf2;
  22190. delete tableState.firstEntryNum;
  22191. delete tableState.entryCount;
  22192. }
  22193. // Per issue 3248: hp scanners generate bad XRef
  22194. if (first === 1 && this.entries[1] && this.entries[1].free) {
  22195. // shifting the entries
  22196. this.entries.shift();
  22197. }
  22198. // Sanity check: as per spec, first object must be free
  22199. if (this.entries[0] && !this.entries[0].free) {
  22200. error('Invalid XRef table: unexpected first object');
  22201. }
  22202. return obj;
  22203. },
  22204. processXRefStream: function XRef_processXRefStream(stream) {
  22205. if (!('streamState' in this)) {
  22206. // Stores state of the stream as we process it so we can resume
  22207. // from middle of stream in case of missing data error
  22208. var streamParameters = stream.dict;
  22209. var byteWidths = streamParameters.get('W');
  22210. var range = streamParameters.get('Index');
  22211. if (!range) {
  22212. range = [0, streamParameters.get('Size')];
  22213. }
  22214. this.streamState = {
  22215. entryRanges: range,
  22216. byteWidths: byteWidths,
  22217. entryNum: 0,
  22218. streamPos: stream.pos
  22219. };
  22220. }
  22221. this.readXRefStream(stream);
  22222. delete this.streamState;
  22223. return stream.dict;
  22224. },
  22225. readXRefStream: function XRef_readXRefStream(stream) {
  22226. var i, j;
  22227. var streamState = this.streamState;
  22228. stream.pos = streamState.streamPos;
  22229. var byteWidths = streamState.byteWidths;
  22230. var typeFieldWidth = byteWidths[0];
  22231. var offsetFieldWidth = byteWidths[1];
  22232. var generationFieldWidth = byteWidths[2];
  22233. var entryRanges = streamState.entryRanges;
  22234. while (entryRanges.length > 0) {
  22235. var first = entryRanges[0];
  22236. var n = entryRanges[1];
  22237. if (!isInt(first) || !isInt(n)) {
  22238. error('Invalid XRef range fields: ' + first + ', ' + n);
  22239. }
  22240. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  22241. !isInt(generationFieldWidth)) {
  22242. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  22243. }
  22244. for (i = streamState.entryNum; i < n; ++i) {
  22245. streamState.entryNum = i;
  22246. streamState.streamPos = stream.pos;
  22247. var type = 0, offset = 0, generation = 0;
  22248. for (j = 0; j < typeFieldWidth; ++j) {
  22249. type = (type << 8) | stream.getByte();
  22250. }
  22251. // if type field is absent, its default value is 1
  22252. if (typeFieldWidth === 0) {
  22253. type = 1;
  22254. }
  22255. for (j = 0; j < offsetFieldWidth; ++j) {
  22256. offset = (offset << 8) | stream.getByte();
  22257. }
  22258. for (j = 0; j < generationFieldWidth; ++j) {
  22259. generation = (generation << 8) | stream.getByte();
  22260. }
  22261. var entry = {};
  22262. entry.offset = offset;
  22263. entry.gen = generation;
  22264. switch (type) {
  22265. case 0:
  22266. entry.free = true;
  22267. break;
  22268. case 1:
  22269. entry.uncompressed = true;
  22270. break;
  22271. case 2:
  22272. break;
  22273. default:
  22274. error('Invalid XRef entry type: ' + type);
  22275. }
  22276. if (!this.entries[first + i]) {
  22277. this.entries[first + i] = entry;
  22278. }
  22279. }
  22280. streamState.entryNum = 0;
  22281. streamState.streamPos = stream.pos;
  22282. entryRanges.splice(0, 2);
  22283. }
  22284. },
  22285. indexObjects: function XRef_indexObjects() {
  22286. // Simple scan through the PDF content to find objects,
  22287. // trailers and XRef streams.
  22288. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  22289. var PERCENT = 0x25, LT = 0x3C;
  22290. function readToken(data, offset) {
  22291. var token = '', ch = data[offset];
  22292. while (ch !== LF && ch !== CR && ch !== LT) {
  22293. if (++offset >= data.length) {
  22294. break;
  22295. }
  22296. token += String.fromCharCode(ch);
  22297. ch = data[offset];
  22298. }
  22299. return token;
  22300. }
  22301. function skipUntil(data, offset, what) {
  22302. var length = what.length, dataLength = data.length;
  22303. var skipped = 0;
  22304. // finding byte sequence
  22305. while (offset < dataLength) {
  22306. var i = 0;
  22307. while (i < length && data[offset + i] === what[i]) {
  22308. ++i;
  22309. }
  22310. if (i >= length) {
  22311. break; // sequence found
  22312. }
  22313. offset++;
  22314. skipped++;
  22315. }
  22316. return skipped;
  22317. }
  22318. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  22319. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  22320. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  22321. 101, 102]);
  22322. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  22323. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  22324. // Clear out any existing entries, since they may be bogus.
  22325. this.entries.length = 0;
  22326. var stream = this.stream;
  22327. stream.pos = 0;
  22328. var buffer = stream.getBytes();
  22329. var position = stream.start, length = buffer.length;
  22330. var trailers = [], xrefStms = [];
  22331. while (position < length) {
  22332. var ch = buffer[position];
  22333. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  22334. ++position;
  22335. continue;
  22336. }
  22337. if (ch === PERCENT) { // %-comment
  22338. do {
  22339. ++position;
  22340. if (position >= length) {
  22341. break;
  22342. }
  22343. ch = buffer[position];
  22344. } while (ch !== LF && ch !== CR);
  22345. continue;
  22346. }
  22347. var token = readToken(buffer, position);
  22348. var m;
  22349. if (token.indexOf('xref') === 0 &&
  22350. (token.length === 4 || /\s/.test(token[4]))) {
  22351. position += skipUntil(buffer, position, trailerBytes);
  22352. trailers.push(position);
  22353. position += skipUntil(buffer, position, startxrefBytes);
  22354. } else if ((m = objRegExp.exec(token))) {
  22355. if (typeof this.entries[m[1]] === 'undefined') {
  22356. this.entries[m[1]] = {
  22357. offset: position - stream.start,
  22358. gen: m[2] | 0,
  22359. uncompressed: true
  22360. };
  22361. }
  22362. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  22363. var content = buffer.subarray(position, position + contentLength);
  22364. // checking XRef stream suspect
  22365. // (it shall have '/XRef' and next char is not a letter)
  22366. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  22367. if (xrefTagOffset < contentLength &&
  22368. content[xrefTagOffset + 5] < 64) {
  22369. xrefStms.push(position - stream.start);
  22370. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  22371. }
  22372. position += contentLength;
  22373. } else if (token.indexOf('trailer') === 0 &&
  22374. (token.length === 7 || /\s/.test(token[7]))) {
  22375. trailers.push(position);
  22376. position += skipUntil(buffer, position, startxrefBytes);
  22377. } else {
  22378. position += token.length + 1;
  22379. }
  22380. }
  22381. // reading XRef streams
  22382. var i, ii;
  22383. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  22384. this.startXRefQueue.push(xrefStms[i]);
  22385. this.readXRef(/* recoveryMode */ true);
  22386. }
  22387. // finding main trailer
  22388. var dict;
  22389. for (i = 0, ii = trailers.length; i < ii; ++i) {
  22390. stream.pos = trailers[i];
  22391. var parser = new Parser(new Lexer(stream), true, this);
  22392. var obj = parser.getObj();
  22393. if (!isCmd(obj, 'trailer')) {
  22394. continue;
  22395. }
  22396. // read the trailer dictionary
  22397. if (!isDict(dict = parser.getObj())) {
  22398. continue;
  22399. }
  22400. // taking the first one with 'ID'
  22401. if (dict.has('ID')) {
  22402. return dict;
  22403. }
  22404. }
  22405. // no tailer with 'ID', taking last one (if exists)
  22406. if (dict) {
  22407. return dict;
  22408. }
  22409. // nothing helps
  22410. // calling error() would reject worker with an UnknownErrorException.
  22411. throw new InvalidPDFException('Invalid PDF structure');
  22412. },
  22413. readXRef: function XRef_readXRef(recoveryMode) {
  22414. var stream = this.stream;
  22415. try {
  22416. while (this.startXRefQueue.length) {
  22417. var startXRef = this.startXRefQueue[0];
  22418. stream.pos = startXRef + stream.start;
  22419. var parser = new Parser(new Lexer(stream), true, this);
  22420. var obj = parser.getObj();
  22421. var dict;
  22422. // Get dictionary
  22423. if (isCmd(obj, 'xref')) {
  22424. // Parse end-of-file XRef
  22425. dict = this.processXRefTable(parser);
  22426. if (!this.topDict) {
  22427. this.topDict = dict;
  22428. }
  22429. // Recursively get other XRefs 'XRefStm', if any
  22430. obj = dict.get('XRefStm');
  22431. if (isInt(obj)) {
  22432. var pos = obj;
  22433. // ignore previously loaded xref streams
  22434. // (possible infinite recursion)
  22435. if (!(pos in this.xrefstms)) {
  22436. this.xrefstms[pos] = 1;
  22437. this.startXRefQueue.push(pos);
  22438. }
  22439. }
  22440. } else if (isInt(obj)) {
  22441. // Parse in-stream XRef
  22442. if (!isInt(parser.getObj()) ||
  22443. !isCmd(parser.getObj(), 'obj') ||
  22444. !isStream(obj = parser.getObj())) {
  22445. error('Invalid XRef stream');
  22446. }
  22447. dict = this.processXRefStream(obj);
  22448. if (!this.topDict) {
  22449. this.topDict = dict;
  22450. }
  22451. if (!dict) {
  22452. error('Failed to read XRef stream');
  22453. }
  22454. } else {
  22455. error('Invalid XRef stream header');
  22456. }
  22457. // Recursively get previous dictionary, if any
  22458. obj = dict.get('Prev');
  22459. if (isInt(obj)) {
  22460. this.startXRefQueue.push(obj);
  22461. } else if (isRef(obj)) {
  22462. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  22463. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  22464. this.startXRefQueue.push(obj.num);
  22465. }
  22466. this.startXRefQueue.shift();
  22467. }
  22468. return this.topDict;
  22469. } catch (e) {
  22470. if (e instanceof MissingDataException) {
  22471. throw e;
  22472. }
  22473. info('(while reading XRef): ' + e);
  22474. }
  22475. if (recoveryMode) {
  22476. return;
  22477. }
  22478. throw new XRefParseException();
  22479. },
  22480. getEntry: function XRef_getEntry(i) {
  22481. var xrefEntry = this.entries[i];
  22482. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  22483. return xrefEntry;
  22484. }
  22485. return null;
  22486. },
  22487. fetchIfRef: function XRef_fetchIfRef(obj) {
  22488. if (!isRef(obj)) {
  22489. return obj;
  22490. }
  22491. return this.fetch(obj);
  22492. },
  22493. fetch: function XRef_fetch(ref, suppressEncryption) {
  22494. assert(isRef(ref), 'ref object is not a reference');
  22495. var num = ref.num;
  22496. if (num in this.cache) {
  22497. var cacheEntry = this.cache[num];
  22498. return cacheEntry;
  22499. }
  22500. var xrefEntry = this.getEntry(num);
  22501. // the referenced entry can be free
  22502. if (xrefEntry === null) {
  22503. return (this.cache[num] = null);
  22504. }
  22505. if (xrefEntry.uncompressed) {
  22506. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  22507. } else {
  22508. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  22509. }
  22510. if (isDict(xrefEntry)){
  22511. xrefEntry.objId = ref.toString();
  22512. } else if (isStream(xrefEntry)) {
  22513. xrefEntry.dict.objId = ref.toString();
  22514. }
  22515. return xrefEntry;
  22516. },
  22517. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  22518. suppressEncryption) {
  22519. var gen = ref.gen;
  22520. var num = ref.num;
  22521. if (xrefEntry.gen !== gen) {
  22522. error('inconsistent generation in XRef');
  22523. }
  22524. var stream = this.stream.makeSubStream(xrefEntry.offset +
  22525. this.stream.start);
  22526. var parser = new Parser(new Lexer(stream), true, this);
  22527. var obj1 = parser.getObj();
  22528. var obj2 = parser.getObj();
  22529. var obj3 = parser.getObj();
  22530. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  22531. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  22532. !isCmd(obj3)) {
  22533. error('bad XRef entry');
  22534. }
  22535. if (!isCmd(obj3, 'obj')) {
  22536. // some bad PDFs use "obj1234" and really mean 1234
  22537. if (obj3.cmd.indexOf('obj') === 0) {
  22538. num = parseInt(obj3.cmd.substring(3), 10);
  22539. if (!isNaN(num)) {
  22540. return num;
  22541. }
  22542. }
  22543. error('bad XRef entry');
  22544. }
  22545. if (this.encrypt && !suppressEncryption) {
  22546. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  22547. } else {
  22548. xrefEntry = parser.getObj();
  22549. }
  22550. if (!isStream(xrefEntry)) {
  22551. this.cache[num] = xrefEntry;
  22552. }
  22553. return xrefEntry;
  22554. },
  22555. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  22556. suppressEncryption) {
  22557. var tableOffset = xrefEntry.offset;
  22558. var stream = this.fetch(new Ref(tableOffset, 0));
  22559. if (!isStream(stream)) {
  22560. error('bad ObjStm stream');
  22561. }
  22562. var first = stream.dict.get('First');
  22563. var n = stream.dict.get('N');
  22564. if (!isInt(first) || !isInt(n)) {
  22565. error('invalid first and n parameters for ObjStm stream');
  22566. }
  22567. var parser = new Parser(new Lexer(stream), false, this);
  22568. parser.allowStreams = true;
  22569. var i, entries = [], num, nums = [];
  22570. // read the object numbers to populate cache
  22571. for (i = 0; i < n; ++i) {
  22572. num = parser.getObj();
  22573. if (!isInt(num)) {
  22574. error('invalid object number in the ObjStm stream: ' + num);
  22575. }
  22576. nums.push(num);
  22577. var offset = parser.getObj();
  22578. if (!isInt(offset)) {
  22579. error('invalid object offset in the ObjStm stream: ' + offset);
  22580. }
  22581. }
  22582. // read stream objects for cache
  22583. for (i = 0; i < n; ++i) {
  22584. entries.push(parser.getObj());
  22585. num = nums[i];
  22586. var entry = this.entries[num];
  22587. if (entry && entry.offset === tableOffset && entry.gen === i) {
  22588. this.cache[num] = entries[i];
  22589. }
  22590. }
  22591. xrefEntry = entries[xrefEntry.gen];
  22592. if (xrefEntry === undefined) {
  22593. error('bad XRef entry for compressed object');
  22594. }
  22595. return xrefEntry;
  22596. },
  22597. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  22598. if (!isRef(obj)) {
  22599. return Promise.resolve(obj);
  22600. }
  22601. return this.fetchAsync(obj);
  22602. },
  22603. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  22604. var streamManager = this.stream.manager;
  22605. var xref = this;
  22606. return new Promise(function tryFetch(resolve, reject) {
  22607. try {
  22608. resolve(xref.fetch(ref, suppressEncryption));
  22609. } catch (e) {
  22610. if (e instanceof MissingDataException) {
  22611. streamManager.requestRange(e.begin, e.end).then(function () {
  22612. tryFetch(resolve, reject);
  22613. }, reject);
  22614. return;
  22615. }
  22616. reject(e);
  22617. }
  22618. });
  22619. },
  22620. getCatalogObj: function XRef_getCatalogObj() {
  22621. return this.root;
  22622. }
  22623. };
  22624. return XRef;
  22625. })();
  22626. /**
  22627. * A NameTree is like a Dict but has some advantageous properties, see the
  22628. * spec (7.9.6) for more details.
  22629. * TODO: implement all the Dict functions and make this more efficent.
  22630. */
  22631. var NameTree = (function NameTreeClosure() {
  22632. function NameTree(root, xref) {
  22633. this.root = root;
  22634. this.xref = xref;
  22635. }
  22636. NameTree.prototype = {
  22637. getAll: function NameTree_getAll() {
  22638. var dict = {};
  22639. if (!this.root) {
  22640. return dict;
  22641. }
  22642. var xref = this.xref;
  22643. // reading name tree
  22644. var processed = new RefSet();
  22645. processed.put(this.root);
  22646. var queue = [this.root];
  22647. while (queue.length > 0) {
  22648. var i, n;
  22649. var obj = xref.fetchIfRef(queue.shift());
  22650. if (!isDict(obj)) {
  22651. continue;
  22652. }
  22653. if (obj.has('Kids')) {
  22654. var kids = obj.get('Kids');
  22655. for (i = 0, n = kids.length; i < n; i++) {
  22656. var kid = kids[i];
  22657. if (processed.has(kid)) {
  22658. error('invalid destinations');
  22659. }
  22660. queue.push(kid);
  22661. processed.put(kid);
  22662. }
  22663. continue;
  22664. }
  22665. var names = obj.get('Names');
  22666. if (names) {
  22667. for (i = 0, n = names.length; i < n; i += 2) {
  22668. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  22669. }
  22670. }
  22671. }
  22672. return dict;
  22673. },
  22674. get: function NameTree_get(destinationId) {
  22675. if (!this.root) {
  22676. return null;
  22677. }
  22678. var xref = this.xref;
  22679. var kidsOrNames = xref.fetchIfRef(this.root);
  22680. var loopCount = 0;
  22681. var MAX_NAMES_LEVELS = 10;
  22682. var l, r, m;
  22683. // Perform a binary search to quickly find the entry that
  22684. // contains the named destination we are looking for.
  22685. while (kidsOrNames.has('Kids')) {
  22686. loopCount++;
  22687. if (loopCount > MAX_NAMES_LEVELS) {
  22688. warn('Search depth limit for named destionations has been reached.');
  22689. return null;
  22690. }
  22691. var kids = kidsOrNames.get('Kids');
  22692. if (!isArray(kids)) {
  22693. return null;
  22694. }
  22695. l = 0;
  22696. r = kids.length - 1;
  22697. while (l <= r) {
  22698. m = (l + r) >> 1;
  22699. var kid = xref.fetchIfRef(kids[m]);
  22700. var limits = kid.get('Limits');
  22701. if (destinationId < xref.fetchIfRef(limits[0])) {
  22702. r = m - 1;
  22703. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  22704. l = m + 1;
  22705. } else {
  22706. kidsOrNames = xref.fetchIfRef(kids[m]);
  22707. break;
  22708. }
  22709. }
  22710. if (l > r) {
  22711. return null;
  22712. }
  22713. }
  22714. // If we get here, then we have found the right entry. Now
  22715. // go through the named destinations in the Named dictionary
  22716. // until we find the exact destination we're looking for.
  22717. var names = kidsOrNames.get('Names');
  22718. if (isArray(names)) {
  22719. // Perform a binary search to reduce the lookup time.
  22720. l = 0;
  22721. r = names.length - 2;
  22722. while (l <= r) {
  22723. // Check only even indices (0, 2, 4, ...) because the
  22724. // odd indices contain the actual D array.
  22725. m = (l + r) & ~1;
  22726. if (destinationId < xref.fetchIfRef(names[m])) {
  22727. r = m - 2;
  22728. } else if (destinationId > xref.fetchIfRef(names[m])) {
  22729. l = m + 2;
  22730. } else {
  22731. return xref.fetchIfRef(names[m + 1]);
  22732. }
  22733. }
  22734. }
  22735. return null;
  22736. }
  22737. };
  22738. return NameTree;
  22739. })();
  22740. /**
  22741. * "A PDF file can refer to the contents of another file by using a File
  22742. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  22743. * NOTE: Only embedded files are supported (as part of the attachments support)
  22744. * TODO: support the 'URL' file system (with caching if !/V), portable
  22745. * collections attributes and related files (/RF)
  22746. */
  22747. var FileSpec = (function FileSpecClosure() {
  22748. function FileSpec(root, xref) {
  22749. if (!root || !isDict(root)) {
  22750. return;
  22751. }
  22752. this.xref = xref;
  22753. this.root = root;
  22754. if (root.has('FS')) {
  22755. this.fs = root.get('FS');
  22756. }
  22757. this.description = root.has('Desc') ?
  22758. stringToPDFString(root.get('Desc')) :
  22759. '';
  22760. if (root.has('RF')) {
  22761. warn('Related file specifications are not supported');
  22762. }
  22763. this.contentAvailable = true;
  22764. if (!root.has('EF')) {
  22765. this.contentAvailable = false;
  22766. warn('Non-embedded file specifications are not supported');
  22767. }
  22768. }
  22769. function pickPlatformItem(dict) {
  22770. // Look for the filename in this order:
  22771. // UF, F, Unix, Mac, DOS
  22772. if (dict.has('UF')) {
  22773. return dict.get('UF');
  22774. } else if (dict.has('F')) {
  22775. return dict.get('F');
  22776. } else if (dict.has('Unix')) {
  22777. return dict.get('Unix');
  22778. } else if (dict.has('Mac')) {
  22779. return dict.get('Mac');
  22780. } else if (dict.has('DOS')) {
  22781. return dict.get('DOS');
  22782. } else {
  22783. return null;
  22784. }
  22785. }
  22786. FileSpec.prototype = {
  22787. get filename() {
  22788. if (!this._filename && this.root) {
  22789. var filename = pickPlatformItem(this.root) || 'unnamed';
  22790. this._filename = stringToPDFString(filename).
  22791. replace(/\\\\/g, '\\').
  22792. replace(/\\\//g, '/').
  22793. replace(/\\/g, '/');
  22794. }
  22795. return this._filename;
  22796. },
  22797. get content() {
  22798. if (!this.contentAvailable) {
  22799. return null;
  22800. }
  22801. if (!this.contentRef && this.root) {
  22802. this.contentRef = pickPlatformItem(this.root.get('EF'));
  22803. }
  22804. var content = null;
  22805. if (this.contentRef) {
  22806. var xref = this.xref;
  22807. var fileObj = xref.fetchIfRef(this.contentRef);
  22808. if (fileObj && isStream(fileObj)) {
  22809. content = fileObj.getBytes();
  22810. } else {
  22811. warn('Embedded file specification points to non-existing/invalid ' +
  22812. 'content');
  22813. }
  22814. } else {
  22815. warn('Embedded file specification does not have a content');
  22816. }
  22817. return content;
  22818. },
  22819. get serializable() {
  22820. return {
  22821. filename: this.filename,
  22822. content: this.content
  22823. };
  22824. }
  22825. };
  22826. return FileSpec;
  22827. })();
  22828. /**
  22829. * A helper for loading missing data in object graphs. It traverses the graph
  22830. * depth first and queues up any objects that have missing data. Once it has
  22831. * has traversed as many objects that are available it attempts to bundle the
  22832. * missing data requests and then resume from the nodes that weren't ready.
  22833. *
  22834. * NOTE: It provides protection from circular references by keeping track of
  22835. * of loaded references. However, you must be careful not to load any graphs
  22836. * that have references to the catalog or other pages since that will cause the
  22837. * entire PDF document object graph to be traversed.
  22838. */
  22839. var ObjectLoader = (function() {
  22840. function mayHaveChildren(value) {
  22841. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  22842. }
  22843. function addChildren(node, nodesToVisit) {
  22844. var value;
  22845. if (isDict(node) || isStream(node)) {
  22846. var map;
  22847. if (isDict(node)) {
  22848. map = node.map;
  22849. } else {
  22850. map = node.dict.map;
  22851. }
  22852. for (var key in map) {
  22853. value = map[key];
  22854. if (mayHaveChildren(value)) {
  22855. nodesToVisit.push(value);
  22856. }
  22857. }
  22858. } else if (isArray(node)) {
  22859. for (var i = 0, ii = node.length; i < ii; i++) {
  22860. value = node[i];
  22861. if (mayHaveChildren(value)) {
  22862. nodesToVisit.push(value);
  22863. }
  22864. }
  22865. }
  22866. }
  22867. function ObjectLoader(obj, keys, xref) {
  22868. this.obj = obj;
  22869. this.keys = keys;
  22870. this.xref = xref;
  22871. this.refSet = null;
  22872. this.capability = null;
  22873. }
  22874. ObjectLoader.prototype = {
  22875. load: function ObjectLoader_load() {
  22876. var keys = this.keys;
  22877. this.capability = createPromiseCapability();
  22878. // Don't walk the graph if all the data is already loaded.
  22879. if (!(this.xref.stream instanceof ChunkedStream) ||
  22880. this.xref.stream.getMissingChunks().length === 0) {
  22881. this.capability.resolve();
  22882. return this.capability.promise;
  22883. }
  22884. this.refSet = new RefSet();
  22885. // Setup the initial nodes to visit.
  22886. var nodesToVisit = [];
  22887. for (var i = 0; i < keys.length; i++) {
  22888. nodesToVisit.push(this.obj[keys[i]]);
  22889. }
  22890. this._walk(nodesToVisit);
  22891. return this.capability.promise;
  22892. },
  22893. _walk: function ObjectLoader_walk(nodesToVisit) {
  22894. var nodesToRevisit = [];
  22895. var pendingRequests = [];
  22896. // DFS walk of the object graph.
  22897. while (nodesToVisit.length) {
  22898. var currentNode = nodesToVisit.pop();
  22899. // Only references or chunked streams can cause missing data exceptions.
  22900. if (isRef(currentNode)) {
  22901. // Skip nodes that have already been visited.
  22902. if (this.refSet.has(currentNode)) {
  22903. continue;
  22904. }
  22905. try {
  22906. var ref = currentNode;
  22907. this.refSet.put(ref);
  22908. currentNode = this.xref.fetch(currentNode);
  22909. } catch (e) {
  22910. if (!(e instanceof MissingDataException)) {
  22911. throw e;
  22912. }
  22913. nodesToRevisit.push(currentNode);
  22914. pendingRequests.push({ begin: e.begin, end: e.end });
  22915. }
  22916. }
  22917. if (currentNode && currentNode.getBaseStreams) {
  22918. var baseStreams = currentNode.getBaseStreams();
  22919. var foundMissingData = false;
  22920. for (var i = 0; i < baseStreams.length; i++) {
  22921. var stream = baseStreams[i];
  22922. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  22923. foundMissingData = true;
  22924. pendingRequests.push({
  22925. begin: stream.start,
  22926. end: stream.end
  22927. });
  22928. }
  22929. }
  22930. if (foundMissingData) {
  22931. nodesToRevisit.push(currentNode);
  22932. }
  22933. }
  22934. addChildren(currentNode, nodesToVisit);
  22935. }
  22936. if (pendingRequests.length) {
  22937. this.xref.stream.manager.requestRanges(pendingRequests).then(
  22938. function pendingRequestCallback() {
  22939. nodesToVisit = nodesToRevisit;
  22940. for (var i = 0; i < nodesToRevisit.length; i++) {
  22941. var node = nodesToRevisit[i];
  22942. // Remove any reference nodes from the currrent refset so they
  22943. // aren't skipped when we revist them.
  22944. if (isRef(node)) {
  22945. this.refSet.remove(node);
  22946. }
  22947. }
  22948. this._walk(nodesToVisit);
  22949. }.bind(this), this.capability.reject);
  22950. return;
  22951. }
  22952. // Everything is loaded.
  22953. this.refSet = null;
  22954. this.capability.resolve();
  22955. }
  22956. };
  22957. return ObjectLoader;
  22958. })();
  22959. exports.Catalog = Catalog;
  22960. exports.ObjectLoader = ObjectLoader;
  22961. exports.XRef = XRef;
  22962. }));
  22963. (function (root, factory) {
  22964. {
  22965. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  22966. root.pdfjsCoreParser);
  22967. }
  22968. }(this, function (exports, sharedUtil, coreParser) {
  22969. var error = sharedUtil.error;
  22970. var EOF = coreParser.EOF;
  22971. var Lexer = coreParser.Lexer;
  22972. var PostScriptParser = (function PostScriptParserClosure() {
  22973. function PostScriptParser(lexer) {
  22974. this.lexer = lexer;
  22975. this.operators = [];
  22976. this.token = null;
  22977. this.prev = null;
  22978. }
  22979. PostScriptParser.prototype = {
  22980. nextToken: function PostScriptParser_nextToken() {
  22981. this.prev = this.token;
  22982. this.token = this.lexer.getToken();
  22983. },
  22984. accept: function PostScriptParser_accept(type) {
  22985. if (this.token.type === type) {
  22986. this.nextToken();
  22987. return true;
  22988. }
  22989. return false;
  22990. },
  22991. expect: function PostScriptParser_expect(type) {
  22992. if (this.accept(type)) {
  22993. return true;
  22994. }
  22995. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  22996. type + '.');
  22997. },
  22998. parse: function PostScriptParser_parse() {
  22999. this.nextToken();
  23000. this.expect(PostScriptTokenTypes.LBRACE);
  23001. this.parseBlock();
  23002. this.expect(PostScriptTokenTypes.RBRACE);
  23003. return this.operators;
  23004. },
  23005. parseBlock: function PostScriptParser_parseBlock() {
  23006. while (true) {
  23007. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  23008. this.operators.push(this.prev.value);
  23009. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  23010. this.operators.push(this.prev.value);
  23011. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23012. this.parseCondition();
  23013. } else {
  23014. return;
  23015. }
  23016. }
  23017. },
  23018. parseCondition: function PostScriptParser_parseCondition() {
  23019. // Add two place holders that will be updated later
  23020. var conditionLocation = this.operators.length;
  23021. this.operators.push(null, null);
  23022. this.parseBlock();
  23023. this.expect(PostScriptTokenTypes.RBRACE);
  23024. if (this.accept(PostScriptTokenTypes.IF)) {
  23025. // The true block is right after the 'if' so it just falls through on
  23026. // true else it jumps and skips the true block.
  23027. this.operators[conditionLocation] = this.operators.length;
  23028. this.operators[conditionLocation + 1] = 'jz';
  23029. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23030. var jumpLocation = this.operators.length;
  23031. this.operators.push(null, null);
  23032. var endOfTrue = this.operators.length;
  23033. this.parseBlock();
  23034. this.expect(PostScriptTokenTypes.RBRACE);
  23035. this.expect(PostScriptTokenTypes.IFELSE);
  23036. // The jump is added at the end of the true block to skip the false
  23037. // block.
  23038. this.operators[jumpLocation] = this.operators.length;
  23039. this.operators[jumpLocation + 1] = 'j';
  23040. this.operators[conditionLocation] = endOfTrue;
  23041. this.operators[conditionLocation + 1] = 'jz';
  23042. } else {
  23043. error('PS Function: error parsing conditional.');
  23044. }
  23045. }
  23046. };
  23047. return PostScriptParser;
  23048. })();
  23049. var PostScriptTokenTypes = {
  23050. LBRACE: 0,
  23051. RBRACE: 1,
  23052. NUMBER: 2,
  23053. OPERATOR: 3,
  23054. IF: 4,
  23055. IFELSE: 5
  23056. };
  23057. var PostScriptToken = (function PostScriptTokenClosure() {
  23058. function PostScriptToken(type, value) {
  23059. this.type = type;
  23060. this.value = value;
  23061. }
  23062. var opCache = {};
  23063. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  23064. var opValue = opCache[op];
  23065. if (opValue) {
  23066. return opValue;
  23067. }
  23068. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  23069. };
  23070. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  23071. '{');
  23072. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  23073. '}');
  23074. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  23075. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  23076. 'IFELSE');
  23077. return PostScriptToken;
  23078. })();
  23079. var PostScriptLexer = (function PostScriptLexerClosure() {
  23080. function PostScriptLexer(stream) {
  23081. this.stream = stream;
  23082. this.nextChar();
  23083. this.strBuf = [];
  23084. }
  23085. PostScriptLexer.prototype = {
  23086. nextChar: function PostScriptLexer_nextChar() {
  23087. return (this.currentChar = this.stream.getByte());
  23088. },
  23089. getToken: function PostScriptLexer_getToken() {
  23090. var comment = false;
  23091. var ch = this.currentChar;
  23092. // skip comments
  23093. while (true) {
  23094. if (ch < 0) {
  23095. return EOF;
  23096. }
  23097. if (comment) {
  23098. if (ch === 0x0A || ch === 0x0D) {
  23099. comment = false;
  23100. }
  23101. } else if (ch === 0x25) { // '%'
  23102. comment = true;
  23103. } else if (!Lexer.isSpace(ch)) {
  23104. break;
  23105. }
  23106. ch = this.nextChar();
  23107. }
  23108. switch (ch | 0) {
  23109. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23110. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23111. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23112. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  23113. this.getNumber());
  23114. case 0x7B: // '{'
  23115. this.nextChar();
  23116. return PostScriptToken.LBRACE;
  23117. case 0x7D: // '}'
  23118. this.nextChar();
  23119. return PostScriptToken.RBRACE;
  23120. }
  23121. // operator
  23122. var strBuf = this.strBuf;
  23123. strBuf.length = 0;
  23124. strBuf[0] = String.fromCharCode(ch);
  23125. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  23126. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  23127. strBuf.push(String.fromCharCode(ch));
  23128. }
  23129. var str = strBuf.join('');
  23130. switch (str.toLowerCase()) {
  23131. case 'if':
  23132. return PostScriptToken.IF;
  23133. case 'ifelse':
  23134. return PostScriptToken.IFELSE;
  23135. default:
  23136. return PostScriptToken.getOperator(str);
  23137. }
  23138. },
  23139. getNumber: function PostScriptLexer_getNumber() {
  23140. var ch = this.currentChar;
  23141. var strBuf = this.strBuf;
  23142. strBuf.length = 0;
  23143. strBuf[0] = String.fromCharCode(ch);
  23144. while ((ch = this.nextChar()) >= 0) {
  23145. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  23146. ch === 0x2D || ch === 0x2E) { // '-', '.'
  23147. strBuf.push(String.fromCharCode(ch));
  23148. } else {
  23149. break;
  23150. }
  23151. }
  23152. var value = parseFloat(strBuf.join(''));
  23153. if (isNaN(value)) {
  23154. error('Invalid floating point number: ' + value);
  23155. }
  23156. return value;
  23157. }
  23158. };
  23159. return PostScriptLexer;
  23160. })();
  23161. exports.PostScriptLexer = PostScriptLexer;
  23162. exports.PostScriptParser = PostScriptParser;
  23163. }));
  23164. (function (root, factory) {
  23165. {
  23166. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  23167. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  23168. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  23169. root.pdfjsCoreFontRenderer);
  23170. }
  23171. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  23172. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  23173. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23174. var FontType = sharedUtil.FontType;
  23175. var Util = sharedUtil.Util;
  23176. var assert = sharedUtil.assert;
  23177. var bytesToString = sharedUtil.bytesToString;
  23178. var error = sharedUtil.error;
  23179. var info = sharedUtil.info;
  23180. var isArray = sharedUtil.isArray;
  23181. var isInt = sharedUtil.isInt;
  23182. var isNum = sharedUtil.isNum;
  23183. var readUint32 = sharedUtil.readUint32;
  23184. var shadow = sharedUtil.shadow;
  23185. var stringToBytes = sharedUtil.stringToBytes;
  23186. var string32 = sharedUtil.string32;
  23187. var warn = sharedUtil.warn;
  23188. var Name = corePrimitives.Name;
  23189. var Stream = coreStream.Stream;
  23190. var Lexer = coreParser.Lexer;
  23191. var CMapFactory = coreCMap.CMapFactory;
  23192. var IdentityCMap = coreCMap.IdentityCMap;
  23193. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  23194. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  23195. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  23196. var ExpertCharset = coreCharsets.ExpertCharset;
  23197. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  23198. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  23199. // Unicode Private Use Area
  23200. var PRIVATE_USE_OFFSET_START = 0xE000;
  23201. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  23202. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  23203. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  23204. // except for Type 3 fonts
  23205. var PDF_GLYPH_SPACE_UNITS = 1000;
  23206. // Hinting is currently disabled due to unknown problems on windows
  23207. // in tracemonkey and various other pdfs with type1 fonts.
  23208. var HINTING_ENABLED = false;
  23209. // Accented charactars are not displayed properly on windows, using this flag
  23210. // to control analysis of seac charstrings.
  23211. var SEAC_ANALYSIS_ENABLED = false;
  23212. var FontFlags = {
  23213. FixedPitch: 1,
  23214. Serif: 2,
  23215. Symbolic: 4,
  23216. Script: 8,
  23217. Nonsymbolic: 32,
  23218. Italic: 64,
  23219. AllCap: 65536,
  23220. SmallCap: 131072,
  23221. ForceBold: 262144
  23222. };
  23223. var Encodings = {
  23224. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23225. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23226. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  23227. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  23228. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  23229. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  23230. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  23231. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  23232. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  23233. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  23234. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  23235. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  23236. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  23237. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  23238. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  23239. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  23240. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  23241. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  23242. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  23243. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23244. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23245. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  23246. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  23247. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  23248. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  23249. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  23250. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  23251. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  23252. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  23253. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  23254. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  23255. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  23256. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  23257. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  23258. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  23259. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  23260. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  23261. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  23262. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  23263. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  23264. 'Ydieresissmall'],
  23265. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23266. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23267. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  23268. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  23269. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23270. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  23271. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  23272. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  23273. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  23274. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  23275. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  23276. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  23277. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  23278. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  23279. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23280. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23281. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23282. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23283. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  23284. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  23285. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  23286. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  23287. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  23288. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  23289. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  23290. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  23291. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  23292. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  23293. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  23294. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  23295. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  23296. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  23297. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  23298. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  23299. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23300. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  23301. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  23302. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  23303. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  23304. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  23305. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23306. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23307. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23308. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23309. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23310. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23311. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23312. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23313. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23314. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23315. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23316. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  23317. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  23318. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  23319. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23320. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  23321. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  23322. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  23323. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  23324. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  23325. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  23326. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  23327. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  23328. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  23329. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  23330. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  23331. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  23332. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  23333. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  23334. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  23335. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  23336. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  23337. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  23338. 'ogonek', 'caron'],
  23339. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23340. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23341. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23342. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23343. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23344. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23345. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23346. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23347. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23348. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  23349. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  23350. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23351. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23352. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  23353. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23354. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23355. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  23356. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  23357. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  23358. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  23359. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  23360. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  23361. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  23362. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  23363. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  23364. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23365. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23366. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23367. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23368. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23369. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23370. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23371. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23372. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23373. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23374. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23375. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23376. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  23377. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  23378. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  23379. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  23380. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  23381. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  23382. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  23383. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  23384. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  23385. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  23386. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  23387. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  23388. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  23389. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  23390. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  23391. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  23392. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  23393. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  23394. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  23395. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  23396. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  23397. 'ydieresis'],
  23398. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23399. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23400. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  23401. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  23402. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23403. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23404. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  23405. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  23406. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  23407. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  23408. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  23409. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  23410. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  23411. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  23412. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  23413. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23414. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  23415. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  23416. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  23417. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  23418. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  23419. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  23420. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  23421. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  23422. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  23423. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  23424. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  23425. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  23426. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  23427. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  23428. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  23429. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  23430. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  23431. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  23432. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  23433. 'bracerightbt'],
  23434. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23435. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23436. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  23437. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  23438. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  23439. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  23440. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  23441. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  23442. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  23443. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  23444. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  23445. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  23446. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  23447. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  23448. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  23449. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  23450. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  23451. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  23452. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  23453. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  23454. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  23455. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  23456. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  23457. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  23458. };
  23459. /**
  23460. * Hold a map of decoded fonts and of the standard fourteen Type1
  23461. * fonts and their acronyms.
  23462. */
  23463. var stdFontMap = {
  23464. 'ArialNarrow': 'Helvetica',
  23465. 'ArialNarrow-Bold': 'Helvetica-Bold',
  23466. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  23467. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  23468. 'ArialBlack': 'Helvetica',
  23469. 'ArialBlack-Bold': 'Helvetica-Bold',
  23470. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  23471. 'ArialBlack-Italic': 'Helvetica-Oblique',
  23472. 'Arial': 'Helvetica',
  23473. 'Arial-Bold': 'Helvetica-Bold',
  23474. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  23475. 'Arial-Italic': 'Helvetica-Oblique',
  23476. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  23477. 'Arial-BoldMT': 'Helvetica-Bold',
  23478. 'Arial-ItalicMT': 'Helvetica-Oblique',
  23479. 'ArialMT': 'Helvetica',
  23480. 'Courier-Bold': 'Courier-Bold',
  23481. 'Courier-BoldItalic': 'Courier-BoldOblique',
  23482. 'Courier-Italic': 'Courier-Oblique',
  23483. 'CourierNew': 'Courier',
  23484. 'CourierNew-Bold': 'Courier-Bold',
  23485. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  23486. 'CourierNew-Italic': 'Courier-Oblique',
  23487. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  23488. 'CourierNewPS-BoldMT': 'Courier-Bold',
  23489. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  23490. 'CourierNewPSMT': 'Courier',
  23491. 'Helvetica': 'Helvetica',
  23492. 'Helvetica-Bold': 'Helvetica-Bold',
  23493. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  23494. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  23495. 'Helvetica-Italic': 'Helvetica-Oblique',
  23496. 'Helvetica-Oblique':'Helvetica-Oblique',
  23497. 'Symbol-Bold': 'Symbol',
  23498. 'Symbol-BoldItalic': 'Symbol',
  23499. 'Symbol-Italic': 'Symbol',
  23500. 'TimesNewRoman': 'Times-Roman',
  23501. 'TimesNewRoman-Bold': 'Times-Bold',
  23502. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  23503. 'TimesNewRoman-Italic': 'Times-Italic',
  23504. 'TimesNewRomanPS': 'Times-Roman',
  23505. 'TimesNewRomanPS-Bold': 'Times-Bold',
  23506. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  23507. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  23508. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  23509. 'TimesNewRomanPS-Italic': 'Times-Italic',
  23510. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  23511. 'TimesNewRomanPSMT': 'Times-Roman',
  23512. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  23513. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  23514. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  23515. };
  23516. /**
  23517. * Holds the map of the non-standard fonts that might be included as a standard
  23518. * fonts without glyph data.
  23519. */
  23520. var nonStdFontMap = {
  23521. 'CenturyGothic': 'Helvetica',
  23522. 'CenturyGothic-Bold': 'Helvetica-Bold',
  23523. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  23524. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  23525. 'ComicSansMS': 'Comic Sans MS',
  23526. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  23527. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  23528. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  23529. 'LucidaConsole': 'Courier',
  23530. 'LucidaConsole-Bold': 'Courier-Bold',
  23531. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  23532. 'LucidaConsole-Italic': 'Courier-Oblique',
  23533. 'MS-Gothic': 'MS Gothic',
  23534. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  23535. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  23536. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  23537. 'MS-Mincho': 'MS Mincho',
  23538. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  23539. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  23540. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  23541. 'MS-PGothic': 'MS PGothic',
  23542. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  23543. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  23544. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  23545. 'MS-PMincho': 'MS PMincho',
  23546. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  23547. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  23548. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  23549. 'Wingdings': 'ZapfDingbats'
  23550. };
  23551. var serifFonts = {
  23552. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  23553. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  23554. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  23555. 'Arno': true, 'Aster': true, 'Aurora': true,
  23556. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  23557. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  23558. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  23559. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  23560. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  23561. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  23562. 'Cartier': true, 'Caslon': true, 'Catull': true,
  23563. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  23564. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  23565. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  23566. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  23567. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  23568. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  23569. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  23570. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  23571. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  23572. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  23573. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  23574. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  23575. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  23576. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  23577. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  23578. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  23579. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  23580. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  23581. 'Miller': true, 'Minion': true, 'Modern': true,
  23582. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  23583. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  23584. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  23585. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  23586. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  23587. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  23588. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  23589. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  23590. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  23591. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  23592. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  23593. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  23594. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  23595. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  23596. };
  23597. var symbolsFonts = {
  23598. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  23599. };
  23600. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  23601. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  23602. // glyphs, but common for some set of the standard fonts.
  23603. var GlyphMapForStandardFonts = {
  23604. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  23605. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  23606. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  23607. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  23608. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  23609. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  23610. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  23611. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  23612. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  23613. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  23614. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  23615. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  23616. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  23617. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  23618. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  23619. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  23620. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  23621. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  23622. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  23623. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  23624. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  23625. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  23626. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  23627. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  23628. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  23629. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  23630. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  23631. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  23632. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  23633. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  23634. '298': 380, '305': 963,
  23635. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  23636. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  23637. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  23638. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  23639. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  23640. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  23641. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  23642. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  23643. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  23644. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  23645. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  23646. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  23647. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  23648. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  23649. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  23650. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  23651. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  23652. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  23653. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  23654. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  23655. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  23656. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  23657. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  23658. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  23659. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  23660. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  23661. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  23662. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  23663. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  23664. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  23665. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  23666. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  23667. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  23668. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  23669. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  23670. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  23671. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  23672. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  23673. };
  23674. // The glyph map for ArialBlack differs slightly from the glyph map used for
  23675. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  23676. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  23677. var SupplementalGlyphMapForArialBlack = {
  23678. '227': 322, '264': 261, '291': 346,
  23679. };
  23680. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  23681. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  23682. // to the similar equivalents in the normal characters range.
  23683. var SpecialPUASymbols = {
  23684. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  23685. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  23686. '63720': 0x00AE, // registersans (0xF8E8) => registered
  23687. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  23688. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  23689. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  23690. '63729': 0x23A7, // bracelefttp (0xF8F1)
  23691. '63730': 0x23A8, // braceleftmid (0xF8F2)
  23692. '63731': 0x23A9, // braceleftbt (0xF8F3)
  23693. '63740': 0x23AB, // bracerighttp (0xF8FC)
  23694. '63741': 0x23AC, // bracerightmid (0xF8FD)
  23695. '63742': 0x23AD, // bracerightbt (0xF8FE)
  23696. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  23697. '63727': 0x23A2, // bracketleftex (0xF8EF)
  23698. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  23699. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  23700. '63738': 0x23A5, // bracketrightex (0xF8FA)
  23701. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  23702. '63723': 0x239B, // parenlefttp (0xF8EB)
  23703. '63724': 0x239C, // parenleftex (0xF8EC)
  23704. '63725': 0x239D, // parenleftbt (0xF8ED)
  23705. '63734': 0x239E, // parenrighttp (0xF8F6)
  23706. '63735': 0x239F, // parenrightex (0xF8F7)
  23707. '63736': 0x23A0, // parenrightbt (0xF8F8)
  23708. };
  23709. function mapSpecialUnicodeValues(code) {
  23710. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  23711. return 0;
  23712. } else if (code >= 0xF600 && code <= 0xF8FF) {
  23713. return (SpecialPUASymbols[code] || code);
  23714. }
  23715. return code;
  23716. }
  23717. var UnicodeRanges = [
  23718. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  23719. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  23720. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  23721. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  23722. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  23723. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  23724. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  23725. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  23726. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  23727. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  23728. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  23729. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  23730. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  23731. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  23732. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  23733. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  23734. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  23735. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  23736. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  23737. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  23738. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  23739. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  23740. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  23741. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  23742. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  23743. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  23744. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  23745. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  23746. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  23747. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  23748. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  23749. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  23750. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  23751. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  23752. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  23753. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  23754. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  23755. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  23756. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  23757. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  23758. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  23759. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  23760. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  23761. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  23762. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  23763. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  23764. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  23765. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  23766. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  23767. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  23768. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  23769. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  23770. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  23771. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  23772. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  23773. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  23774. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  23775. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  23776. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  23777. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  23778. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  23779. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  23780. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  23781. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  23782. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  23783. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  23784. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  23785. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  23786. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  23787. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  23788. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  23789. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  23790. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  23791. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  23792. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  23793. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  23794. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  23795. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  23796. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  23797. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  23798. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  23799. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  23800. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  23801. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  23802. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  23803. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  23804. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  23805. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  23806. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  23807. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  23808. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  23809. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  23810. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  23811. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  23812. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  23813. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  23814. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  23815. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  23816. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  23817. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  23818. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  23819. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  23820. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  23821. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  23822. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  23823. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  23824. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  23825. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  23826. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  23827. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  23828. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  23829. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  23830. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  23831. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  23832. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  23833. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  23834. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  23835. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  23836. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  23837. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  23838. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  23839. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  23840. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  23841. ];
  23842. var MacStandardGlyphOrdering = [
  23843. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  23844. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  23845. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  23846. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  23847. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  23848. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  23849. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  23850. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  23851. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  23852. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  23853. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  23854. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  23855. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23856. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  23857. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  23858. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  23859. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  23860. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  23861. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  23862. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  23863. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  23864. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  23865. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  23866. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  23867. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  23868. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  23869. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  23870. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  23871. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  23872. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  23873. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  23874. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  23875. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  23876. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  23877. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  23878. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  23879. function getUnicodeRangeFor(value) {
  23880. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  23881. var range = UnicodeRanges[i];
  23882. if (value >= range.begin && value < range.end) {
  23883. return i;
  23884. }
  23885. }
  23886. return -1;
  23887. }
  23888. function isRTLRangeFor(value) {
  23889. var range = UnicodeRanges[13];
  23890. if (value >= range.begin && value < range.end) {
  23891. return true;
  23892. }
  23893. range = UnicodeRanges[11];
  23894. if (value >= range.begin && value < range.end) {
  23895. return true;
  23896. }
  23897. return false;
  23898. }
  23899. // The normalization table is obtained by filtering the Unicode characters
  23900. // database with <compat> entries.
  23901. var NormalizedUnicodes = {
  23902. '\u00A8': '\u0020\u0308',
  23903. '\u00AF': '\u0020\u0304',
  23904. '\u00B4': '\u0020\u0301',
  23905. '\u00B5': '\u03BC',
  23906. '\u00B8': '\u0020\u0327',
  23907. '\u0132': '\u0049\u004A',
  23908. '\u0133': '\u0069\u006A',
  23909. '\u013F': '\u004C\u00B7',
  23910. '\u0140': '\u006C\u00B7',
  23911. '\u0149': '\u02BC\u006E',
  23912. '\u017F': '\u0073',
  23913. '\u01C4': '\u0044\u017D',
  23914. '\u01C5': '\u0044\u017E',
  23915. '\u01C6': '\u0064\u017E',
  23916. '\u01C7': '\u004C\u004A',
  23917. '\u01C8': '\u004C\u006A',
  23918. '\u01C9': '\u006C\u006A',
  23919. '\u01CA': '\u004E\u004A',
  23920. '\u01CB': '\u004E\u006A',
  23921. '\u01CC': '\u006E\u006A',
  23922. '\u01F1': '\u0044\u005A',
  23923. '\u01F2': '\u0044\u007A',
  23924. '\u01F3': '\u0064\u007A',
  23925. '\u02D8': '\u0020\u0306',
  23926. '\u02D9': '\u0020\u0307',
  23927. '\u02DA': '\u0020\u030A',
  23928. '\u02DB': '\u0020\u0328',
  23929. '\u02DC': '\u0020\u0303',
  23930. '\u02DD': '\u0020\u030B',
  23931. '\u037A': '\u0020\u0345',
  23932. '\u0384': '\u0020\u0301',
  23933. '\u03D0': '\u03B2',
  23934. '\u03D1': '\u03B8',
  23935. '\u03D2': '\u03A5',
  23936. '\u03D5': '\u03C6',
  23937. '\u03D6': '\u03C0',
  23938. '\u03F0': '\u03BA',
  23939. '\u03F1': '\u03C1',
  23940. '\u03F2': '\u03C2',
  23941. '\u03F4': '\u0398',
  23942. '\u03F5': '\u03B5',
  23943. '\u03F9': '\u03A3',
  23944. '\u0587': '\u0565\u0582',
  23945. '\u0675': '\u0627\u0674',
  23946. '\u0676': '\u0648\u0674',
  23947. '\u0677': '\u06C7\u0674',
  23948. '\u0678': '\u064A\u0674',
  23949. '\u0E33': '\u0E4D\u0E32',
  23950. '\u0EB3': '\u0ECD\u0EB2',
  23951. '\u0EDC': '\u0EAB\u0E99',
  23952. '\u0EDD': '\u0EAB\u0EA1',
  23953. '\u0F77': '\u0FB2\u0F81',
  23954. '\u0F79': '\u0FB3\u0F81',
  23955. '\u1E9A': '\u0061\u02BE',
  23956. '\u1FBD': '\u0020\u0313',
  23957. '\u1FBF': '\u0020\u0313',
  23958. '\u1FC0': '\u0020\u0342',
  23959. '\u1FFE': '\u0020\u0314',
  23960. '\u2002': '\u0020',
  23961. '\u2003': '\u0020',
  23962. '\u2004': '\u0020',
  23963. '\u2005': '\u0020',
  23964. '\u2006': '\u0020',
  23965. '\u2008': '\u0020',
  23966. '\u2009': '\u0020',
  23967. '\u200A': '\u0020',
  23968. '\u2017': '\u0020\u0333',
  23969. '\u2024': '\u002E',
  23970. '\u2025': '\u002E\u002E',
  23971. '\u2026': '\u002E\u002E\u002E',
  23972. '\u2033': '\u2032\u2032',
  23973. '\u2034': '\u2032\u2032\u2032',
  23974. '\u2036': '\u2035\u2035',
  23975. '\u2037': '\u2035\u2035\u2035',
  23976. '\u203C': '\u0021\u0021',
  23977. '\u203E': '\u0020\u0305',
  23978. '\u2047': '\u003F\u003F',
  23979. '\u2048': '\u003F\u0021',
  23980. '\u2049': '\u0021\u003F',
  23981. '\u2057': '\u2032\u2032\u2032\u2032',
  23982. '\u205F': '\u0020',
  23983. '\u20A8': '\u0052\u0073',
  23984. '\u2100': '\u0061\u002F\u0063',
  23985. '\u2101': '\u0061\u002F\u0073',
  23986. '\u2103': '\u00B0\u0043',
  23987. '\u2105': '\u0063\u002F\u006F',
  23988. '\u2106': '\u0063\u002F\u0075',
  23989. '\u2107': '\u0190',
  23990. '\u2109': '\u00B0\u0046',
  23991. '\u2116': '\u004E\u006F',
  23992. '\u2121': '\u0054\u0045\u004C',
  23993. '\u2135': '\u05D0',
  23994. '\u2136': '\u05D1',
  23995. '\u2137': '\u05D2',
  23996. '\u2138': '\u05D3',
  23997. '\u213B': '\u0046\u0041\u0058',
  23998. '\u2160': '\u0049',
  23999. '\u2161': '\u0049\u0049',
  24000. '\u2162': '\u0049\u0049\u0049',
  24001. '\u2163': '\u0049\u0056',
  24002. '\u2164': '\u0056',
  24003. '\u2165': '\u0056\u0049',
  24004. '\u2166': '\u0056\u0049\u0049',
  24005. '\u2167': '\u0056\u0049\u0049\u0049',
  24006. '\u2168': '\u0049\u0058',
  24007. '\u2169': '\u0058',
  24008. '\u216A': '\u0058\u0049',
  24009. '\u216B': '\u0058\u0049\u0049',
  24010. '\u216C': '\u004C',
  24011. '\u216D': '\u0043',
  24012. '\u216E': '\u0044',
  24013. '\u216F': '\u004D',
  24014. '\u2170': '\u0069',
  24015. '\u2171': '\u0069\u0069',
  24016. '\u2172': '\u0069\u0069\u0069',
  24017. '\u2173': '\u0069\u0076',
  24018. '\u2174': '\u0076',
  24019. '\u2175': '\u0076\u0069',
  24020. '\u2176': '\u0076\u0069\u0069',
  24021. '\u2177': '\u0076\u0069\u0069\u0069',
  24022. '\u2178': '\u0069\u0078',
  24023. '\u2179': '\u0078',
  24024. '\u217A': '\u0078\u0069',
  24025. '\u217B': '\u0078\u0069\u0069',
  24026. '\u217C': '\u006C',
  24027. '\u217D': '\u0063',
  24028. '\u217E': '\u0064',
  24029. '\u217F': '\u006D',
  24030. '\u222C': '\u222B\u222B',
  24031. '\u222D': '\u222B\u222B\u222B',
  24032. '\u222F': '\u222E\u222E',
  24033. '\u2230': '\u222E\u222E\u222E',
  24034. '\u2474': '\u0028\u0031\u0029',
  24035. '\u2475': '\u0028\u0032\u0029',
  24036. '\u2476': '\u0028\u0033\u0029',
  24037. '\u2477': '\u0028\u0034\u0029',
  24038. '\u2478': '\u0028\u0035\u0029',
  24039. '\u2479': '\u0028\u0036\u0029',
  24040. '\u247A': '\u0028\u0037\u0029',
  24041. '\u247B': '\u0028\u0038\u0029',
  24042. '\u247C': '\u0028\u0039\u0029',
  24043. '\u247D': '\u0028\u0031\u0030\u0029',
  24044. '\u247E': '\u0028\u0031\u0031\u0029',
  24045. '\u247F': '\u0028\u0031\u0032\u0029',
  24046. '\u2480': '\u0028\u0031\u0033\u0029',
  24047. '\u2481': '\u0028\u0031\u0034\u0029',
  24048. '\u2482': '\u0028\u0031\u0035\u0029',
  24049. '\u2483': '\u0028\u0031\u0036\u0029',
  24050. '\u2484': '\u0028\u0031\u0037\u0029',
  24051. '\u2485': '\u0028\u0031\u0038\u0029',
  24052. '\u2486': '\u0028\u0031\u0039\u0029',
  24053. '\u2487': '\u0028\u0032\u0030\u0029',
  24054. '\u2488': '\u0031\u002E',
  24055. '\u2489': '\u0032\u002E',
  24056. '\u248A': '\u0033\u002E',
  24057. '\u248B': '\u0034\u002E',
  24058. '\u248C': '\u0035\u002E',
  24059. '\u248D': '\u0036\u002E',
  24060. '\u248E': '\u0037\u002E',
  24061. '\u248F': '\u0038\u002E',
  24062. '\u2490': '\u0039\u002E',
  24063. '\u2491': '\u0031\u0030\u002E',
  24064. '\u2492': '\u0031\u0031\u002E',
  24065. '\u2493': '\u0031\u0032\u002E',
  24066. '\u2494': '\u0031\u0033\u002E',
  24067. '\u2495': '\u0031\u0034\u002E',
  24068. '\u2496': '\u0031\u0035\u002E',
  24069. '\u2497': '\u0031\u0036\u002E',
  24070. '\u2498': '\u0031\u0037\u002E',
  24071. '\u2499': '\u0031\u0038\u002E',
  24072. '\u249A': '\u0031\u0039\u002E',
  24073. '\u249B': '\u0032\u0030\u002E',
  24074. '\u249C': '\u0028\u0061\u0029',
  24075. '\u249D': '\u0028\u0062\u0029',
  24076. '\u249E': '\u0028\u0063\u0029',
  24077. '\u249F': '\u0028\u0064\u0029',
  24078. '\u24A0': '\u0028\u0065\u0029',
  24079. '\u24A1': '\u0028\u0066\u0029',
  24080. '\u24A2': '\u0028\u0067\u0029',
  24081. '\u24A3': '\u0028\u0068\u0029',
  24082. '\u24A4': '\u0028\u0069\u0029',
  24083. '\u24A5': '\u0028\u006A\u0029',
  24084. '\u24A6': '\u0028\u006B\u0029',
  24085. '\u24A7': '\u0028\u006C\u0029',
  24086. '\u24A8': '\u0028\u006D\u0029',
  24087. '\u24A9': '\u0028\u006E\u0029',
  24088. '\u24AA': '\u0028\u006F\u0029',
  24089. '\u24AB': '\u0028\u0070\u0029',
  24090. '\u24AC': '\u0028\u0071\u0029',
  24091. '\u24AD': '\u0028\u0072\u0029',
  24092. '\u24AE': '\u0028\u0073\u0029',
  24093. '\u24AF': '\u0028\u0074\u0029',
  24094. '\u24B0': '\u0028\u0075\u0029',
  24095. '\u24B1': '\u0028\u0076\u0029',
  24096. '\u24B2': '\u0028\u0077\u0029',
  24097. '\u24B3': '\u0028\u0078\u0029',
  24098. '\u24B4': '\u0028\u0079\u0029',
  24099. '\u24B5': '\u0028\u007A\u0029',
  24100. '\u2A0C': '\u222B\u222B\u222B\u222B',
  24101. '\u2A74': '\u003A\u003A\u003D',
  24102. '\u2A75': '\u003D\u003D',
  24103. '\u2A76': '\u003D\u003D\u003D',
  24104. '\u2E9F': '\u6BCD',
  24105. '\u2EF3': '\u9F9F',
  24106. '\u2F00': '\u4E00',
  24107. '\u2F01': '\u4E28',
  24108. '\u2F02': '\u4E36',
  24109. '\u2F03': '\u4E3F',
  24110. '\u2F04': '\u4E59',
  24111. '\u2F05': '\u4E85',
  24112. '\u2F06': '\u4E8C',
  24113. '\u2F07': '\u4EA0',
  24114. '\u2F08': '\u4EBA',
  24115. '\u2F09': '\u513F',
  24116. '\u2F0A': '\u5165',
  24117. '\u2F0B': '\u516B',
  24118. '\u2F0C': '\u5182',
  24119. '\u2F0D': '\u5196',
  24120. '\u2F0E': '\u51AB',
  24121. '\u2F0F': '\u51E0',
  24122. '\u2F10': '\u51F5',
  24123. '\u2F11': '\u5200',
  24124. '\u2F12': '\u529B',
  24125. '\u2F13': '\u52F9',
  24126. '\u2F14': '\u5315',
  24127. '\u2F15': '\u531A',
  24128. '\u2F16': '\u5338',
  24129. '\u2F17': '\u5341',
  24130. '\u2F18': '\u535C',
  24131. '\u2F19': '\u5369',
  24132. '\u2F1A': '\u5382',
  24133. '\u2F1B': '\u53B6',
  24134. '\u2F1C': '\u53C8',
  24135. '\u2F1D': '\u53E3',
  24136. '\u2F1E': '\u56D7',
  24137. '\u2F1F': '\u571F',
  24138. '\u2F20': '\u58EB',
  24139. '\u2F21': '\u5902',
  24140. '\u2F22': '\u590A',
  24141. '\u2F23': '\u5915',
  24142. '\u2F24': '\u5927',
  24143. '\u2F25': '\u5973',
  24144. '\u2F26': '\u5B50',
  24145. '\u2F27': '\u5B80',
  24146. '\u2F28': '\u5BF8',
  24147. '\u2F29': '\u5C0F',
  24148. '\u2F2A': '\u5C22',
  24149. '\u2F2B': '\u5C38',
  24150. '\u2F2C': '\u5C6E',
  24151. '\u2F2D': '\u5C71',
  24152. '\u2F2E': '\u5DDB',
  24153. '\u2F2F': '\u5DE5',
  24154. '\u2F30': '\u5DF1',
  24155. '\u2F31': '\u5DFE',
  24156. '\u2F32': '\u5E72',
  24157. '\u2F33': '\u5E7A',
  24158. '\u2F34': '\u5E7F',
  24159. '\u2F35': '\u5EF4',
  24160. '\u2F36': '\u5EFE',
  24161. '\u2F37': '\u5F0B',
  24162. '\u2F38': '\u5F13',
  24163. '\u2F39': '\u5F50',
  24164. '\u2F3A': '\u5F61',
  24165. '\u2F3B': '\u5F73',
  24166. '\u2F3C': '\u5FC3',
  24167. '\u2F3D': '\u6208',
  24168. '\u2F3E': '\u6236',
  24169. '\u2F3F': '\u624B',
  24170. '\u2F40': '\u652F',
  24171. '\u2F41': '\u6534',
  24172. '\u2F42': '\u6587',
  24173. '\u2F43': '\u6597',
  24174. '\u2F44': '\u65A4',
  24175. '\u2F45': '\u65B9',
  24176. '\u2F46': '\u65E0',
  24177. '\u2F47': '\u65E5',
  24178. '\u2F48': '\u66F0',
  24179. '\u2F49': '\u6708',
  24180. '\u2F4A': '\u6728',
  24181. '\u2F4B': '\u6B20',
  24182. '\u2F4C': '\u6B62',
  24183. '\u2F4D': '\u6B79',
  24184. '\u2F4E': '\u6BB3',
  24185. '\u2F4F': '\u6BCB',
  24186. '\u2F50': '\u6BD4',
  24187. '\u2F51': '\u6BDB',
  24188. '\u2F52': '\u6C0F',
  24189. '\u2F53': '\u6C14',
  24190. '\u2F54': '\u6C34',
  24191. '\u2F55': '\u706B',
  24192. '\u2F56': '\u722A',
  24193. '\u2F57': '\u7236',
  24194. '\u2F58': '\u723B',
  24195. '\u2F59': '\u723F',
  24196. '\u2F5A': '\u7247',
  24197. '\u2F5B': '\u7259',
  24198. '\u2F5C': '\u725B',
  24199. '\u2F5D': '\u72AC',
  24200. '\u2F5E': '\u7384',
  24201. '\u2F5F': '\u7389',
  24202. '\u2F60': '\u74DC',
  24203. '\u2F61': '\u74E6',
  24204. '\u2F62': '\u7518',
  24205. '\u2F63': '\u751F',
  24206. '\u2F64': '\u7528',
  24207. '\u2F65': '\u7530',
  24208. '\u2F66': '\u758B',
  24209. '\u2F67': '\u7592',
  24210. '\u2F68': '\u7676',
  24211. '\u2F69': '\u767D',
  24212. '\u2F6A': '\u76AE',
  24213. '\u2F6B': '\u76BF',
  24214. '\u2F6C': '\u76EE',
  24215. '\u2F6D': '\u77DB',
  24216. '\u2F6E': '\u77E2',
  24217. '\u2F6F': '\u77F3',
  24218. '\u2F70': '\u793A',
  24219. '\u2F71': '\u79B8',
  24220. '\u2F72': '\u79BE',
  24221. '\u2F73': '\u7A74',
  24222. '\u2F74': '\u7ACB',
  24223. '\u2F75': '\u7AF9',
  24224. '\u2F76': '\u7C73',
  24225. '\u2F77': '\u7CF8',
  24226. '\u2F78': '\u7F36',
  24227. '\u2F79': '\u7F51',
  24228. '\u2F7A': '\u7F8A',
  24229. '\u2F7B': '\u7FBD',
  24230. '\u2F7C': '\u8001',
  24231. '\u2F7D': '\u800C',
  24232. '\u2F7E': '\u8012',
  24233. '\u2F7F': '\u8033',
  24234. '\u2F80': '\u807F',
  24235. '\u2F81': '\u8089',
  24236. '\u2F82': '\u81E3',
  24237. '\u2F83': '\u81EA',
  24238. '\u2F84': '\u81F3',
  24239. '\u2F85': '\u81FC',
  24240. '\u2F86': '\u820C',
  24241. '\u2F87': '\u821B',
  24242. '\u2F88': '\u821F',
  24243. '\u2F89': '\u826E',
  24244. '\u2F8A': '\u8272',
  24245. '\u2F8B': '\u8278',
  24246. '\u2F8C': '\u864D',
  24247. '\u2F8D': '\u866B',
  24248. '\u2F8E': '\u8840',
  24249. '\u2F8F': '\u884C',
  24250. '\u2F90': '\u8863',
  24251. '\u2F91': '\u897E',
  24252. '\u2F92': '\u898B',
  24253. '\u2F93': '\u89D2',
  24254. '\u2F94': '\u8A00',
  24255. '\u2F95': '\u8C37',
  24256. '\u2F96': '\u8C46',
  24257. '\u2F97': '\u8C55',
  24258. '\u2F98': '\u8C78',
  24259. '\u2F99': '\u8C9D',
  24260. '\u2F9A': '\u8D64',
  24261. '\u2F9B': '\u8D70',
  24262. '\u2F9C': '\u8DB3',
  24263. '\u2F9D': '\u8EAB',
  24264. '\u2F9E': '\u8ECA',
  24265. '\u2F9F': '\u8F9B',
  24266. '\u2FA0': '\u8FB0',
  24267. '\u2FA1': '\u8FB5',
  24268. '\u2FA2': '\u9091',
  24269. '\u2FA3': '\u9149',
  24270. '\u2FA4': '\u91C6',
  24271. '\u2FA5': '\u91CC',
  24272. '\u2FA6': '\u91D1',
  24273. '\u2FA7': '\u9577',
  24274. '\u2FA8': '\u9580',
  24275. '\u2FA9': '\u961C',
  24276. '\u2FAA': '\u96B6',
  24277. '\u2FAB': '\u96B9',
  24278. '\u2FAC': '\u96E8',
  24279. '\u2FAD': '\u9751',
  24280. '\u2FAE': '\u975E',
  24281. '\u2FAF': '\u9762',
  24282. '\u2FB0': '\u9769',
  24283. '\u2FB1': '\u97CB',
  24284. '\u2FB2': '\u97ED',
  24285. '\u2FB3': '\u97F3',
  24286. '\u2FB4': '\u9801',
  24287. '\u2FB5': '\u98A8',
  24288. '\u2FB6': '\u98DB',
  24289. '\u2FB7': '\u98DF',
  24290. '\u2FB8': '\u9996',
  24291. '\u2FB9': '\u9999',
  24292. '\u2FBA': '\u99AC',
  24293. '\u2FBB': '\u9AA8',
  24294. '\u2FBC': '\u9AD8',
  24295. '\u2FBD': '\u9ADF',
  24296. '\u2FBE': '\u9B25',
  24297. '\u2FBF': '\u9B2F',
  24298. '\u2FC0': '\u9B32',
  24299. '\u2FC1': '\u9B3C',
  24300. '\u2FC2': '\u9B5A',
  24301. '\u2FC3': '\u9CE5',
  24302. '\u2FC4': '\u9E75',
  24303. '\u2FC5': '\u9E7F',
  24304. '\u2FC6': '\u9EA5',
  24305. '\u2FC7': '\u9EBB',
  24306. '\u2FC8': '\u9EC3',
  24307. '\u2FC9': '\u9ECD',
  24308. '\u2FCA': '\u9ED1',
  24309. '\u2FCB': '\u9EF9',
  24310. '\u2FCC': '\u9EFD',
  24311. '\u2FCD': '\u9F0E',
  24312. '\u2FCE': '\u9F13',
  24313. '\u2FCF': '\u9F20',
  24314. '\u2FD0': '\u9F3B',
  24315. '\u2FD1': '\u9F4A',
  24316. '\u2FD2': '\u9F52',
  24317. '\u2FD3': '\u9F8D',
  24318. '\u2FD4': '\u9F9C',
  24319. '\u2FD5': '\u9FA0',
  24320. '\u3036': '\u3012',
  24321. '\u3038': '\u5341',
  24322. '\u3039': '\u5344',
  24323. '\u303A': '\u5345',
  24324. '\u309B': '\u0020\u3099',
  24325. '\u309C': '\u0020\u309A',
  24326. '\u3131': '\u1100',
  24327. '\u3132': '\u1101',
  24328. '\u3133': '\u11AA',
  24329. '\u3134': '\u1102',
  24330. '\u3135': '\u11AC',
  24331. '\u3136': '\u11AD',
  24332. '\u3137': '\u1103',
  24333. '\u3138': '\u1104',
  24334. '\u3139': '\u1105',
  24335. '\u313A': '\u11B0',
  24336. '\u313B': '\u11B1',
  24337. '\u313C': '\u11B2',
  24338. '\u313D': '\u11B3',
  24339. '\u313E': '\u11B4',
  24340. '\u313F': '\u11B5',
  24341. '\u3140': '\u111A',
  24342. '\u3141': '\u1106',
  24343. '\u3142': '\u1107',
  24344. '\u3143': '\u1108',
  24345. '\u3144': '\u1121',
  24346. '\u3145': '\u1109',
  24347. '\u3146': '\u110A',
  24348. '\u3147': '\u110B',
  24349. '\u3148': '\u110C',
  24350. '\u3149': '\u110D',
  24351. '\u314A': '\u110E',
  24352. '\u314B': '\u110F',
  24353. '\u314C': '\u1110',
  24354. '\u314D': '\u1111',
  24355. '\u314E': '\u1112',
  24356. '\u314F': '\u1161',
  24357. '\u3150': '\u1162',
  24358. '\u3151': '\u1163',
  24359. '\u3152': '\u1164',
  24360. '\u3153': '\u1165',
  24361. '\u3154': '\u1166',
  24362. '\u3155': '\u1167',
  24363. '\u3156': '\u1168',
  24364. '\u3157': '\u1169',
  24365. '\u3158': '\u116A',
  24366. '\u3159': '\u116B',
  24367. '\u315A': '\u116C',
  24368. '\u315B': '\u116D',
  24369. '\u315C': '\u116E',
  24370. '\u315D': '\u116F',
  24371. '\u315E': '\u1170',
  24372. '\u315F': '\u1171',
  24373. '\u3160': '\u1172',
  24374. '\u3161': '\u1173',
  24375. '\u3162': '\u1174',
  24376. '\u3163': '\u1175',
  24377. '\u3164': '\u1160',
  24378. '\u3165': '\u1114',
  24379. '\u3166': '\u1115',
  24380. '\u3167': '\u11C7',
  24381. '\u3168': '\u11C8',
  24382. '\u3169': '\u11CC',
  24383. '\u316A': '\u11CE',
  24384. '\u316B': '\u11D3',
  24385. '\u316C': '\u11D7',
  24386. '\u316D': '\u11D9',
  24387. '\u316E': '\u111C',
  24388. '\u316F': '\u11DD',
  24389. '\u3170': '\u11DF',
  24390. '\u3171': '\u111D',
  24391. '\u3172': '\u111E',
  24392. '\u3173': '\u1120',
  24393. '\u3174': '\u1122',
  24394. '\u3175': '\u1123',
  24395. '\u3176': '\u1127',
  24396. '\u3177': '\u1129',
  24397. '\u3178': '\u112B',
  24398. '\u3179': '\u112C',
  24399. '\u317A': '\u112D',
  24400. '\u317B': '\u112E',
  24401. '\u317C': '\u112F',
  24402. '\u317D': '\u1132',
  24403. '\u317E': '\u1136',
  24404. '\u317F': '\u1140',
  24405. '\u3180': '\u1147',
  24406. '\u3181': '\u114C',
  24407. '\u3182': '\u11F1',
  24408. '\u3183': '\u11F2',
  24409. '\u3184': '\u1157',
  24410. '\u3185': '\u1158',
  24411. '\u3186': '\u1159',
  24412. '\u3187': '\u1184',
  24413. '\u3188': '\u1185',
  24414. '\u3189': '\u1188',
  24415. '\u318A': '\u1191',
  24416. '\u318B': '\u1192',
  24417. '\u318C': '\u1194',
  24418. '\u318D': '\u119E',
  24419. '\u318E': '\u11A1',
  24420. '\u3200': '\u0028\u1100\u0029',
  24421. '\u3201': '\u0028\u1102\u0029',
  24422. '\u3202': '\u0028\u1103\u0029',
  24423. '\u3203': '\u0028\u1105\u0029',
  24424. '\u3204': '\u0028\u1106\u0029',
  24425. '\u3205': '\u0028\u1107\u0029',
  24426. '\u3206': '\u0028\u1109\u0029',
  24427. '\u3207': '\u0028\u110B\u0029',
  24428. '\u3208': '\u0028\u110C\u0029',
  24429. '\u3209': '\u0028\u110E\u0029',
  24430. '\u320A': '\u0028\u110F\u0029',
  24431. '\u320B': '\u0028\u1110\u0029',
  24432. '\u320C': '\u0028\u1111\u0029',
  24433. '\u320D': '\u0028\u1112\u0029',
  24434. '\u320E': '\u0028\u1100\u1161\u0029',
  24435. '\u320F': '\u0028\u1102\u1161\u0029',
  24436. '\u3210': '\u0028\u1103\u1161\u0029',
  24437. '\u3211': '\u0028\u1105\u1161\u0029',
  24438. '\u3212': '\u0028\u1106\u1161\u0029',
  24439. '\u3213': '\u0028\u1107\u1161\u0029',
  24440. '\u3214': '\u0028\u1109\u1161\u0029',
  24441. '\u3215': '\u0028\u110B\u1161\u0029',
  24442. '\u3216': '\u0028\u110C\u1161\u0029',
  24443. '\u3217': '\u0028\u110E\u1161\u0029',
  24444. '\u3218': '\u0028\u110F\u1161\u0029',
  24445. '\u3219': '\u0028\u1110\u1161\u0029',
  24446. '\u321A': '\u0028\u1111\u1161\u0029',
  24447. '\u321B': '\u0028\u1112\u1161\u0029',
  24448. '\u321C': '\u0028\u110C\u116E\u0029',
  24449. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  24450. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  24451. '\u3220': '\u0028\u4E00\u0029',
  24452. '\u3221': '\u0028\u4E8C\u0029',
  24453. '\u3222': '\u0028\u4E09\u0029',
  24454. '\u3223': '\u0028\u56DB\u0029',
  24455. '\u3224': '\u0028\u4E94\u0029',
  24456. '\u3225': '\u0028\u516D\u0029',
  24457. '\u3226': '\u0028\u4E03\u0029',
  24458. '\u3227': '\u0028\u516B\u0029',
  24459. '\u3228': '\u0028\u4E5D\u0029',
  24460. '\u3229': '\u0028\u5341\u0029',
  24461. '\u322A': '\u0028\u6708\u0029',
  24462. '\u322B': '\u0028\u706B\u0029',
  24463. '\u322C': '\u0028\u6C34\u0029',
  24464. '\u322D': '\u0028\u6728\u0029',
  24465. '\u322E': '\u0028\u91D1\u0029',
  24466. '\u322F': '\u0028\u571F\u0029',
  24467. '\u3230': '\u0028\u65E5\u0029',
  24468. '\u3231': '\u0028\u682A\u0029',
  24469. '\u3232': '\u0028\u6709\u0029',
  24470. '\u3233': '\u0028\u793E\u0029',
  24471. '\u3234': '\u0028\u540D\u0029',
  24472. '\u3235': '\u0028\u7279\u0029',
  24473. '\u3236': '\u0028\u8CA1\u0029',
  24474. '\u3237': '\u0028\u795D\u0029',
  24475. '\u3238': '\u0028\u52B4\u0029',
  24476. '\u3239': '\u0028\u4EE3\u0029',
  24477. '\u323A': '\u0028\u547C\u0029',
  24478. '\u323B': '\u0028\u5B66\u0029',
  24479. '\u323C': '\u0028\u76E3\u0029',
  24480. '\u323D': '\u0028\u4F01\u0029',
  24481. '\u323E': '\u0028\u8CC7\u0029',
  24482. '\u323F': '\u0028\u5354\u0029',
  24483. '\u3240': '\u0028\u796D\u0029',
  24484. '\u3241': '\u0028\u4F11\u0029',
  24485. '\u3242': '\u0028\u81EA\u0029',
  24486. '\u3243': '\u0028\u81F3\u0029',
  24487. '\u32C0': '\u0031\u6708',
  24488. '\u32C1': '\u0032\u6708',
  24489. '\u32C2': '\u0033\u6708',
  24490. '\u32C3': '\u0034\u6708',
  24491. '\u32C4': '\u0035\u6708',
  24492. '\u32C5': '\u0036\u6708',
  24493. '\u32C6': '\u0037\u6708',
  24494. '\u32C7': '\u0038\u6708',
  24495. '\u32C8': '\u0039\u6708',
  24496. '\u32C9': '\u0031\u0030\u6708',
  24497. '\u32CA': '\u0031\u0031\u6708',
  24498. '\u32CB': '\u0031\u0032\u6708',
  24499. '\u3358': '\u0030\u70B9',
  24500. '\u3359': '\u0031\u70B9',
  24501. '\u335A': '\u0032\u70B9',
  24502. '\u335B': '\u0033\u70B9',
  24503. '\u335C': '\u0034\u70B9',
  24504. '\u335D': '\u0035\u70B9',
  24505. '\u335E': '\u0036\u70B9',
  24506. '\u335F': '\u0037\u70B9',
  24507. '\u3360': '\u0038\u70B9',
  24508. '\u3361': '\u0039\u70B9',
  24509. '\u3362': '\u0031\u0030\u70B9',
  24510. '\u3363': '\u0031\u0031\u70B9',
  24511. '\u3364': '\u0031\u0032\u70B9',
  24512. '\u3365': '\u0031\u0033\u70B9',
  24513. '\u3366': '\u0031\u0034\u70B9',
  24514. '\u3367': '\u0031\u0035\u70B9',
  24515. '\u3368': '\u0031\u0036\u70B9',
  24516. '\u3369': '\u0031\u0037\u70B9',
  24517. '\u336A': '\u0031\u0038\u70B9',
  24518. '\u336B': '\u0031\u0039\u70B9',
  24519. '\u336C': '\u0032\u0030\u70B9',
  24520. '\u336D': '\u0032\u0031\u70B9',
  24521. '\u336E': '\u0032\u0032\u70B9',
  24522. '\u336F': '\u0032\u0033\u70B9',
  24523. '\u3370': '\u0032\u0034\u70B9',
  24524. '\u33E0': '\u0031\u65E5',
  24525. '\u33E1': '\u0032\u65E5',
  24526. '\u33E2': '\u0033\u65E5',
  24527. '\u33E3': '\u0034\u65E5',
  24528. '\u33E4': '\u0035\u65E5',
  24529. '\u33E5': '\u0036\u65E5',
  24530. '\u33E6': '\u0037\u65E5',
  24531. '\u33E7': '\u0038\u65E5',
  24532. '\u33E8': '\u0039\u65E5',
  24533. '\u33E9': '\u0031\u0030\u65E5',
  24534. '\u33EA': '\u0031\u0031\u65E5',
  24535. '\u33EB': '\u0031\u0032\u65E5',
  24536. '\u33EC': '\u0031\u0033\u65E5',
  24537. '\u33ED': '\u0031\u0034\u65E5',
  24538. '\u33EE': '\u0031\u0035\u65E5',
  24539. '\u33EF': '\u0031\u0036\u65E5',
  24540. '\u33F0': '\u0031\u0037\u65E5',
  24541. '\u33F1': '\u0031\u0038\u65E5',
  24542. '\u33F2': '\u0031\u0039\u65E5',
  24543. '\u33F3': '\u0032\u0030\u65E5',
  24544. '\u33F4': '\u0032\u0031\u65E5',
  24545. '\u33F5': '\u0032\u0032\u65E5',
  24546. '\u33F6': '\u0032\u0033\u65E5',
  24547. '\u33F7': '\u0032\u0034\u65E5',
  24548. '\u33F8': '\u0032\u0035\u65E5',
  24549. '\u33F9': '\u0032\u0036\u65E5',
  24550. '\u33FA': '\u0032\u0037\u65E5',
  24551. '\u33FB': '\u0032\u0038\u65E5',
  24552. '\u33FC': '\u0032\u0039\u65E5',
  24553. '\u33FD': '\u0033\u0030\u65E5',
  24554. '\u33FE': '\u0033\u0031\u65E5',
  24555. '\uFB00': '\u0066\u0066',
  24556. '\uFB01': '\u0066\u0069',
  24557. '\uFB02': '\u0066\u006C',
  24558. '\uFB03': '\u0066\u0066\u0069',
  24559. '\uFB04': '\u0066\u0066\u006C',
  24560. '\uFB05': '\u017F\u0074',
  24561. '\uFB06': '\u0073\u0074',
  24562. '\uFB13': '\u0574\u0576',
  24563. '\uFB14': '\u0574\u0565',
  24564. '\uFB15': '\u0574\u056B',
  24565. '\uFB16': '\u057E\u0576',
  24566. '\uFB17': '\u0574\u056D',
  24567. '\uFB4F': '\u05D0\u05DC',
  24568. '\uFB50': '\u0671',
  24569. '\uFB51': '\u0671',
  24570. '\uFB52': '\u067B',
  24571. '\uFB53': '\u067B',
  24572. '\uFB54': '\u067B',
  24573. '\uFB55': '\u067B',
  24574. '\uFB56': '\u067E',
  24575. '\uFB57': '\u067E',
  24576. '\uFB58': '\u067E',
  24577. '\uFB59': '\u067E',
  24578. '\uFB5A': '\u0680',
  24579. '\uFB5B': '\u0680',
  24580. '\uFB5C': '\u0680',
  24581. '\uFB5D': '\u0680',
  24582. '\uFB5E': '\u067A',
  24583. '\uFB5F': '\u067A',
  24584. '\uFB60': '\u067A',
  24585. '\uFB61': '\u067A',
  24586. '\uFB62': '\u067F',
  24587. '\uFB63': '\u067F',
  24588. '\uFB64': '\u067F',
  24589. '\uFB65': '\u067F',
  24590. '\uFB66': '\u0679',
  24591. '\uFB67': '\u0679',
  24592. '\uFB68': '\u0679',
  24593. '\uFB69': '\u0679',
  24594. '\uFB6A': '\u06A4',
  24595. '\uFB6B': '\u06A4',
  24596. '\uFB6C': '\u06A4',
  24597. '\uFB6D': '\u06A4',
  24598. '\uFB6E': '\u06A6',
  24599. '\uFB6F': '\u06A6',
  24600. '\uFB70': '\u06A6',
  24601. '\uFB71': '\u06A6',
  24602. '\uFB72': '\u0684',
  24603. '\uFB73': '\u0684',
  24604. '\uFB74': '\u0684',
  24605. '\uFB75': '\u0684',
  24606. '\uFB76': '\u0683',
  24607. '\uFB77': '\u0683',
  24608. '\uFB78': '\u0683',
  24609. '\uFB79': '\u0683',
  24610. '\uFB7A': '\u0686',
  24611. '\uFB7B': '\u0686',
  24612. '\uFB7C': '\u0686',
  24613. '\uFB7D': '\u0686',
  24614. '\uFB7E': '\u0687',
  24615. '\uFB7F': '\u0687',
  24616. '\uFB80': '\u0687',
  24617. '\uFB81': '\u0687',
  24618. '\uFB82': '\u068D',
  24619. '\uFB83': '\u068D',
  24620. '\uFB84': '\u068C',
  24621. '\uFB85': '\u068C',
  24622. '\uFB86': '\u068E',
  24623. '\uFB87': '\u068E',
  24624. '\uFB88': '\u0688',
  24625. '\uFB89': '\u0688',
  24626. '\uFB8A': '\u0698',
  24627. '\uFB8B': '\u0698',
  24628. '\uFB8C': '\u0691',
  24629. '\uFB8D': '\u0691',
  24630. '\uFB8E': '\u06A9',
  24631. '\uFB8F': '\u06A9',
  24632. '\uFB90': '\u06A9',
  24633. '\uFB91': '\u06A9',
  24634. '\uFB92': '\u06AF',
  24635. '\uFB93': '\u06AF',
  24636. '\uFB94': '\u06AF',
  24637. '\uFB95': '\u06AF',
  24638. '\uFB96': '\u06B3',
  24639. '\uFB97': '\u06B3',
  24640. '\uFB98': '\u06B3',
  24641. '\uFB99': '\u06B3',
  24642. '\uFB9A': '\u06B1',
  24643. '\uFB9B': '\u06B1',
  24644. '\uFB9C': '\u06B1',
  24645. '\uFB9D': '\u06B1',
  24646. '\uFB9E': '\u06BA',
  24647. '\uFB9F': '\u06BA',
  24648. '\uFBA0': '\u06BB',
  24649. '\uFBA1': '\u06BB',
  24650. '\uFBA2': '\u06BB',
  24651. '\uFBA3': '\u06BB',
  24652. '\uFBA4': '\u06C0',
  24653. '\uFBA5': '\u06C0',
  24654. '\uFBA6': '\u06C1',
  24655. '\uFBA7': '\u06C1',
  24656. '\uFBA8': '\u06C1',
  24657. '\uFBA9': '\u06C1',
  24658. '\uFBAA': '\u06BE',
  24659. '\uFBAB': '\u06BE',
  24660. '\uFBAC': '\u06BE',
  24661. '\uFBAD': '\u06BE',
  24662. '\uFBAE': '\u06D2',
  24663. '\uFBAF': '\u06D2',
  24664. '\uFBB0': '\u06D3',
  24665. '\uFBB1': '\u06D3',
  24666. '\uFBD3': '\u06AD',
  24667. '\uFBD4': '\u06AD',
  24668. '\uFBD5': '\u06AD',
  24669. '\uFBD6': '\u06AD',
  24670. '\uFBD7': '\u06C7',
  24671. '\uFBD8': '\u06C7',
  24672. '\uFBD9': '\u06C6',
  24673. '\uFBDA': '\u06C6',
  24674. '\uFBDB': '\u06C8',
  24675. '\uFBDC': '\u06C8',
  24676. '\uFBDD': '\u0677',
  24677. '\uFBDE': '\u06CB',
  24678. '\uFBDF': '\u06CB',
  24679. '\uFBE0': '\u06C5',
  24680. '\uFBE1': '\u06C5',
  24681. '\uFBE2': '\u06C9',
  24682. '\uFBE3': '\u06C9',
  24683. '\uFBE4': '\u06D0',
  24684. '\uFBE5': '\u06D0',
  24685. '\uFBE6': '\u06D0',
  24686. '\uFBE7': '\u06D0',
  24687. '\uFBE8': '\u0649',
  24688. '\uFBE9': '\u0649',
  24689. '\uFBEA': '\u0626\u0627',
  24690. '\uFBEB': '\u0626\u0627',
  24691. '\uFBEC': '\u0626\u06D5',
  24692. '\uFBED': '\u0626\u06D5',
  24693. '\uFBEE': '\u0626\u0648',
  24694. '\uFBEF': '\u0626\u0648',
  24695. '\uFBF0': '\u0626\u06C7',
  24696. '\uFBF1': '\u0626\u06C7',
  24697. '\uFBF2': '\u0626\u06C6',
  24698. '\uFBF3': '\u0626\u06C6',
  24699. '\uFBF4': '\u0626\u06C8',
  24700. '\uFBF5': '\u0626\u06C8',
  24701. '\uFBF6': '\u0626\u06D0',
  24702. '\uFBF7': '\u0626\u06D0',
  24703. '\uFBF8': '\u0626\u06D0',
  24704. '\uFBF9': '\u0626\u0649',
  24705. '\uFBFA': '\u0626\u0649',
  24706. '\uFBFB': '\u0626\u0649',
  24707. '\uFBFC': '\u06CC',
  24708. '\uFBFD': '\u06CC',
  24709. '\uFBFE': '\u06CC',
  24710. '\uFBFF': '\u06CC',
  24711. '\uFC00': '\u0626\u062C',
  24712. '\uFC01': '\u0626\u062D',
  24713. '\uFC02': '\u0626\u0645',
  24714. '\uFC03': '\u0626\u0649',
  24715. '\uFC04': '\u0626\u064A',
  24716. '\uFC05': '\u0628\u062C',
  24717. '\uFC06': '\u0628\u062D',
  24718. '\uFC07': '\u0628\u062E',
  24719. '\uFC08': '\u0628\u0645',
  24720. '\uFC09': '\u0628\u0649',
  24721. '\uFC0A': '\u0628\u064A',
  24722. '\uFC0B': '\u062A\u062C',
  24723. '\uFC0C': '\u062A\u062D',
  24724. '\uFC0D': '\u062A\u062E',
  24725. '\uFC0E': '\u062A\u0645',
  24726. '\uFC0F': '\u062A\u0649',
  24727. '\uFC10': '\u062A\u064A',
  24728. '\uFC11': '\u062B\u062C',
  24729. '\uFC12': '\u062B\u0645',
  24730. '\uFC13': '\u062B\u0649',
  24731. '\uFC14': '\u062B\u064A',
  24732. '\uFC15': '\u062C\u062D',
  24733. '\uFC16': '\u062C\u0645',
  24734. '\uFC17': '\u062D\u062C',
  24735. '\uFC18': '\u062D\u0645',
  24736. '\uFC19': '\u062E\u062C',
  24737. '\uFC1A': '\u062E\u062D',
  24738. '\uFC1B': '\u062E\u0645',
  24739. '\uFC1C': '\u0633\u062C',
  24740. '\uFC1D': '\u0633\u062D',
  24741. '\uFC1E': '\u0633\u062E',
  24742. '\uFC1F': '\u0633\u0645',
  24743. '\uFC20': '\u0635\u062D',
  24744. '\uFC21': '\u0635\u0645',
  24745. '\uFC22': '\u0636\u062C',
  24746. '\uFC23': '\u0636\u062D',
  24747. '\uFC24': '\u0636\u062E',
  24748. '\uFC25': '\u0636\u0645',
  24749. '\uFC26': '\u0637\u062D',
  24750. '\uFC27': '\u0637\u0645',
  24751. '\uFC28': '\u0638\u0645',
  24752. '\uFC29': '\u0639\u062C',
  24753. '\uFC2A': '\u0639\u0645',
  24754. '\uFC2B': '\u063A\u062C',
  24755. '\uFC2C': '\u063A\u0645',
  24756. '\uFC2D': '\u0641\u062C',
  24757. '\uFC2E': '\u0641\u062D',
  24758. '\uFC2F': '\u0641\u062E',
  24759. '\uFC30': '\u0641\u0645',
  24760. '\uFC31': '\u0641\u0649',
  24761. '\uFC32': '\u0641\u064A',
  24762. '\uFC33': '\u0642\u062D',
  24763. '\uFC34': '\u0642\u0645',
  24764. '\uFC35': '\u0642\u0649',
  24765. '\uFC36': '\u0642\u064A',
  24766. '\uFC37': '\u0643\u0627',
  24767. '\uFC38': '\u0643\u062C',
  24768. '\uFC39': '\u0643\u062D',
  24769. '\uFC3A': '\u0643\u062E',
  24770. '\uFC3B': '\u0643\u0644',
  24771. '\uFC3C': '\u0643\u0645',
  24772. '\uFC3D': '\u0643\u0649',
  24773. '\uFC3E': '\u0643\u064A',
  24774. '\uFC3F': '\u0644\u062C',
  24775. '\uFC40': '\u0644\u062D',
  24776. '\uFC41': '\u0644\u062E',
  24777. '\uFC42': '\u0644\u0645',
  24778. '\uFC43': '\u0644\u0649',
  24779. '\uFC44': '\u0644\u064A',
  24780. '\uFC45': '\u0645\u062C',
  24781. '\uFC46': '\u0645\u062D',
  24782. '\uFC47': '\u0645\u062E',
  24783. '\uFC48': '\u0645\u0645',
  24784. '\uFC49': '\u0645\u0649',
  24785. '\uFC4A': '\u0645\u064A',
  24786. '\uFC4B': '\u0646\u062C',
  24787. '\uFC4C': '\u0646\u062D',
  24788. '\uFC4D': '\u0646\u062E',
  24789. '\uFC4E': '\u0646\u0645',
  24790. '\uFC4F': '\u0646\u0649',
  24791. '\uFC50': '\u0646\u064A',
  24792. '\uFC51': '\u0647\u062C',
  24793. '\uFC52': '\u0647\u0645',
  24794. '\uFC53': '\u0647\u0649',
  24795. '\uFC54': '\u0647\u064A',
  24796. '\uFC55': '\u064A\u062C',
  24797. '\uFC56': '\u064A\u062D',
  24798. '\uFC57': '\u064A\u062E',
  24799. '\uFC58': '\u064A\u0645',
  24800. '\uFC59': '\u064A\u0649',
  24801. '\uFC5A': '\u064A\u064A',
  24802. '\uFC5B': '\u0630\u0670',
  24803. '\uFC5C': '\u0631\u0670',
  24804. '\uFC5D': '\u0649\u0670',
  24805. '\uFC5E': '\u0020\u064C\u0651',
  24806. '\uFC5F': '\u0020\u064D\u0651',
  24807. '\uFC60': '\u0020\u064E\u0651',
  24808. '\uFC61': '\u0020\u064F\u0651',
  24809. '\uFC62': '\u0020\u0650\u0651',
  24810. '\uFC63': '\u0020\u0651\u0670',
  24811. '\uFC64': '\u0626\u0631',
  24812. '\uFC65': '\u0626\u0632',
  24813. '\uFC66': '\u0626\u0645',
  24814. '\uFC67': '\u0626\u0646',
  24815. '\uFC68': '\u0626\u0649',
  24816. '\uFC69': '\u0626\u064A',
  24817. '\uFC6A': '\u0628\u0631',
  24818. '\uFC6B': '\u0628\u0632',
  24819. '\uFC6C': '\u0628\u0645',
  24820. '\uFC6D': '\u0628\u0646',
  24821. '\uFC6E': '\u0628\u0649',
  24822. '\uFC6F': '\u0628\u064A',
  24823. '\uFC70': '\u062A\u0631',
  24824. '\uFC71': '\u062A\u0632',
  24825. '\uFC72': '\u062A\u0645',
  24826. '\uFC73': '\u062A\u0646',
  24827. '\uFC74': '\u062A\u0649',
  24828. '\uFC75': '\u062A\u064A',
  24829. '\uFC76': '\u062B\u0631',
  24830. '\uFC77': '\u062B\u0632',
  24831. '\uFC78': '\u062B\u0645',
  24832. '\uFC79': '\u062B\u0646',
  24833. '\uFC7A': '\u062B\u0649',
  24834. '\uFC7B': '\u062B\u064A',
  24835. '\uFC7C': '\u0641\u0649',
  24836. '\uFC7D': '\u0641\u064A',
  24837. '\uFC7E': '\u0642\u0649',
  24838. '\uFC7F': '\u0642\u064A',
  24839. '\uFC80': '\u0643\u0627',
  24840. '\uFC81': '\u0643\u0644',
  24841. '\uFC82': '\u0643\u0645',
  24842. '\uFC83': '\u0643\u0649',
  24843. '\uFC84': '\u0643\u064A',
  24844. '\uFC85': '\u0644\u0645',
  24845. '\uFC86': '\u0644\u0649',
  24846. '\uFC87': '\u0644\u064A',
  24847. '\uFC88': '\u0645\u0627',
  24848. '\uFC89': '\u0645\u0645',
  24849. '\uFC8A': '\u0646\u0631',
  24850. '\uFC8B': '\u0646\u0632',
  24851. '\uFC8C': '\u0646\u0645',
  24852. '\uFC8D': '\u0646\u0646',
  24853. '\uFC8E': '\u0646\u0649',
  24854. '\uFC8F': '\u0646\u064A',
  24855. '\uFC90': '\u0649\u0670',
  24856. '\uFC91': '\u064A\u0631',
  24857. '\uFC92': '\u064A\u0632',
  24858. '\uFC93': '\u064A\u0645',
  24859. '\uFC94': '\u064A\u0646',
  24860. '\uFC95': '\u064A\u0649',
  24861. '\uFC96': '\u064A\u064A',
  24862. '\uFC97': '\u0626\u062C',
  24863. '\uFC98': '\u0626\u062D',
  24864. '\uFC99': '\u0626\u062E',
  24865. '\uFC9A': '\u0626\u0645',
  24866. '\uFC9B': '\u0626\u0647',
  24867. '\uFC9C': '\u0628\u062C',
  24868. '\uFC9D': '\u0628\u062D',
  24869. '\uFC9E': '\u0628\u062E',
  24870. '\uFC9F': '\u0628\u0645',
  24871. '\uFCA0': '\u0628\u0647',
  24872. '\uFCA1': '\u062A\u062C',
  24873. '\uFCA2': '\u062A\u062D',
  24874. '\uFCA3': '\u062A\u062E',
  24875. '\uFCA4': '\u062A\u0645',
  24876. '\uFCA5': '\u062A\u0647',
  24877. '\uFCA6': '\u062B\u0645',
  24878. '\uFCA7': '\u062C\u062D',
  24879. '\uFCA8': '\u062C\u0645',
  24880. '\uFCA9': '\u062D\u062C',
  24881. '\uFCAA': '\u062D\u0645',
  24882. '\uFCAB': '\u062E\u062C',
  24883. '\uFCAC': '\u062E\u0645',
  24884. '\uFCAD': '\u0633\u062C',
  24885. '\uFCAE': '\u0633\u062D',
  24886. '\uFCAF': '\u0633\u062E',
  24887. '\uFCB0': '\u0633\u0645',
  24888. '\uFCB1': '\u0635\u062D',
  24889. '\uFCB2': '\u0635\u062E',
  24890. '\uFCB3': '\u0635\u0645',
  24891. '\uFCB4': '\u0636\u062C',
  24892. '\uFCB5': '\u0636\u062D',
  24893. '\uFCB6': '\u0636\u062E',
  24894. '\uFCB7': '\u0636\u0645',
  24895. '\uFCB8': '\u0637\u062D',
  24896. '\uFCB9': '\u0638\u0645',
  24897. '\uFCBA': '\u0639\u062C',
  24898. '\uFCBB': '\u0639\u0645',
  24899. '\uFCBC': '\u063A\u062C',
  24900. '\uFCBD': '\u063A\u0645',
  24901. '\uFCBE': '\u0641\u062C',
  24902. '\uFCBF': '\u0641\u062D',
  24903. '\uFCC0': '\u0641\u062E',
  24904. '\uFCC1': '\u0641\u0645',
  24905. '\uFCC2': '\u0642\u062D',
  24906. '\uFCC3': '\u0642\u0645',
  24907. '\uFCC4': '\u0643\u062C',
  24908. '\uFCC5': '\u0643\u062D',
  24909. '\uFCC6': '\u0643\u062E',
  24910. '\uFCC7': '\u0643\u0644',
  24911. '\uFCC8': '\u0643\u0645',
  24912. '\uFCC9': '\u0644\u062C',
  24913. '\uFCCA': '\u0644\u062D',
  24914. '\uFCCB': '\u0644\u062E',
  24915. '\uFCCC': '\u0644\u0645',
  24916. '\uFCCD': '\u0644\u0647',
  24917. '\uFCCE': '\u0645\u062C',
  24918. '\uFCCF': '\u0645\u062D',
  24919. '\uFCD0': '\u0645\u062E',
  24920. '\uFCD1': '\u0645\u0645',
  24921. '\uFCD2': '\u0646\u062C',
  24922. '\uFCD3': '\u0646\u062D',
  24923. '\uFCD4': '\u0646\u062E',
  24924. '\uFCD5': '\u0646\u0645',
  24925. '\uFCD6': '\u0646\u0647',
  24926. '\uFCD7': '\u0647\u062C',
  24927. '\uFCD8': '\u0647\u0645',
  24928. '\uFCD9': '\u0647\u0670',
  24929. '\uFCDA': '\u064A\u062C',
  24930. '\uFCDB': '\u064A\u062D',
  24931. '\uFCDC': '\u064A\u062E',
  24932. '\uFCDD': '\u064A\u0645',
  24933. '\uFCDE': '\u064A\u0647',
  24934. '\uFCDF': '\u0626\u0645',
  24935. '\uFCE0': '\u0626\u0647',
  24936. '\uFCE1': '\u0628\u0645',
  24937. '\uFCE2': '\u0628\u0647',
  24938. '\uFCE3': '\u062A\u0645',
  24939. '\uFCE4': '\u062A\u0647',
  24940. '\uFCE5': '\u062B\u0645',
  24941. '\uFCE6': '\u062B\u0647',
  24942. '\uFCE7': '\u0633\u0645',
  24943. '\uFCE8': '\u0633\u0647',
  24944. '\uFCE9': '\u0634\u0645',
  24945. '\uFCEA': '\u0634\u0647',
  24946. '\uFCEB': '\u0643\u0644',
  24947. '\uFCEC': '\u0643\u0645',
  24948. '\uFCED': '\u0644\u0645',
  24949. '\uFCEE': '\u0646\u0645',
  24950. '\uFCEF': '\u0646\u0647',
  24951. '\uFCF0': '\u064A\u0645',
  24952. '\uFCF1': '\u064A\u0647',
  24953. '\uFCF2': '\u0640\u064E\u0651',
  24954. '\uFCF3': '\u0640\u064F\u0651',
  24955. '\uFCF4': '\u0640\u0650\u0651',
  24956. '\uFCF5': '\u0637\u0649',
  24957. '\uFCF6': '\u0637\u064A',
  24958. '\uFCF7': '\u0639\u0649',
  24959. '\uFCF8': '\u0639\u064A',
  24960. '\uFCF9': '\u063A\u0649',
  24961. '\uFCFA': '\u063A\u064A',
  24962. '\uFCFB': '\u0633\u0649',
  24963. '\uFCFC': '\u0633\u064A',
  24964. '\uFCFD': '\u0634\u0649',
  24965. '\uFCFE': '\u0634\u064A',
  24966. '\uFCFF': '\u062D\u0649',
  24967. '\uFD00': '\u062D\u064A',
  24968. '\uFD01': '\u062C\u0649',
  24969. '\uFD02': '\u062C\u064A',
  24970. '\uFD03': '\u062E\u0649',
  24971. '\uFD04': '\u062E\u064A',
  24972. '\uFD05': '\u0635\u0649',
  24973. '\uFD06': '\u0635\u064A',
  24974. '\uFD07': '\u0636\u0649',
  24975. '\uFD08': '\u0636\u064A',
  24976. '\uFD09': '\u0634\u062C',
  24977. '\uFD0A': '\u0634\u062D',
  24978. '\uFD0B': '\u0634\u062E',
  24979. '\uFD0C': '\u0634\u0645',
  24980. '\uFD0D': '\u0634\u0631',
  24981. '\uFD0E': '\u0633\u0631',
  24982. '\uFD0F': '\u0635\u0631',
  24983. '\uFD10': '\u0636\u0631',
  24984. '\uFD11': '\u0637\u0649',
  24985. '\uFD12': '\u0637\u064A',
  24986. '\uFD13': '\u0639\u0649',
  24987. '\uFD14': '\u0639\u064A',
  24988. '\uFD15': '\u063A\u0649',
  24989. '\uFD16': '\u063A\u064A',
  24990. '\uFD17': '\u0633\u0649',
  24991. '\uFD18': '\u0633\u064A',
  24992. '\uFD19': '\u0634\u0649',
  24993. '\uFD1A': '\u0634\u064A',
  24994. '\uFD1B': '\u062D\u0649',
  24995. '\uFD1C': '\u062D\u064A',
  24996. '\uFD1D': '\u062C\u0649',
  24997. '\uFD1E': '\u062C\u064A',
  24998. '\uFD1F': '\u062E\u0649',
  24999. '\uFD20': '\u062E\u064A',
  25000. '\uFD21': '\u0635\u0649',
  25001. '\uFD22': '\u0635\u064A',
  25002. '\uFD23': '\u0636\u0649',
  25003. '\uFD24': '\u0636\u064A',
  25004. '\uFD25': '\u0634\u062C',
  25005. '\uFD26': '\u0634\u062D',
  25006. '\uFD27': '\u0634\u062E',
  25007. '\uFD28': '\u0634\u0645',
  25008. '\uFD29': '\u0634\u0631',
  25009. '\uFD2A': '\u0633\u0631',
  25010. '\uFD2B': '\u0635\u0631',
  25011. '\uFD2C': '\u0636\u0631',
  25012. '\uFD2D': '\u0634\u062C',
  25013. '\uFD2E': '\u0634\u062D',
  25014. '\uFD2F': '\u0634\u062E',
  25015. '\uFD30': '\u0634\u0645',
  25016. '\uFD31': '\u0633\u0647',
  25017. '\uFD32': '\u0634\u0647',
  25018. '\uFD33': '\u0637\u0645',
  25019. '\uFD34': '\u0633\u062C',
  25020. '\uFD35': '\u0633\u062D',
  25021. '\uFD36': '\u0633\u062E',
  25022. '\uFD37': '\u0634\u062C',
  25023. '\uFD38': '\u0634\u062D',
  25024. '\uFD39': '\u0634\u062E',
  25025. '\uFD3A': '\u0637\u0645',
  25026. '\uFD3B': '\u0638\u0645',
  25027. '\uFD3C': '\u0627\u064B',
  25028. '\uFD3D': '\u0627\u064B',
  25029. '\uFD50': '\u062A\u062C\u0645',
  25030. '\uFD51': '\u062A\u062D\u062C',
  25031. '\uFD52': '\u062A\u062D\u062C',
  25032. '\uFD53': '\u062A\u062D\u0645',
  25033. '\uFD54': '\u062A\u062E\u0645',
  25034. '\uFD55': '\u062A\u0645\u062C',
  25035. '\uFD56': '\u062A\u0645\u062D',
  25036. '\uFD57': '\u062A\u0645\u062E',
  25037. '\uFD58': '\u062C\u0645\u062D',
  25038. '\uFD59': '\u062C\u0645\u062D',
  25039. '\uFD5A': '\u062D\u0645\u064A',
  25040. '\uFD5B': '\u062D\u0645\u0649',
  25041. '\uFD5C': '\u0633\u062D\u062C',
  25042. '\uFD5D': '\u0633\u062C\u062D',
  25043. '\uFD5E': '\u0633\u062C\u0649',
  25044. '\uFD5F': '\u0633\u0645\u062D',
  25045. '\uFD60': '\u0633\u0645\u062D',
  25046. '\uFD61': '\u0633\u0645\u062C',
  25047. '\uFD62': '\u0633\u0645\u0645',
  25048. '\uFD63': '\u0633\u0645\u0645',
  25049. '\uFD64': '\u0635\u062D\u062D',
  25050. '\uFD65': '\u0635\u062D\u062D',
  25051. '\uFD66': '\u0635\u0645\u0645',
  25052. '\uFD67': '\u0634\u062D\u0645',
  25053. '\uFD68': '\u0634\u062D\u0645',
  25054. '\uFD69': '\u0634\u062C\u064A',
  25055. '\uFD6A': '\u0634\u0645\u062E',
  25056. '\uFD6B': '\u0634\u0645\u062E',
  25057. '\uFD6C': '\u0634\u0645\u0645',
  25058. '\uFD6D': '\u0634\u0645\u0645',
  25059. '\uFD6E': '\u0636\u062D\u0649',
  25060. '\uFD6F': '\u0636\u062E\u0645',
  25061. '\uFD70': '\u0636\u062E\u0645',
  25062. '\uFD71': '\u0637\u0645\u062D',
  25063. '\uFD72': '\u0637\u0645\u062D',
  25064. '\uFD73': '\u0637\u0645\u0645',
  25065. '\uFD74': '\u0637\u0645\u064A',
  25066. '\uFD75': '\u0639\u062C\u0645',
  25067. '\uFD76': '\u0639\u0645\u0645',
  25068. '\uFD77': '\u0639\u0645\u0645',
  25069. '\uFD78': '\u0639\u0645\u0649',
  25070. '\uFD79': '\u063A\u0645\u0645',
  25071. '\uFD7A': '\u063A\u0645\u064A',
  25072. '\uFD7B': '\u063A\u0645\u0649',
  25073. '\uFD7C': '\u0641\u062E\u0645',
  25074. '\uFD7D': '\u0641\u062E\u0645',
  25075. '\uFD7E': '\u0642\u0645\u062D',
  25076. '\uFD7F': '\u0642\u0645\u0645',
  25077. '\uFD80': '\u0644\u062D\u0645',
  25078. '\uFD81': '\u0644\u062D\u064A',
  25079. '\uFD82': '\u0644\u062D\u0649',
  25080. '\uFD83': '\u0644\u062C\u062C',
  25081. '\uFD84': '\u0644\u062C\u062C',
  25082. '\uFD85': '\u0644\u062E\u0645',
  25083. '\uFD86': '\u0644\u062E\u0645',
  25084. '\uFD87': '\u0644\u0645\u062D',
  25085. '\uFD88': '\u0644\u0645\u062D',
  25086. '\uFD89': '\u0645\u062D\u062C',
  25087. '\uFD8A': '\u0645\u062D\u0645',
  25088. '\uFD8B': '\u0645\u062D\u064A',
  25089. '\uFD8C': '\u0645\u062C\u062D',
  25090. '\uFD8D': '\u0645\u062C\u0645',
  25091. '\uFD8E': '\u0645\u062E\u062C',
  25092. '\uFD8F': '\u0645\u062E\u0645',
  25093. '\uFD92': '\u0645\u062C\u062E',
  25094. '\uFD93': '\u0647\u0645\u062C',
  25095. '\uFD94': '\u0647\u0645\u0645',
  25096. '\uFD95': '\u0646\u062D\u0645',
  25097. '\uFD96': '\u0646\u062D\u0649',
  25098. '\uFD97': '\u0646\u062C\u0645',
  25099. '\uFD98': '\u0646\u062C\u0645',
  25100. '\uFD99': '\u0646\u062C\u0649',
  25101. '\uFD9A': '\u0646\u0645\u064A',
  25102. '\uFD9B': '\u0646\u0645\u0649',
  25103. '\uFD9C': '\u064A\u0645\u0645',
  25104. '\uFD9D': '\u064A\u0645\u0645',
  25105. '\uFD9E': '\u0628\u062E\u064A',
  25106. '\uFD9F': '\u062A\u062C\u064A',
  25107. '\uFDA0': '\u062A\u062C\u0649',
  25108. '\uFDA1': '\u062A\u062E\u064A',
  25109. '\uFDA2': '\u062A\u062E\u0649',
  25110. '\uFDA3': '\u062A\u0645\u064A',
  25111. '\uFDA4': '\u062A\u0645\u0649',
  25112. '\uFDA5': '\u062C\u0645\u064A',
  25113. '\uFDA6': '\u062C\u062D\u0649',
  25114. '\uFDA7': '\u062C\u0645\u0649',
  25115. '\uFDA8': '\u0633\u062E\u0649',
  25116. '\uFDA9': '\u0635\u062D\u064A',
  25117. '\uFDAA': '\u0634\u062D\u064A',
  25118. '\uFDAB': '\u0636\u062D\u064A',
  25119. '\uFDAC': '\u0644\u062C\u064A',
  25120. '\uFDAD': '\u0644\u0645\u064A',
  25121. '\uFDAE': '\u064A\u062D\u064A',
  25122. '\uFDAF': '\u064A\u062C\u064A',
  25123. '\uFDB0': '\u064A\u0645\u064A',
  25124. '\uFDB1': '\u0645\u0645\u064A',
  25125. '\uFDB2': '\u0642\u0645\u064A',
  25126. '\uFDB3': '\u0646\u062D\u064A',
  25127. '\uFDB4': '\u0642\u0645\u062D',
  25128. '\uFDB5': '\u0644\u062D\u0645',
  25129. '\uFDB6': '\u0639\u0645\u064A',
  25130. '\uFDB7': '\u0643\u0645\u064A',
  25131. '\uFDB8': '\u0646\u062C\u062D',
  25132. '\uFDB9': '\u0645\u062E\u064A',
  25133. '\uFDBA': '\u0644\u062C\u0645',
  25134. '\uFDBB': '\u0643\u0645\u0645',
  25135. '\uFDBC': '\u0644\u062C\u0645',
  25136. '\uFDBD': '\u0646\u062C\u062D',
  25137. '\uFDBE': '\u062C\u062D\u064A',
  25138. '\uFDBF': '\u062D\u062C\u064A',
  25139. '\uFDC0': '\u0645\u062C\u064A',
  25140. '\uFDC1': '\u0641\u0645\u064A',
  25141. '\uFDC2': '\u0628\u062D\u064A',
  25142. '\uFDC3': '\u0643\u0645\u0645',
  25143. '\uFDC4': '\u0639\u062C\u0645',
  25144. '\uFDC5': '\u0635\u0645\u0645',
  25145. '\uFDC6': '\u0633\u062E\u064A',
  25146. '\uFDC7': '\u0646\u062C\u064A',
  25147. '\uFE49': '\u203E',
  25148. '\uFE4A': '\u203E',
  25149. '\uFE4B': '\u203E',
  25150. '\uFE4C': '\u203E',
  25151. '\uFE4D': '\u005F',
  25152. '\uFE4E': '\u005F',
  25153. '\uFE4F': '\u005F',
  25154. '\uFE80': '\u0621',
  25155. '\uFE81': '\u0622',
  25156. '\uFE82': '\u0622',
  25157. '\uFE83': '\u0623',
  25158. '\uFE84': '\u0623',
  25159. '\uFE85': '\u0624',
  25160. '\uFE86': '\u0624',
  25161. '\uFE87': '\u0625',
  25162. '\uFE88': '\u0625',
  25163. '\uFE89': '\u0626',
  25164. '\uFE8A': '\u0626',
  25165. '\uFE8B': '\u0626',
  25166. '\uFE8C': '\u0626',
  25167. '\uFE8D': '\u0627',
  25168. '\uFE8E': '\u0627',
  25169. '\uFE8F': '\u0628',
  25170. '\uFE90': '\u0628',
  25171. '\uFE91': '\u0628',
  25172. '\uFE92': '\u0628',
  25173. '\uFE93': '\u0629',
  25174. '\uFE94': '\u0629',
  25175. '\uFE95': '\u062A',
  25176. '\uFE96': '\u062A',
  25177. '\uFE97': '\u062A',
  25178. '\uFE98': '\u062A',
  25179. '\uFE99': '\u062B',
  25180. '\uFE9A': '\u062B',
  25181. '\uFE9B': '\u062B',
  25182. '\uFE9C': '\u062B',
  25183. '\uFE9D': '\u062C',
  25184. '\uFE9E': '\u062C',
  25185. '\uFE9F': '\u062C',
  25186. '\uFEA0': '\u062C',
  25187. '\uFEA1': '\u062D',
  25188. '\uFEA2': '\u062D',
  25189. '\uFEA3': '\u062D',
  25190. '\uFEA4': '\u062D',
  25191. '\uFEA5': '\u062E',
  25192. '\uFEA6': '\u062E',
  25193. '\uFEA7': '\u062E',
  25194. '\uFEA8': '\u062E',
  25195. '\uFEA9': '\u062F',
  25196. '\uFEAA': '\u062F',
  25197. '\uFEAB': '\u0630',
  25198. '\uFEAC': '\u0630',
  25199. '\uFEAD': '\u0631',
  25200. '\uFEAE': '\u0631',
  25201. '\uFEAF': '\u0632',
  25202. '\uFEB0': '\u0632',
  25203. '\uFEB1': '\u0633',
  25204. '\uFEB2': '\u0633',
  25205. '\uFEB3': '\u0633',
  25206. '\uFEB4': '\u0633',
  25207. '\uFEB5': '\u0634',
  25208. '\uFEB6': '\u0634',
  25209. '\uFEB7': '\u0634',
  25210. '\uFEB8': '\u0634',
  25211. '\uFEB9': '\u0635',
  25212. '\uFEBA': '\u0635',
  25213. '\uFEBB': '\u0635',
  25214. '\uFEBC': '\u0635',
  25215. '\uFEBD': '\u0636',
  25216. '\uFEBE': '\u0636',
  25217. '\uFEBF': '\u0636',
  25218. '\uFEC0': '\u0636',
  25219. '\uFEC1': '\u0637',
  25220. '\uFEC2': '\u0637',
  25221. '\uFEC3': '\u0637',
  25222. '\uFEC4': '\u0637',
  25223. '\uFEC5': '\u0638',
  25224. '\uFEC6': '\u0638',
  25225. '\uFEC7': '\u0638',
  25226. '\uFEC8': '\u0638',
  25227. '\uFEC9': '\u0639',
  25228. '\uFECA': '\u0639',
  25229. '\uFECB': '\u0639',
  25230. '\uFECC': '\u0639',
  25231. '\uFECD': '\u063A',
  25232. '\uFECE': '\u063A',
  25233. '\uFECF': '\u063A',
  25234. '\uFED0': '\u063A',
  25235. '\uFED1': '\u0641',
  25236. '\uFED2': '\u0641',
  25237. '\uFED3': '\u0641',
  25238. '\uFED4': '\u0641',
  25239. '\uFED5': '\u0642',
  25240. '\uFED6': '\u0642',
  25241. '\uFED7': '\u0642',
  25242. '\uFED8': '\u0642',
  25243. '\uFED9': '\u0643',
  25244. '\uFEDA': '\u0643',
  25245. '\uFEDB': '\u0643',
  25246. '\uFEDC': '\u0643',
  25247. '\uFEDD': '\u0644',
  25248. '\uFEDE': '\u0644',
  25249. '\uFEDF': '\u0644',
  25250. '\uFEE0': '\u0644',
  25251. '\uFEE1': '\u0645',
  25252. '\uFEE2': '\u0645',
  25253. '\uFEE3': '\u0645',
  25254. '\uFEE4': '\u0645',
  25255. '\uFEE5': '\u0646',
  25256. '\uFEE6': '\u0646',
  25257. '\uFEE7': '\u0646',
  25258. '\uFEE8': '\u0646',
  25259. '\uFEE9': '\u0647',
  25260. '\uFEEA': '\u0647',
  25261. '\uFEEB': '\u0647',
  25262. '\uFEEC': '\u0647',
  25263. '\uFEED': '\u0648',
  25264. '\uFEEE': '\u0648',
  25265. '\uFEEF': '\u0649',
  25266. '\uFEF0': '\u0649',
  25267. '\uFEF1': '\u064A',
  25268. '\uFEF2': '\u064A',
  25269. '\uFEF3': '\u064A',
  25270. '\uFEF4': '\u064A',
  25271. '\uFEF5': '\u0644\u0622',
  25272. '\uFEF6': '\u0644\u0622',
  25273. '\uFEF7': '\u0644\u0623',
  25274. '\uFEF8': '\u0644\u0623',
  25275. '\uFEF9': '\u0644\u0625',
  25276. '\uFEFA': '\u0644\u0625',
  25277. '\uFEFB': '\u0644\u0627',
  25278. '\uFEFC': '\u0644\u0627'
  25279. };
  25280. function reverseIfRtl(chars) {
  25281. var charsLength = chars.length;
  25282. //reverse an arabic ligature
  25283. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  25284. return chars;
  25285. }
  25286. var s = '';
  25287. for (var ii = charsLength - 1; ii >= 0; ii--) {
  25288. s += chars[ii];
  25289. }
  25290. return s;
  25291. }
  25292. function adjustWidths(properties) {
  25293. if (!properties.fontMatrix) {
  25294. return;
  25295. }
  25296. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  25297. return;
  25298. }
  25299. // adjusting width to fontMatrix scale
  25300. var scale = 0.001 / properties.fontMatrix[0];
  25301. var glyphsWidths = properties.widths;
  25302. for (var glyph in glyphsWidths) {
  25303. glyphsWidths[glyph] *= scale;
  25304. }
  25305. properties.defaultWidth *= scale;
  25306. }
  25307. function getFontType(type, subtype) {
  25308. switch (type) {
  25309. case 'Type1':
  25310. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  25311. case 'CIDFontType0':
  25312. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  25313. FontType.CIDFONTTYPE0;
  25314. case 'OpenType':
  25315. return FontType.OPENTYPE;
  25316. case 'TrueType':
  25317. return FontType.TRUETYPE;
  25318. case 'CIDFontType2':
  25319. return FontType.CIDFONTTYPE2;
  25320. case 'MMType1':
  25321. return FontType.MMTYPE1;
  25322. case 'Type0':
  25323. return FontType.TYPE0;
  25324. default:
  25325. return FontType.UNKNOWN;
  25326. }
  25327. }
  25328. var Glyph = (function GlyphClosure() {
  25329. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  25330. isSpace) {
  25331. this.fontChar = fontChar;
  25332. this.unicode = unicode;
  25333. this.accent = accent;
  25334. this.width = width;
  25335. this.vmetric = vmetric;
  25336. this.operatorListId = operatorListId;
  25337. this.isSpace = isSpace;
  25338. }
  25339. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  25340. vmetric, operatorListId, isSpace) {
  25341. return this.fontChar === fontChar &&
  25342. this.unicode === unicode &&
  25343. this.accent === accent &&
  25344. this.width === width &&
  25345. this.vmetric === vmetric &&
  25346. this.operatorListId === operatorListId &&
  25347. this.isSpace === isSpace;
  25348. };
  25349. return Glyph;
  25350. })();
  25351. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  25352. function ToUnicodeMap(cmap) {
  25353. // The elements of this._map can be integers or strings, depending on how
  25354. // |cmap| was created.
  25355. this._map = cmap;
  25356. }
  25357. ToUnicodeMap.prototype = {
  25358. get length() {
  25359. return this._map.length;
  25360. },
  25361. forEach: function(callback) {
  25362. for (var charCode in this._map) {
  25363. callback(charCode, this._map[charCode].charCodeAt(0));
  25364. }
  25365. },
  25366. has: function(i) {
  25367. return this._map[i] !== undefined;
  25368. },
  25369. get: function(i) {
  25370. return this._map[i];
  25371. },
  25372. charCodeOf: function(v) {
  25373. return this._map.indexOf(v);
  25374. }
  25375. };
  25376. return ToUnicodeMap;
  25377. })();
  25378. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  25379. function IdentityToUnicodeMap(firstChar, lastChar) {
  25380. this.firstChar = firstChar;
  25381. this.lastChar = lastChar;
  25382. }
  25383. IdentityToUnicodeMap.prototype = {
  25384. get length() {
  25385. return (this.lastChar + 1) - this.firstChar;
  25386. },
  25387. forEach: function (callback) {
  25388. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  25389. callback(i, i);
  25390. }
  25391. },
  25392. has: function (i) {
  25393. return this.firstChar <= i && i <= this.lastChar;
  25394. },
  25395. get: function (i) {
  25396. if (this.firstChar <= i && i <= this.lastChar) {
  25397. return String.fromCharCode(i);
  25398. }
  25399. return undefined;
  25400. },
  25401. charCodeOf: function (v) {
  25402. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  25403. }
  25404. };
  25405. return IdentityToUnicodeMap;
  25406. })();
  25407. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  25408. function writeInt16(dest, offset, num) {
  25409. dest[offset] = (num >> 8) & 0xFF;
  25410. dest[offset + 1] = num & 0xFF;
  25411. }
  25412. function writeInt32(dest, offset, num) {
  25413. dest[offset] = (num >> 24) & 0xFF;
  25414. dest[offset + 1] = (num >> 16) & 0xFF;
  25415. dest[offset + 2] = (num >> 8) & 0xFF;
  25416. dest[offset + 3] = num & 0xFF;
  25417. }
  25418. function writeData(dest, offset, data) {
  25419. var i, ii;
  25420. if (data instanceof Uint8Array) {
  25421. dest.set(data, offset);
  25422. } else if (typeof data === 'string') {
  25423. for (i = 0, ii = data.length; i < ii; i++) {
  25424. dest[offset++] = data.charCodeAt(i) & 0xFF;
  25425. }
  25426. } else {
  25427. // treating everything else as array
  25428. for (i = 0, ii = data.length; i < ii; i++) {
  25429. dest[offset++] = data[i] & 0xFF;
  25430. }
  25431. }
  25432. }
  25433. function OpenTypeFileBuilder(sfnt) {
  25434. this.sfnt = sfnt;
  25435. this.tables = Object.create(null);
  25436. }
  25437. OpenTypeFileBuilder.getSearchParams =
  25438. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  25439. var maxPower2 = 1, log2 = 0;
  25440. while ((maxPower2 ^ entriesCount) > maxPower2) {
  25441. maxPower2 <<= 1;
  25442. log2++;
  25443. }
  25444. var searchRange = maxPower2 * entrySize;
  25445. return {
  25446. range: searchRange,
  25447. entry: log2,
  25448. rangeShift: entrySize * entriesCount - searchRange
  25449. };
  25450. };
  25451. var OTF_HEADER_SIZE = 12;
  25452. var OTF_TABLE_ENTRY_SIZE = 16;
  25453. OpenTypeFileBuilder.prototype = {
  25454. toArray: function OpenTypeFileBuilder_toArray() {
  25455. var sfnt = this.sfnt;
  25456. // Tables needs to be written by ascendant alphabetic order
  25457. var tables = this.tables;
  25458. var tablesNames = Object.keys(tables);
  25459. tablesNames.sort();
  25460. var numTables = tablesNames.length;
  25461. var i, j, jj, table, tableName;
  25462. // layout the tables data
  25463. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  25464. var tableOffsets = [offset];
  25465. for (i = 0; i < numTables; i++) {
  25466. table = tables[tablesNames[i]];
  25467. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  25468. offset += paddedLength;
  25469. tableOffsets.push(offset);
  25470. }
  25471. var file = new Uint8Array(offset);
  25472. // write the table data first (mostly for checksum)
  25473. for (i = 0; i < numTables; i++) {
  25474. table = tables[tablesNames[i]];
  25475. writeData(file, tableOffsets[i], table);
  25476. }
  25477. // sfnt version (4 bytes)
  25478. if (sfnt === 'true') {
  25479. // Windows hates the Mac TrueType sfnt version number
  25480. sfnt = string32(0x00010000);
  25481. }
  25482. file[0] = sfnt.charCodeAt(0) & 0xFF;
  25483. file[1] = sfnt.charCodeAt(1) & 0xFF;
  25484. file[2] = sfnt.charCodeAt(2) & 0xFF;
  25485. file[3] = sfnt.charCodeAt(3) & 0xFF;
  25486. // numTables (2 bytes)
  25487. writeInt16(file, 4, numTables);
  25488. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  25489. // searchRange (2 bytes)
  25490. writeInt16(file, 6, searchParams.range);
  25491. // entrySelector (2 bytes)
  25492. writeInt16(file, 8, searchParams.entry);
  25493. // rangeShift (2 bytes)
  25494. writeInt16(file, 10, searchParams.rangeShift);
  25495. offset = OTF_HEADER_SIZE;
  25496. // writing table entries
  25497. for (i = 0; i < numTables; i++) {
  25498. tableName = tablesNames[i];
  25499. file[offset] = tableName.charCodeAt(0) & 0xFF;
  25500. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  25501. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  25502. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  25503. // checksum
  25504. var checksum = 0;
  25505. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  25506. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  25507. (file[j + 2] << 8) + file[j + 3];
  25508. checksum = (checksum + quad) | 0;
  25509. }
  25510. writeInt32(file, offset + 4, checksum);
  25511. // offset
  25512. writeInt32(file, offset + 8, tableOffsets[i]);
  25513. // length
  25514. writeInt32(file, offset + 12, tables[tableName].length);
  25515. offset += OTF_TABLE_ENTRY_SIZE;
  25516. }
  25517. return file;
  25518. },
  25519. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  25520. if (tag in this.tables) {
  25521. throw new Error('Table ' + tag + ' already exists');
  25522. }
  25523. this.tables[tag] = data;
  25524. }
  25525. };
  25526. return OpenTypeFileBuilder;
  25527. })();
  25528. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  25529. // issues when they are painted on the canvas, e.g. complex-script shaping or
  25530. // control/whitespace characters. The ranges are listed in pairs: the first item
  25531. // is a code of the first problematic code, the second one is the next
  25532. // non-problematic code. The ranges must be in sorted order.
  25533. var ProblematicCharRanges = new Int32Array([
  25534. // Control characters.
  25535. 0x0000, 0x0020,
  25536. 0x007F, 0x00A1,
  25537. 0x00AD, 0x00AE,
  25538. // Chars that is used in complex-script shaping.
  25539. 0x0600, 0x0780,
  25540. 0x08A0, 0x10A0,
  25541. 0x1780, 0x1800,
  25542. // General punctuation chars.
  25543. 0x2000, 0x2010,
  25544. 0x2011, 0x2012,
  25545. 0x2028, 0x2030,
  25546. 0x205F, 0x2070,
  25547. 0x25CC, 0x25CD,
  25548. // Chars that is used in complex-script shaping.
  25549. 0xAA60, 0xAA80,
  25550. // Specials Unicode block.
  25551. 0xFFF0, 0x10000
  25552. ]);
  25553. /**
  25554. * 'Font' is the class the outside world should use, it encapsulate all the font
  25555. * decoding logics whatever type it is (assuming the font type is supported).
  25556. *
  25557. * For example to read a Type1 font and to attach it to the document:
  25558. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  25559. * type1Font.bind();
  25560. */
  25561. var Font = (function FontClosure() {
  25562. function Font(name, file, properties) {
  25563. var charCode, glyphName, fontChar;
  25564. this.name = name;
  25565. this.loadedName = properties.loadedName;
  25566. this.isType3Font = properties.isType3Font;
  25567. this.sizes = [];
  25568. this.glyphCache = {};
  25569. var names = name.split('+');
  25570. names = names.length > 1 ? names[1] : names[0];
  25571. names = names.split(/[-,_]/g)[0];
  25572. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  25573. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  25574. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  25575. var type = properties.type;
  25576. var subtype = properties.subtype;
  25577. this.type = type;
  25578. this.fallbackName = (this.isMonospace ? 'monospace' :
  25579. (this.isSerifFont ? 'serif' : 'sans-serif'));
  25580. this.differences = properties.differences;
  25581. this.widths = properties.widths;
  25582. this.defaultWidth = properties.defaultWidth;
  25583. this.composite = properties.composite;
  25584. this.wideChars = properties.wideChars;
  25585. this.cMap = properties.cMap;
  25586. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  25587. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  25588. this.fontMatrix = properties.fontMatrix;
  25589. this.bbox = properties.bbox;
  25590. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  25591. this.toFontChar = [];
  25592. if (properties.type === 'Type3') {
  25593. for (charCode = 0; charCode < 256; charCode++) {
  25594. this.toFontChar[charCode] = (this.differences[charCode] ||
  25595. properties.defaultEncoding[charCode]);
  25596. }
  25597. this.fontType = FontType.TYPE3;
  25598. return;
  25599. }
  25600. this.cidEncoding = properties.cidEncoding;
  25601. this.vertical = properties.vertical;
  25602. if (this.vertical) {
  25603. this.vmetrics = properties.vmetrics;
  25604. this.defaultVMetrics = properties.defaultVMetrics;
  25605. }
  25606. if (!file || file.isEmpty) {
  25607. if (file) {
  25608. // Some bad PDF generators will include empty font files,
  25609. // attempting to recover by assuming that no file exists.
  25610. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  25611. }
  25612. this.missingFile = true;
  25613. // The file data is not specified. Trying to fix the font name
  25614. // to be used with the canvas.font.
  25615. var fontName = name.replace(/[,_]/g, '-');
  25616. var isStandardFont = !!stdFontMap[fontName] ||
  25617. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  25618. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  25619. this.bold = (fontName.search(/bold/gi) !== -1);
  25620. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  25621. (fontName.search(/italic/gi) !== -1));
  25622. // Use 'name' instead of 'fontName' here because the original
  25623. // name ArialBlack for example will be replaced by Helvetica.
  25624. this.black = (name.search(/Black/g) !== -1);
  25625. // if at least one width is present, remeasure all chars when exists
  25626. this.remeasure = Object.keys(this.widths).length > 0;
  25627. if (isStandardFont && type === 'CIDFontType2' &&
  25628. properties.cidEncoding.indexOf('Identity-') === 0) {
  25629. // Standard fonts might be embedded as CID font without glyph mapping.
  25630. // Building one based on GlyphMapForStandardFonts.
  25631. var map = [];
  25632. for (charCode in GlyphMapForStandardFonts) {
  25633. map[+charCode] = GlyphMapForStandardFonts[charCode];
  25634. }
  25635. if (/ArialBlack/i.test(name)) {
  25636. for (charCode in SupplementalGlyphMapForArialBlack) {
  25637. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  25638. }
  25639. }
  25640. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  25641. if (!isIdentityUnicode) {
  25642. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25643. map[+charCode] = unicodeCharCode;
  25644. });
  25645. }
  25646. this.toFontChar = map;
  25647. this.toUnicode = new ToUnicodeMap(map);
  25648. } else if (/Symbol/i.test(fontName)) {
  25649. var symbols = Encodings.SymbolSetEncoding;
  25650. for (charCode in symbols) {
  25651. fontChar = GlyphsUnicode[symbols[charCode]];
  25652. if (!fontChar) {
  25653. continue;
  25654. }
  25655. this.toFontChar[charCode] = fontChar;
  25656. }
  25657. for (charCode in properties.differences) {
  25658. fontChar = GlyphsUnicode[properties.differences[charCode]];
  25659. if (!fontChar) {
  25660. continue;
  25661. }
  25662. this.toFontChar[charCode] = fontChar;
  25663. }
  25664. } else if (/Dingbats/i.test(fontName)) {
  25665. if (/Wingdings/i.test(name)) {
  25666. warn('Wingdings font without embedded font file, ' +
  25667. 'falling back to the ZapfDingbats encoding.');
  25668. }
  25669. var dingbats = Encodings.ZapfDingbatsEncoding;
  25670. for (charCode in dingbats) {
  25671. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  25672. if (!fontChar) {
  25673. continue;
  25674. }
  25675. this.toFontChar[charCode] = fontChar;
  25676. }
  25677. for (charCode in properties.differences) {
  25678. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  25679. if (!fontChar) {
  25680. continue;
  25681. }
  25682. this.toFontChar[charCode] = fontChar;
  25683. }
  25684. } else if (isStandardFont) {
  25685. this.toFontChar = [];
  25686. for (charCode in properties.defaultEncoding) {
  25687. glyphName = (properties.differences[charCode] ||
  25688. properties.defaultEncoding[charCode]);
  25689. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  25690. }
  25691. } else {
  25692. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25693. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25694. if (notCidFont) {
  25695. glyphName = (properties.differences[charCode] ||
  25696. properties.defaultEncoding[charCode]);
  25697. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  25698. }
  25699. this.toFontChar[charCode] = unicodeCharCode;
  25700. }.bind(this));
  25701. }
  25702. this.loadedName = fontName.split('-')[0];
  25703. this.loading = false;
  25704. this.fontType = getFontType(type, subtype);
  25705. return;
  25706. }
  25707. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25708. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25709. // Some TrueType fonts by mistake claim Type1C
  25710. if (isTrueTypeFile(file)) {
  25711. subtype = 'TrueType';
  25712. } else {
  25713. type = 'Type1';
  25714. }
  25715. }
  25716. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25717. type = 'CIDFontType0';
  25718. }
  25719. if (subtype === 'OpenType') {
  25720. type = 'OpenType';
  25721. }
  25722. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25723. if (type === 'CIDFontType0') {
  25724. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  25725. }
  25726. var data;
  25727. switch (type) {
  25728. case 'MMType1':
  25729. info('MMType1 font (' + name + '), falling back to Type1.');
  25730. /* falls through */
  25731. case 'Type1':
  25732. case 'CIDFontType0':
  25733. this.mimetype = 'font/opentype';
  25734. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25735. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25736. adjustWidths(properties);
  25737. // Wrap the CFF data inside an OTF font file
  25738. data = this.convert(name, cff, properties);
  25739. break;
  25740. case 'OpenType':
  25741. case 'TrueType':
  25742. case 'CIDFontType2':
  25743. this.mimetype = 'font/opentype';
  25744. // Repair the TrueType file. It is can be damaged in the point of
  25745. // view of the sanitizer
  25746. data = this.checkAndRepair(name, file, properties);
  25747. if (this.isOpenType) {
  25748. adjustWidths(properties);
  25749. type = 'OpenType';
  25750. }
  25751. break;
  25752. default:
  25753. error('Font ' + type + ' is not supported');
  25754. break;
  25755. }
  25756. this.data = data;
  25757. this.fontType = getFontType(type, subtype);
  25758. // Transfer some properties again that could change during font conversion
  25759. this.fontMatrix = properties.fontMatrix;
  25760. this.widths = properties.widths;
  25761. this.defaultWidth = properties.defaultWidth;
  25762. this.encoding = properties.baseEncoding;
  25763. this.seacMap = properties.seacMap;
  25764. this.loading = true;
  25765. }
  25766. Font.getFontID = (function () {
  25767. var ID = 1;
  25768. return function Font_getFontID() {
  25769. return String(ID++);
  25770. };
  25771. })();
  25772. function int16(b0, b1) {
  25773. return (b0 << 8) + b1;
  25774. }
  25775. function int32(b0, b1, b2, b3) {
  25776. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25777. }
  25778. function string16(value) {
  25779. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25780. }
  25781. function safeString16(value) {
  25782. // clamp value to the 16-bit int range
  25783. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25784. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25785. }
  25786. function isTrueTypeFile(file) {
  25787. var header = file.peekBytes(4);
  25788. return readUint32(header, 0) === 0x00010000;
  25789. }
  25790. function isType1File(file) {
  25791. var header = file.peekBytes(2);
  25792. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25793. if (header[0] === 0x25 && header[1] === 0x21) {
  25794. return true;
  25795. }
  25796. // ... obviously some fonts violate that part of the specification,
  25797. // please refer to the comment in |Type1Font| below.
  25798. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25799. return true;
  25800. }
  25801. return false;
  25802. }
  25803. /**
  25804. * Helper function for |adjustMapping|.
  25805. * @return {boolean}
  25806. */
  25807. function isProblematicUnicodeLocation(code) {
  25808. // Using binary search to find a range start.
  25809. var i = 0, j = ProblematicCharRanges.length - 1;
  25810. while (i < j) {
  25811. var c = (i + j + 1) >> 1;
  25812. if (code < ProblematicCharRanges[c]) {
  25813. j = c - 1;
  25814. } else {
  25815. i = c;
  25816. }
  25817. }
  25818. // Even index means code in problematic range.
  25819. return !(i & 1);
  25820. }
  25821. /**
  25822. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25823. * with their unicode value. It also moves char codes that are in known
  25824. * problematic locations.
  25825. * @return {Object} Two properties:
  25826. * 'toFontChar' - maps original char codes(the value that will be read
  25827. * from commands such as show text) to the char codes that will be used in the
  25828. * font that we build
  25829. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25830. */
  25831. function adjustMapping(charCodeToGlyphId, properties) {
  25832. var toUnicode = properties.toUnicode;
  25833. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25834. var isIdentityUnicode =
  25835. properties.toUnicode instanceof IdentityToUnicodeMap;
  25836. var newMap = Object.create(null);
  25837. var toFontChar = [];
  25838. var usedFontCharCodes = [];
  25839. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25840. for (var originalCharCode in charCodeToGlyphId) {
  25841. originalCharCode |= 0;
  25842. var glyphId = charCodeToGlyphId[originalCharCode];
  25843. var fontCharCode = originalCharCode;
  25844. // First try to map the value to a unicode position if a non identity map
  25845. // was created.
  25846. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25847. var unicode = toUnicode.get(fontCharCode);
  25848. // TODO: Try to map ligatures to the correct spot.
  25849. if (unicode.length === 1) {
  25850. fontCharCode = unicode.charCodeAt(0);
  25851. }
  25852. }
  25853. // Try to move control characters, special characters and already mapped
  25854. // characters to the private use area since they will not be drawn by
  25855. // canvas if left in their current position. Also, move characters if the
  25856. // font was symbolic and there is only an identity unicode map since the
  25857. // characters probably aren't in the correct position (fixes an issue
  25858. // with firefox and thuluthfont).
  25859. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25860. isProblematicUnicodeLocation(fontCharCode) ||
  25861. (isSymbolic && isIdentityUnicode)) &&
  25862. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25863. // Loop to try and find a free spot in the private use area.
  25864. do {
  25865. fontCharCode = nextAvailableFontCharCode++;
  25866. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25867. fontCharCode = 0xF020;
  25868. nextAvailableFontCharCode = fontCharCode + 1;
  25869. }
  25870. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25871. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25872. }
  25873. newMap[fontCharCode] = glyphId;
  25874. toFontChar[originalCharCode] = fontCharCode;
  25875. usedFontCharCodes[fontCharCode] = true;
  25876. }
  25877. return {
  25878. toFontChar: toFontChar,
  25879. charCodeToGlyphId: newMap,
  25880. nextAvailableFontCharCode: nextAvailableFontCharCode
  25881. };
  25882. }
  25883. function getRanges(glyphs, numGlyphs) {
  25884. // Array.sort() sorts by characters, not numerically, so convert to an
  25885. // array of characters.
  25886. var codes = [];
  25887. for (var charCode in glyphs) {
  25888. // Remove an invalid glyph ID mappings to make OTS happy.
  25889. if (glyphs[charCode] >= numGlyphs) {
  25890. continue;
  25891. }
  25892. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  25893. }
  25894. codes.sort(function fontGetRangesSort(a, b) {
  25895. return a.fontCharCode - b.fontCharCode;
  25896. });
  25897. // Split the sorted codes into ranges.
  25898. var ranges = [];
  25899. var length = codes.length;
  25900. for (var n = 0; n < length; ) {
  25901. var start = codes[n].fontCharCode;
  25902. var codeIndices = [codes[n].glyphId];
  25903. ++n;
  25904. var end = start;
  25905. while (n < length && end + 1 === codes[n].fontCharCode) {
  25906. codeIndices.push(codes[n].glyphId);
  25907. ++end;
  25908. ++n;
  25909. if (end === 0xFFFF) {
  25910. break;
  25911. }
  25912. }
  25913. ranges.push([start, end, codeIndices]);
  25914. }
  25915. return ranges;
  25916. }
  25917. function createCmapTable(glyphs, numGlyphs) {
  25918. var ranges = getRanges(glyphs, numGlyphs);
  25919. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  25920. var cmap = '\x00\x00' + // version
  25921. string16(numTables) + // numTables
  25922. '\x00\x03' + // platformID
  25923. '\x00\x01' + // encodingID
  25924. string32(4 + numTables * 8); // start of the table record
  25925. var i, ii, j, jj;
  25926. for (i = ranges.length - 1; i >= 0; --i) {
  25927. if (ranges[i][0] <= 0xFFFF) { break; }
  25928. }
  25929. var bmpLength = i + 1;
  25930. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  25931. ranges[i][1] = 0xFFFE;
  25932. }
  25933. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  25934. var segCount = bmpLength + trailingRangesCount;
  25935. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  25936. // Fill up the 4 parallel arrays describing the segments.
  25937. var startCount = '';
  25938. var endCount = '';
  25939. var idDeltas = '';
  25940. var idRangeOffsets = '';
  25941. var glyphsIds = '';
  25942. var bias = 0;
  25943. var range, start, end, codes;
  25944. for (i = 0, ii = bmpLength; i < ii; i++) {
  25945. range = ranges[i];
  25946. start = range[0];
  25947. end = range[1];
  25948. startCount += string16(start);
  25949. endCount += string16(end);
  25950. codes = range[2];
  25951. var contiguous = true;
  25952. for (j = 1, jj = codes.length; j < jj; ++j) {
  25953. if (codes[j] !== codes[j - 1] + 1) {
  25954. contiguous = false;
  25955. break;
  25956. }
  25957. }
  25958. if (!contiguous) {
  25959. var offset = (segCount - i) * 2 + bias * 2;
  25960. bias += (end - start + 1);
  25961. idDeltas += string16(0);
  25962. idRangeOffsets += string16(offset);
  25963. for (j = 0, jj = codes.length; j < jj; ++j) {
  25964. glyphsIds += string16(codes[j]);
  25965. }
  25966. } else {
  25967. var startCode = codes[0];
  25968. idDeltas += string16((startCode - start) & 0xFFFF);
  25969. idRangeOffsets += string16(0);
  25970. }
  25971. }
  25972. if (trailingRangesCount > 0) {
  25973. endCount += '\xFF\xFF';
  25974. startCount += '\xFF\xFF';
  25975. idDeltas += '\x00\x01';
  25976. idRangeOffsets += '\x00\x00';
  25977. }
  25978. var format314 = '\x00\x00' + // language
  25979. string16(2 * segCount) +
  25980. string16(searchParams.range) +
  25981. string16(searchParams.entry) +
  25982. string16(searchParams.rangeShift) +
  25983. endCount + '\x00\x00' + startCount +
  25984. idDeltas + idRangeOffsets + glyphsIds;
  25985. var format31012 = '';
  25986. var header31012 = '';
  25987. if (numTables > 1) {
  25988. cmap += '\x00\x03' + // platformID
  25989. '\x00\x0A' + // encodingID
  25990. string32(4 + numTables * 8 +
  25991. 4 + format314.length); // start of the table record
  25992. format31012 = '';
  25993. for (i = 0, ii = ranges.length; i < ii; i++) {
  25994. range = ranges[i];
  25995. start = range[0];
  25996. codes = range[2];
  25997. var code = codes[0];
  25998. for (j = 1, jj = codes.length; j < jj; ++j) {
  25999. if (codes[j] !== codes[j - 1] + 1) {
  26000. end = range[0] + j - 1;
  26001. format31012 += string32(start) + // startCharCode
  26002. string32(end) + // endCharCode
  26003. string32(code); // startGlyphID
  26004. start = end + 1;
  26005. code = codes[j];
  26006. }
  26007. }
  26008. format31012 += string32(start) + // startCharCode
  26009. string32(range[1]) + // endCharCode
  26010. string32(code); // startGlyphID
  26011. }
  26012. header31012 = '\x00\x0C' + // format
  26013. '\x00\x00' + // reserved
  26014. string32(format31012.length + 16) + // length
  26015. '\x00\x00\x00\x00' + // language
  26016. string32(format31012.length / 12); // nGroups
  26017. }
  26018. return cmap + '\x00\x04' + // format
  26019. string16(format314.length + 4) + // length
  26020. format314 + header31012 + format31012;
  26021. }
  26022. function validateOS2Table(os2) {
  26023. var stream = new Stream(os2.data);
  26024. var version = stream.getUint16();
  26025. // TODO verify all OS/2 tables fields, but currently we validate only those
  26026. // that give us issues
  26027. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  26028. var selection = stream.getUint16();
  26029. if (version < 4 && (selection & 0x0300)) {
  26030. return false;
  26031. }
  26032. var firstChar = stream.getUint16();
  26033. var lastChar = stream.getUint16();
  26034. if (firstChar > lastChar) {
  26035. return false;
  26036. }
  26037. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  26038. var usWinAscent = stream.getUint16();
  26039. if (usWinAscent === 0) { // makes font unreadable by windows
  26040. return false;
  26041. }
  26042. // OS/2 appears to be valid, resetting some fields
  26043. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  26044. return true;
  26045. }
  26046. function createOS2Table(properties, charstrings, override) {
  26047. override = override || {
  26048. unitsPerEm: 0,
  26049. yMax: 0,
  26050. yMin: 0,
  26051. ascent: 0,
  26052. descent: 0
  26053. };
  26054. var ulUnicodeRange1 = 0;
  26055. var ulUnicodeRange2 = 0;
  26056. var ulUnicodeRange3 = 0;
  26057. var ulUnicodeRange4 = 0;
  26058. var firstCharIndex = null;
  26059. var lastCharIndex = 0;
  26060. if (charstrings) {
  26061. for (var code in charstrings) {
  26062. code |= 0;
  26063. if (firstCharIndex > code || !firstCharIndex) {
  26064. firstCharIndex = code;
  26065. }
  26066. if (lastCharIndex < code) {
  26067. lastCharIndex = code;
  26068. }
  26069. var position = getUnicodeRangeFor(code);
  26070. if (position < 32) {
  26071. ulUnicodeRange1 |= 1 << position;
  26072. } else if (position < 64) {
  26073. ulUnicodeRange2 |= 1 << position - 32;
  26074. } else if (position < 96) {
  26075. ulUnicodeRange3 |= 1 << position - 64;
  26076. } else if (position < 123) {
  26077. ulUnicodeRange4 |= 1 << position - 96;
  26078. } else {
  26079. error('Unicode ranges Bits > 123 are reserved for internal usage');
  26080. }
  26081. }
  26082. } else {
  26083. // TODO
  26084. firstCharIndex = 0;
  26085. lastCharIndex = 255;
  26086. }
  26087. var bbox = properties.bbox || [0, 0, 0, 0];
  26088. var unitsPerEm = (override.unitsPerEm ||
  26089. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  26090. // if the font units differ to the PDF glyph space units
  26091. // then scale up the values
  26092. var scale = (properties.ascentScaled ? 1.0 :
  26093. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  26094. var typoAscent = (override.ascent ||
  26095. Math.round(scale * (properties.ascent || bbox[3])));
  26096. var typoDescent = (override.descent ||
  26097. Math.round(scale * (properties.descent || bbox[1])));
  26098. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  26099. typoDescent = -typoDescent; // fixing incorrect descent
  26100. }
  26101. var winAscent = override.yMax || typoAscent;
  26102. var winDescent = -override.yMin || -typoDescent;
  26103. return '\x00\x03' + // version
  26104. '\x02\x24' + // xAvgCharWidth
  26105. '\x01\xF4' + // usWeightClass
  26106. '\x00\x05' + // usWidthClass
  26107. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  26108. '\x02\x8A' + // ySubscriptXSize
  26109. '\x02\xBB' + // ySubscriptYSize
  26110. '\x00\x00' + // ySubscriptXOffset
  26111. '\x00\x8C' + // ySubscriptYOffset
  26112. '\x02\x8A' + // ySuperScriptXSize
  26113. '\x02\xBB' + // ySuperScriptYSize
  26114. '\x00\x00' + // ySuperScriptXOffset
  26115. '\x01\xDF' + // ySuperScriptYOffset
  26116. '\x00\x31' + // yStrikeOutSize
  26117. '\x01\x02' + // yStrikeOutPosition
  26118. '\x00\x00' + // sFamilyClass
  26119. '\x00\x00\x06' +
  26120. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  26121. '\x00\x00\x00\x00\x00\x00' + // Panose
  26122. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  26123. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  26124. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  26125. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  26126. '\x2A\x32\x31\x2A' + // achVendID
  26127. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  26128. string16(firstCharIndex ||
  26129. properties.firstChar) + // usFirstCharIndex
  26130. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  26131. string16(typoAscent) + // sTypoAscender
  26132. string16(typoDescent) + // sTypoDescender
  26133. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  26134. string16(winAscent) + // usWinAscent
  26135. string16(winDescent) + // usWinDescent
  26136. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  26137. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  26138. string16(properties.xHeight) + // sxHeight
  26139. string16(properties.capHeight) + // sCapHeight
  26140. string16(0) + // usDefaultChar
  26141. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  26142. '\x00\x03'; // usMaxContext
  26143. }
  26144. function createPostTable(properties) {
  26145. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  26146. return ('\x00\x03\x00\x00' + // Version number
  26147. string32(angle) + // italicAngle
  26148. '\x00\x00' + // underlinePosition
  26149. '\x00\x00' + // underlineThickness
  26150. string32(properties.fixedPitch) + // isFixedPitch
  26151. '\x00\x00\x00\x00' + // minMemType42
  26152. '\x00\x00\x00\x00' + // maxMemType42
  26153. '\x00\x00\x00\x00' + // minMemType1
  26154. '\x00\x00\x00\x00'); // maxMemType1
  26155. }
  26156. function createNameTable(name, proto) {
  26157. if (!proto) {
  26158. proto = [[], []]; // no strings and unicode strings
  26159. }
  26160. var strings = [
  26161. proto[0][0] || 'Original licence', // 0.Copyright
  26162. proto[0][1] || name, // 1.Font family
  26163. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  26164. proto[0][3] || 'uniqueID', // 3.Unique ID
  26165. proto[0][4] || name, // 4.Full font name
  26166. proto[0][5] || 'Version 0.11', // 5.Version
  26167. proto[0][6] || '', // 6.Postscript name
  26168. proto[0][7] || 'Unknown', // 7.Trademark
  26169. proto[0][8] || 'Unknown', // 8.Manufacturer
  26170. proto[0][9] || 'Unknown' // 9.Designer
  26171. ];
  26172. // Mac want 1-byte per character strings while Windows want
  26173. // 2-bytes per character, so duplicate the names table
  26174. var stringsUnicode = [];
  26175. var i, ii, j, jj, str;
  26176. for (i = 0, ii = strings.length; i < ii; i++) {
  26177. str = proto[1][i] || strings[i];
  26178. var strBufUnicode = [];
  26179. for (j = 0, jj = str.length; j < jj; j++) {
  26180. strBufUnicode.push(string16(str.charCodeAt(j)));
  26181. }
  26182. stringsUnicode.push(strBufUnicode.join(''));
  26183. }
  26184. var names = [strings, stringsUnicode];
  26185. var platforms = ['\x00\x01', '\x00\x03'];
  26186. var encodings = ['\x00\x00', '\x00\x01'];
  26187. var languages = ['\x00\x00', '\x04\x09'];
  26188. var namesRecordCount = strings.length * platforms.length;
  26189. var nameTable =
  26190. '\x00\x00' + // format
  26191. string16(namesRecordCount) + // Number of names Record
  26192. string16(namesRecordCount * 12 + 6); // Storage
  26193. // Build the name records field
  26194. var strOffset = 0;
  26195. for (i = 0, ii = platforms.length; i < ii; i++) {
  26196. var strs = names[i];
  26197. for (j = 0, jj = strs.length; j < jj; j++) {
  26198. str = strs[j];
  26199. var nameRecord =
  26200. platforms[i] + // platform ID
  26201. encodings[i] + // encoding ID
  26202. languages[i] + // language ID
  26203. string16(j) + // name ID
  26204. string16(str.length) +
  26205. string16(strOffset);
  26206. nameTable += nameRecord;
  26207. strOffset += str.length;
  26208. }
  26209. }
  26210. nameTable += strings.join('') + stringsUnicode.join('');
  26211. return nameTable;
  26212. }
  26213. Font.prototype = {
  26214. name: null,
  26215. font: null,
  26216. mimetype: null,
  26217. encoding: null,
  26218. get renderer() {
  26219. var renderer = FontRendererFactory.create(this);
  26220. return shadow(this, 'renderer', renderer);
  26221. },
  26222. exportData: function Font_exportData() {
  26223. var data = {};
  26224. for (var i in this) {
  26225. if (this.hasOwnProperty(i)) {
  26226. data[i] = this[i];
  26227. }
  26228. }
  26229. return data;
  26230. },
  26231. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  26232. function readTableEntry(file) {
  26233. var tag = bytesToString(file.getBytes(4));
  26234. var checksum = file.getInt32();
  26235. var offset = file.getInt32() >>> 0;
  26236. var length = file.getInt32() >>> 0;
  26237. // Read the table associated data
  26238. var previousPosition = file.pos;
  26239. file.pos = file.start ? file.start : 0;
  26240. file.skip(offset);
  26241. var data = file.getBytes(length);
  26242. file.pos = previousPosition;
  26243. if (tag === 'head') {
  26244. // clearing checksum adjustment
  26245. data[8] = data[9] = data[10] = data[11] = 0;
  26246. data[17] |= 0x20; //Set font optimized for cleartype flag
  26247. }
  26248. return {
  26249. tag: tag,
  26250. checksum: checksum,
  26251. length: length,
  26252. offset: offset,
  26253. data: data
  26254. };
  26255. }
  26256. function readOpenTypeHeader(ttf) {
  26257. return {
  26258. version: bytesToString(ttf.getBytes(4)),
  26259. numTables: ttf.getUint16(),
  26260. searchRange: ttf.getUint16(),
  26261. entrySelector: ttf.getUint16(),
  26262. rangeShift: ttf.getUint16()
  26263. };
  26264. }
  26265. /**
  26266. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  26267. * PDF spec
  26268. */
  26269. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  26270. if (!cmap) {
  26271. warn('No cmap table available.');
  26272. return {
  26273. platformId: -1,
  26274. encodingId: -1,
  26275. mappings: [],
  26276. hasShortCmap: false
  26277. };
  26278. }
  26279. var segment;
  26280. var start = (font.start ? font.start : 0) + cmap.offset;
  26281. font.pos = start;
  26282. var version = font.getUint16();
  26283. var numTables = font.getUint16();
  26284. var potentialTable;
  26285. var canBreak = false;
  26286. // There's an order of preference in terms of which cmap subtable to
  26287. // use:
  26288. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  26289. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  26290. // The following takes advantage of the fact that the tables are sorted
  26291. // to work.
  26292. for (var i = 0; i < numTables; i++) {
  26293. var platformId = font.getUint16();
  26294. var encodingId = font.getUint16();
  26295. var offset = font.getInt32() >>> 0;
  26296. var useTable = false;
  26297. if (platformId === 0 && encodingId === 0) {
  26298. useTable = true;
  26299. // Continue the loop since there still may be a higher priority
  26300. // table.
  26301. } else if (platformId === 1 && encodingId === 0) {
  26302. useTable = true;
  26303. // Continue the loop since there still may be a higher priority
  26304. // table.
  26305. } else if (platformId === 3 && encodingId === 1 &&
  26306. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  26307. useTable = true;
  26308. if (!isSymbolicFont) {
  26309. canBreak = true;
  26310. }
  26311. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  26312. useTable = true;
  26313. canBreak = true;
  26314. }
  26315. if (useTable) {
  26316. potentialTable = {
  26317. platformId: platformId,
  26318. encodingId: encodingId,
  26319. offset: offset
  26320. };
  26321. }
  26322. if (canBreak) {
  26323. break;
  26324. }
  26325. }
  26326. if (potentialTable) {
  26327. font.pos = start + potentialTable.offset;
  26328. }
  26329. if (!potentialTable || font.peekByte() === -1) {
  26330. warn('Could not find a preferred cmap table.');
  26331. return {
  26332. platformId: -1,
  26333. encodingId: -1,
  26334. mappings: [],
  26335. hasShortCmap: false
  26336. };
  26337. }
  26338. var format = font.getUint16();
  26339. var length = font.getUint16();
  26340. var language = font.getUint16();
  26341. var hasShortCmap = false;
  26342. var mappings = [];
  26343. var j, glyphId;
  26344. // TODO(mack): refactor this cmap subtable reading logic out
  26345. if (format === 0) {
  26346. for (j = 0; j < 256; j++) {
  26347. var index = font.getByte();
  26348. if (!index) {
  26349. continue;
  26350. }
  26351. mappings.push({
  26352. charCode: j,
  26353. glyphId: index
  26354. });
  26355. }
  26356. hasShortCmap = true;
  26357. } else if (format === 4) {
  26358. // re-creating the table in format 4 since the encoding
  26359. // might be changed
  26360. var segCount = (font.getUint16() >> 1);
  26361. font.getBytes(6); // skipping range fields
  26362. var segIndex, segments = [];
  26363. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26364. segments.push({ end: font.getUint16() });
  26365. }
  26366. font.getUint16();
  26367. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26368. segments[segIndex].start = font.getUint16();
  26369. }
  26370. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26371. segments[segIndex].delta = font.getUint16();
  26372. }
  26373. var offsetsCount = 0;
  26374. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26375. segment = segments[segIndex];
  26376. var rangeOffset = font.getUint16();
  26377. if (!rangeOffset) {
  26378. segment.offsetIndex = -1;
  26379. continue;
  26380. }
  26381. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  26382. segment.offsetIndex = offsetIndex;
  26383. offsetsCount = Math.max(offsetsCount, offsetIndex +
  26384. segment.end - segment.start + 1);
  26385. }
  26386. var offsets = [];
  26387. for (j = 0; j < offsetsCount; j++) {
  26388. offsets.push(font.getUint16());
  26389. }
  26390. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26391. segment = segments[segIndex];
  26392. start = segment.start;
  26393. var end = segment.end;
  26394. var delta = segment.delta;
  26395. offsetIndex = segment.offsetIndex;
  26396. for (j = start; j <= end; j++) {
  26397. if (j === 0xFFFF) {
  26398. continue;
  26399. }
  26400. glyphId = (offsetIndex < 0 ?
  26401. j : offsets[offsetIndex + j - start]);
  26402. glyphId = (glyphId + delta) & 0xFFFF;
  26403. if (glyphId === 0) {
  26404. continue;
  26405. }
  26406. mappings.push({
  26407. charCode: j,
  26408. glyphId: glyphId
  26409. });
  26410. }
  26411. }
  26412. } else if (format === 6) {
  26413. // Format 6 is a 2-bytes dense mapping, which means the font data
  26414. // lives glue together even if they are pretty far in the unicode
  26415. // table. (This looks weird, so I can have missed something), this
  26416. // works on Linux but seems to fails on Mac so let's rewrite the
  26417. // cmap table to a 3-1-4 style
  26418. var firstCode = font.getUint16();
  26419. var entryCount = font.getUint16();
  26420. for (j = 0; j < entryCount; j++) {
  26421. glyphId = font.getUint16();
  26422. var charCode = firstCode + j;
  26423. mappings.push({
  26424. charCode: charCode,
  26425. glyphId: glyphId
  26426. });
  26427. }
  26428. } else {
  26429. warn('cmap table has unsupported format: ' + format);
  26430. return {
  26431. platformId: -1,
  26432. encodingId: -1,
  26433. mappings: [],
  26434. hasShortCmap: false
  26435. };
  26436. }
  26437. // removing duplicate entries
  26438. mappings.sort(function (a, b) {
  26439. return a.charCode - b.charCode;
  26440. });
  26441. for (i = 1; i < mappings.length; i++) {
  26442. if (mappings[i - 1].charCode === mappings[i].charCode) {
  26443. mappings.splice(i, 1);
  26444. i--;
  26445. }
  26446. }
  26447. return {
  26448. platformId: potentialTable.platformId,
  26449. encodingId: potentialTable.encodingId,
  26450. mappings: mappings,
  26451. hasShortCmap: hasShortCmap
  26452. };
  26453. }
  26454. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  26455. if (!header) {
  26456. if (metrics) {
  26457. metrics.data = null;
  26458. }
  26459. return;
  26460. }
  26461. font.pos = (font.start ? font.start : 0) + header.offset;
  26462. font.pos += header.length - 2;
  26463. var numOfMetrics = font.getUint16();
  26464. if (numOfMetrics > numGlyphs) {
  26465. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  26466. 'greater than the numGlyphs (' + numGlyphs + ')');
  26467. // Reduce numOfMetrics if it is greater than numGlyphs
  26468. numOfMetrics = numGlyphs;
  26469. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  26470. header.data[35] = numOfMetrics & 0x00ff;
  26471. }
  26472. var numOfSidebearings = numGlyphs - numOfMetrics;
  26473. var numMissing = numOfSidebearings -
  26474. ((metrics.length - numOfMetrics * 4) >> 1);
  26475. if (numMissing > 0) {
  26476. // For each missing glyph, we set both the width and lsb to 0 (zero).
  26477. // Since we need to add two properties for each glyph, this explains
  26478. // the use of |numMissing * 2| when initializing the typed array.
  26479. var entries = new Uint8Array(metrics.length + numMissing * 2);
  26480. entries.set(metrics.data);
  26481. metrics.data = entries;
  26482. }
  26483. }
  26484. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  26485. hintsValid) {
  26486. if (sourceEnd - sourceStart <= 12) {
  26487. // glyph with data less than 12 is invalid one
  26488. return 0;
  26489. }
  26490. var glyf = source.subarray(sourceStart, sourceEnd);
  26491. var contoursCount = (glyf[0] << 8) | glyf[1];
  26492. if (contoursCount & 0x8000) {
  26493. // complex glyph, writing as is
  26494. dest.set(glyf, destStart);
  26495. return glyf.length;
  26496. }
  26497. var i, j = 10, flagsCount = 0;
  26498. for (i = 0; i < contoursCount; i++) {
  26499. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  26500. flagsCount = endPoint + 1;
  26501. j += 2;
  26502. }
  26503. // skipping instructions
  26504. var instructionsStart = j;
  26505. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  26506. j += 2 + instructionsLength;
  26507. var instructionsEnd = j;
  26508. // validating flags
  26509. var coordinatesLength = 0;
  26510. for (i = 0; i < flagsCount; i++) {
  26511. var flag = glyf[j++];
  26512. if (flag & 0xC0) {
  26513. // reserved flags must be zero, cleaning up
  26514. glyf[j - 1] = flag & 0x3F;
  26515. }
  26516. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  26517. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  26518. coordinatesLength += xyLength;
  26519. if (flag & 8) {
  26520. var repeat = glyf[j++];
  26521. i += repeat;
  26522. coordinatesLength += repeat * xyLength;
  26523. }
  26524. }
  26525. // glyph without coordinates will be rejected
  26526. if (coordinatesLength === 0) {
  26527. return 0;
  26528. }
  26529. var glyphDataLength = j + coordinatesLength;
  26530. if (glyphDataLength > glyf.length) {
  26531. // not enough data for coordinates
  26532. return 0;
  26533. }
  26534. if (!hintsValid && instructionsLength > 0) {
  26535. dest.set(glyf.subarray(0, instructionsStart), destStart);
  26536. dest.set([0, 0], destStart + instructionsStart);
  26537. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  26538. destStart + instructionsStart + 2);
  26539. glyphDataLength -= instructionsLength;
  26540. if (glyf.length - glyphDataLength > 3) {
  26541. glyphDataLength = (glyphDataLength + 3) & ~3;
  26542. }
  26543. return glyphDataLength;
  26544. }
  26545. if (glyf.length - glyphDataLength > 3) {
  26546. // truncating and aligning to 4 bytes the long glyph data
  26547. glyphDataLength = (glyphDataLength + 3) & ~3;
  26548. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  26549. return glyphDataLength;
  26550. }
  26551. // glyph data is fine
  26552. dest.set(glyf, destStart);
  26553. return glyf.length;
  26554. }
  26555. function sanitizeHead(head, numGlyphs, locaLength) {
  26556. var data = head.data;
  26557. // Validate version:
  26558. // Should always be 0x00010000
  26559. var version = int32(data[0], data[1], data[2], data[3]);
  26560. if (version >> 16 !== 1) {
  26561. info('Attempting to fix invalid version in head table: ' + version);
  26562. data[0] = 0;
  26563. data[1] = 1;
  26564. data[2] = 0;
  26565. data[3] = 0;
  26566. }
  26567. var indexToLocFormat = int16(data[50], data[51]);
  26568. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  26569. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  26570. indexToLocFormat);
  26571. // The value of indexToLocFormat should be 0 if the loca table
  26572. // consists of short offsets, and should be 1 if the loca table
  26573. // consists of long offsets.
  26574. //
  26575. // The number of entries in the loca table should be numGlyphs + 1.
  26576. //
  26577. // Using this information, we can work backwards to deduce if the
  26578. // size of each offset in the loca table, and thus figure out the
  26579. // appropriate value for indexToLocFormat.
  26580. var numGlyphsPlusOne = numGlyphs + 1;
  26581. if (locaLength === numGlyphsPlusOne << 1) {
  26582. // 0x0000 indicates the loca table consists of short offsets
  26583. data[50] = 0;
  26584. data[51] = 0;
  26585. } else if (locaLength === numGlyphsPlusOne << 2) {
  26586. // 0x0001 indicates the loca table consists of long offsets
  26587. data[50] = 0;
  26588. data[51] = 1;
  26589. } else {
  26590. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  26591. }
  26592. }
  26593. }
  26594. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  26595. isGlyphLocationsLong, hintsValid,
  26596. dupFirstEntry) {
  26597. var itemSize, itemDecode, itemEncode;
  26598. if (isGlyphLocationsLong) {
  26599. itemSize = 4;
  26600. itemDecode = function fontItemDecodeLong(data, offset) {
  26601. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26602. (data[offset + 2] << 8) | data[offset + 3];
  26603. };
  26604. itemEncode = function fontItemEncodeLong(data, offset, value) {
  26605. data[offset] = (value >>> 24) & 0xFF;
  26606. data[offset + 1] = (value >> 16) & 0xFF;
  26607. data[offset + 2] = (value >> 8) & 0xFF;
  26608. data[offset + 3] = value & 0xFF;
  26609. };
  26610. } else {
  26611. itemSize = 2;
  26612. itemDecode = function fontItemDecode(data, offset) {
  26613. return (data[offset] << 9) | (data[offset + 1] << 1);
  26614. };
  26615. itemEncode = function fontItemEncode(data, offset, value) {
  26616. data[offset] = (value >> 9) & 0xFF;
  26617. data[offset + 1] = (value >> 1) & 0xFF;
  26618. };
  26619. }
  26620. var locaData = loca.data;
  26621. var locaDataSize = itemSize * (1 + numGlyphs);
  26622. // is loca.data too short or long?
  26623. if (locaData.length !== locaDataSize) {
  26624. locaData = new Uint8Array(locaDataSize);
  26625. locaData.set(loca.data.subarray(0, locaDataSize));
  26626. loca.data = locaData;
  26627. }
  26628. // removing the invalid glyphs
  26629. var oldGlyfData = glyf.data;
  26630. var oldGlyfDataLength = oldGlyfData.length;
  26631. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  26632. var startOffset = itemDecode(locaData, 0);
  26633. var writeOffset = 0;
  26634. var missingGlyphData = {};
  26635. itemEncode(locaData, 0, writeOffset);
  26636. var i, j;
  26637. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26638. var endOffset = itemDecode(locaData, j);
  26639. if (endOffset > oldGlyfDataLength &&
  26640. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  26641. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  26642. // the glyf table size, which makes last glyph out of range.
  26643. endOffset = oldGlyfDataLength;
  26644. }
  26645. if (endOffset > oldGlyfDataLength) {
  26646. // glyph end offset points outside glyf data, rejecting the glyph
  26647. itemEncode(locaData, j, writeOffset);
  26648. startOffset = endOffset;
  26649. continue;
  26650. }
  26651. if (startOffset === endOffset) {
  26652. missingGlyphData[i] = true;
  26653. }
  26654. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  26655. newGlyfData, writeOffset, hintsValid);
  26656. writeOffset += newLength;
  26657. itemEncode(locaData, j, writeOffset);
  26658. startOffset = endOffset;
  26659. }
  26660. if (writeOffset === 0) {
  26661. // glyf table cannot be empty -- redoing the glyf and loca tables
  26662. // to have single glyph with one point
  26663. var simpleGlyph = new Uint8Array(
  26664. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26665. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26666. itemEncode(locaData, j, simpleGlyph.length);
  26667. }
  26668. glyf.data = simpleGlyph;
  26669. return missingGlyphData;
  26670. }
  26671. if (dupFirstEntry) {
  26672. var firstEntryLength = itemDecode(locaData, itemSize);
  26673. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26674. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26675. } else {
  26676. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26677. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26678. }
  26679. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26680. itemEncode(loca.data, locaData.length - itemSize,
  26681. writeOffset + firstEntryLength);
  26682. } else {
  26683. glyf.data = newGlyfData.subarray(0, writeOffset);
  26684. }
  26685. return missingGlyphData;
  26686. }
  26687. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26688. var start = (font.start ? font.start : 0) + post.offset;
  26689. font.pos = start;
  26690. var length = post.length, end = start + length;
  26691. var version = font.getInt32();
  26692. // skip rest to the tables
  26693. font.getBytes(28);
  26694. var glyphNames;
  26695. var valid = true;
  26696. var i;
  26697. switch (version) {
  26698. case 0x00010000:
  26699. glyphNames = MacStandardGlyphOrdering;
  26700. break;
  26701. case 0x00020000:
  26702. var numGlyphs = font.getUint16();
  26703. if (numGlyphs !== maxpNumGlyphs) {
  26704. valid = false;
  26705. break;
  26706. }
  26707. var glyphNameIndexes = [];
  26708. for (i = 0; i < numGlyphs; ++i) {
  26709. var index = font.getUint16();
  26710. if (index >= 32768) {
  26711. valid = false;
  26712. break;
  26713. }
  26714. glyphNameIndexes.push(index);
  26715. }
  26716. if (!valid) {
  26717. break;
  26718. }
  26719. var customNames = [];
  26720. var strBuf = [];
  26721. while (font.pos < end) {
  26722. var stringLength = font.getByte();
  26723. strBuf.length = stringLength;
  26724. for (i = 0; i < stringLength; ++i) {
  26725. strBuf[i] = String.fromCharCode(font.getByte());
  26726. }
  26727. customNames.push(strBuf.join(''));
  26728. }
  26729. glyphNames = [];
  26730. for (i = 0; i < numGlyphs; ++i) {
  26731. var j = glyphNameIndexes[i];
  26732. if (j < 258) {
  26733. glyphNames.push(MacStandardGlyphOrdering[j]);
  26734. continue;
  26735. }
  26736. glyphNames.push(customNames[j - 258]);
  26737. }
  26738. break;
  26739. case 0x00030000:
  26740. break;
  26741. default:
  26742. warn('Unknown/unsupported post table version ' + version);
  26743. valid = false;
  26744. if (properties.defaultEncoding) {
  26745. glyphNames = properties.defaultEncoding;
  26746. }
  26747. break;
  26748. }
  26749. properties.glyphNames = glyphNames;
  26750. return valid;
  26751. }
  26752. function readNameTable(nameTable) {
  26753. var start = (font.start ? font.start : 0) + nameTable.offset;
  26754. font.pos = start;
  26755. var names = [[], []];
  26756. var length = nameTable.length, end = start + length;
  26757. var format = font.getUint16();
  26758. var FORMAT_0_HEADER_LENGTH = 6;
  26759. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26760. // unsupported name table format or table "too" small
  26761. return names;
  26762. }
  26763. var numRecords = font.getUint16();
  26764. var stringsStart = font.getUint16();
  26765. var records = [];
  26766. var NAME_RECORD_LENGTH = 12;
  26767. var i, ii;
  26768. for (i = 0; i < numRecords &&
  26769. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26770. var r = {
  26771. platform: font.getUint16(),
  26772. encoding: font.getUint16(),
  26773. language: font.getUint16(),
  26774. name: font.getUint16(),
  26775. length: font.getUint16(),
  26776. offset: font.getUint16()
  26777. };
  26778. // using only Macintosh and Windows platform/encoding names
  26779. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26780. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26781. records.push(r);
  26782. }
  26783. }
  26784. for (i = 0, ii = records.length; i < ii; i++) {
  26785. var record = records[i];
  26786. var pos = start + stringsStart + record.offset;
  26787. if (pos + record.length > end) {
  26788. continue; // outside of name table, ignoring
  26789. }
  26790. font.pos = pos;
  26791. var nameIndex = record.name;
  26792. if (record.encoding) {
  26793. // unicode
  26794. var str = '';
  26795. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26796. str += String.fromCharCode(font.getUint16());
  26797. }
  26798. names[1][nameIndex] = str;
  26799. } else {
  26800. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26801. }
  26802. }
  26803. return names;
  26804. }
  26805. var TTOpsStackDeltas = [
  26806. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26807. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26808. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26809. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26810. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26811. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26812. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26813. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26814. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26815. // 0xC0-DF == -1 and 0xE0-FF == -2
  26816. function sanitizeTTProgram(table, ttContext) {
  26817. var data = table.data;
  26818. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26819. var stack = [];
  26820. var callstack = [];
  26821. var functionsCalled = [];
  26822. var tooComplexToFollowFunctions =
  26823. ttContext.tooComplexToFollowFunctions;
  26824. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26825. for (var ii = data.length; i < ii;) {
  26826. var op = data[i++];
  26827. // The TrueType instruction set docs can be found at
  26828. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26829. if (op === 0x40) { // NPUSHB - pushes n bytes
  26830. n = data[i++];
  26831. if (inFDEF || inELSE) {
  26832. i += n;
  26833. } else {
  26834. for (j = 0; j < n; j++) {
  26835. stack.push(data[i++]);
  26836. }
  26837. }
  26838. } else if (op === 0x41) { // NPUSHW - pushes n words
  26839. n = data[i++];
  26840. if (inFDEF || inELSE) {
  26841. i += n * 2;
  26842. } else {
  26843. for (j = 0; j < n; j++) {
  26844. b = data[i++];
  26845. stack.push((b << 8) | data[i++]);
  26846. }
  26847. }
  26848. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26849. n = op - 0xB0 + 1;
  26850. if (inFDEF || inELSE) {
  26851. i += n;
  26852. } else {
  26853. for (j = 0; j < n; j++) {
  26854. stack.push(data[i++]);
  26855. }
  26856. }
  26857. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26858. n = op - 0xB8 + 1;
  26859. if (inFDEF || inELSE) {
  26860. i += n * 2;
  26861. } else {
  26862. for (j = 0; j < n; j++) {
  26863. b = data[i++];
  26864. stack.push((b << 8) | data[i++]);
  26865. }
  26866. }
  26867. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26868. if (!inFDEF && !inELSE) {
  26869. // collecting inforamtion about which functions are used
  26870. funcId = stack[stack.length - 1];
  26871. ttContext.functionsUsed[funcId] = true;
  26872. if (funcId in ttContext.functionsStackDeltas) {
  26873. stack.length += ttContext.functionsStackDeltas[funcId];
  26874. } else if (funcId in ttContext.functionsDefined &&
  26875. functionsCalled.indexOf(funcId) < 0) {
  26876. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26877. functionsCalled.push(funcId);
  26878. pc = ttContext.functionsDefined[funcId];
  26879. if (!pc) {
  26880. warn('TT: CALL non-existent function');
  26881. ttContext.hintsValid = false;
  26882. return;
  26883. }
  26884. data = pc.data;
  26885. i = pc.i;
  26886. }
  26887. }
  26888. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  26889. if (inFDEF || inELSE) {
  26890. warn('TT: nested FDEFs not allowed');
  26891. tooComplexToFollowFunctions = true;
  26892. }
  26893. inFDEF = true;
  26894. // collecting inforamtion about which functions are defined
  26895. lastDeff = i;
  26896. funcId = stack.pop();
  26897. ttContext.functionsDefined[funcId] = {data: data, i: i};
  26898. } else if (op === 0x2D) { // ENDF - end of function
  26899. if (inFDEF) {
  26900. inFDEF = false;
  26901. lastEndf = i;
  26902. } else {
  26903. pc = callstack.pop();
  26904. if (!pc) {
  26905. warn('TT: ENDF bad stack');
  26906. ttContext.hintsValid = false;
  26907. return;
  26908. }
  26909. funcId = functionsCalled.pop();
  26910. data = pc.data;
  26911. i = pc.i;
  26912. ttContext.functionsStackDeltas[funcId] =
  26913. stack.length - pc.stackTop;
  26914. }
  26915. } else if (op === 0x89) { // IDEF - instruction definition
  26916. if (inFDEF || inELSE) {
  26917. warn('TT: nested IDEFs not allowed');
  26918. tooComplexToFollowFunctions = true;
  26919. }
  26920. inFDEF = true;
  26921. // recording it as a function to track ENDF
  26922. lastDeff = i;
  26923. } else if (op === 0x58) { // IF
  26924. ++ifLevel;
  26925. } else if (op === 0x1B) { // ELSE
  26926. inELSE = ifLevel;
  26927. } else if (op === 0x59) { // EIF
  26928. if (inELSE === ifLevel) {
  26929. inELSE = 0;
  26930. }
  26931. --ifLevel;
  26932. } else if (op === 0x1C) { // JMPR
  26933. if (!inFDEF && !inELSE) {
  26934. var offset = stack[stack.length - 1];
  26935. // only jumping forward to prevent infinite loop
  26936. if (offset > 0) {
  26937. i += offset - 1;
  26938. }
  26939. }
  26940. }
  26941. // Adjusting stack not extactly, but just enough to get function id
  26942. if (!inFDEF && !inELSE) {
  26943. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  26944. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  26945. if (op >= 0x71 && op <= 0x75) {
  26946. n = stack.pop();
  26947. if (n === n) {
  26948. stackDelta = -n * 2;
  26949. }
  26950. }
  26951. while (stackDelta < 0 && stack.length > 0) {
  26952. stack.pop();
  26953. stackDelta++;
  26954. }
  26955. while (stackDelta > 0) {
  26956. stack.push(NaN); // pushing any number into stack
  26957. stackDelta--;
  26958. }
  26959. }
  26960. }
  26961. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  26962. var content = [data];
  26963. if (i > data.length) {
  26964. content.push(new Uint8Array(i - data.length));
  26965. }
  26966. if (lastDeff > lastEndf) {
  26967. warn('TT: complementing a missing function tail');
  26968. // new function definition started, but not finished
  26969. // complete function by [CLEAR, ENDF]
  26970. content.push(new Uint8Array([0x22, 0x2D]));
  26971. }
  26972. foldTTTable(table, content);
  26973. }
  26974. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  26975. if (ttContext.tooComplexToFollowFunctions) {
  26976. return;
  26977. }
  26978. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  26979. warn('TT: more functions defined than expected');
  26980. ttContext.hintsValid = false;
  26981. return;
  26982. }
  26983. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  26984. if (j > maxFunctionDefs) {
  26985. warn('TT: invalid function id: ' + j);
  26986. ttContext.hintsValid = false;
  26987. return;
  26988. }
  26989. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  26990. warn('TT: undefined function: ' + j);
  26991. ttContext.hintsValid = false;
  26992. return;
  26993. }
  26994. }
  26995. }
  26996. function foldTTTable(table, content) {
  26997. if (content.length > 1) {
  26998. // concatenating the content items
  26999. var newLength = 0;
  27000. var j, jj;
  27001. for (j = 0, jj = content.length; j < jj; j++) {
  27002. newLength += content[j].length;
  27003. }
  27004. newLength = (newLength + 3) & ~3;
  27005. var result = new Uint8Array(newLength);
  27006. var pos = 0;
  27007. for (j = 0, jj = content.length; j < jj; j++) {
  27008. result.set(content[j], pos);
  27009. pos += content[j].length;
  27010. }
  27011. table.data = result;
  27012. table.length = newLength;
  27013. }
  27014. }
  27015. function sanitizeTTPrograms(fpgm, prep, cvt) {
  27016. var ttContext = {
  27017. functionsDefined: [],
  27018. functionsUsed: [],
  27019. functionsStackDeltas: [],
  27020. tooComplexToFollowFunctions: false,
  27021. hintsValid: true
  27022. };
  27023. if (fpgm) {
  27024. sanitizeTTProgram(fpgm, ttContext);
  27025. }
  27026. if (prep) {
  27027. sanitizeTTProgram(prep, ttContext);
  27028. }
  27029. if (fpgm) {
  27030. checkInvalidFunctions(ttContext, maxFunctionDefs);
  27031. }
  27032. if (cvt && (cvt.length & 1)) {
  27033. var cvtData = new Uint8Array(cvt.length + 1);
  27034. cvtData.set(cvt.data);
  27035. cvt.data = cvtData;
  27036. }
  27037. return ttContext.hintsValid;
  27038. }
  27039. // The following steps modify the original font data, making copy
  27040. font = new Stream(new Uint8Array(font.getBytes()));
  27041. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  27042. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  27043. var header = readOpenTypeHeader(font);
  27044. var numTables = header.numTables;
  27045. var cff, cffFile;
  27046. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  27047. hmtx: null, maxp: null, name: null, post: null };
  27048. var table;
  27049. for (var i = 0; i < numTables; i++) {
  27050. table = readTableEntry(font);
  27051. if (VALID_TABLES.indexOf(table.tag) < 0) {
  27052. continue; // skipping table if it's not a required or optional table
  27053. }
  27054. if (table.length === 0) {
  27055. continue; // skipping empty tables
  27056. }
  27057. tables[table.tag] = table;
  27058. }
  27059. var isTrueType = !tables['CFF '];
  27060. if (!isTrueType) {
  27061. // OpenType font
  27062. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  27063. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  27064. // no major tables: throwing everything at CFFFont
  27065. cffFile = new Stream(tables['CFF '].data);
  27066. cff = new CFFFont(cffFile, properties);
  27067. adjustWidths(properties);
  27068. return this.convert(name, cff, properties);
  27069. }
  27070. delete tables.glyf;
  27071. delete tables.loca;
  27072. delete tables.fpgm;
  27073. delete tables.prep;
  27074. delete tables['cvt '];
  27075. this.isOpenType = true;
  27076. } else {
  27077. if (!tables.glyf || !tables.loca) {
  27078. error('Required "glyf" or "loca" tables are not found');
  27079. }
  27080. this.isOpenType = false;
  27081. }
  27082. if (!tables.maxp) {
  27083. error('Required "maxp" table is not found');
  27084. }
  27085. font.pos = (font.start || 0) + tables.maxp.offset;
  27086. var version = font.getInt32();
  27087. var numGlyphs = font.getUint16();
  27088. var maxFunctionDefs = 0;
  27089. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  27090. // maxZones can be invalid
  27091. font.pos += 8;
  27092. var maxZones = font.getUint16();
  27093. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  27094. tables.maxp.data[14] = 0;
  27095. tables.maxp.data[15] = 2;
  27096. }
  27097. font.pos += 4;
  27098. maxFunctionDefs = font.getUint16();
  27099. }
  27100. var dupFirstEntry = false;
  27101. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  27102. properties.toUnicode.get(0) > '\u0000') {
  27103. // oracle's defect (see 3427), duplicating first entry
  27104. dupFirstEntry = true;
  27105. numGlyphs++;
  27106. tables.maxp.data[4] = numGlyphs >> 8;
  27107. tables.maxp.data[5] = numGlyphs & 255;
  27108. }
  27109. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  27110. tables['cvt '], maxFunctionDefs);
  27111. if (!hintsValid) {
  27112. delete tables.fpgm;
  27113. delete tables.prep;
  27114. delete tables['cvt '];
  27115. }
  27116. // Ensure the hmtx table contains the advance width and
  27117. // sidebearings information for numGlyphs in the maxp table
  27118. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  27119. if (!tables.head) {
  27120. error('Required "head" table is not found');
  27121. }
  27122. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  27123. var missingGlyphs = {};
  27124. if (isTrueType) {
  27125. var isGlyphLocationsLong = int16(tables.head.data[50],
  27126. tables.head.data[51]);
  27127. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  27128. numGlyphs, isGlyphLocationsLong,
  27129. hintsValid, dupFirstEntry);
  27130. }
  27131. if (!tables.hhea) {
  27132. error('Required "hhea" table is not found');
  27133. }
  27134. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  27135. // Sometimes it's 0. That needs to be fixed
  27136. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  27137. tables.hhea.data[10] = 0xFF;
  27138. tables.hhea.data[11] = 0xFF;
  27139. }
  27140. // Extract some more font properties from the OpenType head and
  27141. // hhea tables; yMin and descent value are always negative.
  27142. var metricsOverride = {
  27143. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  27144. yMax: int16(tables.head.data[42], tables.head.data[43]),
  27145. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  27146. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  27147. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  27148. };
  27149. // PDF FontDescriptor metrics lie -- using data from actual font.
  27150. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  27151. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  27152. // The 'post' table has glyphs names.
  27153. if (tables.post) {
  27154. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  27155. if (!valid) {
  27156. tables.post = null;
  27157. }
  27158. }
  27159. var charCodeToGlyphId = [], charCode;
  27160. var toUnicode = properties.toUnicode, widths = properties.widths;
  27161. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  27162. toUnicode.length === 0x10000);
  27163. // Helper function to try to skip mapping of empty glyphs.
  27164. // Note: In some cases, just relying on the glyph data doesn't work,
  27165. // hence we also use a few heuristics to fix various PDF files.
  27166. function hasGlyph(glyphId, charCode, widthCode) {
  27167. if (!missingGlyphs[glyphId]) {
  27168. return true;
  27169. }
  27170. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  27171. return true;
  27172. }
  27173. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  27174. return true;
  27175. }
  27176. return false;
  27177. }
  27178. if (properties.type === 'CIDFontType2') {
  27179. var cidToGidMap = properties.cidToGidMap || [];
  27180. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  27181. properties.cMap.forEach(function(charCode, cid) {
  27182. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27183. var glyphId = -1;
  27184. if (isCidToGidMapEmpty) {
  27185. glyphId = charCode;
  27186. } else if (cidToGidMap[cid] !== undefined) {
  27187. glyphId = cidToGidMap[cid];
  27188. }
  27189. if (glyphId >= 0 && glyphId < numGlyphs &&
  27190. hasGlyph(glyphId, charCode, cid)) {
  27191. charCodeToGlyphId[charCode] = glyphId;
  27192. }
  27193. });
  27194. if (dupFirstEntry) {
  27195. charCodeToGlyphId[0] = numGlyphs - 1;
  27196. }
  27197. } else {
  27198. // Most of the following logic in this code branch is based on the
  27199. // 9.6.6.4 of the PDF spec.
  27200. var hasEncoding =
  27201. properties.differences.length > 0 || !!properties.baseEncodingName;
  27202. var cmapTable =
  27203. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  27204. var cmapPlatformId = cmapTable.platformId;
  27205. var cmapEncodingId = cmapTable.encodingId;
  27206. var cmapMappings = cmapTable.mappings;
  27207. var cmapMappingsLength = cmapMappings.length;
  27208. // The spec seems to imply that if the font is symbolic the encoding
  27209. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  27210. // where the the font is symbolic and it has an encoding.
  27211. if (hasEncoding &&
  27212. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  27213. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  27214. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  27215. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  27216. // When no preferred cmap table was found and |baseEncodingName| is
  27217. // one of the predefined encodings, we seem to obtain a better
  27218. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  27219. // TODO: Note that this is a hack which should be removed as soon as
  27220. // we have proper support for more exotic cmap tables.
  27221. var baseEncoding = [];
  27222. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  27223. properties.baseEncodingName === 'WinAnsiEncoding') {
  27224. baseEncoding = Encodings[properties.baseEncodingName];
  27225. }
  27226. for (charCode = 0; charCode < 256; charCode++) {
  27227. var glyphName;
  27228. if (this.differences && charCode in this.differences) {
  27229. glyphName = this.differences[charCode];
  27230. } else if (charCode in baseEncoding &&
  27231. baseEncoding[charCode] !== '') {
  27232. glyphName = baseEncoding[charCode];
  27233. } else {
  27234. glyphName = Encodings.StandardEncoding[charCode];
  27235. }
  27236. if (!glyphName) {
  27237. continue;
  27238. }
  27239. var unicodeOrCharCode, isUnicode = false;
  27240. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  27241. unicodeOrCharCode = GlyphsUnicode[glyphName];
  27242. isUnicode = true;
  27243. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  27244. // TODO: the encoding needs to be updated with mac os table.
  27245. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  27246. }
  27247. var found = false;
  27248. for (i = 0; i < cmapMappingsLength; ++i) {
  27249. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  27250. continue;
  27251. }
  27252. var code = isUnicode ? charCode : unicodeOrCharCode;
  27253. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  27254. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27255. found = true;
  27256. break;
  27257. }
  27258. }
  27259. if (!found && properties.glyphNames) {
  27260. // Try to map using the post table.
  27261. var glyphId = properties.glyphNames.indexOf(glyphName);
  27262. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  27263. charCodeToGlyphId[charCode] = glyphId;
  27264. } else {
  27265. charCodeToGlyphId[charCode] = 0; // notdef
  27266. }
  27267. }
  27268. }
  27269. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  27270. // Default Unicode semantics, use the charcodes as is.
  27271. for (i = 0; i < cmapMappingsLength; ++i) {
  27272. charCodeToGlyphId[cmapMappings[i].charCode] =
  27273. cmapMappings[i].glyphId;
  27274. }
  27275. } else {
  27276. // For (3, 0) cmap tables:
  27277. // The charcode key being stored in charCodeToGlyphId is the lower
  27278. // byte of the two-byte charcodes of the cmap table since according to
  27279. // the spec: 'each byte from the string shall be prepended with the
  27280. // high byte of the range [of charcodes in the cmap table], to form
  27281. // a two-byte character, which shall be used to select the
  27282. // associated glyph description from the subtable'.
  27283. //
  27284. // For (1, 0) cmap tables:
  27285. // 'single bytes from the string shall be used to look up the
  27286. // associated glyph descriptions from the subtable'. This means
  27287. // charcodes in the cmap will be single bytes, so no-op since
  27288. // glyph.charCode & 0xFF === glyph.charCode
  27289. for (i = 0; i < cmapMappingsLength; ++i) {
  27290. charCode = cmapMappings[i].charCode & 0xFF;
  27291. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27292. }
  27293. }
  27294. }
  27295. if (charCodeToGlyphId.length === 0) {
  27296. // defines at least one glyph
  27297. charCodeToGlyphId[0] = 0;
  27298. }
  27299. // Converting glyphs and ids into font's cmap table
  27300. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  27301. this.toFontChar = newMapping.toFontChar;
  27302. tables.cmap = {
  27303. tag: 'cmap',
  27304. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  27305. };
  27306. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  27307. tables['OS/2'] = {
  27308. tag: 'OS/2',
  27309. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  27310. metricsOverride)
  27311. };
  27312. }
  27313. // Rewrite the 'post' table if needed
  27314. if (!tables.post) {
  27315. tables.post = {
  27316. tag: 'post',
  27317. data: createPostTable(properties)
  27318. };
  27319. }
  27320. if (!isTrueType) {
  27321. try {
  27322. // Trying to repair CFF file
  27323. cffFile = new Stream(tables['CFF '].data);
  27324. var parser = new CFFParser(cffFile, properties);
  27325. cff = parser.parse();
  27326. var compiler = new CFFCompiler(cff);
  27327. tables['CFF '].data = compiler.compile();
  27328. } catch (e) {
  27329. warn('Failed to compile font ' + properties.loadedName);
  27330. }
  27331. }
  27332. // Re-creating 'name' table
  27333. if (!tables.name) {
  27334. tables.name = {
  27335. tag: 'name',
  27336. data: createNameTable(this.name)
  27337. };
  27338. } else {
  27339. // ... using existing 'name' table as prototype
  27340. var namePrototype = readNameTable(tables.name);
  27341. tables.name.data = createNameTable(name, namePrototype);
  27342. }
  27343. var builder = new OpenTypeFileBuilder(header.version);
  27344. for (var tableTag in tables) {
  27345. builder.addTable(tableTag, tables[tableTag].data);
  27346. }
  27347. return builder.toArray();
  27348. },
  27349. convert: function Font_convert(fontName, font, properties) {
  27350. // TODO: Check the charstring widths to determine this.
  27351. properties.fixedPitch = false;
  27352. var mapping = font.getGlyphMapping(properties);
  27353. var newMapping = adjustMapping(mapping, properties);
  27354. this.toFontChar = newMapping.toFontChar;
  27355. var numGlyphs = font.numGlyphs;
  27356. function getCharCodes(charCodeToGlyphId, glyphId) {
  27357. var charCodes = null;
  27358. for (var charCode in charCodeToGlyphId) {
  27359. if (glyphId === charCodeToGlyphId[charCode]) {
  27360. if (!charCodes) {
  27361. charCodes = [];
  27362. }
  27363. charCodes.push(charCode | 0);
  27364. }
  27365. }
  27366. return charCodes;
  27367. }
  27368. function createCharCode(charCodeToGlyphId, glyphId) {
  27369. for (var charCode in charCodeToGlyphId) {
  27370. if (glyphId === charCodeToGlyphId[charCode]) {
  27371. return charCode | 0;
  27372. }
  27373. }
  27374. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  27375. glyphId;
  27376. return newMapping.nextAvailableFontCharCode++;
  27377. }
  27378. var seacs = font.seacs;
  27379. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  27380. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  27381. var charset = font.getCharset();
  27382. var seacMap = Object.create(null);
  27383. for (var glyphId in seacs) {
  27384. glyphId |= 0;
  27385. var seac = seacs[glyphId];
  27386. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  27387. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  27388. var baseGlyphId = charset.indexOf(baseGlyphName);
  27389. var accentGlyphId = charset.indexOf(accentGlyphName);
  27390. if (baseGlyphId < 0 || accentGlyphId < 0) {
  27391. continue;
  27392. }
  27393. var accentOffset = {
  27394. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  27395. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  27396. };
  27397. var charCodes = getCharCodes(mapping, glyphId);
  27398. if (!charCodes) {
  27399. // There's no point in mapping it if the char code was never mapped
  27400. // to begin with.
  27401. continue;
  27402. }
  27403. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  27404. var charCode = charCodes[i];
  27405. // Find a fontCharCode that maps to the base and accent glyphs.
  27406. // If one doesn't exists, create it.
  27407. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  27408. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  27409. baseGlyphId);
  27410. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  27411. accentGlyphId);
  27412. seacMap[charCode] = {
  27413. baseFontCharCode: baseFontCharCode,
  27414. accentFontCharCode: accentFontCharCode,
  27415. accentOffset: accentOffset
  27416. };
  27417. }
  27418. }
  27419. properties.seacMap = seacMap;
  27420. }
  27421. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  27422. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  27423. // PostScript Font Program
  27424. builder.addTable('CFF ', font.data);
  27425. // OS/2 and Windows Specific metrics
  27426. builder.addTable('OS/2', createOS2Table(properties,
  27427. newMapping.charCodeToGlyphId));
  27428. // Character to glyphs mapping
  27429. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  27430. numGlyphs));
  27431. // Font header
  27432. builder.addTable('head',
  27433. '\x00\x01\x00\x00' + // Version number
  27434. '\x00\x00\x10\x00' + // fontRevision
  27435. '\x00\x00\x00\x00' + // checksumAdjustement
  27436. '\x5F\x0F\x3C\xF5' + // magicNumber
  27437. '\x00\x00' + // Flags
  27438. safeString16(unitsPerEm) + // unitsPerEM
  27439. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  27440. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  27441. '\x00\x00' + // xMin
  27442. safeString16(properties.descent) + // yMin
  27443. '\x0F\xFF' + // xMax
  27444. safeString16(properties.ascent) + // yMax
  27445. string16(properties.italicAngle ? 2 : 0) + // macStyle
  27446. '\x00\x11' + // lowestRecPPEM
  27447. '\x00\x00' + // fontDirectionHint
  27448. '\x00\x00' + // indexToLocFormat
  27449. '\x00\x00'); // glyphDataFormat
  27450. // Horizontal header
  27451. builder.addTable('hhea',
  27452. '\x00\x01\x00\x00' + // Version number
  27453. safeString16(properties.ascent) + // Typographic Ascent
  27454. safeString16(properties.descent) + // Typographic Descent
  27455. '\x00\x00' + // Line Gap
  27456. '\xFF\xFF' + // advanceWidthMax
  27457. '\x00\x00' + // minLeftSidebearing
  27458. '\x00\x00' + // minRightSidebearing
  27459. '\x00\x00' + // xMaxExtent
  27460. safeString16(properties.capHeight) + // caretSlopeRise
  27461. safeString16(Math.tan(properties.italicAngle) *
  27462. properties.xHeight) + // caretSlopeRun
  27463. '\x00\x00' + // caretOffset
  27464. '\x00\x00' + // -reserved-
  27465. '\x00\x00' + // -reserved-
  27466. '\x00\x00' + // -reserved-
  27467. '\x00\x00' + // -reserved-
  27468. '\x00\x00' + // metricDataFormat
  27469. string16(numGlyphs)); // Number of HMetrics
  27470. // Horizontal metrics
  27471. builder.addTable('hmtx', (function fontFieldsHmtx() {
  27472. var charstrings = font.charstrings;
  27473. var cffWidths = font.cff ? font.cff.widths : null;
  27474. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  27475. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  27476. var width = 0;
  27477. if (charstrings) {
  27478. var charstring = charstrings[i - 1];
  27479. width = 'width' in charstring ? charstring.width : 0;
  27480. } else if (cffWidths) {
  27481. width = Math.ceil(cffWidths[i] || 0);
  27482. }
  27483. hmtx += string16(width) + string16(0);
  27484. }
  27485. return hmtx;
  27486. })());
  27487. // Maximum profile
  27488. builder.addTable('maxp',
  27489. '\x00\x00\x50\x00' + // Version number
  27490. string16(numGlyphs)); // Num of glyphs
  27491. // Naming tables
  27492. builder.addTable('name', createNameTable(fontName));
  27493. // PostScript informations
  27494. builder.addTable('post', createPostTable(properties));
  27495. return builder.toArray();
  27496. },
  27497. /**
  27498. * Builds a char code to unicode map based on section 9.10 of the spec.
  27499. * @param {Object} properties Font properties object.
  27500. * @return {Object} A ToUnicodeMap object.
  27501. */
  27502. buildToUnicode: function Font_buildToUnicode(properties) {
  27503. // Section 9.10.2 Mapping Character Codes to Unicode Values
  27504. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  27505. return properties.toUnicode;
  27506. }
  27507. // According to the spec if the font is a simple font we should only map
  27508. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  27509. // the differences array only contains adobe standard or symbol set names,
  27510. // in pratice it seems better to always try to create a toUnicode
  27511. // map based of the default encoding.
  27512. var toUnicode, charcode;
  27513. if (!properties.composite /* is simple font */) {
  27514. toUnicode = [];
  27515. var encoding = properties.defaultEncoding.slice();
  27516. var baseEncodingName = properties.baseEncodingName;
  27517. // Merge in the differences array.
  27518. var differences = properties.differences;
  27519. for (charcode in differences) {
  27520. encoding[charcode] = differences[charcode];
  27521. }
  27522. for (charcode in encoding) {
  27523. // a) Map the character code to a character name.
  27524. var glyphName = encoding[charcode];
  27525. // b) Look up the character name in the Adobe Glyph List (see the
  27526. // Bibliography) to obtain the corresponding Unicode value.
  27527. if (glyphName === '') {
  27528. continue;
  27529. } else if (GlyphsUnicode[glyphName] === undefined) {
  27530. // (undocumented) c) Few heuristics to recognize unknown glyphs
  27531. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  27532. var code = 0;
  27533. switch (glyphName[0]) {
  27534. case 'G': // Gxx glyph
  27535. if (glyphName.length === 3) {
  27536. code = parseInt(glyphName.substr(1), 16);
  27537. }
  27538. break;
  27539. case 'g': // g00xx glyph
  27540. if (glyphName.length === 5) {
  27541. code = parseInt(glyphName.substr(1), 16);
  27542. }
  27543. break;
  27544. case 'C': // Cddd glyph
  27545. case 'c': // cddd glyph
  27546. if (glyphName.length >= 3) {
  27547. code = +glyphName.substr(1);
  27548. }
  27549. break;
  27550. }
  27551. if (code) {
  27552. // If |baseEncodingName| is one the predefined encodings,
  27553. // and |code| equals |charcode|, using the glyph defined in the
  27554. // baseEncoding seems to yield a better |toUnicode| mapping
  27555. // (fixes issue 5070).
  27556. if (baseEncodingName && code === +charcode) {
  27557. var baseEncoding = Encodings[baseEncodingName];
  27558. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  27559. toUnicode[charcode] =
  27560. String.fromCharCode(GlyphsUnicode[glyphName]);
  27561. continue;
  27562. }
  27563. }
  27564. toUnicode[charcode] = String.fromCharCode(code);
  27565. }
  27566. continue;
  27567. }
  27568. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  27569. }
  27570. return new ToUnicodeMap(toUnicode);
  27571. }
  27572. // If the font is a composite font that uses one of the predefined CMaps
  27573. // listed in Table 118 (except Identity–H and Identity–V) or whose
  27574. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  27575. // Adobe-Korea1 character collection:
  27576. if (properties.composite && (
  27577. (properties.cMap.builtInCMap &&
  27578. !(properties.cMap instanceof IdentityCMap)) ||
  27579. (properties.cidSystemInfo.registry === 'Adobe' &&
  27580. (properties.cidSystemInfo.ordering === 'GB1' ||
  27581. properties.cidSystemInfo.ordering === 'CNS1' ||
  27582. properties.cidSystemInfo.ordering === 'Japan1' ||
  27583. properties.cidSystemInfo.ordering === 'Korea1')))) {
  27584. // Then:
  27585. // a) Map the character code to a character identifier (CID) according
  27586. // to the font’s CMap.
  27587. // b) Obtain the registry and ordering of the character collection used
  27588. // by the font’s CMap (for example, Adobe and Japan1) from its
  27589. // CIDSystemInfo dictionary.
  27590. var registry = properties.cidSystemInfo.registry;
  27591. var ordering = properties.cidSystemInfo.ordering;
  27592. // c) Construct a second CMap name by concatenating the registry and
  27593. // ordering obtained in step (b) in the format registry–ordering–UCS2
  27594. // (for example, Adobe–Japan1–UCS2).
  27595. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  27596. // d) Obtain the CMap with the name constructed in step (c) (available
  27597. // from the ASN Web site; see the Bibliography).
  27598. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  27599. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  27600. var cMap = properties.cMap;
  27601. toUnicode = [];
  27602. cMap.forEach(function(charcode, cid) {
  27603. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27604. // e) Map the CID obtained in step (a) according to the CMap obtained
  27605. // in step (d), producing a Unicode value.
  27606. var ucs2 = ucs2CMap.lookup(cid);
  27607. if (ucs2) {
  27608. toUnicode[charcode] =
  27609. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  27610. ucs2.charCodeAt(1));
  27611. }
  27612. });
  27613. return new ToUnicodeMap(toUnicode);
  27614. }
  27615. // The viewer's choice, just use an identity map.
  27616. return new IdentityToUnicodeMap(properties.firstChar,
  27617. properties.lastChar);
  27618. },
  27619. get spaceWidth() {
  27620. if ('_shadowWidth' in this) {
  27621. return this._shadowWidth;
  27622. }
  27623. // trying to estimate space character width
  27624. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  27625. var width;
  27626. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  27627. var glyphName = possibleSpaceReplacements[i];
  27628. // if possible, getting width by glyph name
  27629. if (glyphName in this.widths) {
  27630. width = this.widths[glyphName];
  27631. break;
  27632. }
  27633. var glyphUnicode = GlyphsUnicode[glyphName];
  27634. // finding the charcode via unicodeToCID map
  27635. var charcode = 0;
  27636. if (this.composite) {
  27637. if (this.cMap.contains(glyphUnicode)) {
  27638. charcode = this.cMap.lookup(glyphUnicode);
  27639. }
  27640. }
  27641. // ... via toUnicode map
  27642. if (!charcode && this.toUnicode) {
  27643. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27644. }
  27645. // setting it to unicode if negative or undefined
  27646. if (charcode <= 0) {
  27647. charcode = glyphUnicode;
  27648. }
  27649. // trying to get width via charcode
  27650. width = this.widths[charcode];
  27651. if (width) {
  27652. break; // the non-zero width found
  27653. }
  27654. }
  27655. width = width || this.defaultWidth;
  27656. // Do not shadow the property here. See discussion:
  27657. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27658. this._shadowWidth = width;
  27659. return width;
  27660. },
  27661. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27662. var fontCharCode, width, operatorListId;
  27663. var widthCode = charcode;
  27664. if (this.cMap && this.cMap.contains(charcode)) {
  27665. widthCode = this.cMap.lookup(charcode);
  27666. }
  27667. width = this.widths[widthCode];
  27668. width = isNum(width) ? width : this.defaultWidth;
  27669. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27670. var unicode = this.toUnicode.get(charcode) || charcode;
  27671. if (typeof unicode === 'number') {
  27672. unicode = String.fromCharCode(unicode);
  27673. }
  27674. // First try the toFontChar map, if it's not there then try falling
  27675. // back to the char code.
  27676. fontCharCode = this.toFontChar[charcode] || charcode;
  27677. if (this.missingFile) {
  27678. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27679. }
  27680. if (this.isType3Font) {
  27681. // Font char code in this case is actually a glyph name.
  27682. operatorListId = fontCharCode;
  27683. }
  27684. var accent = null;
  27685. if (this.seacMap && this.seacMap[charcode]) {
  27686. var seac = this.seacMap[charcode];
  27687. fontCharCode = seac.baseFontCharCode;
  27688. accent = {
  27689. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27690. offset: seac.accentOffset
  27691. };
  27692. }
  27693. var fontChar = String.fromCharCode(fontCharCode);
  27694. var glyph = this.glyphCache[charcode];
  27695. if (!glyph ||
  27696. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27697. operatorListId, isSpace)) {
  27698. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27699. operatorListId, isSpace);
  27700. this.glyphCache[charcode] = glyph;
  27701. }
  27702. return glyph;
  27703. },
  27704. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27705. var charsCache = this.charsCache;
  27706. var glyphs, glyph, charcode;
  27707. // if we translated this string before, just grab it from the cache
  27708. if (charsCache) {
  27709. glyphs = charsCache[chars];
  27710. if (glyphs) {
  27711. return glyphs;
  27712. }
  27713. }
  27714. // lazily create the translation cache
  27715. if (!charsCache) {
  27716. charsCache = this.charsCache = Object.create(null);
  27717. }
  27718. glyphs = [];
  27719. var charsCacheKey = chars;
  27720. var i = 0, ii;
  27721. if (this.cMap) {
  27722. // composite fonts have multi-byte strings convert the string from
  27723. // single-byte to multi-byte
  27724. var c = {};
  27725. while (i < chars.length) {
  27726. this.cMap.readCharCode(chars, i, c);
  27727. charcode = c.charcode;
  27728. var length = c.length;
  27729. i += length;
  27730. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27731. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27732. glyph = this.charToGlyph(charcode, isSpace);
  27733. glyphs.push(glyph);
  27734. }
  27735. } else {
  27736. for (i = 0, ii = chars.length; i < ii; ++i) {
  27737. charcode = chars.charCodeAt(i);
  27738. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27739. glyphs.push(glyph);
  27740. }
  27741. }
  27742. // Enter the translated string into the cache
  27743. return (charsCache[charsCacheKey] = glyphs);
  27744. }
  27745. };
  27746. return Font;
  27747. })();
  27748. var ErrorFont = (function ErrorFontClosure() {
  27749. function ErrorFont(error) {
  27750. this.error = error;
  27751. this.loadedName = 'g_font_error';
  27752. this.loading = false;
  27753. }
  27754. ErrorFont.prototype = {
  27755. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27756. return [];
  27757. },
  27758. exportData: function ErrorFont_exportData() {
  27759. return {error: this.error};
  27760. }
  27761. };
  27762. return ErrorFont;
  27763. })();
  27764. /**
  27765. * Shared logic for building a char code to glyph id mapping for Type1 and
  27766. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27767. * @param {Object} properties Font properties object.
  27768. * @param {Object} builtInEncoding The encoding contained within the actual font
  27769. * data.
  27770. * @param {Array} Array of glyph names where the index is the glyph ID.
  27771. * @returns {Object} A char code to glyph ID map.
  27772. */
  27773. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27774. var charCodeToGlyphId = Object.create(null);
  27775. var glyphId, charCode, baseEncoding;
  27776. if (properties.baseEncodingName) {
  27777. // If a valid base encoding name was used, the mapping is initialized with
  27778. // that.
  27779. baseEncoding = Encodings[properties.baseEncodingName];
  27780. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27781. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27782. if (glyphId >= 0) {
  27783. charCodeToGlyphId[charCode] = glyphId;
  27784. } else {
  27785. charCodeToGlyphId[charCode] = 0; // notdef
  27786. }
  27787. }
  27788. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27789. // For a symbolic font the encoding should be the fonts built-in
  27790. // encoding.
  27791. for (charCode in builtInEncoding) {
  27792. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27793. }
  27794. } else {
  27795. // For non-symbolic fonts that don't have a base encoding the standard
  27796. // encoding should be used.
  27797. baseEncoding = Encodings.StandardEncoding;
  27798. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27799. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27800. if (glyphId >= 0) {
  27801. charCodeToGlyphId[charCode] = glyphId;
  27802. } else {
  27803. charCodeToGlyphId[charCode] = 0; // notdef
  27804. }
  27805. }
  27806. }
  27807. // Lastly, merge in the differences.
  27808. var differences = properties.differences;
  27809. if (differences) {
  27810. for (charCode in differences) {
  27811. var glyphName = differences[charCode];
  27812. glyphId = glyphNames.indexOf(glyphName);
  27813. if (glyphId >= 0) {
  27814. charCodeToGlyphId[charCode] = glyphId;
  27815. } else {
  27816. charCodeToGlyphId[charCode] = 0; // notdef
  27817. }
  27818. }
  27819. }
  27820. return charCodeToGlyphId;
  27821. }
  27822. /*
  27823. * CharStrings are encoded following the the CharString Encoding sequence
  27824. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27825. * The value in a byte indicates a command, a number, or subsequent bytes
  27826. * that are to be interpreted in a special way.
  27827. *
  27828. * CharString Number Encoding:
  27829. * A CharString byte containing the values from 32 through 255 inclusive
  27830. * indicate an integer. These values are decoded in four ranges.
  27831. *
  27832. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27833. * indicate the integer v - 139. Thus, the integer values from -107 through
  27834. * 107 inclusive may be encoded in single byte.
  27835. *
  27836. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27837. * indicates an integer involving the next byte, w, according to the formula:
  27838. * [(v - 247) x 256] + w + 108
  27839. *
  27840. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27841. * indicates an integer involving the next byte, w, according to the formula:
  27842. * -[(v - 251) * 256] - w - 108
  27843. *
  27844. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27845. * are a two complement signed integer. The first of these bytes contains the
  27846. * highest order bits, the second byte contains the next higher order bits
  27847. * and the fourth byte contain the lowest order bits.
  27848. *
  27849. *
  27850. * CharString Command Encoding:
  27851. * CharStrings commands are encoded in 1 or 2 bytes.
  27852. *
  27853. * Single byte commands are encoded in 1 byte that contains a value between
  27854. * 0 and 31 inclusive.
  27855. * If a command byte contains the value 12, then the value in the next byte
  27856. * indicates a command. This "escape" mechanism allows many extra commands
  27857. * to be encoded and this encoding technique helps to minimize the length of
  27858. * the charStrings.
  27859. */
  27860. var Type1CharString = (function Type1CharStringClosure() {
  27861. var COMMAND_MAP = {
  27862. 'hstem': [1],
  27863. 'vstem': [3],
  27864. 'vmoveto': [4],
  27865. 'rlineto': [5],
  27866. 'hlineto': [6],
  27867. 'vlineto': [7],
  27868. 'rrcurveto': [8],
  27869. 'callsubr': [10],
  27870. 'flex': [12, 35],
  27871. 'drop' : [12, 18],
  27872. 'endchar': [14],
  27873. 'rmoveto': [21],
  27874. 'hmoveto': [22],
  27875. 'vhcurveto': [30],
  27876. 'hvcurveto': [31]
  27877. };
  27878. function Type1CharString() {
  27879. this.width = 0;
  27880. this.lsb = 0;
  27881. this.flexing = false;
  27882. this.output = [];
  27883. this.stack = [];
  27884. }
  27885. Type1CharString.prototype = {
  27886. convert: function Type1CharString_convert(encoded, subrs) {
  27887. var count = encoded.length;
  27888. var error = false;
  27889. var wx, sbx, subrNumber;
  27890. for (var i = 0; i < count; i++) {
  27891. var value = encoded[i];
  27892. if (value < 32) {
  27893. if (value === 12) {
  27894. value = (value << 8) + encoded[++i];
  27895. }
  27896. switch (value) {
  27897. case 1: // hstem
  27898. if (!HINTING_ENABLED) {
  27899. this.stack = [];
  27900. break;
  27901. }
  27902. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27903. break;
  27904. case 3: // vstem
  27905. if (!HINTING_ENABLED) {
  27906. this.stack = [];
  27907. break;
  27908. }
  27909. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27910. break;
  27911. case 4: // vmoveto
  27912. if (this.flexing) {
  27913. if (this.stack.length < 1) {
  27914. error = true;
  27915. break;
  27916. }
  27917. // Add the dx for flex and but also swap the values so they are
  27918. // the right order.
  27919. var dy = this.stack.pop();
  27920. this.stack.push(0, dy);
  27921. break;
  27922. }
  27923. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  27924. break;
  27925. case 5: // rlineto
  27926. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  27927. break;
  27928. case 6: // hlineto
  27929. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  27930. break;
  27931. case 7: // vlineto
  27932. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  27933. break;
  27934. case 8: // rrcurveto
  27935. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  27936. break;
  27937. case 9: // closepath
  27938. // closepath is a Type1 command that does not take argument and is
  27939. // useless in Type2 and it can simply be ignored.
  27940. this.stack = [];
  27941. break;
  27942. case 10: // callsubr
  27943. if (this.stack.length < 1) {
  27944. error = true;
  27945. break;
  27946. }
  27947. subrNumber = this.stack.pop();
  27948. error = this.convert(subrs[subrNumber], subrs);
  27949. break;
  27950. case 11: // return
  27951. return error;
  27952. case 13: // hsbw
  27953. if (this.stack.length < 2) {
  27954. error = true;
  27955. break;
  27956. }
  27957. // To convert to type2 we have to move the width value to the
  27958. // first part of the charstring and then use hmoveto with lsb.
  27959. wx = this.stack.pop();
  27960. sbx = this.stack.pop();
  27961. this.lsb = sbx;
  27962. this.width = wx;
  27963. this.stack.push(wx, sbx);
  27964. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  27965. break;
  27966. case 14: // endchar
  27967. this.output.push(COMMAND_MAP.endchar[0]);
  27968. break;
  27969. case 21: // rmoveto
  27970. if (this.flexing) {
  27971. break;
  27972. }
  27973. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  27974. break;
  27975. case 22: // hmoveto
  27976. if (this.flexing) {
  27977. // Add the dy for flex.
  27978. this.stack.push(0);
  27979. break;
  27980. }
  27981. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  27982. break;
  27983. case 30: // vhcurveto
  27984. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  27985. break;
  27986. case 31: // hvcurveto
  27987. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  27988. break;
  27989. case (12 << 8) + 0: // dotsection
  27990. // dotsection is a Type1 command to specify some hinting feature
  27991. // for dots that do not take a parameter and it can safely be
  27992. // ignored for Type2.
  27993. this.stack = [];
  27994. break;
  27995. case (12 << 8) + 1: // vstem3
  27996. if (!HINTING_ENABLED) {
  27997. this.stack = [];
  27998. break;
  27999. }
  28000. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28001. // multiple parameters, so instead of returning [vh]stem3 take a
  28002. // shortcut and return [vhstem] instead.
  28003. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28004. break;
  28005. case (12 << 8) + 2: // hstem3
  28006. if (!HINTING_ENABLED) {
  28007. this.stack = [];
  28008. break;
  28009. }
  28010. // See vstem3.
  28011. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28012. break;
  28013. case (12 << 8) + 6: // seac
  28014. // seac is like type 2's special endchar but it doesn't use the
  28015. // first argument asb, so remove it.
  28016. if (SEAC_ANALYSIS_ENABLED) {
  28017. this.seac = this.stack.splice(-4, 4);
  28018. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28019. } else {
  28020. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28021. }
  28022. break;
  28023. case (12 << 8) + 7: // sbw
  28024. if (this.stack.length < 4) {
  28025. error = true;
  28026. break;
  28027. }
  28028. // To convert to type2 we have to move the width value to the
  28029. // first part of the charstring and then use rmoveto with
  28030. // (dx, dy). The height argument will not be used for vmtx and
  28031. // vhea tables reconstruction -- ignoring it.
  28032. var wy = this.stack.pop();
  28033. wx = this.stack.pop();
  28034. var sby = this.stack.pop();
  28035. sbx = this.stack.pop();
  28036. this.lsb = sbx;
  28037. this.width = wx;
  28038. this.stack.push(wx, sbx, sby);
  28039. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28040. break;
  28041. case (12 << 8) + 12: // div
  28042. if (this.stack.length < 2) {
  28043. error = true;
  28044. break;
  28045. }
  28046. var num2 = this.stack.pop();
  28047. var num1 = this.stack.pop();
  28048. this.stack.push(num1 / num2);
  28049. break;
  28050. case (12 << 8) + 16: // callothersubr
  28051. if (this.stack.length < 2) {
  28052. error = true;
  28053. break;
  28054. }
  28055. subrNumber = this.stack.pop();
  28056. var numArgs = this.stack.pop();
  28057. if (subrNumber === 0 && numArgs === 3) {
  28058. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28059. this.stack.push(
  28060. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28061. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28062. flexArgs[4], // bcp2x
  28063. flexArgs[5], // bcp2y
  28064. flexArgs[6], // p2x
  28065. flexArgs[7], // p2y
  28066. flexArgs[8], // bcp3x
  28067. flexArgs[9], // bcp3y
  28068. flexArgs[10], // bcp4x
  28069. flexArgs[11], // bcp4y
  28070. flexArgs[12], // p3x
  28071. flexArgs[13], // p3y
  28072. flexArgs[14] // flexDepth
  28073. // 15 = finalx unused by flex
  28074. // 16 = finaly unused by flex
  28075. );
  28076. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28077. this.flexing = false;
  28078. this.stack.push(flexArgs[15], flexArgs[16]);
  28079. } else if (subrNumber === 1 && numArgs === 0) {
  28080. this.flexing = true;
  28081. }
  28082. break;
  28083. case (12 << 8) + 17: // pop
  28084. // Ignore this since it is only used with othersubr.
  28085. break;
  28086. case (12 << 8) + 33: // setcurrentpoint
  28087. // Ignore for now.
  28088. this.stack = [];
  28089. break;
  28090. default:
  28091. warn('Unknown type 1 charstring command of "' + value + '"');
  28092. break;
  28093. }
  28094. if (error) {
  28095. break;
  28096. }
  28097. continue;
  28098. } else if (value <= 246) {
  28099. value = value - 139;
  28100. } else if (value <= 250) {
  28101. value = ((value - 247) * 256) + encoded[++i] + 108;
  28102. } else if (value <= 254) {
  28103. value = -((value - 251) * 256) - encoded[++i] - 108;
  28104. } else {
  28105. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28106. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28107. }
  28108. this.stack.push(value);
  28109. }
  28110. return error;
  28111. },
  28112. executeCommand: function(howManyArgs, command, keepStack) {
  28113. var stackLength = this.stack.length;
  28114. if (howManyArgs > stackLength) {
  28115. return true;
  28116. }
  28117. var start = stackLength - howManyArgs;
  28118. for (var i = start; i < stackLength; i++) {
  28119. var value = this.stack[i];
  28120. if (value === (value | 0)) { // int
  28121. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28122. } else { // fixed point
  28123. value = (65536 * value) | 0;
  28124. this.output.push(255,
  28125. (value >> 24) & 0xFF,
  28126. (value >> 16) & 0xFF,
  28127. (value >> 8) & 0xFF,
  28128. value & 0xFF);
  28129. }
  28130. }
  28131. this.output.push.apply(this.output, command);
  28132. if (keepStack) {
  28133. this.stack.splice(start, howManyArgs);
  28134. } else {
  28135. this.stack.length = 0;
  28136. }
  28137. return false;
  28138. }
  28139. };
  28140. return Type1CharString;
  28141. })();
  28142. /*
  28143. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28144. * program. Some of its logic depends on the Type2 charstrings
  28145. * structure.
  28146. * Note: this doesn't really parse the font since that would require evaluation
  28147. * of PostScript, but it is possible in most cases to extract what we need
  28148. * without a full parse.
  28149. */
  28150. var Type1Parser = (function Type1ParserClosure() {
  28151. /*
  28152. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28153. * of Plaintext Bytes. The function took a key as a parameter which can be
  28154. * for decrypting the eexec block of for decoding charStrings.
  28155. */
  28156. var EEXEC_ENCRYPT_KEY = 55665;
  28157. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28158. function isHexDigit(code) {
  28159. return code >= 48 && code <= 57 || // '0'-'9'
  28160. code >= 65 && code <= 70 || // 'A'-'F'
  28161. code >= 97 && code <= 102; // 'a'-'f'
  28162. }
  28163. function decrypt(data, key, discardNumber) {
  28164. var r = key | 0, c1 = 52845, c2 = 22719;
  28165. var count = data.length;
  28166. var decrypted = new Uint8Array(count);
  28167. for (var i = 0; i < count; i++) {
  28168. var value = data[i];
  28169. decrypted[i] = value ^ (r >> 8);
  28170. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28171. }
  28172. return Array.prototype.slice.call(decrypted, discardNumber);
  28173. }
  28174. function decryptAscii(data, key, discardNumber) {
  28175. var r = key | 0, c1 = 52845, c2 = 22719;
  28176. var count = data.length, maybeLength = count >>> 1;
  28177. var decrypted = new Uint8Array(maybeLength);
  28178. var i, j;
  28179. for (i = 0, j = 0; i < count; i++) {
  28180. var digit1 = data[i];
  28181. if (!isHexDigit(digit1)) {
  28182. continue;
  28183. }
  28184. i++;
  28185. var digit2;
  28186. while (i < count && !isHexDigit(digit2 = data[i])) {
  28187. i++;
  28188. }
  28189. if (i < count) {
  28190. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28191. decrypted[j++] = value ^ (r >> 8);
  28192. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28193. }
  28194. }
  28195. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28196. }
  28197. function isSpecial(c) {
  28198. return c === 0x2F || // '/'
  28199. c === 0x5B || c === 0x5D || // '[', ']'
  28200. c === 0x7B || c === 0x7D || // '{', '}'
  28201. c === 0x28 || c === 0x29; // '(', ')'
  28202. }
  28203. function Type1Parser(stream, encrypted) {
  28204. if (encrypted) {
  28205. var data = stream.getBytes();
  28206. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28207. isHexDigit(data[2]) && isHexDigit(data[3]));
  28208. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28209. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28210. }
  28211. this.stream = stream;
  28212. this.nextChar();
  28213. }
  28214. Type1Parser.prototype = {
  28215. readNumberArray: function Type1Parser_readNumberArray() {
  28216. this.getToken(); // read '[' or '{' (arrays can start with either)
  28217. var array = [];
  28218. while (true) {
  28219. var token = this.getToken();
  28220. if (token === null || token === ']' || token === '}') {
  28221. break;
  28222. }
  28223. array.push(parseFloat(token || 0));
  28224. }
  28225. return array;
  28226. },
  28227. readNumber: function Type1Parser_readNumber() {
  28228. var token = this.getToken();
  28229. return parseFloat(token || 0);
  28230. },
  28231. readInt: function Type1Parser_readInt() {
  28232. // Use '| 0' to prevent setting a double into length such as the double
  28233. // does not flow into the loop variable.
  28234. var token = this.getToken();
  28235. return parseInt(token || 0, 10) | 0;
  28236. },
  28237. readBoolean: function Type1Parser_readBoolean() {
  28238. var token = this.getToken();
  28239. // Use 1 and 0 since that's what type2 charstrings use.
  28240. return token === 'true' ? 1 : 0;
  28241. },
  28242. nextChar : function Type1_nextChar() {
  28243. return (this.currentChar = this.stream.getByte());
  28244. },
  28245. getToken: function Type1Parser_getToken() {
  28246. // Eat whitespace and comments.
  28247. var comment = false;
  28248. var ch = this.currentChar;
  28249. while (true) {
  28250. if (ch === -1) {
  28251. return null;
  28252. }
  28253. if (comment) {
  28254. if (ch === 0x0A || ch === 0x0D) {
  28255. comment = false;
  28256. }
  28257. } else if (ch === 0x25) { // '%'
  28258. comment = true;
  28259. } else if (!Lexer.isSpace(ch)) {
  28260. break;
  28261. }
  28262. ch = this.nextChar();
  28263. }
  28264. if (isSpecial(ch)) {
  28265. this.nextChar();
  28266. return String.fromCharCode(ch);
  28267. }
  28268. var token = '';
  28269. do {
  28270. token += String.fromCharCode(ch);
  28271. ch = this.nextChar();
  28272. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  28273. return token;
  28274. },
  28275. /*
  28276. * Returns an object containing a Subrs array and a CharStrings
  28277. * array extracted from and eexec encrypted block of data
  28278. */
  28279. extractFontProgram: function Type1Parser_extractFontProgram() {
  28280. var stream = this.stream;
  28281. var subrs = [], charstrings = [];
  28282. var program = {
  28283. subrs: [],
  28284. charstrings: [],
  28285. properties: {
  28286. 'privateData': {
  28287. 'lenIV': 4
  28288. }
  28289. }
  28290. };
  28291. var token, length, data, lenIV, encoded;
  28292. while ((token = this.getToken()) !== null) {
  28293. if (token !== '/') {
  28294. continue;
  28295. }
  28296. token = this.getToken();
  28297. switch (token) {
  28298. case 'CharStrings':
  28299. // The number immediately following CharStrings must be greater or
  28300. // equal to the number of CharStrings.
  28301. this.getToken();
  28302. this.getToken(); // read in 'dict'
  28303. this.getToken(); // read in 'dup'
  28304. this.getToken(); // read in 'begin'
  28305. while(true) {
  28306. token = this.getToken();
  28307. if (token === null || token === 'end') {
  28308. break;
  28309. }
  28310. if (token !== '/') {
  28311. continue;
  28312. }
  28313. var glyph = this.getToken();
  28314. length = this.readInt();
  28315. this.getToken(); // read in 'RD' or '-|'
  28316. data = stream.makeSubStream(stream.pos, length);
  28317. lenIV = program.properties.privateData['lenIV'];
  28318. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28319. // Skip past the required space and binary data.
  28320. stream.skip(length);
  28321. this.nextChar();
  28322. token = this.getToken(); // read in 'ND' or '|-'
  28323. if (token === 'noaccess') {
  28324. this.getToken(); // read in 'def'
  28325. }
  28326. charstrings.push({
  28327. glyph: glyph,
  28328. encoded: encoded
  28329. });
  28330. }
  28331. break;
  28332. case 'Subrs':
  28333. var num = this.readInt();
  28334. this.getToken(); // read in 'array'
  28335. while ((token = this.getToken()) === 'dup') {
  28336. var index = this.readInt();
  28337. length = this.readInt();
  28338. this.getToken(); // read in 'RD' or '-|'
  28339. data = stream.makeSubStream(stream.pos, length);
  28340. lenIV = program.properties.privateData['lenIV'];
  28341. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28342. // Skip past the required space and binary data.
  28343. stream.skip(length);
  28344. this.nextChar();
  28345. token = this.getToken(); // read in 'NP' or '|'
  28346. if (token === 'noaccess') {
  28347. this.getToken(); // read in 'put'
  28348. }
  28349. subrs[index] = encoded;
  28350. }
  28351. break;
  28352. case 'BlueValues':
  28353. case 'OtherBlues':
  28354. case 'FamilyBlues':
  28355. case 'FamilyOtherBlues':
  28356. var blueArray = this.readNumberArray();
  28357. // *Blue* values may contain invalid data: disables reading of
  28358. // those values when hinting is disabled.
  28359. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28360. HINTING_ENABLED) {
  28361. program.properties.privateData[token] = blueArray;
  28362. }
  28363. break;
  28364. case 'StemSnapH':
  28365. case 'StemSnapV':
  28366. program.properties.privateData[token] = this.readNumberArray();
  28367. break;
  28368. case 'StdHW':
  28369. case 'StdVW':
  28370. program.properties.privateData[token] =
  28371. this.readNumberArray()[0];
  28372. break;
  28373. case 'BlueShift':
  28374. case 'lenIV':
  28375. case 'BlueFuzz':
  28376. case 'BlueScale':
  28377. case 'LanguageGroup':
  28378. case 'ExpansionFactor':
  28379. program.properties.privateData[token] = this.readNumber();
  28380. break;
  28381. case 'ForceBold':
  28382. program.properties.privateData[token] = this.readBoolean();
  28383. break;
  28384. }
  28385. }
  28386. for (var i = 0; i < charstrings.length; i++) {
  28387. glyph = charstrings[i].glyph;
  28388. encoded = charstrings[i].encoded;
  28389. var charString = new Type1CharString();
  28390. var error = charString.convert(encoded, subrs);
  28391. var output = charString.output;
  28392. if (error) {
  28393. // It seems when FreeType encounters an error while evaluating a glyph
  28394. // that it completely ignores the glyph so we'll mimic that behaviour
  28395. // here and put an endchar to make the validator happy.
  28396. output = [14];
  28397. }
  28398. program.charstrings.push({
  28399. glyphName: glyph,
  28400. charstring: output,
  28401. width: charString.width,
  28402. lsb: charString.lsb,
  28403. seac: charString.seac
  28404. });
  28405. }
  28406. return program;
  28407. },
  28408. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28409. var token;
  28410. while ((token = this.getToken()) !== null) {
  28411. if (token !== '/') {
  28412. continue;
  28413. }
  28414. token = this.getToken();
  28415. switch (token) {
  28416. case 'FontMatrix':
  28417. var matrix = this.readNumberArray();
  28418. properties.fontMatrix = matrix;
  28419. break;
  28420. case 'Encoding':
  28421. var encodingArg = this.getToken();
  28422. var encoding;
  28423. if (!/^\d+$/.test(encodingArg)) {
  28424. // encoding name is specified
  28425. encoding = Encodings[encodingArg];
  28426. } else {
  28427. encoding = [];
  28428. var size = parseInt(encodingArg, 10) | 0;
  28429. this.getToken(); // read in 'array'
  28430. for (var j = 0; j < size; j++) {
  28431. token = this.getToken();
  28432. // skipping till first dup or def (e.g. ignoring for statement)
  28433. while (token !== 'dup' && token !== 'def') {
  28434. token = this.getToken();
  28435. if (token === null) {
  28436. return; // invalid header
  28437. }
  28438. }
  28439. if (token === 'def') {
  28440. break; // read all array data
  28441. }
  28442. var index = this.readInt();
  28443. this.getToken(); // read in '/'
  28444. var glyph = this.getToken();
  28445. encoding[index] = glyph;
  28446. this.getToken(); // read the in 'put'
  28447. }
  28448. }
  28449. properties.builtInEncoding = encoding;
  28450. break;
  28451. case 'FontBBox':
  28452. var fontBBox = this.readNumberArray();
  28453. // adjusting ascent/descent
  28454. properties.ascent = fontBBox[3];
  28455. properties.descent = fontBBox[1];
  28456. properties.ascentScaled = true;
  28457. break;
  28458. }
  28459. }
  28460. }
  28461. };
  28462. return Type1Parser;
  28463. })();
  28464. /**
  28465. * The CFF class takes a Type1 file and wrap it into a
  28466. * 'Compact Font Format' which itself embed Type2 charstrings.
  28467. */
  28468. var CFFStandardStrings = [
  28469. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  28470. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  28471. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  28472. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  28473. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  28474. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  28475. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  28476. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  28477. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  28478. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  28479. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  28480. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  28481. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  28482. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  28483. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  28484. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  28485. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  28486. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  28487. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  28488. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  28489. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  28490. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  28491. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  28492. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  28493. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  28494. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  28495. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  28496. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  28497. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  28498. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  28499. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  28500. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  28501. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  28502. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  28503. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  28504. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  28505. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  28506. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  28507. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  28508. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  28509. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  28510. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  28511. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  28512. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  28513. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  28514. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  28515. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  28516. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  28517. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  28518. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  28519. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  28520. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  28521. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  28522. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  28523. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  28524. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  28525. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  28526. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  28527. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  28528. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  28529. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  28530. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  28531. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  28532. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  28533. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  28534. ];
  28535. // Type1Font is also a CIDFontType0.
  28536. var Type1Font = function Type1Font(name, file, properties) {
  28537. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  28538. // Also, length1 and length2 might be off by 6 bytes as well.
  28539. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  28540. var PFB_HEADER_SIZE = 6;
  28541. var headerBlockLength = properties.length1;
  28542. var eexecBlockLength = properties.length2;
  28543. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  28544. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  28545. if (pfbHeaderPresent) {
  28546. file.skip(PFB_HEADER_SIZE);
  28547. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28548. (pfbHeader[3] << 8) | pfbHeader[2];
  28549. }
  28550. // Get the data block containing glyphs and subrs informations
  28551. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  28552. var headerBlockParser = new Type1Parser(headerBlock);
  28553. headerBlockParser.extractFontHeader(properties);
  28554. if (pfbHeaderPresent) {
  28555. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  28556. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28557. (pfbHeader[3] << 8) | pfbHeader[2];
  28558. }
  28559. // Decrypt the data blocks and retrieve it's content
  28560. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  28561. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  28562. var data = eexecBlockParser.extractFontProgram();
  28563. for (var info in data.properties) {
  28564. properties[info] = data.properties[info];
  28565. }
  28566. var charstrings = data.charstrings;
  28567. var type2Charstrings = this.getType2Charstrings(charstrings);
  28568. var subrs = this.getType2Subrs(data.subrs);
  28569. this.charstrings = charstrings;
  28570. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  28571. subrs, properties);
  28572. this.seacs = this.getSeacs(data.charstrings);
  28573. };
  28574. Type1Font.prototype = {
  28575. get numGlyphs() {
  28576. return this.charstrings.length + 1;
  28577. },
  28578. getCharset: function Type1Font_getCharset() {
  28579. var charset = ['.notdef'];
  28580. var charstrings = this.charstrings;
  28581. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28582. charset.push(charstrings[glyphId].glyphName);
  28583. }
  28584. return charset;
  28585. },
  28586. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  28587. var charstrings = this.charstrings;
  28588. var glyphNames = ['.notdef'], glyphId;
  28589. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28590. glyphNames.push(charstrings[glyphId].glyphName);
  28591. }
  28592. var encoding = properties.builtInEncoding;
  28593. if (encoding) {
  28594. var builtInEncoding = {};
  28595. for (var charCode in encoding) {
  28596. glyphId = glyphNames.indexOf(encoding[charCode]);
  28597. if (glyphId >= 0) {
  28598. builtInEncoding[charCode] = glyphId;
  28599. }
  28600. }
  28601. }
  28602. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  28603. },
  28604. getSeacs: function Type1Font_getSeacs(charstrings) {
  28605. var i, ii;
  28606. var seacMap = [];
  28607. for (i = 0, ii = charstrings.length; i < ii; i++) {
  28608. var charstring = charstrings[i];
  28609. if (charstring.seac) {
  28610. // Offset by 1 for .notdef
  28611. seacMap[i + 1] = charstring.seac;
  28612. }
  28613. }
  28614. return seacMap;
  28615. },
  28616. getType2Charstrings: function Type1Font_getType2Charstrings(
  28617. type1Charstrings) {
  28618. var type2Charstrings = [];
  28619. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  28620. type2Charstrings.push(type1Charstrings[i].charstring);
  28621. }
  28622. return type2Charstrings;
  28623. },
  28624. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28625. var bias = 0;
  28626. var count = type1Subrs.length;
  28627. if (count < 1133) {
  28628. bias = 107;
  28629. } else if (count < 33769) {
  28630. bias = 1131;
  28631. } else {
  28632. bias = 32768;
  28633. }
  28634. // Add a bunch of empty subrs to deal with the Type2 bias
  28635. var type2Subrs = [];
  28636. var i;
  28637. for (i = 0; i < bias; i++) {
  28638. type2Subrs.push([0x0B]);
  28639. }
  28640. for (i = 0; i < count; i++) {
  28641. type2Subrs.push(type1Subrs[i]);
  28642. }
  28643. return type2Subrs;
  28644. },
  28645. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28646. var cff = new CFF();
  28647. cff.header = new CFFHeader(1, 0, 4, 4);
  28648. cff.names = [name];
  28649. var topDict = new CFFTopDict();
  28650. // CFF strings IDs 0...390 are predefined names, so refering
  28651. // to entries in our own String INDEX starts at SID 391.
  28652. topDict.setByName('version', 391);
  28653. topDict.setByName('Notice', 392);
  28654. topDict.setByName('FullName', 393);
  28655. topDict.setByName('FamilyName', 394);
  28656. topDict.setByName('Weight', 395);
  28657. topDict.setByName('Encoding', null); // placeholder
  28658. topDict.setByName('FontMatrix', properties.fontMatrix);
  28659. topDict.setByName('FontBBox', properties.bbox);
  28660. topDict.setByName('charset', null); // placeholder
  28661. topDict.setByName('CharStrings', null); // placeholder
  28662. topDict.setByName('Private', null); // placeholder
  28663. cff.topDict = topDict;
  28664. var strings = new CFFStrings();
  28665. strings.add('Version 0.11'); // Version
  28666. strings.add('See original notice'); // Notice
  28667. strings.add(name); // FullName
  28668. strings.add(name); // FamilyName
  28669. strings.add('Medium'); // Weight
  28670. cff.strings = strings;
  28671. cff.globalSubrIndex = new CFFIndex();
  28672. var count = glyphs.length;
  28673. var charsetArray = [0];
  28674. var i, ii;
  28675. for (i = 0; i < count; i++) {
  28676. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28677. // TODO: Insert the string and correctly map it. Previously it was
  28678. // thought mapping names that aren't in the standard strings to .notdef
  28679. // was fine, however in issue818 when mapping them all to .notdef the
  28680. // adieresis glyph no longer worked.
  28681. if (index === -1) {
  28682. index = 0;
  28683. }
  28684. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28685. }
  28686. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28687. var charStringsIndex = new CFFIndex();
  28688. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28689. for (i = 0; i < count; i++) {
  28690. charStringsIndex.add(glyphs[i]);
  28691. }
  28692. cff.charStrings = charStringsIndex;
  28693. var privateDict = new CFFPrivateDict();
  28694. privateDict.setByName('Subrs', null); // placeholder
  28695. var fields = [
  28696. 'BlueValues',
  28697. 'OtherBlues',
  28698. 'FamilyBlues',
  28699. 'FamilyOtherBlues',
  28700. 'StemSnapH',
  28701. 'StemSnapV',
  28702. 'BlueShift',
  28703. 'BlueFuzz',
  28704. 'BlueScale',
  28705. 'LanguageGroup',
  28706. 'ExpansionFactor',
  28707. 'ForceBold',
  28708. 'StdHW',
  28709. 'StdVW'
  28710. ];
  28711. for (i = 0, ii = fields.length; i < ii; i++) {
  28712. var field = fields[i];
  28713. if (!properties.privateData.hasOwnProperty(field)) {
  28714. continue;
  28715. }
  28716. var value = properties.privateData[field];
  28717. if (isArray(value)) {
  28718. // All of the private dictionary array data in CFF must be stored as
  28719. // "delta-encoded" numbers.
  28720. for (var j = value.length - 1; j > 0; j--) {
  28721. value[j] -= value[j - 1]; // ... difference from previous value
  28722. }
  28723. }
  28724. privateDict.setByName(field, value);
  28725. }
  28726. cff.topDict.privateDict = privateDict;
  28727. var subrIndex = new CFFIndex();
  28728. for (i = 0, ii = subrs.length; i < ii; i++) {
  28729. subrIndex.add(subrs[i]);
  28730. }
  28731. privateDict.subrsIndex = subrIndex;
  28732. var compiler = new CFFCompiler(cff);
  28733. return compiler.compile();
  28734. }
  28735. };
  28736. var CFFFont = (function CFFFontClosure() {
  28737. function CFFFont(file, properties) {
  28738. this.properties = properties;
  28739. var parser = new CFFParser(file, properties);
  28740. this.cff = parser.parse();
  28741. var compiler = new CFFCompiler(this.cff);
  28742. this.seacs = this.cff.seacs;
  28743. try {
  28744. this.data = compiler.compile();
  28745. } catch (e) {
  28746. warn('Failed to compile font ' + properties.loadedName);
  28747. // There may have just been an issue with the compiler, set the data
  28748. // anyway and hope the font loaded.
  28749. this.data = file;
  28750. }
  28751. }
  28752. CFFFont.prototype = {
  28753. get numGlyphs() {
  28754. return this.cff.charStrings.count;
  28755. },
  28756. getCharset: function CFFFont_getCharset() {
  28757. return this.cff.charset.charset;
  28758. },
  28759. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28760. var cff = this.cff;
  28761. var properties = this.properties;
  28762. var charsets = cff.charset.charset;
  28763. var charCodeToGlyphId;
  28764. var glyphId;
  28765. if (properties.composite) {
  28766. charCodeToGlyphId = Object.create(null);
  28767. if (cff.isCIDFont) {
  28768. // If the font is actually a CID font then we should use the charset
  28769. // to map CIDs to GIDs.
  28770. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28771. var cid = charsets[glyphId];
  28772. var charCode = properties.cMap.charCodeOf(cid);
  28773. charCodeToGlyphId[charCode] = glyphId;
  28774. }
  28775. } else {
  28776. // If it is NOT actually a CID font then CIDs should be mapped
  28777. // directly to GIDs.
  28778. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28779. charCodeToGlyphId[glyphId] = glyphId;
  28780. }
  28781. }
  28782. return charCodeToGlyphId;
  28783. }
  28784. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28785. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28786. return charCodeToGlyphId;
  28787. }
  28788. };
  28789. return CFFFont;
  28790. })();
  28791. var CFFParser = (function CFFParserClosure() {
  28792. var CharstringValidationData = [
  28793. null,
  28794. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28795. null,
  28796. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28797. { id: 'vmoveto', min: 1, stackClearing: true },
  28798. { id: 'rlineto', min: 2, resetStack: true },
  28799. { id: 'hlineto', min: 1, resetStack: true },
  28800. { id: 'vlineto', min: 1, resetStack: true },
  28801. { id: 'rrcurveto', min: 6, resetStack: true },
  28802. null,
  28803. { id: 'callsubr', min: 1, undefStack: true },
  28804. { id: 'return', min: 0, undefStack: true },
  28805. null, // 12
  28806. null,
  28807. { id: 'endchar', min: 0, stackClearing: true },
  28808. null,
  28809. null,
  28810. null,
  28811. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28812. { id: 'hintmask', min: 0, stackClearing: true },
  28813. { id: 'cntrmask', min: 0, stackClearing: true },
  28814. { id: 'rmoveto', min: 2, stackClearing: true },
  28815. { id: 'hmoveto', min: 1, stackClearing: true },
  28816. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28817. { id: 'rcurveline', min: 8, resetStack: true },
  28818. { id: 'rlinecurve', min: 8, resetStack: true },
  28819. { id: 'vvcurveto', min: 4, resetStack: true },
  28820. { id: 'hhcurveto', min: 4, resetStack: true },
  28821. null, // shortint
  28822. { id: 'callgsubr', min: 1, undefStack: true },
  28823. { id: 'vhcurveto', min: 4, resetStack: true },
  28824. { id: 'hvcurveto', min: 4, resetStack: true }
  28825. ];
  28826. var CharstringValidationData12 = [
  28827. null,
  28828. null,
  28829. null,
  28830. { id: 'and', min: 2, stackDelta: -1 },
  28831. { id: 'or', min: 2, stackDelta: -1 },
  28832. { id: 'not', min: 1, stackDelta: 0 },
  28833. null,
  28834. null,
  28835. null,
  28836. { id: 'abs', min: 1, stackDelta: 0 },
  28837. { id: 'add', min: 2, stackDelta: -1,
  28838. stackFn: function stack_div(stack, index) {
  28839. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28840. }
  28841. },
  28842. { id: 'sub', min: 2, stackDelta: -1,
  28843. stackFn: function stack_div(stack, index) {
  28844. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28845. }
  28846. },
  28847. { id: 'div', min: 2, stackDelta: -1,
  28848. stackFn: function stack_div(stack, index) {
  28849. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28850. }
  28851. },
  28852. null,
  28853. { id: 'neg', min: 1, stackDelta: 0,
  28854. stackFn: function stack_div(stack, index) {
  28855. stack[index - 1] = -stack[index - 1];
  28856. }
  28857. },
  28858. { id: 'eq', min: 2, stackDelta: -1 },
  28859. null,
  28860. null,
  28861. { id: 'drop', min: 1, stackDelta: -1 },
  28862. null,
  28863. { id: 'put', min: 2, stackDelta: -2 },
  28864. { id: 'get', min: 1, stackDelta: 0 },
  28865. { id: 'ifelse', min: 4, stackDelta: -3 },
  28866. { id: 'random', min: 0, stackDelta: 1 },
  28867. { id: 'mul', min: 2, stackDelta: -1,
  28868. stackFn: function stack_div(stack, index) {
  28869. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28870. }
  28871. },
  28872. null,
  28873. { id: 'sqrt', min: 1, stackDelta: 0 },
  28874. { id: 'dup', min: 1, stackDelta: 1 },
  28875. { id: 'exch', min: 2, stackDelta: 0 },
  28876. { id: 'index', min: 2, stackDelta: 0 },
  28877. { id: 'roll', min: 3, stackDelta: -2 },
  28878. null,
  28879. null,
  28880. null,
  28881. { id: 'hflex', min: 7, resetStack: true },
  28882. { id: 'flex', min: 13, resetStack: true },
  28883. { id: 'hflex1', min: 9, resetStack: true },
  28884. { id: 'flex1', min: 11, resetStack: true }
  28885. ];
  28886. function CFFParser(file, properties) {
  28887. this.bytes = file.getBytes();
  28888. this.properties = properties;
  28889. }
  28890. CFFParser.prototype = {
  28891. parse: function CFFParser_parse() {
  28892. var properties = this.properties;
  28893. var cff = new CFF();
  28894. this.cff = cff;
  28895. // The first five sections must be in order, all the others are reached
  28896. // via offsets contained in one of the below.
  28897. var header = this.parseHeader();
  28898. var nameIndex = this.parseIndex(header.endPos);
  28899. var topDictIndex = this.parseIndex(nameIndex.endPos);
  28900. var stringIndex = this.parseIndex(topDictIndex.endPos);
  28901. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  28902. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  28903. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  28904. cff.header = header.obj;
  28905. cff.names = this.parseNameIndex(nameIndex.obj);
  28906. cff.strings = this.parseStringIndex(stringIndex.obj);
  28907. cff.topDict = topDict;
  28908. cff.globalSubrIndex = globalSubrIndex.obj;
  28909. this.parsePrivateDict(cff.topDict);
  28910. cff.isCIDFont = topDict.hasName('ROS');
  28911. var charStringOffset = topDict.getByName('CharStrings');
  28912. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  28913. cff.charStrings = charStringsAndSeacs.charStrings;
  28914. cff.seacs = charStringsAndSeacs.seacs;
  28915. cff.widths = charStringsAndSeacs.widths;
  28916. var fontMatrix = topDict.getByName('FontMatrix');
  28917. if (fontMatrix) {
  28918. properties.fontMatrix = fontMatrix;
  28919. }
  28920. var fontBBox = topDict.getByName('FontBBox');
  28921. if (fontBBox) {
  28922. // adjusting ascent/descent
  28923. properties.ascent = fontBBox[3];
  28924. properties.descent = fontBBox[1];
  28925. properties.ascentScaled = true;
  28926. }
  28927. var charset, encoding;
  28928. if (cff.isCIDFont) {
  28929. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  28930. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  28931. var dictRaw = fdArrayIndex.get(i);
  28932. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  28933. cff.strings);
  28934. this.parsePrivateDict(fontDict);
  28935. cff.fdArray.push(fontDict);
  28936. }
  28937. // cid fonts don't have an encoding
  28938. encoding = null;
  28939. charset = this.parseCharsets(topDict.getByName('charset'),
  28940. cff.charStrings.count, cff.strings, true);
  28941. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  28942. cff.charStrings.count);
  28943. } else {
  28944. charset = this.parseCharsets(topDict.getByName('charset'),
  28945. cff.charStrings.count, cff.strings, false);
  28946. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  28947. properties,
  28948. cff.strings, charset.charset);
  28949. }
  28950. cff.charset = charset;
  28951. cff.encoding = encoding;
  28952. return cff;
  28953. },
  28954. parseHeader: function CFFParser_parseHeader() {
  28955. var bytes = this.bytes;
  28956. var bytesLength = bytes.length;
  28957. var offset = 0;
  28958. // Prevent an infinite loop, by checking that the offset is within the
  28959. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  28960. while (offset < bytesLength && bytes[offset] !== 1) {
  28961. ++offset;
  28962. }
  28963. if (offset >= bytesLength) {
  28964. error('Invalid CFF header');
  28965. } else if (offset !== 0) {
  28966. info('cff data is shifted');
  28967. bytes = bytes.subarray(offset);
  28968. this.bytes = bytes;
  28969. }
  28970. var major = bytes[0];
  28971. var minor = bytes[1];
  28972. var hdrSize = bytes[2];
  28973. var offSize = bytes[3];
  28974. var header = new CFFHeader(major, minor, hdrSize, offSize);
  28975. return { obj: header, endPos: hdrSize };
  28976. },
  28977. parseDict: function CFFParser_parseDict(dict) {
  28978. var pos = 0;
  28979. function parseOperand() {
  28980. var value = dict[pos++];
  28981. if (value === 30) {
  28982. return parseFloatOperand(pos);
  28983. } else if (value === 28) {
  28984. value = dict[pos++];
  28985. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  28986. return value;
  28987. } else if (value === 29) {
  28988. value = dict[pos++];
  28989. value = (value << 8) | dict[pos++];
  28990. value = (value << 8) | dict[pos++];
  28991. value = (value << 8) | dict[pos++];
  28992. return value;
  28993. } else if (value >= 32 && value <= 246) {
  28994. return value - 139;
  28995. } else if (value >= 247 && value <= 250) {
  28996. return ((value - 247) * 256) + dict[pos++] + 108;
  28997. } else if (value >= 251 && value <= 254) {
  28998. return -((value - 251) * 256) - dict[pos++] - 108;
  28999. } else {
  29000. error('255 is not a valid DICT command');
  29001. }
  29002. return -1;
  29003. }
  29004. function parseFloatOperand() {
  29005. var str = '';
  29006. var eof = 15;
  29007. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  29008. '9', '.', 'E', 'E-', null, '-'];
  29009. var length = dict.length;
  29010. while (pos < length) {
  29011. var b = dict[pos++];
  29012. var b1 = b >> 4;
  29013. var b2 = b & 15;
  29014. if (b1 === eof) {
  29015. break;
  29016. }
  29017. str += lookup[b1];
  29018. if (b2 === eof) {
  29019. break;
  29020. }
  29021. str += lookup[b2];
  29022. }
  29023. return parseFloat(str);
  29024. }
  29025. var operands = [];
  29026. var entries = [];
  29027. pos = 0;
  29028. var end = dict.length;
  29029. while (pos < end) {
  29030. var b = dict[pos];
  29031. if (b <= 21) {
  29032. if (b === 12) {
  29033. b = (b << 8) | dict[++pos];
  29034. }
  29035. entries.push([b, operands]);
  29036. operands = [];
  29037. ++pos;
  29038. } else {
  29039. operands.push(parseOperand());
  29040. }
  29041. }
  29042. return entries;
  29043. },
  29044. parseIndex: function CFFParser_parseIndex(pos) {
  29045. var cffIndex = new CFFIndex();
  29046. var bytes = this.bytes;
  29047. var count = (bytes[pos++] << 8) | bytes[pos++];
  29048. var offsets = [];
  29049. var end = pos;
  29050. var i, ii;
  29051. if (count !== 0) {
  29052. var offsetSize = bytes[pos++];
  29053. // add 1 for offset to determine size of last object
  29054. var startPos = pos + ((count + 1) * offsetSize) - 1;
  29055. for (i = 0, ii = count + 1; i < ii; ++i) {
  29056. var offset = 0;
  29057. for (var j = 0; j < offsetSize; ++j) {
  29058. offset <<= 8;
  29059. offset += bytes[pos++];
  29060. }
  29061. offsets.push(startPos + offset);
  29062. }
  29063. end = offsets[count];
  29064. }
  29065. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  29066. var offsetStart = offsets[i];
  29067. var offsetEnd = offsets[i + 1];
  29068. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  29069. }
  29070. return {obj: cffIndex, endPos: end};
  29071. },
  29072. parseNameIndex: function CFFParser_parseNameIndex(index) {
  29073. var names = [];
  29074. for (var i = 0, ii = index.count; i < ii; ++i) {
  29075. var name = index.get(i);
  29076. // OTS doesn't allow names to be over 127 characters.
  29077. var length = Math.min(name.length, 127);
  29078. var data = [];
  29079. // OTS also only permits certain characters in the name.
  29080. for (var j = 0; j < length; ++j) {
  29081. var c = name[j];
  29082. if (j === 0 && c === 0) {
  29083. data[j] = c;
  29084. continue;
  29085. }
  29086. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  29087. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  29088. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  29089. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  29090. data[j] = 95;
  29091. continue;
  29092. }
  29093. data[j] = c;
  29094. }
  29095. names.push(bytesToString(data));
  29096. }
  29097. return names;
  29098. },
  29099. parseStringIndex: function CFFParser_parseStringIndex(index) {
  29100. var strings = new CFFStrings();
  29101. for (var i = 0, ii = index.count; i < ii; ++i) {
  29102. var data = index.get(i);
  29103. strings.add(bytesToString(data));
  29104. }
  29105. return strings;
  29106. },
  29107. createDict: function CFFParser_createDict(Type, dict, strings) {
  29108. var cffDict = new Type(strings);
  29109. for (var i = 0, ii = dict.length; i < ii; ++i) {
  29110. var pair = dict[i];
  29111. var key = pair[0];
  29112. var value = pair[1];
  29113. cffDict.setByKey(key, value);
  29114. }
  29115. return cffDict;
  29116. },
  29117. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  29118. var charStrings = this.parseIndex(charStringOffset).obj;
  29119. var seacs = [];
  29120. var widths = [];
  29121. var count = charStrings.count;
  29122. for (var i = 0; i < count; i++) {
  29123. var charstring = charStrings.get(i);
  29124. var stackSize = 0;
  29125. var stack = [];
  29126. var undefStack = true;
  29127. var hints = 0;
  29128. var valid = true;
  29129. var data = charstring;
  29130. var length = data.length;
  29131. var firstStackClearing = true;
  29132. for (var j = 0; j < length;) {
  29133. var value = data[j++];
  29134. var validationCommand = null;
  29135. if (value === 12) {
  29136. var q = data[j++];
  29137. if (q === 0) {
  29138. // The CFF specification state that the 'dotsection' command
  29139. // (12, 0) is deprecated and treated as a no-op, but all Type2
  29140. // charstrings processors should support them. Unfortunately
  29141. // the font sanitizer don't. As a workaround the sequence (12, 0)
  29142. // is replaced by a useless (0, hmoveto).
  29143. data[j - 2] = 139;
  29144. data[j - 1] = 22;
  29145. stackSize = 0;
  29146. } else {
  29147. validationCommand = CharstringValidationData12[q];
  29148. }
  29149. } else if (value === 28) { // number (16 bit)
  29150. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  29151. j += 2;
  29152. stackSize++;
  29153. } else if (value === 14) {
  29154. if (stackSize >= 4) {
  29155. stackSize -= 4;
  29156. if (SEAC_ANALYSIS_ENABLED) {
  29157. seacs[i] = stack.slice(stackSize, stackSize + 4);
  29158. valid = false;
  29159. }
  29160. }
  29161. validationCommand = CharstringValidationData[value];
  29162. } else if (value >= 32 && value <= 246) { // number
  29163. stack[stackSize] = value - 139;
  29164. stackSize++;
  29165. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  29166. stack[stackSize] = (value < 251 ?
  29167. ((value - 247) << 8) + data[j] + 108 :
  29168. -((value - 251) << 8) - data[j] - 108);
  29169. j++;
  29170. stackSize++;
  29171. } else if (value === 255) { // number (32 bit)
  29172. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  29173. (data[j + 2] << 8) | data[j + 3]) / 65536;
  29174. j += 4;
  29175. stackSize++;
  29176. } else if (value === 19 || value === 20) {
  29177. hints += stackSize >> 1;
  29178. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  29179. stackSize %= 2;
  29180. validationCommand = CharstringValidationData[value];
  29181. } else {
  29182. validationCommand = CharstringValidationData[value];
  29183. }
  29184. if (validationCommand) {
  29185. if (validationCommand.stem) {
  29186. hints += stackSize >> 1;
  29187. }
  29188. if ('min' in validationCommand) {
  29189. if (!undefStack && stackSize < validationCommand.min) {
  29190. warn('Not enough parameters for ' + validationCommand.id +
  29191. '; actual: ' + stackSize +
  29192. ', expected: ' + validationCommand.min);
  29193. valid = false;
  29194. break;
  29195. }
  29196. }
  29197. if (firstStackClearing && validationCommand.stackClearing) {
  29198. firstStackClearing = false;
  29199. // the optional character width can be found before the first
  29200. // stack-clearing command arguments
  29201. stackSize -= validationCommand.min;
  29202. if (stackSize >= 2 && validationCommand.stem) {
  29203. // there are even amount of arguments for stem commands
  29204. stackSize %= 2;
  29205. } else if (stackSize > 1) {
  29206. warn('Found too many parameters for stack-clearing command');
  29207. }
  29208. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  29209. widths[i] = stack[stackSize - 1];
  29210. }
  29211. }
  29212. if ('stackDelta' in validationCommand) {
  29213. if ('stackFn' in validationCommand) {
  29214. validationCommand.stackFn(stack, stackSize);
  29215. }
  29216. stackSize += validationCommand.stackDelta;
  29217. } else if (validationCommand.stackClearing) {
  29218. stackSize = 0;
  29219. } else if (validationCommand.resetStack) {
  29220. stackSize = 0;
  29221. undefStack = false;
  29222. } else if (validationCommand.undefStack) {
  29223. stackSize = 0;
  29224. undefStack = true;
  29225. firstStackClearing = false;
  29226. }
  29227. }
  29228. }
  29229. if (!valid) {
  29230. // resetting invalid charstring to single 'endchar'
  29231. charStrings.set(i, new Uint8Array([14]));
  29232. }
  29233. }
  29234. return { charStrings: charStrings, seacs: seacs, widths: widths };
  29235. },
  29236. emptyPrivateDictionary:
  29237. function CFFParser_emptyPrivateDictionary(parentDict) {
  29238. var privateDict = this.createDict(CFFPrivateDict, [],
  29239. parentDict.strings);
  29240. parentDict.setByKey(18, [0, 0]);
  29241. parentDict.privateDict = privateDict;
  29242. },
  29243. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  29244. // no private dict, do nothing
  29245. if (!parentDict.hasName('Private')) {
  29246. this.emptyPrivateDictionary(parentDict);
  29247. return;
  29248. }
  29249. var privateOffset = parentDict.getByName('Private');
  29250. // make sure the params are formatted correctly
  29251. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  29252. parentDict.removeByName('Private');
  29253. return;
  29254. }
  29255. var size = privateOffset[0];
  29256. var offset = privateOffset[1];
  29257. // remove empty dicts or ones that refer to invalid location
  29258. if (size === 0 || offset >= this.bytes.length) {
  29259. this.emptyPrivateDictionary(parentDict);
  29260. return;
  29261. }
  29262. var privateDictEnd = offset + size;
  29263. var dictData = this.bytes.subarray(offset, privateDictEnd);
  29264. var dict = this.parseDict(dictData);
  29265. var privateDict = this.createDict(CFFPrivateDict, dict,
  29266. parentDict.strings);
  29267. parentDict.privateDict = privateDict;
  29268. // Parse the Subrs index also since it's relative to the private dict.
  29269. if (!privateDict.getByName('Subrs')) {
  29270. return;
  29271. }
  29272. var subrsOffset = privateDict.getByName('Subrs');
  29273. var relativeOffset = offset + subrsOffset;
  29274. // Validate the offset.
  29275. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  29276. this.emptyPrivateDictionary(parentDict);
  29277. return;
  29278. }
  29279. var subrsIndex = this.parseIndex(relativeOffset);
  29280. privateDict.subrsIndex = subrsIndex.obj;
  29281. },
  29282. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  29283. if (pos === 0) {
  29284. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  29285. ISOAdobeCharset);
  29286. } else if (pos === 1) {
  29287. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  29288. ExpertCharset);
  29289. } else if (pos === 2) {
  29290. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  29291. ExpertSubsetCharset);
  29292. }
  29293. var bytes = this.bytes;
  29294. var start = pos;
  29295. var format = bytes[pos++];
  29296. var charset = ['.notdef'];
  29297. var id, count, i;
  29298. // subtract 1 for the .notdef glyph
  29299. length -= 1;
  29300. switch (format) {
  29301. case 0:
  29302. for (i = 0; i < length; i++) {
  29303. id = (bytes[pos++] << 8) | bytes[pos++];
  29304. charset.push(cid ? id : strings.get(id));
  29305. }
  29306. break;
  29307. case 1:
  29308. while (charset.length <= length) {
  29309. id = (bytes[pos++] << 8) | bytes[pos++];
  29310. count = bytes[pos++];
  29311. for (i = 0; i <= count; i++) {
  29312. charset.push(cid ? id++ : strings.get(id++));
  29313. }
  29314. }
  29315. break;
  29316. case 2:
  29317. while (charset.length <= length) {
  29318. id = (bytes[pos++] << 8) | bytes[pos++];
  29319. count = (bytes[pos++] << 8) | bytes[pos++];
  29320. for (i = 0; i <= count; i++) {
  29321. charset.push(cid ? id++ : strings.get(id++));
  29322. }
  29323. }
  29324. break;
  29325. default:
  29326. error('Unknown charset format');
  29327. }
  29328. // Raw won't be needed if we actually compile the charset.
  29329. var end = pos;
  29330. var raw = bytes.subarray(start, end);
  29331. return new CFFCharset(false, format, charset, raw);
  29332. },
  29333. parseEncoding: function CFFParser_parseEncoding(pos,
  29334. properties,
  29335. strings,
  29336. charset) {
  29337. var encoding = {};
  29338. var bytes = this.bytes;
  29339. var predefined = false;
  29340. var hasSupplement = false;
  29341. var format, i, ii;
  29342. var raw = null;
  29343. function readSupplement() {
  29344. var supplementsCount = bytes[pos++];
  29345. for (i = 0; i < supplementsCount; i++) {
  29346. var code = bytes[pos++];
  29347. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  29348. encoding[code] = charset.indexOf(strings.get(sid));
  29349. }
  29350. }
  29351. if (pos === 0 || pos === 1) {
  29352. predefined = true;
  29353. format = pos;
  29354. var baseEncoding = pos ? Encodings.ExpertEncoding :
  29355. Encodings.StandardEncoding;
  29356. for (i = 0, ii = charset.length; i < ii; i++) {
  29357. var index = baseEncoding.indexOf(charset[i]);
  29358. if (index !== -1) {
  29359. encoding[index] = i;
  29360. }
  29361. }
  29362. } else {
  29363. var dataStart = pos;
  29364. format = bytes[pos++];
  29365. switch (format & 0x7f) {
  29366. case 0:
  29367. var glyphsCount = bytes[pos++];
  29368. for (i = 1; i <= glyphsCount; i++) {
  29369. encoding[bytes[pos++]] = i;
  29370. }
  29371. break;
  29372. case 1:
  29373. var rangesCount = bytes[pos++];
  29374. var gid = 1;
  29375. for (i = 0; i < rangesCount; i++) {
  29376. var start = bytes[pos++];
  29377. var left = bytes[pos++];
  29378. for (var j = start; j <= start + left; j++) {
  29379. encoding[j] = gid++;
  29380. }
  29381. }
  29382. break;
  29383. default:
  29384. error('Unknow encoding format: ' + format + ' in CFF');
  29385. break;
  29386. }
  29387. var dataEnd = pos;
  29388. if (format & 0x80) {
  29389. // The font sanitizer does not support CFF encoding with a
  29390. // supplement, since the encoding is not really used to map
  29391. // between gid to glyph, let's overwrite what is declared in
  29392. // the top dictionary to let the sanitizer think the font use
  29393. // StandardEncoding, that's a lie but that's ok.
  29394. bytes[dataStart] &= 0x7f;
  29395. readSupplement();
  29396. hasSupplement = true;
  29397. }
  29398. raw = bytes.subarray(dataStart, dataEnd);
  29399. }
  29400. format = format & 0x7f;
  29401. return new CFFEncoding(predefined, format, encoding, raw);
  29402. },
  29403. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  29404. var start = pos;
  29405. var bytes = this.bytes;
  29406. var format = bytes[pos++];
  29407. var fdSelect = [];
  29408. var i;
  29409. switch (format) {
  29410. case 0:
  29411. for (i = 0; i < length; ++i) {
  29412. var id = bytes[pos++];
  29413. fdSelect.push(id);
  29414. }
  29415. break;
  29416. case 3:
  29417. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  29418. for (i = 0; i < rangesCount; ++i) {
  29419. var first = (bytes[pos++] << 8) | bytes[pos++];
  29420. var fdIndex = bytes[pos++];
  29421. var next = (bytes[pos] << 8) | bytes[pos + 1];
  29422. for (var j = first; j < next; ++j) {
  29423. fdSelect.push(fdIndex);
  29424. }
  29425. }
  29426. // Advance past the sentinel(next).
  29427. pos += 2;
  29428. break;
  29429. default:
  29430. error('Unknown fdselect format ' + format);
  29431. break;
  29432. }
  29433. var end = pos;
  29434. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  29435. }
  29436. };
  29437. return CFFParser;
  29438. })();
  29439. // Compact Font Format
  29440. var CFF = (function CFFClosure() {
  29441. function CFF() {
  29442. this.header = null;
  29443. this.names = [];
  29444. this.topDict = null;
  29445. this.strings = new CFFStrings();
  29446. this.globalSubrIndex = null;
  29447. // The following could really be per font, but since we only have one font
  29448. // store them here.
  29449. this.encoding = null;
  29450. this.charset = null;
  29451. this.charStrings = null;
  29452. this.fdArray = [];
  29453. this.fdSelect = null;
  29454. this.isCIDFont = false;
  29455. }
  29456. return CFF;
  29457. })();
  29458. var CFFHeader = (function CFFHeaderClosure() {
  29459. function CFFHeader(major, minor, hdrSize, offSize) {
  29460. this.major = major;
  29461. this.minor = minor;
  29462. this.hdrSize = hdrSize;
  29463. this.offSize = offSize;
  29464. }
  29465. return CFFHeader;
  29466. })();
  29467. var CFFStrings = (function CFFStringsClosure() {
  29468. function CFFStrings() {
  29469. this.strings = [];
  29470. }
  29471. CFFStrings.prototype = {
  29472. get: function CFFStrings_get(index) {
  29473. if (index >= 0 && index <= 390) {
  29474. return CFFStandardStrings[index];
  29475. }
  29476. if (index - 391 <= this.strings.length) {
  29477. return this.strings[index - 391];
  29478. }
  29479. return CFFStandardStrings[0];
  29480. },
  29481. add: function CFFStrings_add(value) {
  29482. this.strings.push(value);
  29483. },
  29484. get count() {
  29485. return this.strings.length;
  29486. }
  29487. };
  29488. return CFFStrings;
  29489. })();
  29490. var CFFIndex = (function CFFIndexClosure() {
  29491. function CFFIndex() {
  29492. this.objects = [];
  29493. this.length = 0;
  29494. }
  29495. CFFIndex.prototype = {
  29496. add: function CFFIndex_add(data) {
  29497. this.length += data.length;
  29498. this.objects.push(data);
  29499. },
  29500. set: function CFFIndex_set(index, data) {
  29501. this.length += data.length - this.objects[index].length;
  29502. this.objects[index] = data;
  29503. },
  29504. get: function CFFIndex_get(index) {
  29505. return this.objects[index];
  29506. },
  29507. get count() {
  29508. return this.objects.length;
  29509. }
  29510. };
  29511. return CFFIndex;
  29512. })();
  29513. var CFFDict = (function CFFDictClosure() {
  29514. function CFFDict(tables, strings) {
  29515. this.keyToNameMap = tables.keyToNameMap;
  29516. this.nameToKeyMap = tables.nameToKeyMap;
  29517. this.defaults = tables.defaults;
  29518. this.types = tables.types;
  29519. this.opcodes = tables.opcodes;
  29520. this.order = tables.order;
  29521. this.strings = strings;
  29522. this.values = {};
  29523. }
  29524. CFFDict.prototype = {
  29525. // value should always be an array
  29526. setByKey: function CFFDict_setByKey(key, value) {
  29527. if (!(key in this.keyToNameMap)) {
  29528. return false;
  29529. }
  29530. // ignore empty values
  29531. if (value.length === 0) {
  29532. return true;
  29533. }
  29534. var type = this.types[key];
  29535. // remove the array wrapping these types of values
  29536. if (type === 'num' || type === 'sid' || type === 'offset') {
  29537. value = value[0];
  29538. }
  29539. this.values[key] = value;
  29540. return true;
  29541. },
  29542. setByName: function CFFDict_setByName(name, value) {
  29543. if (!(name in this.nameToKeyMap)) {
  29544. error('Invalid dictionary name "' + name + '"');
  29545. }
  29546. this.values[this.nameToKeyMap[name]] = value;
  29547. },
  29548. hasName: function CFFDict_hasName(name) {
  29549. return this.nameToKeyMap[name] in this.values;
  29550. },
  29551. getByName: function CFFDict_getByName(name) {
  29552. if (!(name in this.nameToKeyMap)) {
  29553. error('Invalid dictionary name "' + name + '"');
  29554. }
  29555. var key = this.nameToKeyMap[name];
  29556. if (!(key in this.values)) {
  29557. return this.defaults[key];
  29558. }
  29559. return this.values[key];
  29560. },
  29561. removeByName: function CFFDict_removeByName(name) {
  29562. delete this.values[this.nameToKeyMap[name]];
  29563. }
  29564. };
  29565. CFFDict.createTables = function CFFDict_createTables(layout) {
  29566. var tables = {
  29567. keyToNameMap: {},
  29568. nameToKeyMap: {},
  29569. defaults: {},
  29570. types: {},
  29571. opcodes: {},
  29572. order: []
  29573. };
  29574. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29575. var entry = layout[i];
  29576. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29577. tables.keyToNameMap[key] = entry[1];
  29578. tables.nameToKeyMap[entry[1]] = key;
  29579. tables.types[key] = entry[2];
  29580. tables.defaults[key] = entry[3];
  29581. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29582. tables.order.push(key);
  29583. }
  29584. return tables;
  29585. };
  29586. return CFFDict;
  29587. })();
  29588. var CFFTopDict = (function CFFTopDictClosure() {
  29589. var layout = [
  29590. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29591. [[12, 20], 'SyntheticBase', 'num', null],
  29592. [0, 'version', 'sid', null],
  29593. [1, 'Notice', 'sid', null],
  29594. [[12, 0], 'Copyright', 'sid', null],
  29595. [2, 'FullName', 'sid', null],
  29596. [3, 'FamilyName', 'sid', null],
  29597. [4, 'Weight', 'sid', null],
  29598. [[12, 1], 'isFixedPitch', 'num', 0],
  29599. [[12, 2], 'ItalicAngle', 'num', 0],
  29600. [[12, 3], 'UnderlinePosition', 'num', -100],
  29601. [[12, 4], 'UnderlineThickness', 'num', 50],
  29602. [[12, 5], 'PaintType', 'num', 0],
  29603. [[12, 6], 'CharstringType', 'num', 2],
  29604. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29605. [0.001, 0, 0, 0.001, 0, 0]],
  29606. [13, 'UniqueID', 'num', null],
  29607. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29608. [[12, 8], 'StrokeWidth', 'num', 0],
  29609. [14, 'XUID', 'array', null],
  29610. [15, 'charset', 'offset', 0],
  29611. [16, 'Encoding', 'offset', 0],
  29612. [17, 'CharStrings', 'offset', 0],
  29613. [18, 'Private', ['offset', 'offset'], null],
  29614. [[12, 21], 'PostScript', 'sid', null],
  29615. [[12, 22], 'BaseFontName', 'sid', null],
  29616. [[12, 23], 'BaseFontBlend', 'delta', null],
  29617. [[12, 31], 'CIDFontVersion', 'num', 0],
  29618. [[12, 32], 'CIDFontRevision', 'num', 0],
  29619. [[12, 33], 'CIDFontType', 'num', 0],
  29620. [[12, 34], 'CIDCount', 'num', 8720],
  29621. [[12, 35], 'UIDBase', 'num', null],
  29622. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29623. // before FDArray.
  29624. [[12, 37], 'FDSelect', 'offset', null],
  29625. [[12, 36], 'FDArray', 'offset', null],
  29626. [[12, 38], 'FontName', 'sid', null]
  29627. ];
  29628. var tables = null;
  29629. function CFFTopDict(strings) {
  29630. if (tables === null) {
  29631. tables = CFFDict.createTables(layout);
  29632. }
  29633. CFFDict.call(this, tables, strings);
  29634. this.privateDict = null;
  29635. }
  29636. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29637. return CFFTopDict;
  29638. })();
  29639. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29640. var layout = [
  29641. [6, 'BlueValues', 'delta', null],
  29642. [7, 'OtherBlues', 'delta', null],
  29643. [8, 'FamilyBlues', 'delta', null],
  29644. [9, 'FamilyOtherBlues', 'delta', null],
  29645. [[12, 9], 'BlueScale', 'num', 0.039625],
  29646. [[12, 10], 'BlueShift', 'num', 7],
  29647. [[12, 11], 'BlueFuzz', 'num', 1],
  29648. [10, 'StdHW', 'num', null],
  29649. [11, 'StdVW', 'num', null],
  29650. [[12, 12], 'StemSnapH', 'delta', null],
  29651. [[12, 13], 'StemSnapV', 'delta', null],
  29652. [[12, 14], 'ForceBold', 'num', 0],
  29653. [[12, 17], 'LanguageGroup', 'num', 0],
  29654. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29655. [[12, 19], 'initialRandomSeed', 'num', 0],
  29656. [20, 'defaultWidthX', 'num', 0],
  29657. [21, 'nominalWidthX', 'num', 0],
  29658. [19, 'Subrs', 'offset', null]
  29659. ];
  29660. var tables = null;
  29661. function CFFPrivateDict(strings) {
  29662. if (tables === null) {
  29663. tables = CFFDict.createTables(layout);
  29664. }
  29665. CFFDict.call(this, tables, strings);
  29666. this.subrsIndex = null;
  29667. }
  29668. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29669. return CFFPrivateDict;
  29670. })();
  29671. var CFFCharsetPredefinedTypes = {
  29672. ISO_ADOBE: 0,
  29673. EXPERT: 1,
  29674. EXPERT_SUBSET: 2
  29675. };
  29676. var CFFCharset = (function CFFCharsetClosure() {
  29677. function CFFCharset(predefined, format, charset, raw) {
  29678. this.predefined = predefined;
  29679. this.format = format;
  29680. this.charset = charset;
  29681. this.raw = raw;
  29682. }
  29683. return CFFCharset;
  29684. })();
  29685. var CFFEncoding = (function CFFEncodingClosure() {
  29686. function CFFEncoding(predefined, format, encoding, raw) {
  29687. this.predefined = predefined;
  29688. this.format = format;
  29689. this.encoding = encoding;
  29690. this.raw = raw;
  29691. }
  29692. return CFFEncoding;
  29693. })();
  29694. var CFFFDSelect = (function CFFFDSelectClosure() {
  29695. function CFFFDSelect(fdSelect, raw) {
  29696. this.fdSelect = fdSelect;
  29697. this.raw = raw;
  29698. }
  29699. return CFFFDSelect;
  29700. })();
  29701. // Helper class to keep track of where an offset is within the data and helps
  29702. // filling in that offset once it's known.
  29703. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29704. function CFFOffsetTracker() {
  29705. this.offsets = {};
  29706. }
  29707. CFFOffsetTracker.prototype = {
  29708. isTracking: function CFFOffsetTracker_isTracking(key) {
  29709. return key in this.offsets;
  29710. },
  29711. track: function CFFOffsetTracker_track(key, location) {
  29712. if (key in this.offsets) {
  29713. error('Already tracking location of ' + key);
  29714. }
  29715. this.offsets[key] = location;
  29716. },
  29717. offset: function CFFOffsetTracker_offset(value) {
  29718. for (var key in this.offsets) {
  29719. this.offsets[key] += value;
  29720. }
  29721. },
  29722. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29723. values,
  29724. output) {
  29725. if (!(key in this.offsets)) {
  29726. error('Not tracking location of ' + key);
  29727. }
  29728. var data = output.data;
  29729. var dataOffset = this.offsets[key];
  29730. var size = 5;
  29731. for (var i = 0, ii = values.length; i < ii; ++i) {
  29732. var offset0 = i * size + dataOffset;
  29733. var offset1 = offset0 + 1;
  29734. var offset2 = offset0 + 2;
  29735. var offset3 = offset0 + 3;
  29736. var offset4 = offset0 + 4;
  29737. // It's easy to screw up offsets so perform this sanity check.
  29738. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29739. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29740. error('writing to an offset that is not empty');
  29741. }
  29742. var value = values[i];
  29743. data[offset0] = 0x1d;
  29744. data[offset1] = (value >> 24) & 0xFF;
  29745. data[offset2] = (value >> 16) & 0xFF;
  29746. data[offset3] = (value >> 8) & 0xFF;
  29747. data[offset4] = value & 0xFF;
  29748. }
  29749. }
  29750. };
  29751. return CFFOffsetTracker;
  29752. })();
  29753. // Takes a CFF and converts it to the binary representation.
  29754. var CFFCompiler = (function CFFCompilerClosure() {
  29755. function CFFCompiler(cff) {
  29756. this.cff = cff;
  29757. }
  29758. CFFCompiler.prototype = {
  29759. compile: function CFFCompiler_compile() {
  29760. var cff = this.cff;
  29761. var output = {
  29762. data: [],
  29763. length: 0,
  29764. add: function CFFCompiler_add(data) {
  29765. this.data = this.data.concat(data);
  29766. this.length = this.data.length;
  29767. }
  29768. };
  29769. // Compile the five entries that must be in order.
  29770. var header = this.compileHeader(cff.header);
  29771. output.add(header);
  29772. var nameIndex = this.compileNameIndex(cff.names);
  29773. output.add(nameIndex);
  29774. if (cff.isCIDFont) {
  29775. // The spec is unclear on how font matrices should relate to each other
  29776. // when there is one in the main top dict and the sub top dicts.
  29777. // Windows handles this differently than linux and osx so we have to
  29778. // normalize to work on all.
  29779. // Rules based off of some mailing list discussions:
  29780. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29781. // - If no main font matrix and there is a subfont matrix, use the
  29782. // subfont matrix.
  29783. // - If both have matrices, concat together.
  29784. // - If neither have matrices, use default.
  29785. // To make this work on all platforms we move the top matrix into each
  29786. // sub top dict and concat if necessary.
  29787. if (cff.topDict.hasName('FontMatrix')) {
  29788. var base = cff.topDict.getByName('FontMatrix');
  29789. cff.topDict.removeByName('FontMatrix');
  29790. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29791. var subDict = cff.fdArray[i];
  29792. var matrix = base.slice(0);
  29793. if (subDict.hasName('FontMatrix')) {
  29794. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29795. }
  29796. subDict.setByName('FontMatrix', matrix);
  29797. }
  29798. }
  29799. }
  29800. var compiled = this.compileTopDicts([cff.topDict],
  29801. output.length,
  29802. cff.isCIDFont);
  29803. output.add(compiled.output);
  29804. var topDictTracker = compiled.trackers[0];
  29805. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29806. output.add(stringIndex);
  29807. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29808. output.add(globalSubrIndex);
  29809. // Now start on the other entries that have no specfic order.
  29810. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29811. if (cff.encoding.predefined) {
  29812. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29813. output);
  29814. } else {
  29815. var encoding = this.compileEncoding(cff.encoding);
  29816. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29817. output.add(encoding);
  29818. }
  29819. }
  29820. if (cff.charset && cff.topDict.hasName('charset')) {
  29821. if (cff.charset.predefined) {
  29822. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29823. output);
  29824. } else {
  29825. var charset = this.compileCharset(cff.charset);
  29826. topDictTracker.setEntryLocation('charset', [output.length], output);
  29827. output.add(charset);
  29828. }
  29829. }
  29830. var charStrings = this.compileCharStrings(cff.charStrings);
  29831. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29832. output.add(charStrings);
  29833. if (cff.isCIDFont) {
  29834. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29835. // and linux don't seem to care.
  29836. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29837. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29838. output.add(fdSelect);
  29839. // It is unclear if the sub font dictionary can have CID related
  29840. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29841. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29842. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29843. output.add(compiled.output);
  29844. var fontDictTrackers = compiled.trackers;
  29845. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29846. }
  29847. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29848. // If the font data ends with INDEX whose object data is zero-length,
  29849. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29850. output.add([0]);
  29851. return output.data;
  29852. },
  29853. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29854. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29855. return this.encodeInteger(value);
  29856. } else {
  29857. return this.encodeFloat(value);
  29858. }
  29859. },
  29860. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29861. var value = num.toString();
  29862. // rounding inaccurate doubles
  29863. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  29864. if (m) {
  29865. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  29866. value = (Math.round(num * epsilon) / epsilon).toString();
  29867. }
  29868. var nibbles = '';
  29869. var i, ii;
  29870. for (i = 0, ii = value.length; i < ii; ++i) {
  29871. var a = value[i];
  29872. if (a === 'e') {
  29873. nibbles += value[++i] === '-' ? 'c' : 'b';
  29874. } else if (a === '.') {
  29875. nibbles += 'a';
  29876. } else if (a === '-') {
  29877. nibbles += 'e';
  29878. } else {
  29879. nibbles += a;
  29880. }
  29881. }
  29882. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  29883. var out = [30];
  29884. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  29885. out.push(parseInt(nibbles.substr(i, 2), 16));
  29886. }
  29887. return out;
  29888. },
  29889. encodeInteger: function CFFCompiler_encodeInteger(value) {
  29890. var code;
  29891. if (value >= -107 && value <= 107) {
  29892. code = [value + 139];
  29893. } else if (value >= 108 && value <= 1131) {
  29894. value = [value - 108];
  29895. code = [(value >> 8) + 247, value & 0xFF];
  29896. } else if (value >= -1131 && value <= -108) {
  29897. value = -value - 108;
  29898. code = [(value >> 8) + 251, value & 0xFF];
  29899. } else if (value >= -32768 && value <= 32767) {
  29900. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  29901. } else {
  29902. code = [0x1d,
  29903. (value >> 24) & 0xFF,
  29904. (value >> 16) & 0xFF,
  29905. (value >> 8) & 0xFF,
  29906. value & 0xFF];
  29907. }
  29908. return code;
  29909. },
  29910. compileHeader: function CFFCompiler_compileHeader(header) {
  29911. return [
  29912. header.major,
  29913. header.minor,
  29914. header.hdrSize,
  29915. header.offSize
  29916. ];
  29917. },
  29918. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  29919. var nameIndex = new CFFIndex();
  29920. for (var i = 0, ii = names.length; i < ii; ++i) {
  29921. nameIndex.add(stringToBytes(names[i]));
  29922. }
  29923. return this.compileIndex(nameIndex);
  29924. },
  29925. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  29926. length,
  29927. removeCidKeys) {
  29928. var fontDictTrackers = [];
  29929. var fdArrayIndex = new CFFIndex();
  29930. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29931. var fontDict = dicts[i];
  29932. if (removeCidKeys) {
  29933. fontDict.removeByName('CIDFontVersion');
  29934. fontDict.removeByName('CIDFontRevision');
  29935. fontDict.removeByName('CIDFontType');
  29936. fontDict.removeByName('CIDCount');
  29937. fontDict.removeByName('UIDBase');
  29938. }
  29939. var fontDictTracker = new CFFOffsetTracker();
  29940. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  29941. fontDictTrackers.push(fontDictTracker);
  29942. fdArrayIndex.add(fontDictData);
  29943. fontDictTracker.offset(length);
  29944. }
  29945. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  29946. return {
  29947. trackers: fontDictTrackers,
  29948. output: fdArrayIndex
  29949. };
  29950. },
  29951. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  29952. trackers,
  29953. output) {
  29954. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29955. var fontDict = dicts[i];
  29956. assert(fontDict.privateDict && fontDict.hasName('Private'),
  29957. 'There must be an private dictionary.');
  29958. var privateDict = fontDict.privateDict;
  29959. var privateDictTracker = new CFFOffsetTracker();
  29960. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  29961. var outputLength = output.length;
  29962. privateDictTracker.offset(outputLength);
  29963. if (!privateDictData.length) {
  29964. // The private dictionary was empty, set the output length to zero to
  29965. // ensure the offset length isn't out of bounds in the eyes of the
  29966. // sanitizer.
  29967. outputLength = 0;
  29968. }
  29969. trackers[i].setEntryLocation('Private',
  29970. [privateDictData.length, outputLength],
  29971. output);
  29972. output.add(privateDictData);
  29973. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  29974. var subrs = this.compileIndex(privateDict.subrsIndex);
  29975. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  29976. output);
  29977. output.add(subrs);
  29978. }
  29979. }
  29980. },
  29981. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  29982. var out = [];
  29983. // The dictionary keys must be in a certain order.
  29984. var order = dict.order;
  29985. for (var i = 0; i < order.length; ++i) {
  29986. var key = order[i];
  29987. if (!(key in dict.values)) {
  29988. continue;
  29989. }
  29990. var values = dict.values[key];
  29991. var types = dict.types[key];
  29992. if (!isArray(types)) {
  29993. types = [types];
  29994. }
  29995. if (!isArray(values)) {
  29996. values = [values];
  29997. }
  29998. // Remove any empty dict values.
  29999. if (values.length === 0) {
  30000. continue;
  30001. }
  30002. for (var j = 0, jj = types.length; j < jj; ++j) {
  30003. var type = types[j];
  30004. var value = values[j];
  30005. switch (type) {
  30006. case 'num':
  30007. case 'sid':
  30008. out = out.concat(this.encodeNumber(value));
  30009. break;
  30010. case 'offset':
  30011. // For offsets we just insert a 32bit integer so we don't have to
  30012. // deal with figuring out the length of the offset when it gets
  30013. // replaced later on by the compiler.
  30014. var name = dict.keyToNameMap[key];
  30015. // Some offsets have the offset and the length, so just record the
  30016. // position of the first one.
  30017. if (!offsetTracker.isTracking(name)) {
  30018. offsetTracker.track(name, out.length);
  30019. }
  30020. out = out.concat([0x1d, 0, 0, 0, 0]);
  30021. break;
  30022. case 'array':
  30023. case 'delta':
  30024. out = out.concat(this.encodeNumber(value));
  30025. for (var k = 1, kk = values.length; k < kk; ++k) {
  30026. out = out.concat(this.encodeNumber(values[k]));
  30027. }
  30028. break;
  30029. default:
  30030. error('Unknown data type of ' + type);
  30031. break;
  30032. }
  30033. }
  30034. out = out.concat(dict.opcodes[key]);
  30035. }
  30036. return out;
  30037. },
  30038. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  30039. var stringIndex = new CFFIndex();
  30040. for (var i = 0, ii = strings.length; i < ii; ++i) {
  30041. stringIndex.add(stringToBytes(strings[i]));
  30042. }
  30043. return this.compileIndex(stringIndex);
  30044. },
  30045. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  30046. var globalSubrIndex = this.cff.globalSubrIndex;
  30047. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  30048. },
  30049. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  30050. return this.compileIndex(charStrings);
  30051. },
  30052. compileCharset: function CFFCompiler_compileCharset(charset) {
  30053. return this.compileTypedArray(charset.raw);
  30054. },
  30055. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  30056. return this.compileTypedArray(encoding.raw);
  30057. },
  30058. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  30059. return this.compileTypedArray(fdSelect);
  30060. },
  30061. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  30062. var out = [];
  30063. for (var i = 0, ii = data.length; i < ii; ++i) {
  30064. out[i] = data[i];
  30065. }
  30066. return out;
  30067. },
  30068. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  30069. trackers = trackers || [];
  30070. var objects = index.objects;
  30071. // First 2 bytes contains the number of objects contained into this index
  30072. var count = objects.length;
  30073. // If there is no object, just create an index. This technically
  30074. // should just be [0, 0] but OTS has an issue with that.
  30075. if (count === 0) {
  30076. return [0, 0, 0];
  30077. }
  30078. var data = [(count >> 8) & 0xFF, count & 0xff];
  30079. var lastOffset = 1, i;
  30080. for (i = 0; i < count; ++i) {
  30081. lastOffset += objects[i].length;
  30082. }
  30083. var offsetSize;
  30084. if (lastOffset < 0x100) {
  30085. offsetSize = 1;
  30086. } else if (lastOffset < 0x10000) {
  30087. offsetSize = 2;
  30088. } else if (lastOffset < 0x1000000) {
  30089. offsetSize = 3;
  30090. } else {
  30091. offsetSize = 4;
  30092. }
  30093. // Next byte contains the offset size use to reference object in the file
  30094. data.push(offsetSize);
  30095. // Add another offset after this one because we need a new offset
  30096. var relativeOffset = 1;
  30097. for (i = 0; i < count + 1; i++) {
  30098. if (offsetSize === 1) {
  30099. data.push(relativeOffset & 0xFF);
  30100. } else if (offsetSize === 2) {
  30101. data.push((relativeOffset >> 8) & 0xFF,
  30102. relativeOffset & 0xFF);
  30103. } else if (offsetSize === 3) {
  30104. data.push((relativeOffset >> 16) & 0xFF,
  30105. (relativeOffset >> 8) & 0xFF,
  30106. relativeOffset & 0xFF);
  30107. } else {
  30108. data.push((relativeOffset >>> 24) & 0xFF,
  30109. (relativeOffset >> 16) & 0xFF,
  30110. (relativeOffset >> 8) & 0xFF,
  30111. relativeOffset & 0xFF);
  30112. }
  30113. if (objects[i]) {
  30114. relativeOffset += objects[i].length;
  30115. }
  30116. }
  30117. for (i = 0; i < count; i++) {
  30118. // Notify the tracker where the object will be offset in the data.
  30119. if (trackers[i]) {
  30120. trackers[i].offset(data.length);
  30121. }
  30122. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  30123. data.push(objects[i][j]);
  30124. }
  30125. }
  30126. return data;
  30127. }
  30128. };
  30129. return CFFCompiler;
  30130. })();
  30131. function _enableSeacAnalysis(enabled) {
  30132. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  30133. }
  30134. // Workaround for seac on Windows.
  30135. (function checkSeacSupport() {
  30136. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  30137. SEAC_ANALYSIS_ENABLED = true;
  30138. }
  30139. })();
  30140. // Workaround for Private Use Area characters in Chrome on Windows
  30141. // http://code.google.com/p/chromium/issues/detail?id=122465
  30142. // https://github.com/mozilla/pdf.js/issues/1689
  30143. (function checkChromeWindows() {
  30144. if (typeof navigator !== 'undefined' &&
  30145. /Windows.*Chrome/.test(navigator.userAgent)) {
  30146. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  30147. }
  30148. })();
  30149. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  30150. exports.CFFCompiler = CFFCompiler;
  30151. exports.CFFIndex = CFFIndex;
  30152. exports.CFFParser = CFFParser;
  30153. exports.CFFStrings = CFFStrings;
  30154. exports.Encodings = Encodings;
  30155. exports.ErrorFont = ErrorFont;
  30156. exports.FontFlags = FontFlags;
  30157. exports.Font = Font;
  30158. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  30159. exports.NormalizedUnicodes = NormalizedUnicodes;
  30160. exports.ToUnicodeMap = ToUnicodeMap;
  30161. exports.Type1Parser = Type1Parser;
  30162. exports.getFontType = getFontType;
  30163. exports.reverseIfRtl = reverseIfRtl;
  30164. exports.serifFonts = serifFonts;
  30165. exports.symbolsFonts = symbolsFonts;
  30166. exports.stdFontMap = stdFontMap;
  30167. exports._enableSeacAnalysis = _enableSeacAnalysis;
  30168. // TODO refactor to remove cyclic dependency on font_renderer.js
  30169. coreFontRenderer._setCoreFonts(exports);
  30170. }));
  30171. (function (root, factory) {
  30172. {
  30173. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  30174. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  30175. }
  30176. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  30177. var error = sharedUtil.error;
  30178. var info = sharedUtil.info;
  30179. var isArray = sharedUtil.isArray;
  30180. var isBool = sharedUtil.isBool;
  30181. var isDict = corePrimitives.isDict;
  30182. var isStream = corePrimitives.isStream;
  30183. var PostScriptLexer = corePsParser.PostScriptLexer;
  30184. var PostScriptParser = corePsParser.PostScriptParser;
  30185. var PDFFunction = (function PDFFunctionClosure() {
  30186. var CONSTRUCT_SAMPLED = 0;
  30187. var CONSTRUCT_INTERPOLATED = 2;
  30188. var CONSTRUCT_STICHED = 3;
  30189. var CONSTRUCT_POSTSCRIPT = 4;
  30190. return {
  30191. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  30192. str) {
  30193. var i, ii;
  30194. var length = 1;
  30195. for (i = 0, ii = size.length; i < ii; i++) {
  30196. length *= size[i];
  30197. }
  30198. length *= outputSize;
  30199. var array = new Array(length);
  30200. var codeSize = 0;
  30201. var codeBuf = 0;
  30202. // 32 is a valid bps so shifting won't work
  30203. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  30204. var strBytes = str.getBytes((length * bps + 7) / 8);
  30205. var strIdx = 0;
  30206. for (i = 0; i < length; i++) {
  30207. while (codeSize < bps) {
  30208. codeBuf <<= 8;
  30209. codeBuf |= strBytes[strIdx++];
  30210. codeSize += 8;
  30211. }
  30212. codeSize -= bps;
  30213. array[i] = (codeBuf >> codeSize) * sampleMul;
  30214. codeBuf &= (1 << codeSize) - 1;
  30215. }
  30216. return array;
  30217. },
  30218. getIR: function PDFFunction_getIR(xref, fn) {
  30219. var dict = fn.dict;
  30220. if (!dict) {
  30221. dict = fn;
  30222. }
  30223. var types = [this.constructSampled,
  30224. null,
  30225. this.constructInterpolated,
  30226. this.constructStiched,
  30227. this.constructPostScript];
  30228. var typeNum = dict.get('FunctionType');
  30229. var typeFn = types[typeNum];
  30230. if (!typeFn) {
  30231. error('Unknown type of function');
  30232. }
  30233. return typeFn.call(this, fn, dict, xref);
  30234. },
  30235. fromIR: function PDFFunction_fromIR(IR) {
  30236. var type = IR[0];
  30237. switch (type) {
  30238. case CONSTRUCT_SAMPLED:
  30239. return this.constructSampledFromIR(IR);
  30240. case CONSTRUCT_INTERPOLATED:
  30241. return this.constructInterpolatedFromIR(IR);
  30242. case CONSTRUCT_STICHED:
  30243. return this.constructStichedFromIR(IR);
  30244. //case CONSTRUCT_POSTSCRIPT:
  30245. default:
  30246. return this.constructPostScriptFromIR(IR);
  30247. }
  30248. },
  30249. parse: function PDFFunction_parse(xref, fn) {
  30250. var IR = this.getIR(xref, fn);
  30251. return this.fromIR(IR);
  30252. },
  30253. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  30254. if (!isArray(fnObj)) {
  30255. // not an array -- parsing as regular function
  30256. return this.parse(xref, fnObj);
  30257. }
  30258. var fnArray = [];
  30259. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  30260. var obj = xref.fetchIfRef(fnObj[j]);
  30261. fnArray.push(PDFFunction.parse(xref, obj));
  30262. }
  30263. return function (src, srcOffset, dest, destOffset) {
  30264. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  30265. fnArray[i](src, srcOffset, dest, destOffset + i);
  30266. }
  30267. };
  30268. },
  30269. constructSampled: function PDFFunction_constructSampled(str, dict) {
  30270. function toMultiArray(arr) {
  30271. var inputLength = arr.length;
  30272. var out = [];
  30273. var index = 0;
  30274. for (var i = 0; i < inputLength; i += 2) {
  30275. out[index] = [arr[i], arr[i + 1]];
  30276. ++index;
  30277. }
  30278. return out;
  30279. }
  30280. var domain = dict.get('Domain');
  30281. var range = dict.get('Range');
  30282. if (!domain || !range) {
  30283. error('No domain or range');
  30284. }
  30285. var inputSize = domain.length / 2;
  30286. var outputSize = range.length / 2;
  30287. domain = toMultiArray(domain);
  30288. range = toMultiArray(range);
  30289. var size = dict.get('Size');
  30290. var bps = dict.get('BitsPerSample');
  30291. var order = dict.get('Order') || 1;
  30292. if (order !== 1) {
  30293. // No description how cubic spline interpolation works in PDF32000:2008
  30294. // As in poppler, ignoring order, linear interpolation may work as good
  30295. info('No support for cubic spline interpolation: ' + order);
  30296. }
  30297. var encode = dict.get('Encode');
  30298. if (!encode) {
  30299. encode = [];
  30300. for (var i = 0; i < inputSize; ++i) {
  30301. encode.push(0);
  30302. encode.push(size[i] - 1);
  30303. }
  30304. }
  30305. encode = toMultiArray(encode);
  30306. var decode = dict.get('Decode');
  30307. if (!decode) {
  30308. decode = range;
  30309. } else {
  30310. decode = toMultiArray(decode);
  30311. }
  30312. var samples = this.getSampleArray(size, outputSize, bps, str);
  30313. return [
  30314. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  30315. outputSize, Math.pow(2, bps) - 1, range
  30316. ];
  30317. },
  30318. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  30319. // See chapter 3, page 109 of the PDF reference
  30320. function interpolate(x, xmin, xmax, ymin, ymax) {
  30321. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  30322. }
  30323. return function constructSampledFromIRResult(src, srcOffset,
  30324. dest, destOffset) {
  30325. // See chapter 3, page 110 of the PDF reference.
  30326. var m = IR[1];
  30327. var domain = IR[2];
  30328. var encode = IR[3];
  30329. var decode = IR[4];
  30330. var samples = IR[5];
  30331. var size = IR[6];
  30332. var n = IR[7];
  30333. //var mask = IR[8];
  30334. var range = IR[9];
  30335. // Building the cube vertices: its part and sample index
  30336. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  30337. var cubeVertices = 1 << m;
  30338. var cubeN = new Float64Array(cubeVertices);
  30339. var cubeVertex = new Uint32Array(cubeVertices);
  30340. var i, j;
  30341. for (j = 0; j < cubeVertices; j++) {
  30342. cubeN[j] = 1;
  30343. }
  30344. var k = n, pos = 1;
  30345. // Map x_i to y_j for 0 <= i < m using the sampled function.
  30346. for (i = 0; i < m; ++i) {
  30347. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  30348. var domain_2i = domain[i][0];
  30349. var domain_2i_1 = domain[i][1];
  30350. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  30351. domain_2i_1);
  30352. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  30353. // Encode_2i, Encode_2i+1)
  30354. var e = interpolate(xi, domain_2i, domain_2i_1,
  30355. encode[i][0], encode[i][1]);
  30356. // e_i' = min(max(e_i, 0), Size_i - 1)
  30357. var size_i = size[i];
  30358. e = Math.min(Math.max(e, 0), size_i - 1);
  30359. // Adjusting the cube: N and vertex sample index
  30360. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  30361. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  30362. var n1 = e - e0; // (e - e0) / (e1 - e0);
  30363. var offset0 = e0 * k;
  30364. var offset1 = offset0 + k; // e1 * k
  30365. for (j = 0; j < cubeVertices; j++) {
  30366. if (j & pos) {
  30367. cubeN[j] *= n1;
  30368. cubeVertex[j] += offset1;
  30369. } else {
  30370. cubeN[j] *= n0;
  30371. cubeVertex[j] += offset0;
  30372. }
  30373. }
  30374. k *= size_i;
  30375. pos <<= 1;
  30376. }
  30377. for (j = 0; j < n; ++j) {
  30378. // Sum all cube vertices' samples portions
  30379. var rj = 0;
  30380. for (i = 0; i < cubeVertices; i++) {
  30381. rj += samples[cubeVertex[i] + j] * cubeN[i];
  30382. }
  30383. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  30384. // Decode_2j, Decode_2j+1)
  30385. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  30386. // y_j = min(max(r_j, range_2j), range_2j+1)
  30387. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  30388. range[j][1]);
  30389. }
  30390. };
  30391. },
  30392. constructInterpolated: function PDFFunction_constructInterpolated(str,
  30393. dict) {
  30394. var c0 = dict.get('C0') || [0];
  30395. var c1 = dict.get('C1') || [1];
  30396. var n = dict.get('N');
  30397. if (!isArray(c0) || !isArray(c1)) {
  30398. error('Illegal dictionary for interpolated function');
  30399. }
  30400. var length = c0.length;
  30401. var diff = [];
  30402. for (var i = 0; i < length; ++i) {
  30403. diff.push(c1[i] - c0[i]);
  30404. }
  30405. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30406. },
  30407. constructInterpolatedFromIR:
  30408. function PDFFunction_constructInterpolatedFromIR(IR) {
  30409. var c0 = IR[1];
  30410. var diff = IR[2];
  30411. var n = IR[3];
  30412. var length = diff.length;
  30413. return function constructInterpolatedFromIRResult(src, srcOffset,
  30414. dest, destOffset) {
  30415. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30416. for (var j = 0; j < length; ++j) {
  30417. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30418. }
  30419. };
  30420. },
  30421. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30422. var domain = dict.get('Domain');
  30423. if (!domain) {
  30424. error('No domain');
  30425. }
  30426. var inputSize = domain.length / 2;
  30427. if (inputSize !== 1) {
  30428. error('Bad domain for stiched function');
  30429. }
  30430. var fnRefs = dict.get('Functions');
  30431. var fns = [];
  30432. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30433. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30434. }
  30435. var bounds = dict.get('Bounds');
  30436. var encode = dict.get('Encode');
  30437. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30438. },
  30439. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30440. var domain = IR[1];
  30441. var bounds = IR[2];
  30442. var encode = IR[3];
  30443. var fnsIR = IR[4];
  30444. var fns = [];
  30445. var tmpBuf = new Float32Array(1);
  30446. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30447. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30448. }
  30449. return function constructStichedFromIRResult(src, srcOffset,
  30450. dest, destOffset) {
  30451. var clip = function constructStichedFromIRClip(v, min, max) {
  30452. if (v > max) {
  30453. v = max;
  30454. } else if (v < min) {
  30455. v = min;
  30456. }
  30457. return v;
  30458. };
  30459. // clip to domain
  30460. var v = clip(src[srcOffset], domain[0], domain[1]);
  30461. // calulate which bound the value is in
  30462. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30463. if (v < bounds[i]) {
  30464. break;
  30465. }
  30466. }
  30467. // encode value into domain of function
  30468. var dmin = domain[0];
  30469. if (i > 0) {
  30470. dmin = bounds[i - 1];
  30471. }
  30472. var dmax = domain[1];
  30473. if (i < bounds.length) {
  30474. dmax = bounds[i];
  30475. }
  30476. var rmin = encode[2 * i];
  30477. var rmax = encode[2 * i + 1];
  30478. // Prevent the value from becoming NaN as a result
  30479. // of division by zero (fixes issue6113.pdf).
  30480. tmpBuf[0] = dmin === dmax ? rmin :
  30481. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30482. // call the appropriate function
  30483. fns[i](tmpBuf, 0, dest, destOffset);
  30484. };
  30485. },
  30486. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30487. xref) {
  30488. var domain = dict.get('Domain');
  30489. var range = dict.get('Range');
  30490. if (!domain) {
  30491. error('No domain.');
  30492. }
  30493. if (!range) {
  30494. error('No range.');
  30495. }
  30496. var lexer = new PostScriptLexer(fn);
  30497. var parser = new PostScriptParser(lexer);
  30498. var code = parser.parse();
  30499. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30500. },
  30501. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30502. IR) {
  30503. var domain = IR[1];
  30504. var range = IR[2];
  30505. var code = IR[3];
  30506. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30507. if (compiled) {
  30508. // Compiled function consists of simple expressions such as addition,
  30509. // subtraction, Math.max, and also contains 'var' and 'return'
  30510. // statements. See the generation in the PostScriptCompiler below.
  30511. /*jshint -W054 */
  30512. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30513. }
  30514. info('Unable to compile PS function');
  30515. var numOutputs = range.length >> 1;
  30516. var numInputs = domain.length >> 1;
  30517. var evaluator = new PostScriptEvaluator(code);
  30518. // Cache the values for a big speed up, the cache size is limited though
  30519. // since the number of possible values can be huge from a PS function.
  30520. var cache = {};
  30521. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30522. // seen in our tests.
  30523. var MAX_CACHE_SIZE = 2048 * 4;
  30524. var cache_available = MAX_CACHE_SIZE;
  30525. var tmpBuf = new Float32Array(numInputs);
  30526. return function constructPostScriptFromIRResult(src, srcOffset,
  30527. dest, destOffset) {
  30528. var i, value;
  30529. var key = '';
  30530. var input = tmpBuf;
  30531. for (i = 0; i < numInputs; i++) {
  30532. value = src[srcOffset + i];
  30533. input[i] = value;
  30534. key += value + '_';
  30535. }
  30536. var cachedValue = cache[key];
  30537. if (cachedValue !== undefined) {
  30538. dest.set(cachedValue, destOffset);
  30539. return;
  30540. }
  30541. var output = new Float32Array(numOutputs);
  30542. var stack = evaluator.execute(input);
  30543. var stackIndex = stack.length - numOutputs;
  30544. for (i = 0; i < numOutputs; i++) {
  30545. value = stack[stackIndex + i];
  30546. var bound = range[i * 2];
  30547. if (value < bound) {
  30548. value = bound;
  30549. } else {
  30550. bound = range[i * 2 +1];
  30551. if (value > bound) {
  30552. value = bound;
  30553. }
  30554. }
  30555. output[i] = value;
  30556. }
  30557. if (cache_available > 0) {
  30558. cache_available--;
  30559. cache[key] = output;
  30560. }
  30561. dest.set(output, destOffset);
  30562. };
  30563. }
  30564. };
  30565. })();
  30566. function isPDFFunction(v) {
  30567. var fnDict;
  30568. if (typeof v !== 'object') {
  30569. return false;
  30570. } else if (isDict(v)) {
  30571. fnDict = v;
  30572. } else if (isStream(v)) {
  30573. fnDict = v.dict;
  30574. } else {
  30575. return false;
  30576. }
  30577. return fnDict.has('FunctionType');
  30578. }
  30579. var PostScriptStack = (function PostScriptStackClosure() {
  30580. var MAX_STACK_SIZE = 100;
  30581. function PostScriptStack(initialStack) {
  30582. this.stack = !initialStack ? [] :
  30583. Array.prototype.slice.call(initialStack, 0);
  30584. }
  30585. PostScriptStack.prototype = {
  30586. push: function PostScriptStack_push(value) {
  30587. if (this.stack.length >= MAX_STACK_SIZE) {
  30588. error('PostScript function stack overflow.');
  30589. }
  30590. this.stack.push(value);
  30591. },
  30592. pop: function PostScriptStack_pop() {
  30593. if (this.stack.length <= 0) {
  30594. error('PostScript function stack underflow.');
  30595. }
  30596. return this.stack.pop();
  30597. },
  30598. copy: function PostScriptStack_copy(n) {
  30599. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30600. error('PostScript function stack overflow.');
  30601. }
  30602. var stack = this.stack;
  30603. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30604. stack.push(stack[i]);
  30605. }
  30606. },
  30607. index: function PostScriptStack_index(n) {
  30608. this.push(this.stack[this.stack.length - n - 1]);
  30609. },
  30610. // rotate the last n stack elements p times
  30611. roll: function PostScriptStack_roll(n, p) {
  30612. var stack = this.stack;
  30613. var l = stack.length - n;
  30614. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30615. for (i = l, j = r; i < j; i++, j--) {
  30616. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30617. }
  30618. for (i = l, j = c - 1; i < j; i++, j--) {
  30619. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30620. }
  30621. for (i = c, j = r; i < j; i++, j--) {
  30622. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30623. }
  30624. }
  30625. };
  30626. return PostScriptStack;
  30627. })();
  30628. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30629. function PostScriptEvaluator(operators) {
  30630. this.operators = operators;
  30631. }
  30632. PostScriptEvaluator.prototype = {
  30633. execute: function PostScriptEvaluator_execute(initialStack) {
  30634. var stack = new PostScriptStack(initialStack);
  30635. var counter = 0;
  30636. var operators = this.operators;
  30637. var length = operators.length;
  30638. var operator, a, b;
  30639. while (counter < length) {
  30640. operator = operators[counter++];
  30641. if (typeof operator === 'number') {
  30642. // Operator is really an operand and should be pushed to the stack.
  30643. stack.push(operator);
  30644. continue;
  30645. }
  30646. switch (operator) {
  30647. // non standard ps operators
  30648. case 'jz': // jump if false
  30649. b = stack.pop();
  30650. a = stack.pop();
  30651. if (!a) {
  30652. counter = b;
  30653. }
  30654. break;
  30655. case 'j': // jump
  30656. a = stack.pop();
  30657. counter = a;
  30658. break;
  30659. // all ps operators in alphabetical order (excluding if/ifelse)
  30660. case 'abs':
  30661. a = stack.pop();
  30662. stack.push(Math.abs(a));
  30663. break;
  30664. case 'add':
  30665. b = stack.pop();
  30666. a = stack.pop();
  30667. stack.push(a + b);
  30668. break;
  30669. case 'and':
  30670. b = stack.pop();
  30671. a = stack.pop();
  30672. if (isBool(a) && isBool(b)) {
  30673. stack.push(a && b);
  30674. } else {
  30675. stack.push(a & b);
  30676. }
  30677. break;
  30678. case 'atan':
  30679. a = stack.pop();
  30680. stack.push(Math.atan(a));
  30681. break;
  30682. case 'bitshift':
  30683. b = stack.pop();
  30684. a = stack.pop();
  30685. if (a > 0) {
  30686. stack.push(a << b);
  30687. } else {
  30688. stack.push(a >> b);
  30689. }
  30690. break;
  30691. case 'ceiling':
  30692. a = stack.pop();
  30693. stack.push(Math.ceil(a));
  30694. break;
  30695. case 'copy':
  30696. a = stack.pop();
  30697. stack.copy(a);
  30698. break;
  30699. case 'cos':
  30700. a = stack.pop();
  30701. stack.push(Math.cos(a));
  30702. break;
  30703. case 'cvi':
  30704. a = stack.pop() | 0;
  30705. stack.push(a);
  30706. break;
  30707. case 'cvr':
  30708. // noop
  30709. break;
  30710. case 'div':
  30711. b = stack.pop();
  30712. a = stack.pop();
  30713. stack.push(a / b);
  30714. break;
  30715. case 'dup':
  30716. stack.copy(1);
  30717. break;
  30718. case 'eq':
  30719. b = stack.pop();
  30720. a = stack.pop();
  30721. stack.push(a === b);
  30722. break;
  30723. case 'exch':
  30724. stack.roll(2, 1);
  30725. break;
  30726. case 'exp':
  30727. b = stack.pop();
  30728. a = stack.pop();
  30729. stack.push(Math.pow(a, b));
  30730. break;
  30731. case 'false':
  30732. stack.push(false);
  30733. break;
  30734. case 'floor':
  30735. a = stack.pop();
  30736. stack.push(Math.floor(a));
  30737. break;
  30738. case 'ge':
  30739. b = stack.pop();
  30740. a = stack.pop();
  30741. stack.push(a >= b);
  30742. break;
  30743. case 'gt':
  30744. b = stack.pop();
  30745. a = stack.pop();
  30746. stack.push(a > b);
  30747. break;
  30748. case 'idiv':
  30749. b = stack.pop();
  30750. a = stack.pop();
  30751. stack.push((a / b) | 0);
  30752. break;
  30753. case 'index':
  30754. a = stack.pop();
  30755. stack.index(a);
  30756. break;
  30757. case 'le':
  30758. b = stack.pop();
  30759. a = stack.pop();
  30760. stack.push(a <= b);
  30761. break;
  30762. case 'ln':
  30763. a = stack.pop();
  30764. stack.push(Math.log(a));
  30765. break;
  30766. case 'log':
  30767. a = stack.pop();
  30768. stack.push(Math.log(a) / Math.LN10);
  30769. break;
  30770. case 'lt':
  30771. b = stack.pop();
  30772. a = stack.pop();
  30773. stack.push(a < b);
  30774. break;
  30775. case 'mod':
  30776. b = stack.pop();
  30777. a = stack.pop();
  30778. stack.push(a % b);
  30779. break;
  30780. case 'mul':
  30781. b = stack.pop();
  30782. a = stack.pop();
  30783. stack.push(a * b);
  30784. break;
  30785. case 'ne':
  30786. b = stack.pop();
  30787. a = stack.pop();
  30788. stack.push(a !== b);
  30789. break;
  30790. case 'neg':
  30791. a = stack.pop();
  30792. stack.push(-a);
  30793. break;
  30794. case 'not':
  30795. a = stack.pop();
  30796. if (isBool(a)) {
  30797. stack.push(!a);
  30798. } else {
  30799. stack.push(~a);
  30800. }
  30801. break;
  30802. case 'or':
  30803. b = stack.pop();
  30804. a = stack.pop();
  30805. if (isBool(a) && isBool(b)) {
  30806. stack.push(a || b);
  30807. } else {
  30808. stack.push(a | b);
  30809. }
  30810. break;
  30811. case 'pop':
  30812. stack.pop();
  30813. break;
  30814. case 'roll':
  30815. b = stack.pop();
  30816. a = stack.pop();
  30817. stack.roll(a, b);
  30818. break;
  30819. case 'round':
  30820. a = stack.pop();
  30821. stack.push(Math.round(a));
  30822. break;
  30823. case 'sin':
  30824. a = stack.pop();
  30825. stack.push(Math.sin(a));
  30826. break;
  30827. case 'sqrt':
  30828. a = stack.pop();
  30829. stack.push(Math.sqrt(a));
  30830. break;
  30831. case 'sub':
  30832. b = stack.pop();
  30833. a = stack.pop();
  30834. stack.push(a - b);
  30835. break;
  30836. case 'true':
  30837. stack.push(true);
  30838. break;
  30839. case 'truncate':
  30840. a = stack.pop();
  30841. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30842. stack.push(a);
  30843. break;
  30844. case 'xor':
  30845. b = stack.pop();
  30846. a = stack.pop();
  30847. if (isBool(a) && isBool(b)) {
  30848. stack.push(a !== b);
  30849. } else {
  30850. stack.push(a ^ b);
  30851. }
  30852. break;
  30853. default:
  30854. error('Unknown operator ' + operator);
  30855. break;
  30856. }
  30857. }
  30858. return stack.stack;
  30859. }
  30860. };
  30861. return PostScriptEvaluator;
  30862. })();
  30863. // Most of the PDFs functions consist of simple operations such as:
  30864. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30865. //
  30866. // We can compile most of such programs, and at the same moment, we can
  30867. // optimize some expressions using basic math properties. Keeping track of
  30868. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30869. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30870. function AstNode(type) {
  30871. this.type = type;
  30872. }
  30873. AstNode.prototype.visit = function (visitor) {
  30874. throw new Error('abstract method');
  30875. };
  30876. function AstArgument(index, min, max) {
  30877. AstNode.call(this, 'args');
  30878. this.index = index;
  30879. this.min = min;
  30880. this.max = max;
  30881. }
  30882. AstArgument.prototype = Object.create(AstNode.prototype);
  30883. AstArgument.prototype.visit = function (visitor) {
  30884. visitor.visitArgument(this);
  30885. };
  30886. function AstLiteral(number) {
  30887. AstNode.call(this, 'literal');
  30888. this.number = number;
  30889. this.min = number;
  30890. this.max = number;
  30891. }
  30892. AstLiteral.prototype = Object.create(AstNode.prototype);
  30893. AstLiteral.prototype.visit = function (visitor) {
  30894. visitor.visitLiteral(this);
  30895. };
  30896. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30897. AstNode.call(this, 'binary');
  30898. this.op = op;
  30899. this.arg1 = arg1;
  30900. this.arg2 = arg2;
  30901. this.min = min;
  30902. this.max = max;
  30903. }
  30904. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30905. AstBinaryOperation.prototype.visit = function (visitor) {
  30906. visitor.visitBinaryOperation(this);
  30907. };
  30908. function AstMin(arg, max) {
  30909. AstNode.call(this, 'max');
  30910. this.arg = arg;
  30911. this.min = arg.min;
  30912. this.max = max;
  30913. }
  30914. AstMin.prototype = Object.create(AstNode.prototype);
  30915. AstMin.prototype.visit = function (visitor) {
  30916. visitor.visitMin(this);
  30917. };
  30918. function AstVariable(index, min, max) {
  30919. AstNode.call(this, 'var');
  30920. this.index = index;
  30921. this.min = min;
  30922. this.max = max;
  30923. }
  30924. AstVariable.prototype = Object.create(AstNode.prototype);
  30925. AstVariable.prototype.visit = function (visitor) {
  30926. visitor.visitVariable(this);
  30927. };
  30928. function AstVariableDefinition(variable, arg) {
  30929. AstNode.call(this, 'definition');
  30930. this.variable = variable;
  30931. this.arg = arg;
  30932. }
  30933. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30934. AstVariableDefinition.prototype.visit = function (visitor) {
  30935. visitor.visitVariableDefinition(this);
  30936. };
  30937. function ExpressionBuilderVisitor() {
  30938. this.parts = [];
  30939. }
  30940. ExpressionBuilderVisitor.prototype = {
  30941. visitArgument: function (arg) {
  30942. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30943. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30944. },
  30945. visitVariable: function (variable) {
  30946. this.parts.push('v', variable.index);
  30947. },
  30948. visitLiteral: function (literal) {
  30949. this.parts.push(literal.number);
  30950. },
  30951. visitBinaryOperation: function (operation) {
  30952. this.parts.push('(');
  30953. operation.arg1.visit(this);
  30954. this.parts.push(' ', operation.op, ' ');
  30955. operation.arg2.visit(this);
  30956. this.parts.push(')');
  30957. },
  30958. visitVariableDefinition: function (definition) {
  30959. this.parts.push('var ');
  30960. definition.variable.visit(this);
  30961. this.parts.push(' = ');
  30962. definition.arg.visit(this);
  30963. this.parts.push(';');
  30964. },
  30965. visitMin: function (max) {
  30966. this.parts.push('Math.min(');
  30967. max.arg.visit(this);
  30968. this.parts.push(', ', max.max, ')');
  30969. },
  30970. toString: function () {
  30971. return this.parts.join('');
  30972. }
  30973. };
  30974. function buildAddOperation(num1, num2) {
  30975. if (num2.type === 'literal' && num2.number === 0) {
  30976. // optimization: second operand is 0
  30977. return num1;
  30978. }
  30979. if (num1.type === 'literal' && num1.number === 0) {
  30980. // optimization: first operand is 0
  30981. return num2;
  30982. }
  30983. if (num2.type === 'literal' && num1.type === 'literal') {
  30984. // optimization: operands operand are literals
  30985. return new AstLiteral(num1.number + num2.number);
  30986. }
  30987. return new AstBinaryOperation('+', num1, num2,
  30988. num1.min + num2.min, num1.max + num2.max);
  30989. }
  30990. function buildMulOperation(num1, num2) {
  30991. if (num2.type === 'literal') {
  30992. // optimization: second operands is a literal...
  30993. if (num2.number === 0) {
  30994. return new AstLiteral(0); // and it's 0
  30995. } else if (num2.number === 1) {
  30996. return num1; // and it's 1
  30997. } else if (num1.type === 'literal') {
  30998. // ... and first operands is a literal too
  30999. return new AstLiteral(num1.number * num2.number);
  31000. }
  31001. }
  31002. if (num1.type === 'literal') {
  31003. // optimization: first operands is a literal...
  31004. if (num1.number === 0) {
  31005. return new AstLiteral(0); // and it's 0
  31006. } else if (num1.number === 1) {
  31007. return num2; // and it's 1
  31008. }
  31009. }
  31010. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  31011. num1.max * num2.min, num1.max * num2.max);
  31012. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  31013. num1.max * num2.min, num1.max * num2.max);
  31014. return new AstBinaryOperation('*', num1, num2, min, max);
  31015. }
  31016. function buildSubOperation(num1, num2) {
  31017. if (num2.type === 'literal') {
  31018. // optimization: second operands is a literal...
  31019. if (num2.number === 0) {
  31020. return num1; // ... and it's 0
  31021. } else if (num1.type === 'literal') {
  31022. // ... and first operands is a literal too
  31023. return new AstLiteral(num1.number - num2.number);
  31024. }
  31025. }
  31026. if (num2.type === 'binary' && num2.op === '-' &&
  31027. num1.type === 'literal' && num1.number === 1 &&
  31028. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  31029. // optimization for case: 1 - (1 - x)
  31030. return num2.arg2;
  31031. }
  31032. return new AstBinaryOperation('-', num1, num2,
  31033. num1.min - num2.max, num1.max - num2.min);
  31034. }
  31035. function buildMinOperation(num1, max) {
  31036. if (num1.min >= max) {
  31037. // optimization: num1 min value is not less than required max
  31038. return new AstLiteral(max); // just returning max
  31039. } else if (num1.max <= max) {
  31040. // optimization: num1 max value is not greater than required max
  31041. return num1; // just returning an argument
  31042. }
  31043. return new AstMin(num1, max);
  31044. }
  31045. function PostScriptCompiler() {}
  31046. PostScriptCompiler.prototype = {
  31047. compile: function PostScriptCompiler_compile(code, domain, range) {
  31048. var stack = [];
  31049. var i, ii;
  31050. var instructions = [];
  31051. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  31052. var lastRegister = 0;
  31053. var n, j;
  31054. var num1, num2, ast1, ast2, tmpVar, item;
  31055. for (i = 0; i < inputSize; i++) {
  31056. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  31057. }
  31058. for (i = 0, ii = code.length; i < ii; i++) {
  31059. item = code[i];
  31060. if (typeof item === 'number') {
  31061. stack.push(new AstLiteral(item));
  31062. continue;
  31063. }
  31064. switch (item) {
  31065. case 'add':
  31066. if (stack.length < 2) {
  31067. return null;
  31068. }
  31069. num2 = stack.pop();
  31070. num1 = stack.pop();
  31071. stack.push(buildAddOperation(num1, num2));
  31072. break;
  31073. case 'cvr':
  31074. if (stack.length < 1) {
  31075. return null;
  31076. }
  31077. break;
  31078. case 'mul':
  31079. if (stack.length < 2) {
  31080. return null;
  31081. }
  31082. num2 = stack.pop();
  31083. num1 = stack.pop();
  31084. stack.push(buildMulOperation(num1, num2));
  31085. break;
  31086. case 'sub':
  31087. if (stack.length < 2) {
  31088. return null;
  31089. }
  31090. num2 = stack.pop();
  31091. num1 = stack.pop();
  31092. stack.push(buildSubOperation(num1, num2));
  31093. break;
  31094. case 'exch':
  31095. if (stack.length < 2) {
  31096. return null;
  31097. }
  31098. ast1 = stack.pop(); ast2 = stack.pop();
  31099. stack.push(ast1, ast2);
  31100. break;
  31101. case 'pop':
  31102. if (stack.length < 1) {
  31103. return null;
  31104. }
  31105. stack.pop();
  31106. break;
  31107. case 'index':
  31108. if (stack.length < 1) {
  31109. return null;
  31110. }
  31111. num1 = stack.pop();
  31112. if (num1.type !== 'literal') {
  31113. return null;
  31114. }
  31115. n = num1.number;
  31116. if (n < 0 || (n|0) !== n || stack.length < n) {
  31117. return null;
  31118. }
  31119. ast1 = stack[stack.length - n - 1];
  31120. if (ast1.type === 'literal' || ast1.type === 'var') {
  31121. stack.push(ast1);
  31122. break;
  31123. }
  31124. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31125. stack[stack.length - n - 1] = tmpVar;
  31126. stack.push(tmpVar);
  31127. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31128. break;
  31129. case 'dup':
  31130. if (stack.length < 1) {
  31131. return null;
  31132. }
  31133. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  31134. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  31135. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  31136. // special case of the commands sequence for the min operation
  31137. num1 = stack.pop();
  31138. stack.push(buildMinOperation(num1, code[i + 1]));
  31139. i += 6;
  31140. break;
  31141. }
  31142. ast1 = stack[stack.length - 1];
  31143. if (ast1.type === 'literal' || ast1.type === 'var') {
  31144. // we don't have to save into intermediate variable a literal or
  31145. // variable.
  31146. stack.push(ast1);
  31147. break;
  31148. }
  31149. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31150. stack[stack.length - 1] = tmpVar;
  31151. stack.push(tmpVar);
  31152. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31153. break;
  31154. case 'roll':
  31155. if (stack.length < 2) {
  31156. return null;
  31157. }
  31158. num2 = stack.pop();
  31159. num1 = stack.pop();
  31160. if (num2.type !== 'literal' || num1.type !== 'literal') {
  31161. // both roll operands must be numbers
  31162. return null;
  31163. }
  31164. j = num2.number;
  31165. n = num1.number;
  31166. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  31167. // ... and integers
  31168. return null;
  31169. }
  31170. j = ((j % n) + n) % n;
  31171. if (j === 0) {
  31172. break; // just skipping -- there are nothing to rotate
  31173. }
  31174. Array.prototype.push.apply(stack,
  31175. stack.splice(stack.length - n, n - j));
  31176. break;
  31177. default:
  31178. return null; // unsupported operator
  31179. }
  31180. }
  31181. if (stack.length !== outputSize) {
  31182. return null;
  31183. }
  31184. var result = [];
  31185. instructions.forEach(function (instruction) {
  31186. var statementBuilder = new ExpressionBuilderVisitor();
  31187. instruction.visit(statementBuilder);
  31188. result.push(statementBuilder.toString());
  31189. });
  31190. stack.forEach(function (expr, i) {
  31191. var statementBuilder = new ExpressionBuilderVisitor();
  31192. expr.visit(statementBuilder);
  31193. var min = range[i * 2], max = range[i * 2 + 1];
  31194. var out = [statementBuilder.toString()];
  31195. if (min > expr.min) {
  31196. out.unshift('Math.max(', min, ', ');
  31197. out.push(')');
  31198. }
  31199. if (max < expr.max) {
  31200. out.unshift('Math.min(', max, ', ');
  31201. out.push(')');
  31202. }
  31203. out.unshift('dest[destOffset + ', i, '] = ');
  31204. out.push(';');
  31205. result.push(out.join(''));
  31206. });
  31207. return result.join('\n');
  31208. }
  31209. };
  31210. return PostScriptCompiler;
  31211. })();
  31212. exports.isPDFFunction = isPDFFunction;
  31213. exports.PDFFunction = PDFFunction;
  31214. exports.PostScriptEvaluator = PostScriptEvaluator;
  31215. exports.PostScriptCompiler = PostScriptCompiler;
  31216. }));
  31217. (function (root, factory) {
  31218. {
  31219. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  31220. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  31221. }
  31222. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  31223. coreStream) {
  31224. var error = sharedUtil.error;
  31225. var info = sharedUtil.info;
  31226. var isArray = sharedUtil.isArray;
  31227. var isString = sharedUtil.isString;
  31228. var shadow = sharedUtil.shadow;
  31229. var warn = sharedUtil.warn;
  31230. var isDict = corePrimitives.isDict;
  31231. var isName = corePrimitives.isName;
  31232. var isStream = corePrimitives.isStream;
  31233. var PDFFunction = coreFunction.PDFFunction;
  31234. var coreImage; // see _setCoreImage below
  31235. var PDFImage; // = coreImage.PDFImage;
  31236. var ColorSpace = (function ColorSpaceClosure() {
  31237. // Constructor should define this.numComps, this.defaultColor, this.name
  31238. function ColorSpace() {
  31239. error('should not call ColorSpace constructor');
  31240. }
  31241. ColorSpace.prototype = {
  31242. /**
  31243. * Converts the color value to the RGB color. The color components are
  31244. * located in the src array starting from the srcOffset. Returns the array
  31245. * of the rgb components, each value ranging from [0,255].
  31246. */
  31247. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  31248. var rgb = new Uint8Array(3);
  31249. this.getRgbItem(src, srcOffset, rgb, 0);
  31250. return rgb;
  31251. },
  31252. /**
  31253. * Converts the color value to the RGB color, similar to the getRgb method.
  31254. * The result placed into the dest array starting from the destOffset.
  31255. */
  31256. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  31257. dest, destOffset) {
  31258. error('Should not call ColorSpace.getRgbItem');
  31259. },
  31260. /**
  31261. * Converts the specified number of the color values to the RGB colors.
  31262. * The colors are located in the src array starting from the srcOffset.
  31263. * The result is placed into the dest array starting from the destOffset.
  31264. * The src array items shall be in [0,2^bits) range, the dest array items
  31265. * will be in [0,255] range. alpha01 indicates how many alpha components
  31266. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  31267. * array).
  31268. */
  31269. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  31270. dest, destOffset, bits,
  31271. alpha01) {
  31272. error('Should not call ColorSpace.getRgbBuffer');
  31273. },
  31274. /**
  31275. * Determines the number of bytes required to store the result of the
  31276. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  31277. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  31278. */
  31279. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  31280. alpha01) {
  31281. error('Should not call ColorSpace.getOutputLength');
  31282. },
  31283. /**
  31284. * Returns true if source data will be equal the result/output data.
  31285. */
  31286. isPassthrough: function ColorSpace_isPassthrough(bits) {
  31287. return false;
  31288. },
  31289. /**
  31290. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  31291. * how many alpha components there are in the dest array; it will be either
  31292. * 0 (RGB array) or 1 (RGBA array).
  31293. */
  31294. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  31295. originalHeight, width, height,
  31296. actualHeight, bpc, comps, alpha01) {
  31297. var count = originalWidth * originalHeight;
  31298. var rgbBuf = null;
  31299. var numComponentColors = 1 << bpc;
  31300. var needsResizing = originalHeight !== height || originalWidth !== width;
  31301. var i, ii;
  31302. if (this.isPassthrough(bpc)) {
  31303. rgbBuf = comps;
  31304. } else if (this.numComps === 1 && count > numComponentColors &&
  31305. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  31306. // Optimization: create a color map when there is just one component and
  31307. // we are converting more colors than the size of the color map. We
  31308. // don't build the map if the colorspace is gray or rgb since those
  31309. // methods are faster than building a map. This mainly offers big speed
  31310. // ups for indexed and alternate colorspaces.
  31311. //
  31312. // TODO it may be worth while to cache the color map. While running
  31313. // testing I never hit a cache so I will leave that out for now (perhaps
  31314. // we are reparsing colorspaces too much?).
  31315. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  31316. new Uint16Array(numComponentColors);
  31317. var key;
  31318. for (i = 0; i < numComponentColors; i++) {
  31319. allColors[i] = i;
  31320. }
  31321. var colorMap = new Uint8Array(numComponentColors * 3);
  31322. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  31323. /* alpha01 = */ 0);
  31324. var destPos, rgbPos;
  31325. if (!needsResizing) {
  31326. // Fill in the RGB values directly into |dest|.
  31327. destPos = 0;
  31328. for (i = 0; i < count; ++i) {
  31329. key = comps[i] * 3;
  31330. dest[destPos++] = colorMap[key];
  31331. dest[destPos++] = colorMap[key + 1];
  31332. dest[destPos++] = colorMap[key + 2];
  31333. destPos += alpha01;
  31334. }
  31335. } else {
  31336. rgbBuf = new Uint8Array(count * 3);
  31337. rgbPos = 0;
  31338. for (i = 0; i < count; ++i) {
  31339. key = comps[i] * 3;
  31340. rgbBuf[rgbPos++] = colorMap[key];
  31341. rgbBuf[rgbPos++] = colorMap[key + 1];
  31342. rgbBuf[rgbPos++] = colorMap[key + 2];
  31343. }
  31344. }
  31345. } else {
  31346. if (!needsResizing) {
  31347. // Fill in the RGB values directly into |dest|.
  31348. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  31349. alpha01);
  31350. } else {
  31351. rgbBuf = new Uint8Array(count * 3);
  31352. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  31353. /* alpha01 = */ 0);
  31354. }
  31355. }
  31356. if (rgbBuf) {
  31357. if (needsResizing) {
  31358. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  31359. height, dest, alpha01);
  31360. } else {
  31361. rgbPos = 0;
  31362. destPos = 0;
  31363. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  31364. dest[destPos++] = rgbBuf[rgbPos++];
  31365. dest[destPos++] = rgbBuf[rgbPos++];
  31366. dest[destPos++] = rgbBuf[rgbPos++];
  31367. destPos += alpha01;
  31368. }
  31369. }
  31370. }
  31371. },
  31372. /**
  31373. * True if the colorspace has components in the default range of [0, 1].
  31374. * This should be true for all colorspaces except for lab color spaces
  31375. * which are [0,100], [-128, 127], [-128, 127].
  31376. */
  31377. usesZeroToOneRange: true
  31378. };
  31379. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31380. var IR = ColorSpace.parseToIR(cs, xref, res);
  31381. if (IR instanceof AlternateCS) {
  31382. return IR;
  31383. }
  31384. return ColorSpace.fromIR(IR);
  31385. };
  31386. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31387. var name = isArray(IR) ? IR[0] : IR;
  31388. var whitePoint, blackPoint, gamma;
  31389. switch (name) {
  31390. case 'DeviceGrayCS':
  31391. return this.singletons.gray;
  31392. case 'DeviceRgbCS':
  31393. return this.singletons.rgb;
  31394. case 'DeviceCmykCS':
  31395. return this.singletons.cmyk;
  31396. case 'CalGrayCS':
  31397. whitePoint = IR[1].WhitePoint;
  31398. blackPoint = IR[1].BlackPoint;
  31399. gamma = IR[1].Gamma;
  31400. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31401. case 'CalRGBCS':
  31402. whitePoint = IR[1].WhitePoint;
  31403. blackPoint = IR[1].BlackPoint;
  31404. gamma = IR[1].Gamma;
  31405. var matrix = IR[1].Matrix;
  31406. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31407. case 'PatternCS':
  31408. var basePatternCS = IR[1];
  31409. if (basePatternCS) {
  31410. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31411. }
  31412. return new PatternCS(basePatternCS);
  31413. case 'IndexedCS':
  31414. var baseIndexedCS = IR[1];
  31415. var hiVal = IR[2];
  31416. var lookup = IR[3];
  31417. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31418. case 'AlternateCS':
  31419. var numComps = IR[1];
  31420. var alt = IR[2];
  31421. var tintFnIR = IR[3];
  31422. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31423. PDFFunction.fromIR(tintFnIR));
  31424. case 'LabCS':
  31425. whitePoint = IR[1].WhitePoint;
  31426. blackPoint = IR[1].BlackPoint;
  31427. var range = IR[1].Range;
  31428. return new LabCS(whitePoint, blackPoint, range);
  31429. default:
  31430. error('Unknown name ' + name);
  31431. }
  31432. return null;
  31433. };
  31434. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31435. if (isName(cs)) {
  31436. var colorSpaces = res.get('ColorSpace');
  31437. if (isDict(colorSpaces)) {
  31438. var refcs = colorSpaces.get(cs.name);
  31439. if (refcs) {
  31440. cs = refcs;
  31441. }
  31442. }
  31443. }
  31444. cs = xref.fetchIfRef(cs);
  31445. var mode;
  31446. if (isName(cs)) {
  31447. mode = cs.name;
  31448. this.mode = mode;
  31449. switch (mode) {
  31450. case 'DeviceGray':
  31451. case 'G':
  31452. return 'DeviceGrayCS';
  31453. case 'DeviceRGB':
  31454. case 'RGB':
  31455. return 'DeviceRgbCS';
  31456. case 'DeviceCMYK':
  31457. case 'CMYK':
  31458. return 'DeviceCmykCS';
  31459. case 'Pattern':
  31460. return ['PatternCS', null];
  31461. default:
  31462. error('unrecognized colorspace ' + mode);
  31463. }
  31464. } else if (isArray(cs)) {
  31465. mode = xref.fetchIfRef(cs[0]).name;
  31466. this.mode = mode;
  31467. var numComps, params, alt;
  31468. switch (mode) {
  31469. case 'DeviceGray':
  31470. case 'G':
  31471. return 'DeviceGrayCS';
  31472. case 'DeviceRGB':
  31473. case 'RGB':
  31474. return 'DeviceRgbCS';
  31475. case 'DeviceCMYK':
  31476. case 'CMYK':
  31477. return 'DeviceCmykCS';
  31478. case 'CalGray':
  31479. params = xref.fetchIfRef(cs[1]).getAll();
  31480. return ['CalGrayCS', params];
  31481. case 'CalRGB':
  31482. params = xref.fetchIfRef(cs[1]).getAll();
  31483. return ['CalRGBCS', params];
  31484. case 'ICCBased':
  31485. var stream = xref.fetchIfRef(cs[1]);
  31486. var dict = stream.dict;
  31487. numComps = dict.get('N');
  31488. alt = dict.get('Alternate');
  31489. if (alt) {
  31490. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31491. // Parse the /Alternate CS to ensure that the number of components
  31492. // are correct, and also (indirectly) that it is not a PatternCS.
  31493. var altCS = ColorSpace.fromIR(altIR);
  31494. if (altCS.numComps === numComps) {
  31495. return altIR;
  31496. }
  31497. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31498. }
  31499. if (numComps === 1) {
  31500. return 'DeviceGrayCS';
  31501. } else if (numComps === 3) {
  31502. return 'DeviceRgbCS';
  31503. } else if (numComps === 4) {
  31504. return 'DeviceCmykCS';
  31505. }
  31506. break;
  31507. case 'Pattern':
  31508. var basePatternCS = cs[1] || null;
  31509. if (basePatternCS) {
  31510. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31511. }
  31512. return ['PatternCS', basePatternCS];
  31513. case 'Indexed':
  31514. case 'I':
  31515. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31516. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31517. var lookup = xref.fetchIfRef(cs[3]);
  31518. if (isStream(lookup)) {
  31519. lookup = lookup.getBytes();
  31520. }
  31521. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31522. case 'Separation':
  31523. case 'DeviceN':
  31524. var name = xref.fetchIfRef(cs[1]);
  31525. numComps = 1;
  31526. if (isName(name)) {
  31527. numComps = 1;
  31528. } else if (isArray(name)) {
  31529. numComps = name.length;
  31530. }
  31531. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31532. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31533. return ['AlternateCS', numComps, alt, tintFnIR];
  31534. case 'Lab':
  31535. params = xref.fetchIfRef(cs[1]).getAll();
  31536. return ['LabCS', params];
  31537. default:
  31538. error('unimplemented color space object "' + mode + '"');
  31539. }
  31540. } else {
  31541. error('unrecognized color space object: "' + cs + '"');
  31542. }
  31543. return null;
  31544. };
  31545. /**
  31546. * Checks if a decode map matches the default decode map for a color space.
  31547. * This handles the general decode maps where there are two values per
  31548. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31549. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31550. * slightly different.
  31551. * @param {Array} decode Decode map (usually from an image).
  31552. * @param {Number} n Number of components the color space has.
  31553. */
  31554. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31555. if (!isArray(decode)) {
  31556. return true;
  31557. }
  31558. if (n * 2 !== decode.length) {
  31559. warn('The decode map is not the correct length');
  31560. return true;
  31561. }
  31562. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31563. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31564. return false;
  31565. }
  31566. }
  31567. return true;
  31568. };
  31569. ColorSpace.singletons = {
  31570. get gray() {
  31571. return shadow(this, 'gray', new DeviceGrayCS());
  31572. },
  31573. get rgb() {
  31574. return shadow(this, 'rgb', new DeviceRgbCS());
  31575. },
  31576. get cmyk() {
  31577. return shadow(this, 'cmyk', new DeviceCmykCS());
  31578. }
  31579. };
  31580. return ColorSpace;
  31581. })();
  31582. /**
  31583. * Alternate color space handles both Separation and DeviceN color spaces. A
  31584. * Separation color space is actually just a DeviceN with one color component.
  31585. * Both color spaces use a tinting function to convert colors to a base color
  31586. * space.
  31587. */
  31588. var AlternateCS = (function AlternateCSClosure() {
  31589. function AlternateCS(numComps, base, tintFn) {
  31590. this.name = 'Alternate';
  31591. this.numComps = numComps;
  31592. this.defaultColor = new Float32Array(numComps);
  31593. for (var i = 0; i < numComps; ++i) {
  31594. this.defaultColor[i] = 1;
  31595. }
  31596. this.base = base;
  31597. this.tintFn = tintFn;
  31598. this.tmpBuf = new Float32Array(base.numComps);
  31599. }
  31600. AlternateCS.prototype = {
  31601. getRgb: ColorSpace.prototype.getRgb,
  31602. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31603. dest, destOffset) {
  31604. var tmpBuf = this.tmpBuf;
  31605. this.tintFn(src, srcOffset, tmpBuf, 0);
  31606. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31607. },
  31608. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31609. dest, destOffset, bits,
  31610. alpha01) {
  31611. var tintFn = this.tintFn;
  31612. var base = this.base;
  31613. var scale = 1 / ((1 << bits) - 1);
  31614. var baseNumComps = base.numComps;
  31615. var usesZeroToOneRange = base.usesZeroToOneRange;
  31616. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31617. alpha01 === 0;
  31618. var pos = isPassthrough ? destOffset : 0;
  31619. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31620. var numComps = this.numComps;
  31621. var scaled = new Float32Array(numComps);
  31622. var tinted = new Float32Array(baseNumComps);
  31623. var i, j;
  31624. if (usesZeroToOneRange) {
  31625. for (i = 0; i < count; i++) {
  31626. for (j = 0; j < numComps; j++) {
  31627. scaled[j] = src[srcOffset++] * scale;
  31628. }
  31629. tintFn(scaled, 0, tinted, 0);
  31630. for (j = 0; j < baseNumComps; j++) {
  31631. baseBuf[pos++] = tinted[j] * 255;
  31632. }
  31633. }
  31634. } else {
  31635. for (i = 0; i < count; i++) {
  31636. for (j = 0; j < numComps; j++) {
  31637. scaled[j] = src[srcOffset++] * scale;
  31638. }
  31639. tintFn(scaled, 0, tinted, 0);
  31640. base.getRgbItem(tinted, 0, baseBuf, pos);
  31641. pos += baseNumComps;
  31642. }
  31643. }
  31644. if (!isPassthrough) {
  31645. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31646. }
  31647. },
  31648. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31649. alpha01) {
  31650. return this.base.getOutputLength(inputLength *
  31651. this.base.numComps / this.numComps,
  31652. alpha01);
  31653. },
  31654. isPassthrough: ColorSpace.prototype.isPassthrough,
  31655. fillRgb: ColorSpace.prototype.fillRgb,
  31656. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31657. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31658. },
  31659. usesZeroToOneRange: true
  31660. };
  31661. return AlternateCS;
  31662. })();
  31663. var PatternCS = (function PatternCSClosure() {
  31664. function PatternCS(baseCS) {
  31665. this.name = 'Pattern';
  31666. this.base = baseCS;
  31667. }
  31668. PatternCS.prototype = {};
  31669. return PatternCS;
  31670. })();
  31671. var IndexedCS = (function IndexedCSClosure() {
  31672. function IndexedCS(base, highVal, lookup) {
  31673. this.name = 'Indexed';
  31674. this.numComps = 1;
  31675. this.defaultColor = new Uint8Array([0]);
  31676. this.base = base;
  31677. this.highVal = highVal;
  31678. var baseNumComps = base.numComps;
  31679. var length = baseNumComps * highVal;
  31680. var lookupArray;
  31681. if (isStream(lookup)) {
  31682. lookupArray = new Uint8Array(length);
  31683. var bytes = lookup.getBytes(length);
  31684. lookupArray.set(bytes);
  31685. } else if (isString(lookup)) {
  31686. lookupArray = new Uint8Array(length);
  31687. for (var i = 0; i < length; ++i) {
  31688. lookupArray[i] = lookup.charCodeAt(i);
  31689. }
  31690. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31691. lookupArray = lookup;
  31692. } else {
  31693. error('Unrecognized lookup table: ' + lookup);
  31694. }
  31695. this.lookup = lookupArray;
  31696. }
  31697. IndexedCS.prototype = {
  31698. getRgb: ColorSpace.prototype.getRgb,
  31699. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31700. dest, destOffset) {
  31701. var numComps = this.base.numComps;
  31702. var start = src[srcOffset] * numComps;
  31703. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31704. },
  31705. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31706. dest, destOffset, bits,
  31707. alpha01) {
  31708. var base = this.base;
  31709. var numComps = base.numComps;
  31710. var outputDelta = base.getOutputLength(numComps, alpha01);
  31711. var lookup = this.lookup;
  31712. for (var i = 0; i < count; ++i) {
  31713. var lookupPos = src[srcOffset++] * numComps;
  31714. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31715. destOffset += outputDelta;
  31716. }
  31717. },
  31718. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31719. return this.base.getOutputLength(inputLength * this.base.numComps,
  31720. alpha01);
  31721. },
  31722. isPassthrough: ColorSpace.prototype.isPassthrough,
  31723. fillRgb: ColorSpace.prototype.fillRgb,
  31724. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31725. // indexed color maps shouldn't be changed
  31726. return true;
  31727. },
  31728. usesZeroToOneRange: true
  31729. };
  31730. return IndexedCS;
  31731. })();
  31732. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31733. function DeviceGrayCS() {
  31734. this.name = 'DeviceGray';
  31735. this.numComps = 1;
  31736. this.defaultColor = new Float32Array([0]);
  31737. }
  31738. DeviceGrayCS.prototype = {
  31739. getRgb: ColorSpace.prototype.getRgb,
  31740. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31741. dest, destOffset) {
  31742. var c = (src[srcOffset] * 255) | 0;
  31743. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31744. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31745. },
  31746. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31747. dest, destOffset, bits,
  31748. alpha01) {
  31749. var scale = 255 / ((1 << bits) - 1);
  31750. var j = srcOffset, q = destOffset;
  31751. for (var i = 0; i < count; ++i) {
  31752. var c = (scale * src[j++]) | 0;
  31753. dest[q++] = c;
  31754. dest[q++] = c;
  31755. dest[q++] = c;
  31756. q += alpha01;
  31757. }
  31758. },
  31759. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31760. alpha01) {
  31761. return inputLength * (3 + alpha01);
  31762. },
  31763. isPassthrough: ColorSpace.prototype.isPassthrough,
  31764. fillRgb: ColorSpace.prototype.fillRgb,
  31765. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31766. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31767. },
  31768. usesZeroToOneRange: true
  31769. };
  31770. return DeviceGrayCS;
  31771. })();
  31772. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31773. function DeviceRgbCS() {
  31774. this.name = 'DeviceRGB';
  31775. this.numComps = 3;
  31776. this.defaultColor = new Float32Array([0, 0, 0]);
  31777. }
  31778. DeviceRgbCS.prototype = {
  31779. getRgb: ColorSpace.prototype.getRgb,
  31780. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31781. dest, destOffset) {
  31782. var r = (src[srcOffset] * 255) | 0;
  31783. var g = (src[srcOffset + 1] * 255) | 0;
  31784. var b = (src[srcOffset + 2] * 255) | 0;
  31785. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31786. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31787. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31788. },
  31789. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31790. dest, destOffset, bits,
  31791. alpha01) {
  31792. if (bits === 8 && alpha01 === 0) {
  31793. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31794. return;
  31795. }
  31796. var scale = 255 / ((1 << bits) - 1);
  31797. var j = srcOffset, q = destOffset;
  31798. for (var i = 0; i < count; ++i) {
  31799. dest[q++] = (scale * src[j++]) | 0;
  31800. dest[q++] = (scale * src[j++]) | 0;
  31801. dest[q++] = (scale * src[j++]) | 0;
  31802. q += alpha01;
  31803. }
  31804. },
  31805. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31806. alpha01) {
  31807. return (inputLength * (3 + alpha01) / 3) | 0;
  31808. },
  31809. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31810. return bits === 8;
  31811. },
  31812. fillRgb: ColorSpace.prototype.fillRgb,
  31813. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31814. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31815. },
  31816. usesZeroToOneRange: true
  31817. };
  31818. return DeviceRgbCS;
  31819. })();
  31820. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31821. // The coefficients below was found using numerical analysis: the method of
  31822. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31823. // where color_value is the tabular value from the table of sampled RGB colors
  31824. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31825. // CMYK color conversion using the estimation below:
  31826. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31827. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31828. var c = src[srcOffset + 0] * srcScale;
  31829. var m = src[srcOffset + 1] * srcScale;
  31830. var y = src[srcOffset + 2] * srcScale;
  31831. var k = src[srcOffset + 3] * srcScale;
  31832. var r =
  31833. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31834. 18.82290502165302 * y + 212.25662451639585 * k +
  31835. -285.2331026137004) +
  31836. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31837. -17.873870861415444 * k - 5.497006427196366) +
  31838. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31839. 17.5119270841813) +
  31840. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31841. var g =
  31842. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31843. 6.871425592049007 * y + 31.159100130055922 * k +
  31844. -79.2970844816548) +
  31845. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31846. 131.35250912493976 * k - 190.9453302588951) +
  31847. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31848. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31849. var b =
  31850. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31851. 30.89978309703729 * y - 0.23883238689178934 * k +
  31852. -14.183576799673286) +
  31853. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31854. 50.606957656360734 * k - 112.23884253719248) +
  31855. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31856. -193.58209356861505) +
  31857. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31858. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31859. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31860. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31861. }
  31862. function DeviceCmykCS() {
  31863. this.name = 'DeviceCMYK';
  31864. this.numComps = 4;
  31865. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31866. }
  31867. DeviceCmykCS.prototype = {
  31868. getRgb: ColorSpace.prototype.getRgb,
  31869. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31870. dest, destOffset) {
  31871. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31872. },
  31873. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31874. dest, destOffset, bits,
  31875. alpha01) {
  31876. var scale = 1 / ((1 << bits) - 1);
  31877. for (var i = 0; i < count; i++) {
  31878. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31879. srcOffset += 4;
  31880. destOffset += 3 + alpha01;
  31881. }
  31882. },
  31883. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31884. alpha01) {
  31885. return (inputLength / 4 * (3 + alpha01)) | 0;
  31886. },
  31887. isPassthrough: ColorSpace.prototype.isPassthrough,
  31888. fillRgb: ColorSpace.prototype.fillRgb,
  31889. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31890. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31891. },
  31892. usesZeroToOneRange: true
  31893. };
  31894. return DeviceCmykCS;
  31895. })();
  31896. //
  31897. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31898. //
  31899. var CalGrayCS = (function CalGrayCSClosure() {
  31900. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31901. this.name = 'CalGray';
  31902. this.numComps = 1;
  31903. this.defaultColor = new Float32Array([0]);
  31904. if (!whitePoint) {
  31905. error('WhitePoint missing - required for color space CalGray');
  31906. }
  31907. blackPoint = blackPoint || [0, 0, 0];
  31908. gamma = gamma || 1;
  31909. // Translate arguments to spec variables.
  31910. this.XW = whitePoint[0];
  31911. this.YW = whitePoint[1];
  31912. this.ZW = whitePoint[2];
  31913. this.XB = blackPoint[0];
  31914. this.YB = blackPoint[1];
  31915. this.ZB = blackPoint[2];
  31916. this.G = gamma;
  31917. // Validate variables as per spec.
  31918. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31919. error('Invalid WhitePoint components for ' + this.name +
  31920. ', no fallback available');
  31921. }
  31922. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31923. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31924. this.XB = this.YB = this.ZB = 0;
  31925. }
  31926. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31927. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31928. ', ZB: ' + this.ZB + ', only default values are supported.');
  31929. }
  31930. if (this.G < 1) {
  31931. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31932. ', falling back to default');
  31933. this.G = 1;
  31934. }
  31935. }
  31936. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31937. // A represents a gray component of a calibrated gray space.
  31938. // A <---> AG in the spec
  31939. var A = src[srcOffset] * scale;
  31940. var AG = Math.pow(A, cs.G);
  31941. // Computes L as per spec. ( = cs.YW * AG )
  31942. // Except if other than default BlackPoint values are used.
  31943. var L = cs.YW * AG;
  31944. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31945. // Convert values to rgb range [0, 255].
  31946. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31947. dest[destOffset] = val;
  31948. dest[destOffset + 1] = val;
  31949. dest[destOffset + 2] = val;
  31950. }
  31951. CalGrayCS.prototype = {
  31952. getRgb: ColorSpace.prototype.getRgb,
  31953. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31954. dest, destOffset) {
  31955. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31956. },
  31957. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31958. dest, destOffset, bits,
  31959. alpha01) {
  31960. var scale = 1 / ((1 << bits) - 1);
  31961. for (var i = 0; i < count; ++i) {
  31962. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31963. srcOffset += 1;
  31964. destOffset += 3 + alpha01;
  31965. }
  31966. },
  31967. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31968. return inputLength * (3 + alpha01);
  31969. },
  31970. isPassthrough: ColorSpace.prototype.isPassthrough,
  31971. fillRgb: ColorSpace.prototype.fillRgb,
  31972. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31973. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31974. },
  31975. usesZeroToOneRange: true
  31976. };
  31977. return CalGrayCS;
  31978. })();
  31979. //
  31980. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31981. //
  31982. var CalRGBCS = (function CalRGBCSClosure() {
  31983. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31984. // matrices.
  31985. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31986. 0.8951, 0.2664, -0.1614,
  31987. -0.7502, 1.7135, 0.0367,
  31988. 0.0389, -0.0685, 1.0296]);
  31989. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31990. 0.9869929, -0.1470543, 0.1599627,
  31991. 0.4323053, 0.5183603, 0.0492912,
  31992. -0.0085287, 0.0400428, 0.9684867]);
  31993. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31994. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31995. 3.2404542, -1.5371385, -0.4985314,
  31996. -0.9692660, 1.8760108, 0.0415560,
  31997. 0.0556434, -0.2040259, 1.0572252]);
  31998. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31999. var tempNormalizeMatrix = new Float32Array(3);
  32000. var tempConvertMatrix1 = new Float32Array(3);
  32001. var tempConvertMatrix2 = new Float32Array(3);
  32002. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  32003. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  32004. this.name = 'CalRGB';
  32005. this.numComps = 3;
  32006. this.defaultColor = new Float32Array(3);
  32007. if (!whitePoint) {
  32008. error('WhitePoint missing - required for color space CalRGB');
  32009. }
  32010. blackPoint = blackPoint || new Float32Array(3);
  32011. gamma = gamma || new Float32Array([1, 1, 1]);
  32012. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  32013. // Translate arguments to spec variables.
  32014. var XW = whitePoint[0];
  32015. var YW = whitePoint[1];
  32016. var ZW = whitePoint[2];
  32017. this.whitePoint = whitePoint;
  32018. var XB = blackPoint[0];
  32019. var YB = blackPoint[1];
  32020. var ZB = blackPoint[2];
  32021. this.blackPoint = blackPoint;
  32022. this.GR = gamma[0];
  32023. this.GG = gamma[1];
  32024. this.GB = gamma[2];
  32025. this.MXA = matrix[0];
  32026. this.MYA = matrix[1];
  32027. this.MZA = matrix[2];
  32028. this.MXB = matrix[3];
  32029. this.MYB = matrix[4];
  32030. this.MZB = matrix[5];
  32031. this.MXC = matrix[6];
  32032. this.MYC = matrix[7];
  32033. this.MZC = matrix[8];
  32034. // Validate variables as per spec.
  32035. if (XW < 0 || ZW < 0 || YW !== 1) {
  32036. error('Invalid WhitePoint components for ' + this.name +
  32037. ', no fallback available');
  32038. }
  32039. if (XB < 0 || YB < 0 || ZB < 0) {
  32040. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  32041. ', ' + ZB + '], falling back to default');
  32042. this.blackPoint = new Float32Array(3);
  32043. }
  32044. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  32045. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  32046. '] for ' + this.name + ', falling back to default');
  32047. this.GR = this.GG = this.GB = 1;
  32048. }
  32049. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  32050. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  32051. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  32052. info('Invalid Matrix for ' + this.name + ' [' +
  32053. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  32054. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  32055. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  32056. '], falling back to default');
  32057. this.MXA = this.MYB = this.MZC = 1;
  32058. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  32059. }
  32060. }
  32061. function matrixProduct(a, b, result) {
  32062. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  32063. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  32064. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  32065. }
  32066. function convertToFlat(sourceWhitePoint, LMS, result) {
  32067. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  32068. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  32069. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  32070. }
  32071. function convertToD65(sourceWhitePoint, LMS, result) {
  32072. var D65X = 0.95047;
  32073. var D65Y = 1;
  32074. var D65Z = 1.08883;
  32075. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  32076. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  32077. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  32078. }
  32079. function sRGBTransferFunction(color) {
  32080. // See http://en.wikipedia.org/wiki/SRGB.
  32081. if (color <= 0.0031308){
  32082. return adjustToRange(0, 1, 12.92 * color);
  32083. }
  32084. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  32085. }
  32086. function adjustToRange(min, max, value) {
  32087. return Math.max(min, Math.min(max, value));
  32088. }
  32089. function decodeL(L) {
  32090. if (L < 0) {
  32091. return -decodeL(-L);
  32092. }
  32093. if (L > 8.0) {
  32094. return Math.pow(((L + 16) / 116), 3);
  32095. }
  32096. return L * DECODE_L_CONSTANT;
  32097. }
  32098. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  32099. // In case the blackPoint is already the default blackPoint then there is
  32100. // no need to do compensation.
  32101. if (sourceBlackPoint[0] === 0 &&
  32102. sourceBlackPoint[1] === 0 &&
  32103. sourceBlackPoint[2] === 0) {
  32104. result[0] = XYZ_Flat[0];
  32105. result[1] = XYZ_Flat[1];
  32106. result[2] = XYZ_Flat[2];
  32107. return;
  32108. }
  32109. // For the blackPoint calculation details, please see
  32110. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32111. // AdobeBPC.pdf.
  32112. // The destination blackPoint is the default blackPoint [0, 0, 0].
  32113. var zeroDecodeL = decodeL(0);
  32114. var X_DST = zeroDecodeL;
  32115. var X_SRC = decodeL(sourceBlackPoint[0]);
  32116. var Y_DST = zeroDecodeL;
  32117. var Y_SRC = decodeL(sourceBlackPoint[1]);
  32118. var Z_DST = zeroDecodeL;
  32119. var Z_SRC = decodeL(sourceBlackPoint[2]);
  32120. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  32121. var X_Offset = 1 - X_Scale;
  32122. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  32123. var Y_Offset = 1 - Y_Scale;
  32124. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  32125. var Z_Offset = 1 - Z_Scale;
  32126. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  32127. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  32128. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  32129. }
  32130. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  32131. // In case the whitePoint is already flat then there is no need to do
  32132. // normalization.
  32133. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  32134. result[0] = XYZ_In[0];
  32135. result[1] = XYZ_In[1];
  32136. result[2] = XYZ_In[2];
  32137. return;
  32138. }
  32139. var LMS = result;
  32140. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32141. var LMS_Flat = tempNormalizeMatrix;
  32142. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  32143. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  32144. }
  32145. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  32146. var LMS = result;
  32147. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32148. var LMS_D65 = tempNormalizeMatrix;
  32149. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  32150. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  32151. }
  32152. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32153. // A, B and C represent a red, green and blue components of a calibrated
  32154. // rgb space.
  32155. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  32156. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  32157. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  32158. // A <---> AGR in the spec
  32159. // B <---> BGG in the spec
  32160. // C <---> CGB in the spec
  32161. var AGR = Math.pow(A, cs.GR);
  32162. var BGG = Math.pow(B, cs.GG);
  32163. var CGB = Math.pow(C, cs.GB);
  32164. // Computes intermediate variables L, M, N as per spec.
  32165. // To decode X, Y, Z values map L, M, N directly to them.
  32166. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  32167. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  32168. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  32169. // The following calculations are based on this document:
  32170. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32171. // AdobeBPC.pdf.
  32172. var XYZ = tempConvertMatrix1;
  32173. XYZ[0] = X;
  32174. XYZ[1] = Y;
  32175. XYZ[2] = Z;
  32176. var XYZ_Flat = tempConvertMatrix2;
  32177. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  32178. var XYZ_Black = tempConvertMatrix1;
  32179. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  32180. var XYZ_D65 = tempConvertMatrix2;
  32181. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  32182. var SRGB = tempConvertMatrix1;
  32183. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  32184. var sR = sRGBTransferFunction(SRGB[0]);
  32185. var sG = sRGBTransferFunction(SRGB[1]);
  32186. var sB = sRGBTransferFunction(SRGB[2]);
  32187. // Convert the values to rgb range [0, 255].
  32188. dest[destOffset] = Math.round(sR * 255);
  32189. dest[destOffset + 1] = Math.round(sG * 255);
  32190. dest[destOffset + 2] = Math.round(sB * 255);
  32191. }
  32192. CalRGBCS.prototype = {
  32193. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  32194. var rgb = new Uint8Array(3);
  32195. this.getRgbItem(src, srcOffset, rgb, 0);
  32196. return rgb;
  32197. },
  32198. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  32199. dest, destOffset) {
  32200. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32201. },
  32202. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  32203. dest, destOffset, bits,
  32204. alpha01) {
  32205. var scale = 1 / ((1 << bits) - 1);
  32206. for (var i = 0; i < count; ++i) {
  32207. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32208. srcOffset += 3;
  32209. destOffset += 3 + alpha01;
  32210. }
  32211. },
  32212. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  32213. return (inputLength * (3 + alpha01) / 3) | 0;
  32214. },
  32215. isPassthrough: ColorSpace.prototype.isPassthrough,
  32216. fillRgb: ColorSpace.prototype.fillRgb,
  32217. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  32218. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32219. },
  32220. usesZeroToOneRange: true
  32221. };
  32222. return CalRGBCS;
  32223. })();
  32224. //
  32225. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  32226. //
  32227. var LabCS = (function LabCSClosure() {
  32228. function LabCS(whitePoint, blackPoint, range) {
  32229. this.name = 'Lab';
  32230. this.numComps = 3;
  32231. this.defaultColor = new Float32Array([0, 0, 0]);
  32232. if (!whitePoint) {
  32233. error('WhitePoint missing - required for color space Lab');
  32234. }
  32235. blackPoint = blackPoint || [0, 0, 0];
  32236. range = range || [-100, 100, -100, 100];
  32237. // Translate args to spec variables
  32238. this.XW = whitePoint[0];
  32239. this.YW = whitePoint[1];
  32240. this.ZW = whitePoint[2];
  32241. this.amin = range[0];
  32242. this.amax = range[1];
  32243. this.bmin = range[2];
  32244. this.bmax = range[3];
  32245. // These are here just for completeness - the spec doesn't offer any
  32246. // formulas that use BlackPoint in Lab
  32247. this.XB = blackPoint[0];
  32248. this.YB = blackPoint[1];
  32249. this.ZB = blackPoint[2];
  32250. // Validate vars as per spec
  32251. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32252. error('Invalid WhitePoint components, no fallback available');
  32253. }
  32254. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32255. info('Invalid BlackPoint, falling back to default');
  32256. this.XB = this.YB = this.ZB = 0;
  32257. }
  32258. if (this.amin > this.amax || this.bmin > this.bmax) {
  32259. info('Invalid Range, falling back to defaults');
  32260. this.amin = -100;
  32261. this.amax = 100;
  32262. this.bmin = -100;
  32263. this.bmax = 100;
  32264. }
  32265. }
  32266. // Function g(x) from spec
  32267. function fn_g(x) {
  32268. if (x >= 6 / 29) {
  32269. return x * x * x;
  32270. } else {
  32271. return (108 / 841) * (x - 4 / 29);
  32272. }
  32273. }
  32274. function decode(value, high1, low2, high2) {
  32275. return low2 + (value) * (high2 - low2) / (high1);
  32276. }
  32277. // If decoding is needed maxVal should be 2^bits per component - 1.
  32278. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  32279. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  32280. // not the usual [0, 1]. If a command like setFillColor is used the src
  32281. // values will already be within the correct range. However, if we are
  32282. // converting an image we have to map the values to the correct range given
  32283. // above.
  32284. // Ls,as,bs <---> L*,a*,b* in the spec
  32285. var Ls = src[srcOffset];
  32286. var as = src[srcOffset + 1];
  32287. var bs = src[srcOffset + 2];
  32288. if (maxVal !== false) {
  32289. Ls = decode(Ls, maxVal, 0, 100);
  32290. as = decode(as, maxVal, cs.amin, cs.amax);
  32291. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  32292. }
  32293. // Adjust limits of 'as' and 'bs'
  32294. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  32295. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  32296. // Computes intermediate variables X,Y,Z as per spec
  32297. var M = (Ls + 16) / 116;
  32298. var L = M + (as / 500);
  32299. var N = M - (bs / 200);
  32300. var X = cs.XW * fn_g(L);
  32301. var Y = cs.YW * fn_g(M);
  32302. var Z = cs.ZW * fn_g(N);
  32303. var r, g, b;
  32304. // Using different conversions for D50 and D65 white points,
  32305. // per http://www.color.org/srgb.pdf
  32306. if (cs.ZW < 1) {
  32307. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  32308. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  32309. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  32310. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  32311. } else {
  32312. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  32313. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  32314. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  32315. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  32316. }
  32317. // clamp color values to [0,1] range then convert to [0,255] range.
  32318. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  32319. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  32320. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  32321. }
  32322. LabCS.prototype = {
  32323. getRgb: ColorSpace.prototype.getRgb,
  32324. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  32325. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  32326. },
  32327. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  32328. dest, destOffset, bits,
  32329. alpha01) {
  32330. var maxVal = (1 << bits) - 1;
  32331. for (var i = 0; i < count; i++) {
  32332. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  32333. srcOffset += 3;
  32334. destOffset += 3 + alpha01;
  32335. }
  32336. },
  32337. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  32338. return (inputLength * (3 + alpha01) / 3) | 0;
  32339. },
  32340. isPassthrough: ColorSpace.prototype.isPassthrough,
  32341. fillRgb: ColorSpace.prototype.fillRgb,
  32342. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  32343. // XXX: Decoding is handled with the lab conversion because of the strange
  32344. // ranges that are used.
  32345. return true;
  32346. },
  32347. usesZeroToOneRange: false
  32348. };
  32349. return LabCS;
  32350. })();
  32351. // TODO refactor to remove dependency on image.js
  32352. function _setCoreImage(coreImage_) {
  32353. coreImage = coreImage_;
  32354. PDFImage = coreImage_.PDFImage;
  32355. }
  32356. exports._setCoreImage = _setCoreImage;
  32357. exports.ColorSpace = ColorSpace;
  32358. // TODO refactor to remove dependency on colorspace.js
  32359. coreStream._setCoreColorSpace(exports);
  32360. }));
  32361. (function (root, factory) {
  32362. {
  32363. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  32364. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  32365. root.pdfjsCoreJpx);
  32366. }
  32367. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  32368. coreStream, coreJpx) {
  32369. var ImageKind = sharedUtil.ImageKind;
  32370. var assert = sharedUtil.assert;
  32371. var error = sharedUtil.error;
  32372. var info = sharedUtil.info;
  32373. var isArray = sharedUtil.isArray;
  32374. var warn = sharedUtil.warn;
  32375. var Name = corePrimitives.Name;
  32376. var isStream = corePrimitives.isStream;
  32377. var ColorSpace = coreColorSpace.ColorSpace;
  32378. var DecodeStream = coreStream.DecodeStream;
  32379. var Stream = coreStream.Stream;
  32380. var JpegStream = coreStream.JpegStream;
  32381. var JpxImage = coreJpx.JpxImage;
  32382. var PDFImage = (function PDFImageClosure() {
  32383. /**
  32384. * Decode the image in the main thread if it supported. Resovles the promise
  32385. * when the image data is ready.
  32386. */
  32387. function handleImageData(handler, xref, res, image) {
  32388. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  32389. // For natively supported jpegs send them to the main thread for decoding.
  32390. var dict = image.dict;
  32391. var colorSpace = dict.get('ColorSpace', 'CS');
  32392. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32393. var numComps = colorSpace.numComps;
  32394. var decodePromise = handler.sendWithPromise('JpegDecode',
  32395. [image.getIR(), numComps]);
  32396. return decodePromise.then(function (message) {
  32397. var data = message.data;
  32398. return new Stream(data, 0, data.length, image.dict);
  32399. });
  32400. } else {
  32401. return Promise.resolve(image);
  32402. }
  32403. }
  32404. /**
  32405. * Decode and clamp a value. The formula is different from the spec because we
  32406. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32407. */
  32408. function decodeAndClamp(value, addend, coefficient, max) {
  32409. value = addend + value * coefficient;
  32410. // Clamp the value to the range
  32411. return (value < 0 ? 0 : (value > max ? max : value));
  32412. }
  32413. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32414. this.image = image;
  32415. var dict = image.dict;
  32416. if (dict.has('Filter')) {
  32417. var filter = dict.get('Filter').name;
  32418. if (filter === 'JPXDecode') {
  32419. var jpxImage = new JpxImage();
  32420. jpxImage.parseImageProperties(image.stream);
  32421. image.stream.reset();
  32422. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32423. image.numComps = jpxImage.componentsCount;
  32424. } else if (filter === 'JBIG2Decode') {
  32425. image.bitsPerComponent = 1;
  32426. image.numComps = 1;
  32427. }
  32428. }
  32429. // TODO cache rendered images?
  32430. this.width = dict.get('Width', 'W');
  32431. this.height = dict.get('Height', 'H');
  32432. if (this.width < 1 || this.height < 1) {
  32433. error('Invalid image width: ' + this.width + ' or height: ' +
  32434. this.height);
  32435. }
  32436. this.interpolate = dict.get('Interpolate', 'I') || false;
  32437. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32438. this.matte = dict.get('Matte') || false;
  32439. var bitsPerComponent = image.bitsPerComponent;
  32440. if (!bitsPerComponent) {
  32441. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32442. if (!bitsPerComponent) {
  32443. if (this.imageMask) {
  32444. bitsPerComponent = 1;
  32445. } else {
  32446. error('Bits per component missing in image: ' + this.imageMask);
  32447. }
  32448. }
  32449. }
  32450. this.bpc = bitsPerComponent;
  32451. if (!this.imageMask) {
  32452. var colorSpace = dict.get('ColorSpace', 'CS');
  32453. if (!colorSpace) {
  32454. info('JPX images (which do not require color spaces)');
  32455. switch (image.numComps) {
  32456. case 1:
  32457. colorSpace = Name.get('DeviceGray');
  32458. break;
  32459. case 3:
  32460. colorSpace = Name.get('DeviceRGB');
  32461. break;
  32462. case 4:
  32463. colorSpace = Name.get('DeviceCMYK');
  32464. break;
  32465. default:
  32466. error('JPX images with ' + this.numComps +
  32467. ' color components not supported.');
  32468. }
  32469. }
  32470. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32471. this.numComps = this.colorSpace.numComps;
  32472. }
  32473. this.decode = dict.get('Decode', 'D');
  32474. this.needsDecode = false;
  32475. if (this.decode &&
  32476. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32477. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32478. this.needsDecode = true;
  32479. // Do some preprocessing to avoid more math.
  32480. var max = (1 << bitsPerComponent) - 1;
  32481. this.decodeCoefficients = [];
  32482. this.decodeAddends = [];
  32483. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32484. var dmin = this.decode[i];
  32485. var dmax = this.decode[i + 1];
  32486. this.decodeCoefficients[j] = dmax - dmin;
  32487. this.decodeAddends[j] = max * dmin;
  32488. }
  32489. }
  32490. if (smask) {
  32491. this.smask = new PDFImage(xref, res, smask, false);
  32492. } else if (mask) {
  32493. if (isStream(mask)) {
  32494. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32495. if (!imageMask) {
  32496. warn('Ignoring /Mask in image without /ImageMask.');
  32497. } else {
  32498. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32499. }
  32500. } else {
  32501. // Color key mask (just an array).
  32502. this.mask = mask;
  32503. }
  32504. }
  32505. }
  32506. /**
  32507. * Handles processing of image data and returns the Promise that is resolved
  32508. * with a PDFImage when the image is ready to be used.
  32509. */
  32510. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32511. res, image, inline) {
  32512. var imagePromise = handleImageData(handler, xref, res, image);
  32513. var smaskPromise;
  32514. var maskPromise;
  32515. var smask = image.dict.get('SMask');
  32516. var mask = image.dict.get('Mask');
  32517. if (smask) {
  32518. smaskPromise = handleImageData(handler, xref, res, smask);
  32519. maskPromise = Promise.resolve(null);
  32520. } else {
  32521. smaskPromise = Promise.resolve(null);
  32522. if (mask) {
  32523. if (isStream(mask)) {
  32524. maskPromise = handleImageData(handler, xref, res, mask);
  32525. } else if (isArray(mask)) {
  32526. maskPromise = Promise.resolve(mask);
  32527. } else {
  32528. warn('Unsupported mask format.');
  32529. maskPromise = Promise.resolve(null);
  32530. }
  32531. } else {
  32532. maskPromise = Promise.resolve(null);
  32533. }
  32534. }
  32535. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32536. function(results) {
  32537. var imageData = results[0];
  32538. var smaskData = results[1];
  32539. var maskData = results[2];
  32540. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32541. });
  32542. };
  32543. /**
  32544. * Resize an image using the nearest neighbor algorithm. Currently only
  32545. * supports one and three component images.
  32546. * @param {TypedArray} pixels The original image with one component.
  32547. * @param {Number} bpc Number of bits per component.
  32548. * @param {Number} components Number of color components, 1 or 3 is supported.
  32549. * @param {Number} w1 Original width.
  32550. * @param {Number} h1 Original height.
  32551. * @param {Number} w2 New width.
  32552. * @param {Number} h2 New height.
  32553. * @param {TypedArray} dest (Optional) The destination buffer.
  32554. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32555. * @return {TypedArray} Resized image data.
  32556. */
  32557. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32558. w1, h1, w2, h2, dest, alpha01) {
  32559. if (components !== 1 && components !== 3) {
  32560. error('Unsupported component count for resizing.');
  32561. }
  32562. var length = w2 * h2 * components;
  32563. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32564. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32565. var xRatio = w1 / w2;
  32566. var yRatio = h1 / h2;
  32567. var i, j, py, newIndex = 0, oldIndex;
  32568. var xScaled = new Uint16Array(w2);
  32569. var w1Scanline = w1 * components;
  32570. if (alpha01 !== 1) {
  32571. alpha01 = 0;
  32572. }
  32573. for (j = 0; j < w2; j++) {
  32574. xScaled[j] = Math.floor(j * xRatio) * components;
  32575. }
  32576. if (components === 1) {
  32577. for (i = 0; i < h2; i++) {
  32578. py = Math.floor(i * yRatio) * w1Scanline;
  32579. for (j = 0; j < w2; j++) {
  32580. oldIndex = py + xScaled[j];
  32581. temp[newIndex++] = pixels[oldIndex];
  32582. }
  32583. }
  32584. } else if (components === 3) {
  32585. for (i = 0; i < h2; i++) {
  32586. py = Math.floor(i * yRatio) * w1Scanline;
  32587. for (j = 0; j < w2; j++) {
  32588. oldIndex = py + xScaled[j];
  32589. temp[newIndex++] = pixels[oldIndex++];
  32590. temp[newIndex++] = pixels[oldIndex++];
  32591. temp[newIndex++] = pixels[oldIndex++];
  32592. newIndex += alpha01;
  32593. }
  32594. }
  32595. }
  32596. return temp;
  32597. };
  32598. PDFImage.createMask =
  32599. function PDFImage_createMask(imgArray, width, height,
  32600. imageIsFromDecodeStream, inverseDecode) {
  32601. // |imgArray| might not contain full data for every pixel of the mask, so
  32602. // we need to distinguish between |computedLength| and |actualLength|.
  32603. // In particular, if inverseDecode is true, then the array we return must
  32604. // have a length of |computedLength|.
  32605. var computedLength = ((width + 7) >> 3) * height;
  32606. var actualLength = imgArray.byteLength;
  32607. var haveFullData = computedLength === actualLength;
  32608. var data, i;
  32609. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32610. // imgArray came from a DecodeStream and its data is in an appropriate
  32611. // form, so we can just transfer it.
  32612. data = imgArray;
  32613. } else if (!inverseDecode) {
  32614. data = new Uint8Array(actualLength);
  32615. data.set(imgArray);
  32616. } else {
  32617. data = new Uint8Array(computedLength);
  32618. data.set(imgArray);
  32619. for (i = actualLength; i < computedLength; i++) {
  32620. data[i] = 0xff;
  32621. }
  32622. }
  32623. // If necessary, invert the original mask data (but not any extra we might
  32624. // have added above). It's safe to modify the array -- whether it's the
  32625. // original or a copy, we're about to transfer it anyway, so nothing else
  32626. // in this thread can be relying on its contents.
  32627. if (inverseDecode) {
  32628. for (i = 0; i < actualLength; i++) {
  32629. data[i] = ~data[i];
  32630. }
  32631. }
  32632. return {data: data, width: width, height: height};
  32633. };
  32634. PDFImage.prototype = {
  32635. get drawWidth() {
  32636. return Math.max(this.width,
  32637. this.smask && this.smask.width || 0,
  32638. this.mask && this.mask.width || 0);
  32639. },
  32640. get drawHeight() {
  32641. return Math.max(this.height,
  32642. this.smask && this.smask.height || 0,
  32643. this.mask && this.mask.height || 0);
  32644. },
  32645. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32646. var bpc = this.bpc;
  32647. var numComps = this.numComps;
  32648. var decodeAddends = this.decodeAddends;
  32649. var decodeCoefficients = this.decodeCoefficients;
  32650. var max = (1 << bpc) - 1;
  32651. var i, ii;
  32652. if (bpc === 1) {
  32653. // If the buffer needed decode that means it just needs to be inverted.
  32654. for (i = 0, ii = buffer.length; i < ii; i++) {
  32655. buffer[i] = +!(buffer[i]);
  32656. }
  32657. return;
  32658. }
  32659. var index = 0;
  32660. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32661. for (var j = 0; j < numComps; j++) {
  32662. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32663. decodeCoefficients[j], max);
  32664. index++;
  32665. }
  32666. }
  32667. },
  32668. getComponents: function PDFImage_getComponents(buffer) {
  32669. var bpc = this.bpc;
  32670. // This image doesn't require any extra work.
  32671. if (bpc === 8) {
  32672. return buffer;
  32673. }
  32674. var width = this.width;
  32675. var height = this.height;
  32676. var numComps = this.numComps;
  32677. var length = width * height * numComps;
  32678. var bufferPos = 0;
  32679. var output = (bpc <= 8 ? new Uint8Array(length) :
  32680. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32681. var rowComps = width * numComps;
  32682. var max = (1 << bpc) - 1;
  32683. var i = 0, ii, buf;
  32684. if (bpc === 1) {
  32685. // Optimization for reading 1 bpc images.
  32686. var mask, loop1End, loop2End;
  32687. for (var j = 0; j < height; j++) {
  32688. loop1End = i + (rowComps & ~7);
  32689. loop2End = i + rowComps;
  32690. // unroll loop for all full bytes
  32691. while (i < loop1End) {
  32692. buf = buffer[bufferPos++];
  32693. output[i] = (buf >> 7) & 1;
  32694. output[i + 1] = (buf >> 6) & 1;
  32695. output[i + 2] = (buf >> 5) & 1;
  32696. output[i + 3] = (buf >> 4) & 1;
  32697. output[i + 4] = (buf >> 3) & 1;
  32698. output[i + 5] = (buf >> 2) & 1;
  32699. output[i + 6] = (buf >> 1) & 1;
  32700. output[i + 7] = buf & 1;
  32701. i += 8;
  32702. }
  32703. // handle remaing bits
  32704. if (i < loop2End) {
  32705. buf = buffer[bufferPos++];
  32706. mask = 128;
  32707. while (i < loop2End) {
  32708. output[i++] = +!!(buf & mask);
  32709. mask >>= 1;
  32710. }
  32711. }
  32712. }
  32713. } else {
  32714. // The general case that handles all other bpc values.
  32715. var bits = 0;
  32716. buf = 0;
  32717. for (i = 0, ii = length; i < ii; ++i) {
  32718. if (i % rowComps === 0) {
  32719. buf = 0;
  32720. bits = 0;
  32721. }
  32722. while (bits < bpc) {
  32723. buf = (buf << 8) | buffer[bufferPos++];
  32724. bits += 8;
  32725. }
  32726. var remainingBits = bits - bpc;
  32727. var value = buf >> remainingBits;
  32728. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32729. buf = buf & ((1 << remainingBits) - 1);
  32730. bits = remainingBits;
  32731. }
  32732. }
  32733. return output;
  32734. },
  32735. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32736. actualHeight, image) {
  32737. var smask = this.smask;
  32738. var mask = this.mask;
  32739. var alphaBuf, sw, sh, i, ii, j;
  32740. if (smask) {
  32741. sw = smask.width;
  32742. sh = smask.height;
  32743. alphaBuf = new Uint8Array(sw * sh);
  32744. smask.fillGrayBuffer(alphaBuf);
  32745. if (sw !== width || sh !== height) {
  32746. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32747. height);
  32748. }
  32749. } else if (mask) {
  32750. if (mask instanceof PDFImage) {
  32751. sw = mask.width;
  32752. sh = mask.height;
  32753. alphaBuf = new Uint8Array(sw * sh);
  32754. mask.numComps = 1;
  32755. mask.fillGrayBuffer(alphaBuf);
  32756. // Need to invert values in rgbaBuf
  32757. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32758. alphaBuf[i] = 255 - alphaBuf[i];
  32759. }
  32760. if (sw !== width || sh !== height) {
  32761. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32762. height);
  32763. }
  32764. } else if (isArray(mask)) {
  32765. // Color key mask: if any of the compontents are outside the range
  32766. // then they should be painted.
  32767. alphaBuf = new Uint8Array(width * height);
  32768. var numComps = this.numComps;
  32769. for (i = 0, ii = width * height; i < ii; ++i) {
  32770. var opacity = 0;
  32771. var imageOffset = i * numComps;
  32772. for (j = 0; j < numComps; ++j) {
  32773. var color = image[imageOffset + j];
  32774. var maskOffset = j * 2;
  32775. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32776. opacity = 255;
  32777. break;
  32778. }
  32779. }
  32780. alphaBuf[i] = opacity;
  32781. }
  32782. } else {
  32783. error('Unknown mask format.');
  32784. }
  32785. }
  32786. if (alphaBuf) {
  32787. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32788. rgbaBuf[j] = alphaBuf[i];
  32789. }
  32790. } else {
  32791. // No mask.
  32792. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32793. rgbaBuf[j] = 255;
  32794. }
  32795. }
  32796. },
  32797. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32798. var matte = this.smask && this.smask.matte;
  32799. if (!matte) {
  32800. return;
  32801. }
  32802. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32803. var matteR = matteRgb[0];
  32804. var matteG = matteRgb[1];
  32805. var matteB = matteRgb[2];
  32806. var length = width * height * 4;
  32807. var r, g, b;
  32808. for (var i = 0; i < length; i += 4) {
  32809. var alpha = buffer[i + 3];
  32810. if (alpha === 0) {
  32811. // according formula we have to get Infinity in all components
  32812. // making it white (typical paper color) should be okay
  32813. buffer[i] = 255;
  32814. buffer[i + 1] = 255;
  32815. buffer[i + 2] = 255;
  32816. continue;
  32817. }
  32818. var k = 255 / alpha;
  32819. r = (buffer[i] - matteR) * k + matteR;
  32820. g = (buffer[i + 1] - matteG) * k + matteG;
  32821. b = (buffer[i + 2] - matteB) * k + matteB;
  32822. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32823. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32824. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32825. }
  32826. },
  32827. createImageData: function PDFImage_createImageData(forceRGBA) {
  32828. var drawWidth = this.drawWidth;
  32829. var drawHeight = this.drawHeight;
  32830. var imgData = { // other fields are filled in below
  32831. width: drawWidth,
  32832. height: drawHeight
  32833. };
  32834. var numComps = this.numComps;
  32835. var originalWidth = this.width;
  32836. var originalHeight = this.height;
  32837. var bpc = this.bpc;
  32838. // Rows start at byte boundary.
  32839. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32840. var imgArray;
  32841. if (!forceRGBA) {
  32842. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32843. // without any complications, we pass a same-sized copy to the main
  32844. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32845. // of memory for many scanned documents. It's also much faster.
  32846. //
  32847. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32848. // complications, we avoid expanding by 1.333x to RGBA form.
  32849. var kind;
  32850. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32851. kind = ImageKind.GRAYSCALE_1BPP;
  32852. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32853. !this.needsDecode) {
  32854. kind = ImageKind.RGB_24BPP;
  32855. }
  32856. if (kind && !this.smask && !this.mask &&
  32857. drawWidth === originalWidth && drawHeight === originalHeight) {
  32858. imgData.kind = kind;
  32859. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32860. // If imgArray came from a DecodeStream, we're safe to transfer it
  32861. // (and thus neuter it) because it will constitute the entire
  32862. // DecodeStream's data. But if it came from a Stream, we need to
  32863. // copy it because it'll only be a portion of the Stream's data, and
  32864. // the rest will be read later on.
  32865. if (this.image instanceof DecodeStream) {
  32866. imgData.data = imgArray;
  32867. } else {
  32868. var newArray = new Uint8Array(imgArray.length);
  32869. newArray.set(imgArray);
  32870. imgData.data = newArray;
  32871. }
  32872. if (this.needsDecode) {
  32873. // Invert the buffer (which must be grayscale if we reached here).
  32874. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32875. var buffer = imgData.data;
  32876. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32877. buffer[i] ^= 0xff;
  32878. }
  32879. }
  32880. return imgData;
  32881. }
  32882. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32883. (this.colorSpace.name === 'DeviceGray' ||
  32884. this.colorSpace.name === 'DeviceRGB' ||
  32885. this.colorSpace.name === 'DeviceCMYK')) {
  32886. imgData.kind = ImageKind.RGB_24BPP;
  32887. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32888. drawWidth, drawHeight, true);
  32889. return imgData;
  32890. }
  32891. }
  32892. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32893. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32894. var actualHeight = 0 | (imgArray.length / rowBytes *
  32895. drawHeight / originalHeight);
  32896. var comps = this.getComponents(imgArray);
  32897. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32898. // more compact RGB_24BPP form if allowable.
  32899. var alpha01, maybeUndoPreblend;
  32900. if (!forceRGBA && !this.smask && !this.mask) {
  32901. imgData.kind = ImageKind.RGB_24BPP;
  32902. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32903. alpha01 = 0;
  32904. maybeUndoPreblend = false;
  32905. } else {
  32906. imgData.kind = ImageKind.RGBA_32BPP;
  32907. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32908. alpha01 = 1;
  32909. maybeUndoPreblend = true;
  32910. // Color key masking (opacity) must be performed before decoding.
  32911. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32912. comps);
  32913. }
  32914. if (this.needsDecode) {
  32915. this.decodeBuffer(comps);
  32916. }
  32917. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32918. drawWidth, drawHeight, actualHeight, bpc, comps,
  32919. alpha01);
  32920. if (maybeUndoPreblend) {
  32921. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32922. }
  32923. return imgData;
  32924. },
  32925. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32926. var numComps = this.numComps;
  32927. if (numComps !== 1) {
  32928. error('Reading gray scale from a color image: ' + numComps);
  32929. }
  32930. var width = this.width;
  32931. var height = this.height;
  32932. var bpc = this.bpc;
  32933. // rows start at byte boundary
  32934. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32935. var imgArray = this.getImageBytes(height * rowBytes);
  32936. var comps = this.getComponents(imgArray);
  32937. var i, length;
  32938. if (bpc === 1) {
  32939. // inline decoding (= inversion) for 1 bpc images
  32940. length = width * height;
  32941. if (this.needsDecode) {
  32942. // invert and scale to {0, 255}
  32943. for (i = 0; i < length; ++i) {
  32944. buffer[i] = (comps[i] - 1) & 255;
  32945. }
  32946. } else {
  32947. // scale to {0, 255}
  32948. for (i = 0; i < length; ++i) {
  32949. buffer[i] = (-comps[i]) & 255;
  32950. }
  32951. }
  32952. return;
  32953. }
  32954. if (this.needsDecode) {
  32955. this.decodeBuffer(comps);
  32956. }
  32957. length = width * height;
  32958. // we aren't using a colorspace so we need to scale the value
  32959. var scale = 255 / ((1 << bpc) - 1);
  32960. for (i = 0; i < length; ++i) {
  32961. buffer[i] = (scale * comps[i]) | 0;
  32962. }
  32963. },
  32964. getImageBytes: function PDFImage_getImageBytes(length,
  32965. drawWidth, drawHeight,
  32966. forceRGB) {
  32967. this.image.reset();
  32968. this.image.drawWidth = drawWidth || this.width;
  32969. this.image.drawHeight = drawHeight || this.height;
  32970. this.image.forceRGB = !!forceRGB;
  32971. return this.image.getBytes(length);
  32972. }
  32973. };
  32974. return PDFImage;
  32975. })();
  32976. exports.PDFImage = PDFImage;
  32977. // TODO refactor to remove dependency on colorspace.js
  32978. coreColorSpace._setCoreImage(exports);
  32979. }));
  32980. (function (root, factory) {
  32981. {
  32982. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  32983. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  32984. root.pdfjsCoreColorSpace);
  32985. }
  32986. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  32987. coreColorSpace) {
  32988. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  32989. var MissingDataException = sharedUtil.MissingDataException;
  32990. var Util = sharedUtil.Util;
  32991. var assert = sharedUtil.assert;
  32992. var error = sharedUtil.error;
  32993. var info = sharedUtil.info;
  32994. var warn = sharedUtil.warn;
  32995. var isStream = corePrimitives.isStream;
  32996. var PDFFunction = coreFunction.PDFFunction;
  32997. var ColorSpace = coreColorSpace.ColorSpace;
  32998. var ShadingType = {
  32999. FUNCTION_BASED: 1,
  33000. AXIAL: 2,
  33001. RADIAL: 3,
  33002. FREE_FORM_MESH: 4,
  33003. LATTICE_FORM_MESH: 5,
  33004. COONS_PATCH_MESH: 6,
  33005. TENSOR_PATCH_MESH: 7
  33006. };
  33007. var Pattern = (function PatternClosure() {
  33008. // Constructor should define this.getPattern
  33009. function Pattern() {
  33010. error('should not call Pattern constructor');
  33011. }
  33012. Pattern.prototype = {
  33013. // Input: current Canvas context
  33014. // Output: the appropriate fillStyle or strokeStyle
  33015. getPattern: function Pattern_getPattern(ctx) {
  33016. error('Should not call Pattern.getStyle: ' + ctx);
  33017. }
  33018. };
  33019. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33020. res, handler) {
  33021. var dict = isStream(shading) ? shading.dict : shading;
  33022. var type = dict.get('ShadingType');
  33023. try {
  33024. switch (type) {
  33025. case ShadingType.AXIAL:
  33026. case ShadingType.RADIAL:
  33027. // Both radial and axial shadings are handled by RadialAxial shading.
  33028. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33029. case ShadingType.FREE_FORM_MESH:
  33030. case ShadingType.LATTICE_FORM_MESH:
  33031. case ShadingType.COONS_PATCH_MESH:
  33032. case ShadingType.TENSOR_PATCH_MESH:
  33033. return new Shadings.Mesh(shading, matrix, xref, res);
  33034. default:
  33035. throw new Error('Unsupported ShadingType: ' + type);
  33036. }
  33037. } catch (ex) {
  33038. if (ex instanceof MissingDataException) {
  33039. throw ex;
  33040. }
  33041. handler.send('UnsupportedFeature',
  33042. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33043. warn(ex);
  33044. return new Shadings.Dummy();
  33045. }
  33046. };
  33047. return Pattern;
  33048. })();
  33049. var Shadings = {};
  33050. // A small number to offset the first/last color stops so we can insert ones to
  33051. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  33052. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  33053. // internally so we have to go bigger.
  33054. Shadings.SMALL_NUMBER = 1e-2;
  33055. // Radial and axial shading have very similar implementations
  33056. // If needed, the implementations can be broken into two classes
  33057. Shadings.RadialAxial = (function RadialAxialClosure() {
  33058. function RadialAxial(dict, matrix, xref, res) {
  33059. this.matrix = matrix;
  33060. this.coordsArr = dict.get('Coords');
  33061. this.shadingType = dict.get('ShadingType');
  33062. this.type = 'Pattern';
  33063. var cs = dict.get('ColorSpace', 'CS');
  33064. cs = ColorSpace.parse(cs, xref, res);
  33065. this.cs = cs;
  33066. var t0 = 0.0, t1 = 1.0;
  33067. if (dict.has('Domain')) {
  33068. var domainArr = dict.get('Domain');
  33069. t0 = domainArr[0];
  33070. t1 = domainArr[1];
  33071. }
  33072. var extendStart = false, extendEnd = false;
  33073. if (dict.has('Extend')) {
  33074. var extendArr = dict.get('Extend');
  33075. extendStart = extendArr[0];
  33076. extendEnd = extendArr[1];
  33077. }
  33078. if (this.shadingType === ShadingType.RADIAL &&
  33079. (!extendStart || !extendEnd)) {
  33080. // Radial gradient only currently works if either circle is fully within
  33081. // the other circle.
  33082. var x1 = this.coordsArr[0];
  33083. var y1 = this.coordsArr[1];
  33084. var r1 = this.coordsArr[2];
  33085. var x2 = this.coordsArr[3];
  33086. var y2 = this.coordsArr[4];
  33087. var r2 = this.coordsArr[5];
  33088. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  33089. if (r1 <= r2 + distance &&
  33090. r2 <= r1 + distance) {
  33091. warn('Unsupported radial gradient.');
  33092. }
  33093. }
  33094. this.extendStart = extendStart;
  33095. this.extendEnd = extendEnd;
  33096. var fnObj = dict.get('Function');
  33097. var fn = PDFFunction.parseArray(xref, fnObj);
  33098. // 10 samples seems good enough for now, but probably won't work
  33099. // if there are sharp color changes. Ideally, we would implement
  33100. // the spec faithfully and add lossless optimizations.
  33101. var diff = t1 - t0;
  33102. var step = diff / 10;
  33103. var colorStops = this.colorStops = [];
  33104. // Protect against bad domains so we don't end up in an infinte loop below.
  33105. if (t0 >= t1 || step <= 0) {
  33106. // Acrobat doesn't seem to handle these cases so we'll ignore for
  33107. // now.
  33108. info('Bad shading domain.');
  33109. return;
  33110. }
  33111. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  33112. var rgbColor;
  33113. for (var i = t0; i <= t1; i += step) {
  33114. ratio[0] = i;
  33115. fn(ratio, 0, color, 0);
  33116. rgbColor = cs.getRgb(color, 0);
  33117. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33118. colorStops.push([(i - t0) / diff, cssColor]);
  33119. }
  33120. var background = 'transparent';
  33121. if (dict.has('Background')) {
  33122. rgbColor = cs.getRgb(dict.get('Background'), 0);
  33123. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33124. }
  33125. if (!extendStart) {
  33126. // Insert a color stop at the front and offset the first real color stop
  33127. // so it doesn't conflict with the one we insert.
  33128. colorStops.unshift([0, background]);
  33129. colorStops[1][0] += Shadings.SMALL_NUMBER;
  33130. }
  33131. if (!extendEnd) {
  33132. // Same idea as above in extendStart but for the end.
  33133. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  33134. colorStops.push([1, background]);
  33135. }
  33136. this.colorStops = colorStops;
  33137. }
  33138. RadialAxial.prototype = {
  33139. getIR: function RadialAxial_getIR() {
  33140. var coordsArr = this.coordsArr;
  33141. var shadingType = this.shadingType;
  33142. var type, p0, p1, r0, r1;
  33143. if (shadingType === ShadingType.AXIAL) {
  33144. p0 = [coordsArr[0], coordsArr[1]];
  33145. p1 = [coordsArr[2], coordsArr[3]];
  33146. r0 = null;
  33147. r1 = null;
  33148. type = 'axial';
  33149. } else if (shadingType === ShadingType.RADIAL) {
  33150. p0 = [coordsArr[0], coordsArr[1]];
  33151. p1 = [coordsArr[3], coordsArr[4]];
  33152. r0 = coordsArr[2];
  33153. r1 = coordsArr[5];
  33154. type = 'radial';
  33155. } else {
  33156. error('getPattern type unknown: ' + shadingType);
  33157. }
  33158. var matrix = this.matrix;
  33159. if (matrix) {
  33160. p0 = Util.applyTransform(p0, matrix);
  33161. p1 = Util.applyTransform(p1, matrix);
  33162. if (shadingType === ShadingType.RADIAL) {
  33163. var scale = Util.singularValueDecompose2dScale(matrix);
  33164. r0 *= scale[0];
  33165. r1 *= scale[1];
  33166. }
  33167. }
  33168. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  33169. }
  33170. };
  33171. return RadialAxial;
  33172. })();
  33173. // All mesh shading. For now, they will be presented as set of the triangles
  33174. // to be drawn on the canvas and rgb color for each vertex.
  33175. Shadings.Mesh = (function MeshClosure() {
  33176. function MeshStreamReader(stream, context) {
  33177. this.stream = stream;
  33178. this.context = context;
  33179. this.buffer = 0;
  33180. this.bufferLength = 0;
  33181. var numComps = context.numComps;
  33182. this.tmpCompsBuf = new Float32Array(numComps);
  33183. var csNumComps = context.colorSpace.numComps;
  33184. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  33185. this.tmpCompsBuf;
  33186. }
  33187. MeshStreamReader.prototype = {
  33188. get hasData() {
  33189. if (this.stream.end) {
  33190. return this.stream.pos < this.stream.end;
  33191. }
  33192. if (this.bufferLength > 0) {
  33193. return true;
  33194. }
  33195. var nextByte = this.stream.getByte();
  33196. if (nextByte < 0) {
  33197. return false;
  33198. }
  33199. this.buffer = nextByte;
  33200. this.bufferLength = 8;
  33201. return true;
  33202. },
  33203. readBits: function MeshStreamReader_readBits(n) {
  33204. var buffer = this.buffer;
  33205. var bufferLength = this.bufferLength;
  33206. if (n === 32) {
  33207. if (bufferLength === 0) {
  33208. return ((this.stream.getByte() << 24) |
  33209. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  33210. this.stream.getByte()) >>> 0;
  33211. }
  33212. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  33213. (this.stream.getByte() << 8) | this.stream.getByte();
  33214. var nextByte = this.stream.getByte();
  33215. this.buffer = nextByte & ((1 << bufferLength) - 1);
  33216. return ((buffer << (8 - bufferLength)) |
  33217. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  33218. }
  33219. if (n === 8 && bufferLength === 0) {
  33220. return this.stream.getByte();
  33221. }
  33222. while (bufferLength < n) {
  33223. buffer = (buffer << 8) | this.stream.getByte();
  33224. bufferLength += 8;
  33225. }
  33226. bufferLength -= n;
  33227. this.bufferLength = bufferLength;
  33228. this.buffer = buffer & ((1 << bufferLength) - 1);
  33229. return buffer >> bufferLength;
  33230. },
  33231. align: function MeshStreamReader_align() {
  33232. this.buffer = 0;
  33233. this.bufferLength = 0;
  33234. },
  33235. readFlag: function MeshStreamReader_readFlag() {
  33236. return this.readBits(this.context.bitsPerFlag);
  33237. },
  33238. readCoordinate: function MeshStreamReader_readCoordinate() {
  33239. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  33240. var xi = this.readBits(bitsPerCoordinate);
  33241. var yi = this.readBits(bitsPerCoordinate);
  33242. var decode = this.context.decode;
  33243. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  33244. 2.3283064365386963e-10; // 2 ^ -32
  33245. return [
  33246. xi * scale * (decode[1] - decode[0]) + decode[0],
  33247. yi * scale * (decode[3] - decode[2]) + decode[2]
  33248. ];
  33249. },
  33250. readComponents: function MeshStreamReader_readComponents() {
  33251. var numComps = this.context.numComps;
  33252. var bitsPerComponent = this.context.bitsPerComponent;
  33253. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  33254. 2.3283064365386963e-10; // 2 ^ -32
  33255. var decode = this.context.decode;
  33256. var components = this.tmpCompsBuf;
  33257. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  33258. var ci = this.readBits(bitsPerComponent);
  33259. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  33260. }
  33261. var color = this.tmpCsCompsBuf;
  33262. if (this.context.colorFn) {
  33263. this.context.colorFn(components, 0, color, 0);
  33264. }
  33265. return this.context.colorSpace.getRgb(color, 0);
  33266. }
  33267. };
  33268. function decodeType4Shading(mesh, reader) {
  33269. var coords = mesh.coords;
  33270. var colors = mesh.colors;
  33271. var operators = [];
  33272. var ps = []; // not maintaining cs since that will match ps
  33273. var verticesLeft = 0; // assuming we have all data to start a new triangle
  33274. while (reader.hasData) {
  33275. var f = reader.readFlag();
  33276. var coord = reader.readCoordinate();
  33277. var color = reader.readComponents();
  33278. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  33279. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  33280. switch (f) {
  33281. case 0:
  33282. verticesLeft = 3;
  33283. break;
  33284. case 1:
  33285. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  33286. verticesLeft = 1;
  33287. break;
  33288. case 2:
  33289. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  33290. verticesLeft = 1;
  33291. break;
  33292. }
  33293. operators.push(f);
  33294. }
  33295. ps.push(coords.length);
  33296. coords.push(coord);
  33297. colors.push(color);
  33298. verticesLeft--;
  33299. reader.align();
  33300. }
  33301. mesh.figures.push({
  33302. type: 'triangles',
  33303. coords: new Int32Array(ps),
  33304. colors: new Int32Array(ps),
  33305. });
  33306. }
  33307. function decodeType5Shading(mesh, reader, verticesPerRow) {
  33308. var coords = mesh.coords;
  33309. var colors = mesh.colors;
  33310. var ps = []; // not maintaining cs since that will match ps
  33311. while (reader.hasData) {
  33312. var coord = reader.readCoordinate();
  33313. var color = reader.readComponents();
  33314. ps.push(coords.length);
  33315. coords.push(coord);
  33316. colors.push(color);
  33317. }
  33318. mesh.figures.push({
  33319. type: 'lattice',
  33320. coords: new Int32Array(ps),
  33321. colors: new Int32Array(ps),
  33322. verticesPerRow: verticesPerRow
  33323. });
  33324. }
  33325. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  33326. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  33327. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  33328. var getB = (function getBClosure() {
  33329. function buildB(count) {
  33330. var lut = [];
  33331. for (var i = 0; i <= count; i++) {
  33332. var t = i / count, t_ = 1 - t;
  33333. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  33334. 3 * t * t * t_, t * t * t]));
  33335. }
  33336. return lut;
  33337. }
  33338. var cache = [];
  33339. return function getB(count) {
  33340. if (!cache[count]) {
  33341. cache[count] = buildB(count);
  33342. }
  33343. return cache[count];
  33344. };
  33345. })();
  33346. function buildFigureFromPatch(mesh, index) {
  33347. var figure = mesh.figures[index];
  33348. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  33349. var coords = mesh.coords, colors = mesh.colors;
  33350. var pi = figure.coords;
  33351. var ci = figure.colors;
  33352. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  33353. coords[pi[12]][0], coords[pi[15]][0]);
  33354. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  33355. coords[pi[12]][1], coords[pi[15]][1]);
  33356. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  33357. coords[pi[12]][0], coords[pi[15]][0]);
  33358. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  33359. coords[pi[12]][1], coords[pi[15]][1]);
  33360. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  33361. (mesh.bounds[2] - mesh.bounds[0]));
  33362. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33363. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  33364. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  33365. (mesh.bounds[3] - mesh.bounds[1]));
  33366. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33367. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  33368. var verticesPerRow = splitXBy + 1;
  33369. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  33370. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  33371. var k = 0;
  33372. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  33373. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  33374. c2 = colors[ci[2]], c3 = colors[ci[3]];
  33375. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  33376. for (var row = 0; row <= splitYBy; row++) {
  33377. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  33378. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  33379. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  33380. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  33381. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  33382. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  33383. for (var col = 0; col <= splitXBy; col++, k++) {
  33384. if ((row === 0 || row === splitYBy) &&
  33385. (col === 0 || col === splitXBy)) {
  33386. continue;
  33387. }
  33388. var x = 0, y = 0;
  33389. var q = 0;
  33390. for (var i = 0; i <= 3; i++) {
  33391. for (var j = 0; j <= 3; j++, q++) {
  33392. var m = bRow[row][i] * bCol[col][j];
  33393. x += coords[pi[q]][0] * m;
  33394. y += coords[pi[q]][1] * m;
  33395. }
  33396. }
  33397. figureCoords[k] = coords.length;
  33398. coords.push([x, y]);
  33399. figureColors[k] = colors.length;
  33400. var newColor = new Uint8Array(3);
  33401. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  33402. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  33403. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  33404. colors.push(newColor);
  33405. }
  33406. }
  33407. figureCoords[0] = pi[0];
  33408. figureColors[0] = ci[0];
  33409. figureCoords[splitXBy] = pi[3];
  33410. figureColors[splitXBy] = ci[1];
  33411. figureCoords[verticesPerRow * splitYBy] = pi[12];
  33412. figureColors[verticesPerRow * splitYBy] = ci[2];
  33413. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  33414. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  33415. mesh.figures[index] = {
  33416. type: 'lattice',
  33417. coords: figureCoords,
  33418. colors: figureColors,
  33419. verticesPerRow: verticesPerRow
  33420. };
  33421. }
  33422. function decodeType6Shading(mesh, reader) {
  33423. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  33424. var coords = mesh.coords;
  33425. var colors = mesh.colors;
  33426. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33427. var cs = new Int32Array(4); // c00, c30, c03, c33
  33428. while (reader.hasData) {
  33429. var f = reader.readFlag();
  33430. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  33431. var i, ii;
  33432. var pi = coords.length;
  33433. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  33434. coords.push(reader.readCoordinate());
  33435. }
  33436. var ci = colors.length;
  33437. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33438. colors.push(reader.readComponents());
  33439. }
  33440. var tmp1, tmp2, tmp3, tmp4;
  33441. switch (f) {
  33442. case 0:
  33443. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33444. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  33445. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  33446. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33447. cs[2] = ci + 1; cs[3] = ci + 2;
  33448. cs[0] = ci; cs[1] = ci + 3;
  33449. break;
  33450. case 1:
  33451. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33452. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33453. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33454. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33455. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33456. tmp1 = cs[2]; tmp2 = cs[3];
  33457. cs[2] = tmp2; cs[3] = ci;
  33458. cs[0] = tmp1; cs[1] = ci + 1;
  33459. break;
  33460. case 2:
  33461. tmp1 = ps[15];
  33462. tmp2 = ps[11];
  33463. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33464. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33465. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33466. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33467. tmp1 = cs[3];
  33468. cs[2] = cs[1]; cs[3] = ci;
  33469. cs[0] = tmp1; cs[1] = ci + 1;
  33470. break;
  33471. case 3:
  33472. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33473. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33474. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  33475. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33476. cs[2] = cs[0]; cs[3] = ci;
  33477. cs[0] = cs[1]; cs[1] = ci + 1;
  33478. break;
  33479. }
  33480. // set p11, p12, p21, p22
  33481. ps[5] = coords.length;
  33482. coords.push([
  33483. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  33484. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  33485. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33486. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  33487. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  33488. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  33489. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33490. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  33491. ]);
  33492. ps[6] = coords.length;
  33493. coords.push([
  33494. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  33495. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  33496. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33497. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  33498. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  33499. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  33500. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33501. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  33502. ]);
  33503. ps[9] = coords.length;
  33504. coords.push([
  33505. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  33506. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  33507. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33508. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  33509. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  33510. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  33511. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33512. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  33513. ]);
  33514. ps[10] = coords.length;
  33515. coords.push([
  33516. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  33517. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  33518. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33519. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  33520. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  33521. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  33522. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33523. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  33524. ]);
  33525. mesh.figures.push({
  33526. type: 'patch',
  33527. coords: new Int32Array(ps), // making copies of ps and cs
  33528. colors: new Int32Array(cs)
  33529. });
  33530. }
  33531. }
  33532. function decodeType7Shading(mesh, reader) {
  33533. var coords = mesh.coords;
  33534. var colors = mesh.colors;
  33535. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33536. var cs = new Int32Array(4); // c00, c30, c03, c33
  33537. while (reader.hasData) {
  33538. var f = reader.readFlag();
  33539. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  33540. var i, ii;
  33541. var pi = coords.length;
  33542. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  33543. coords.push(reader.readCoordinate());
  33544. }
  33545. var ci = colors.length;
  33546. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33547. colors.push(reader.readComponents());
  33548. }
  33549. var tmp1, tmp2, tmp3, tmp4;
  33550. switch (f) {
  33551. case 0:
  33552. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33553. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  33554. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  33555. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33556. cs[2] = ci + 1; cs[3] = ci + 2;
  33557. cs[0] = ci; cs[1] = ci + 3;
  33558. break;
  33559. case 1:
  33560. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33561. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33562. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33563. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33564. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33565. tmp1 = cs[2]; tmp2 = cs[3];
  33566. cs[2] = tmp2; cs[3] = ci;
  33567. cs[0] = tmp1; cs[1] = ci + 1;
  33568. break;
  33569. case 2:
  33570. tmp1 = ps[15];
  33571. tmp2 = ps[11];
  33572. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33573. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33574. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33575. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33576. tmp1 = cs[3];
  33577. cs[2] = cs[1]; cs[3] = ci;
  33578. cs[0] = tmp1; cs[1] = ci + 1;
  33579. break;
  33580. case 3:
  33581. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33582. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33583. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33584. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33585. cs[2] = cs[0]; cs[3] = ci;
  33586. cs[0] = cs[1]; cs[1] = ci + 1;
  33587. break;
  33588. }
  33589. mesh.figures.push({
  33590. type: 'patch',
  33591. coords: new Int32Array(ps), // making copies of ps and cs
  33592. colors: new Int32Array(cs)
  33593. });
  33594. }
  33595. }
  33596. function updateBounds(mesh) {
  33597. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  33598. maxX = minX, maxY = minY;
  33599. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  33600. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  33601. minX = minX > x ? x : minX;
  33602. minY = minY > y ? y : minY;
  33603. maxX = maxX < x ? x : maxX;
  33604. maxY = maxY < y ? y : maxY;
  33605. }
  33606. mesh.bounds = [minX, minY, maxX, maxY];
  33607. }
  33608. function packData(mesh) {
  33609. var i, ii, j, jj;
  33610. var coords = mesh.coords;
  33611. var coordsPacked = new Float32Array(coords.length * 2);
  33612. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  33613. var xy = coords[i];
  33614. coordsPacked[j++] = xy[0];
  33615. coordsPacked[j++] = xy[1];
  33616. }
  33617. mesh.coords = coordsPacked;
  33618. var colors = mesh.colors;
  33619. var colorsPacked = new Uint8Array(colors.length * 3);
  33620. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  33621. var c = colors[i];
  33622. colorsPacked[j++] = c[0];
  33623. colorsPacked[j++] = c[1];
  33624. colorsPacked[j++] = c[2];
  33625. }
  33626. mesh.colors = colorsPacked;
  33627. var figures = mesh.figures;
  33628. for (i = 0, ii = figures.length; i < ii; i++) {
  33629. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  33630. for (j = 0, jj = ps.length; j < jj; j++) {
  33631. ps[j] *= 2;
  33632. cs[j] *= 3;
  33633. }
  33634. }
  33635. }
  33636. function Mesh(stream, matrix, xref, res) {
  33637. assert(isStream(stream), 'Mesh data is not a stream');
  33638. var dict = stream.dict;
  33639. this.matrix = matrix;
  33640. this.shadingType = dict.get('ShadingType');
  33641. this.type = 'Pattern';
  33642. this.bbox = dict.get('BBox');
  33643. var cs = dict.get('ColorSpace', 'CS');
  33644. cs = ColorSpace.parse(cs, xref, res);
  33645. this.cs = cs;
  33646. this.background = dict.has('Background') ?
  33647. cs.getRgb(dict.get('Background'), 0) : null;
  33648. var fnObj = dict.get('Function');
  33649. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  33650. this.coords = [];
  33651. this.colors = [];
  33652. this.figures = [];
  33653. var decodeContext = {
  33654. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  33655. bitsPerComponent: dict.get('BitsPerComponent'),
  33656. bitsPerFlag: dict.get('BitsPerFlag'),
  33657. decode: dict.get('Decode'),
  33658. colorFn: fn,
  33659. colorSpace: cs,
  33660. numComps: fn ? 1 : cs.numComps
  33661. };
  33662. var reader = new MeshStreamReader(stream, decodeContext);
  33663. var patchMesh = false;
  33664. switch (this.shadingType) {
  33665. case ShadingType.FREE_FORM_MESH:
  33666. decodeType4Shading(this, reader);
  33667. break;
  33668. case ShadingType.LATTICE_FORM_MESH:
  33669. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  33670. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  33671. decodeType5Shading(this, reader, verticesPerRow);
  33672. break;
  33673. case ShadingType.COONS_PATCH_MESH:
  33674. decodeType6Shading(this, reader);
  33675. patchMesh = true;
  33676. break;
  33677. case ShadingType.TENSOR_PATCH_MESH:
  33678. decodeType7Shading(this, reader);
  33679. patchMesh = true;
  33680. break;
  33681. default:
  33682. error('Unsupported mesh type.');
  33683. break;
  33684. }
  33685. if (patchMesh) {
  33686. // dirty bounds calculation for determining, how dense shall be triangles
  33687. updateBounds(this);
  33688. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  33689. buildFigureFromPatch(this, i);
  33690. }
  33691. }
  33692. // calculate bounds
  33693. updateBounds(this);
  33694. packData(this);
  33695. }
  33696. Mesh.prototype = {
  33697. getIR: function Mesh_getIR() {
  33698. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  33699. this.bounds, this.matrix, this.bbox, this.background];
  33700. }
  33701. };
  33702. return Mesh;
  33703. })();
  33704. Shadings.Dummy = (function DummyClosure() {
  33705. function Dummy() {
  33706. this.type = 'Pattern';
  33707. }
  33708. Dummy.prototype = {
  33709. getIR: function Dummy_getIR() {
  33710. return ['Dummy'];
  33711. }
  33712. };
  33713. return Dummy;
  33714. })();
  33715. function getTilingPatternIR(operatorList, dict, args) {
  33716. var matrix = dict.get('Matrix');
  33717. var bbox = dict.get('BBox');
  33718. var xstep = dict.get('XStep');
  33719. var ystep = dict.get('YStep');
  33720. var paintType = dict.get('PaintType');
  33721. var tilingType = dict.get('TilingType');
  33722. return [
  33723. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  33724. paintType, tilingType
  33725. ];
  33726. }
  33727. exports.Pattern = Pattern;
  33728. exports.getTilingPatternIR = getTilingPatternIR;
  33729. }));
  33730. (function (root, factory) {
  33731. {
  33732. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  33733. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  33734. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  33735. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  33736. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  33737. }
  33738. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  33739. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  33740. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  33741. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33742. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33743. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33744. var ImageKind = sharedUtil.ImageKind;
  33745. var OPS = sharedUtil.OPS;
  33746. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33747. var Util = sharedUtil.Util;
  33748. var assert = sharedUtil.assert;
  33749. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33750. var error = sharedUtil.error;
  33751. var info = sharedUtil.info;
  33752. var isArray = sharedUtil.isArray;
  33753. var isNum = sharedUtil.isNum;
  33754. var isString = sharedUtil.isString;
  33755. var warn = sharedUtil.warn;
  33756. var Dict = corePrimitives.Dict;
  33757. var Name = corePrimitives.Name;
  33758. var isCmd = corePrimitives.isCmd;
  33759. var isDict = corePrimitives.isDict;
  33760. var isName = corePrimitives.isName;
  33761. var isRef = corePrimitives.isRef;
  33762. var isStream = corePrimitives.isStream;
  33763. var DecodeStream = coreStream.DecodeStream;
  33764. var JpegStream = coreStream.JpegStream;
  33765. var Lexer = coreParser.Lexer;
  33766. var Parser = coreParser.Parser;
  33767. var isEOF = coreParser.isEOF;
  33768. var PDFImage = coreImage.PDFImage;
  33769. var ColorSpace = coreColorSpace.ColorSpace;
  33770. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  33771. var Encodings = coreFonts.Encodings;
  33772. var ErrorFont = coreFonts.ErrorFont;
  33773. var FontFlags = coreFonts.FontFlags;
  33774. var Font = coreFonts.Font;
  33775. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  33776. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  33777. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  33778. var getFontType = coreFonts.getFontType;
  33779. var reverseIfRtl = coreFonts.reverseIfRtl;
  33780. var serifFonts = coreFonts.serifFonts;
  33781. var symbolsFonts = coreFonts.symbolsFonts;
  33782. var stdFontMap = coreFonts.stdFontMap;
  33783. var isPDFFunction = coreFunction.isPDFFunction;
  33784. var PDFFunction = coreFunction.PDFFunction;
  33785. var Pattern = corePattern.Pattern;
  33786. var getTilingPatternIR = corePattern.getTilingPatternIR;
  33787. var CMapFactory = coreCMap.CMapFactory;
  33788. var IdentityCMap = coreCMap.IdentityCMap;
  33789. var Metrics = coreMetrics.Metrics;
  33790. var bidi = coreBidi.bidi;
  33791. var PartialEvaluator = (function PartialEvaluatorClosure() {
  33792. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  33793. uniquePrefix, idCounters, fontCache) {
  33794. this.pdfManager = pdfManager;
  33795. this.xref = xref;
  33796. this.handler = handler;
  33797. this.pageIndex = pageIndex;
  33798. this.uniquePrefix = uniquePrefix;
  33799. this.idCounters = idCounters;
  33800. this.fontCache = fontCache;
  33801. }
  33802. // Trying to minimize Date.now() usage and check every 100 time
  33803. var TIME_SLOT_DURATION_MS = 20;
  33804. var CHECK_TIME_EVERY = 100;
  33805. function TimeSlotManager() {
  33806. this.reset();
  33807. }
  33808. TimeSlotManager.prototype = {
  33809. check: function TimeSlotManager_check() {
  33810. if (++this.checked < CHECK_TIME_EVERY) {
  33811. return false;
  33812. }
  33813. this.checked = 0;
  33814. return this.endTime <= Date.now();
  33815. },
  33816. reset: function TimeSlotManager_reset() {
  33817. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  33818. this.checked = 0;
  33819. }
  33820. };
  33821. var deferred = Promise.resolve();
  33822. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  33823. PartialEvaluator.prototype = {
  33824. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  33825. if (!isDict(resources)) {
  33826. return false;
  33827. }
  33828. var processed = Object.create(null);
  33829. if (resources.objId) {
  33830. processed[resources.objId] = true;
  33831. }
  33832. var nodes = [resources];
  33833. while (nodes.length) {
  33834. var key;
  33835. var node = nodes.shift();
  33836. // First check the current resources for blend modes.
  33837. var graphicStates = node.get('ExtGState');
  33838. if (isDict(graphicStates)) {
  33839. graphicStates = graphicStates.getAll();
  33840. for (key in graphicStates) {
  33841. var graphicState = graphicStates[key];
  33842. var bm = graphicState['BM'];
  33843. if (isName(bm) && bm.name !== 'Normal') {
  33844. return true;
  33845. }
  33846. }
  33847. }
  33848. // Descend into the XObjects to look for more resources and blend modes.
  33849. var xObjects = node.get('XObject');
  33850. if (!isDict(xObjects)) {
  33851. continue;
  33852. }
  33853. xObjects = xObjects.getAll();
  33854. for (key in xObjects) {
  33855. var xObject = xObjects[key];
  33856. if (!isStream(xObject)) {
  33857. continue;
  33858. }
  33859. if (xObject.dict.objId) {
  33860. if (processed[xObject.dict.objId]) {
  33861. // stream has objId and is processed already
  33862. continue;
  33863. }
  33864. processed[xObject.dict.objId] = true;
  33865. }
  33866. var xResources = xObject.dict.get('Resources');
  33867. // Checking objId to detect an infinite loop.
  33868. if (isDict(xResources) &&
  33869. (!xResources.objId || !processed[xResources.objId])) {
  33870. nodes.push(xResources);
  33871. if (xResources.objId) {
  33872. processed[xResources.objId] = true;
  33873. }
  33874. }
  33875. }
  33876. }
  33877. return false;
  33878. },
  33879. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  33880. xobj, smask,
  33881. operatorList,
  33882. task,
  33883. initialState) {
  33884. var matrix = xobj.dict.getArray('Matrix');
  33885. var bbox = xobj.dict.getArray('BBox');
  33886. var group = xobj.dict.get('Group');
  33887. if (group) {
  33888. var groupOptions = {
  33889. matrix: matrix,
  33890. bbox: bbox,
  33891. smask: smask,
  33892. isolated: false,
  33893. knockout: false
  33894. };
  33895. var groupSubtype = group.get('S');
  33896. var colorSpace;
  33897. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  33898. groupOptions.isolated = (group.get('I') || false);
  33899. groupOptions.knockout = (group.get('K') || false);
  33900. colorSpace = (group.has('CS') ?
  33901. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  33902. }
  33903. if (smask && smask.backdrop) {
  33904. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  33905. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  33906. }
  33907. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  33908. }
  33909. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  33910. return this.getOperatorList(xobj, task,
  33911. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  33912. then(function () {
  33913. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  33914. if (group) {
  33915. operatorList.addOp(OPS.endGroup, [groupOptions]);
  33916. }
  33917. });
  33918. },
  33919. buildPaintImageXObject:
  33920. function PartialEvaluator_buildPaintImageXObject(resources, image,
  33921. inline, operatorList,
  33922. cacheKey, imageCache) {
  33923. var self = this;
  33924. var dict = image.dict;
  33925. var w = dict.get('Width', 'W');
  33926. var h = dict.get('Height', 'H');
  33927. if (!(w && isNum(w)) || !(h && isNum(h))) {
  33928. warn('Image dimensions are missing, or not numbers.');
  33929. return;
  33930. }
  33931. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  33932. warn('Image exceeded maximum allowed size and was removed.');
  33933. return;
  33934. }
  33935. var imageMask = (dict.get('ImageMask', 'IM') || false);
  33936. var imgData, args;
  33937. if (imageMask) {
  33938. // This depends on a tmpCanvas being filled with the
  33939. // current fillStyle, such that processing the pixel
  33940. // data can't be done here. Instead of creating a
  33941. // complete PDFImage, only read the information needed
  33942. // for later.
  33943. var width = dict.get('Width', 'W');
  33944. var height = dict.get('Height', 'H');
  33945. var bitStrideLength = (width + 7) >> 3;
  33946. var imgArray = image.getBytes(bitStrideLength * height);
  33947. var decode = dict.get('Decode', 'D');
  33948. var inverseDecode = (!!decode && decode[0] > 0);
  33949. imgData = PDFImage.createMask(imgArray, width, height,
  33950. image instanceof DecodeStream,
  33951. inverseDecode);
  33952. imgData.cached = true;
  33953. args = [imgData];
  33954. operatorList.addOp(OPS.paintImageMaskXObject, args);
  33955. if (cacheKey) {
  33956. imageCache[cacheKey] = {
  33957. fn: OPS.paintImageMaskXObject,
  33958. args: args
  33959. };
  33960. }
  33961. return;
  33962. }
  33963. var softMask = (dict.get('SMask', 'SM') || false);
  33964. var mask = (dict.get('Mask') || false);
  33965. var SMALL_IMAGE_DIMENSIONS = 200;
  33966. // Inlining small images into the queue as RGB data
  33967. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  33968. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  33969. var imageObj = new PDFImage(this.xref, resources, image,
  33970. inline, null, null);
  33971. // We force the use of RGBA_32BPP images here, because we can't handle
  33972. // any other kind.
  33973. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  33974. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  33975. return;
  33976. }
  33977. // If there is no imageMask, create the PDFImage and a lot
  33978. // of image processing can be done here.
  33979. var uniquePrefix = (this.uniquePrefix || '');
  33980. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  33981. operatorList.addDependency(objId);
  33982. args = [objId, w, h];
  33983. if (!softMask && !mask && image instanceof JpegStream &&
  33984. image.isNativelySupported(this.xref, resources)) {
  33985. // These JPEGs don't need any more processing so we can just send it.
  33986. operatorList.addOp(OPS.paintJpegXObject, args);
  33987. this.handler.send('obj',
  33988. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  33989. return;
  33990. }
  33991. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  33992. then(function(imageObj) {
  33993. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  33994. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  33995. [imgData.data.buffer]);
  33996. }).then(undefined, function (reason) {
  33997. warn('Unable to decode image: ' + reason);
  33998. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  33999. });
  34000. operatorList.addOp(OPS.paintImageXObject, args);
  34001. if (cacheKey) {
  34002. imageCache[cacheKey] = {
  34003. fn: OPS.paintImageXObject,
  34004. args: args
  34005. };
  34006. }
  34007. },
  34008. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34009. operatorList, task,
  34010. stateManager) {
  34011. var smaskContent = smask.get('G');
  34012. var smaskOptions = {
  34013. subtype: smask.get('S').name,
  34014. backdrop: smask.get('BC')
  34015. };
  34016. // The SMask might have a alpha/luminosity value transfer function --
  34017. // we will build a map of integer values in range 0..255 to be fast.
  34018. var transferObj = smask.get('TR');
  34019. if (isPDFFunction(transferObj)) {
  34020. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34021. var transferMap = new Uint8Array(256);
  34022. var tmp = new Float32Array(1);
  34023. for (var i = 0; i < 255; i++) {
  34024. tmp[0] = i / 255;
  34025. transferFn(tmp, 0, tmp, 0);
  34026. transferMap[i] = (tmp[0] * 255) | 0;
  34027. }
  34028. smaskOptions.transferMap = transferMap;
  34029. }
  34030. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34031. operatorList, task, stateManager.state.clone());
  34032. },
  34033. handleTilingType:
  34034. function PartialEvaluator_handleTilingType(fn, args, resources,
  34035. pattern, patternDict,
  34036. operatorList, task) {
  34037. // Create an IR of the pattern code.
  34038. var tilingOpList = new OperatorList();
  34039. // Merge the available resources, to prevent issues when the patternDict
  34040. // is missing some /Resources entries (fixes issue6541.pdf).
  34041. var resourcesArray = [patternDict.get('Resources'), resources];
  34042. var patternResources = Dict.merge(this.xref, resourcesArray);
  34043. return this.getOperatorList(pattern, task, patternResources,
  34044. tilingOpList).then(function () {
  34045. // Add the dependencies to the parent operator list so they are
  34046. // resolved before sub operator list is executed synchronously.
  34047. operatorList.addDependencies(tilingOpList.dependencies);
  34048. operatorList.addOp(fn, getTilingPatternIR({
  34049. fnArray: tilingOpList.fnArray,
  34050. argsArray: tilingOpList.argsArray
  34051. }, patternDict, args));
  34052. });
  34053. },
  34054. handleSetFont:
  34055. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  34056. operatorList, task, state) {
  34057. // TODO(mack): Not needed?
  34058. var fontName;
  34059. if (fontArgs) {
  34060. fontArgs = fontArgs.slice();
  34061. fontName = fontArgs[0].name;
  34062. }
  34063. var self = this;
  34064. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  34065. function (translated) {
  34066. if (!translated.font.isType3Font) {
  34067. return translated;
  34068. }
  34069. return translated.loadType3Data(self, resources, operatorList, task).
  34070. then(function () {
  34071. return translated;
  34072. }, function (reason) {
  34073. // Error in the font data -- sending unsupported feature notification.
  34074. self.handler.send('UnsupportedFeature',
  34075. {featureId: UNSUPPORTED_FEATURES.font});
  34076. return new TranslatedFont('g_font_error',
  34077. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  34078. });
  34079. }).then(function (translated) {
  34080. state.font = translated.font;
  34081. translated.send(self.handler);
  34082. return translated.loadedName;
  34083. });
  34084. },
  34085. handleText: function PartialEvaluator_handleText(chars, state) {
  34086. var font = state.font;
  34087. var glyphs = font.charsToGlyphs(chars);
  34088. var isAddToPathSet = !!(state.textRenderingMode &
  34089. TextRenderingMode.ADD_TO_PATH_FLAG);
  34090. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  34091. var buildPath = function (fontChar) {
  34092. if (!font.renderer.hasBuiltPath(fontChar)) {
  34093. var path = font.renderer.getPathJs(fontChar);
  34094. this.handler.send('commonobj', [
  34095. font.loadedName + '_path_' + fontChar,
  34096. 'FontPath',
  34097. path
  34098. ]);
  34099. }
  34100. }.bind(this);
  34101. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  34102. var glyph = glyphs[i];
  34103. buildPath(glyph.fontChar);
  34104. // If the glyph has an accent we need to build a path for its
  34105. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  34106. var accent = glyph.accent;
  34107. if (accent && accent.fontChar) {
  34108. buildPath(accent.fontChar);
  34109. }
  34110. }
  34111. }
  34112. return glyphs;
  34113. },
  34114. setGState: function PartialEvaluator_setGState(resources, gState,
  34115. operatorList, task,
  34116. xref, stateManager) {
  34117. // This array holds the converted/processed state data.
  34118. var gStateObj = [];
  34119. var gStateMap = gState.map;
  34120. var self = this;
  34121. var promise = Promise.resolve();
  34122. for (var key in gStateMap) {
  34123. var value = gStateMap[key];
  34124. switch (key) {
  34125. case 'Type':
  34126. break;
  34127. case 'LW':
  34128. case 'LC':
  34129. case 'LJ':
  34130. case 'ML':
  34131. case 'D':
  34132. case 'RI':
  34133. case 'FL':
  34134. case 'CA':
  34135. case 'ca':
  34136. gStateObj.push([key, value]);
  34137. break;
  34138. case 'Font':
  34139. promise = promise.then(function () {
  34140. return self.handleSetFont(resources, null, value[0], operatorList,
  34141. task, stateManager.state).
  34142. then(function (loadedName) {
  34143. operatorList.addDependency(loadedName);
  34144. gStateObj.push([key, [loadedName, value[1]]]);
  34145. });
  34146. });
  34147. break;
  34148. case 'BM':
  34149. gStateObj.push([key, value]);
  34150. break;
  34151. case 'SMask':
  34152. if (isName(value) && value.name === 'None') {
  34153. gStateObj.push([key, false]);
  34154. break;
  34155. }
  34156. var dict = xref.fetchIfRef(value);
  34157. if (isDict(dict)) {
  34158. promise = promise.then(function () {
  34159. return self.handleSMask(dict, resources, operatorList,
  34160. task, stateManager);
  34161. });
  34162. gStateObj.push([key, true]);
  34163. } else {
  34164. warn('Unsupported SMask type');
  34165. }
  34166. break;
  34167. // Only generate info log messages for the following since
  34168. // they are unlikely to have a big impact on the rendering.
  34169. case 'OP':
  34170. case 'op':
  34171. case 'OPM':
  34172. case 'BG':
  34173. case 'BG2':
  34174. case 'UCR':
  34175. case 'UCR2':
  34176. case 'TR':
  34177. case 'TR2':
  34178. case 'HT':
  34179. case 'SM':
  34180. case 'SA':
  34181. case 'AIS':
  34182. case 'TK':
  34183. // TODO implement these operators.
  34184. info('graphic state operator ' + key);
  34185. break;
  34186. default:
  34187. info('Unknown graphic state operator ' + key);
  34188. break;
  34189. }
  34190. }
  34191. return promise.then(function () {
  34192. if (gStateObj.length >= 0) {
  34193. operatorList.addOp(OPS.setGState, [gStateObj]);
  34194. }
  34195. });
  34196. },
  34197. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  34198. resources) {
  34199. function errorFont() {
  34200. return Promise.resolve(new TranslatedFont('g_font_error',
  34201. new ErrorFont('Font ' + fontName + ' is not available'), font));
  34202. }
  34203. var fontRef;
  34204. if (font) { // Loading by ref.
  34205. assert(isRef(font));
  34206. fontRef = font;
  34207. } else { // Loading by name.
  34208. var fontRes = resources.get('Font');
  34209. if (fontRes) {
  34210. fontRef = fontRes.getRaw(fontName);
  34211. } else {
  34212. warn('fontRes not available');
  34213. return errorFont();
  34214. }
  34215. }
  34216. if (!fontRef) {
  34217. warn('fontRef not available');
  34218. return errorFont();
  34219. }
  34220. if (this.fontCache.has(fontRef)) {
  34221. return this.fontCache.get(fontRef);
  34222. }
  34223. font = xref.fetchIfRef(fontRef);
  34224. if (!isDict(font)) {
  34225. return errorFont();
  34226. }
  34227. // We are holding font.translated references just for fontRef that are not
  34228. // dictionaries (Dict). See explanation below.
  34229. if (font.translated) {
  34230. return font.translated;
  34231. }
  34232. var fontCapability = createPromiseCapability();
  34233. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  34234. var descriptor = preEvaluatedFont.descriptor;
  34235. var fontID = fontRef.num + '_' + fontRef.gen;
  34236. if (isDict(descriptor)) {
  34237. if (!descriptor.fontAliases) {
  34238. descriptor.fontAliases = Object.create(null);
  34239. }
  34240. var fontAliases = descriptor.fontAliases;
  34241. var hash = preEvaluatedFont.hash;
  34242. if (fontAliases[hash]) {
  34243. var aliasFontRef = fontAliases[hash].aliasRef;
  34244. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  34245. this.fontCache.putAlias(fontRef, aliasFontRef);
  34246. return this.fontCache.get(fontRef);
  34247. }
  34248. }
  34249. if (!fontAliases[hash]) {
  34250. fontAliases[hash] = {
  34251. fontID: Font.getFontID()
  34252. };
  34253. }
  34254. fontAliases[hash].aliasRef = fontRef;
  34255. fontID = fontAliases[hash].fontID;
  34256. }
  34257. // Workaround for bad PDF generators that don't reference fonts
  34258. // properly, i.e. by not using an object identifier.
  34259. // Check if the fontRef is a Dict (as opposed to a standard object),
  34260. // in which case we don't cache the font and instead reference it by
  34261. // fontName in font.loadedName below.
  34262. var fontRefIsDict = isDict(fontRef);
  34263. if (!fontRefIsDict) {
  34264. this.fontCache.put(fontRef, fontCapability.promise);
  34265. }
  34266. // Keep track of each font we translated so the caller can
  34267. // load them asynchronously before calling display on a page.
  34268. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  34269. fontName.replace(/\W/g, '') : fontID);
  34270. font.translated = fontCapability.promise;
  34271. // TODO move promises into translate font
  34272. var translatedPromise;
  34273. try {
  34274. translatedPromise = Promise.resolve(
  34275. this.translateFont(preEvaluatedFont, xref));
  34276. } catch (e) {
  34277. translatedPromise = Promise.reject(e);
  34278. }
  34279. var self = this;
  34280. translatedPromise.then(function (translatedFont) {
  34281. if (translatedFont.fontType !== undefined) {
  34282. var xrefFontStats = xref.stats.fontTypes;
  34283. xrefFontStats[translatedFont.fontType] = true;
  34284. }
  34285. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34286. translatedFont, font));
  34287. }, function (reason) {
  34288. // TODO fontCapability.reject?
  34289. // Error in the font data -- sending unsupported feature notification.
  34290. self.handler.send('UnsupportedFeature',
  34291. {featureId: UNSUPPORTED_FEATURES.font});
  34292. try {
  34293. // error, but it's still nice to have font type reported
  34294. var descriptor = preEvaluatedFont.descriptor;
  34295. var fontFile3 = descriptor && descriptor.get('FontFile3');
  34296. var subtype = fontFile3 && fontFile3.get('Subtype');
  34297. var fontType = getFontType(preEvaluatedFont.type,
  34298. subtype && subtype.name);
  34299. var xrefFontStats = xref.stats.fontTypes;
  34300. xrefFontStats[fontType] = true;
  34301. } catch (ex) { }
  34302. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34303. new ErrorFont(reason instanceof Error ? reason.message : reason),
  34304. font));
  34305. });
  34306. return fontCapability.promise;
  34307. },
  34308. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  34309. var lastIndex = operatorList.length - 1;
  34310. if (!args) {
  34311. args = [];
  34312. }
  34313. if (lastIndex < 0 ||
  34314. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  34315. operatorList.addOp(OPS.constructPath, [[fn], args]);
  34316. } else {
  34317. var opArgs = operatorList.argsArray[lastIndex];
  34318. opArgs[0].push(fn);
  34319. Array.prototype.push.apply(opArgs[1], args);
  34320. }
  34321. },
  34322. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  34323. cs, patterns, resources, task, xref) {
  34324. // compile tiling patterns
  34325. var patternName = args[args.length - 1];
  34326. // SCN/scn applies patterns along with normal colors
  34327. var pattern;
  34328. if (isName(patternName) &&
  34329. (pattern = patterns.get(patternName.name))) {
  34330. var dict = (isStream(pattern) ? pattern.dict : pattern);
  34331. var typeNum = dict.get('PatternType');
  34332. if (typeNum === TILING_PATTERN) {
  34333. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  34334. return this.handleTilingType(fn, color, resources, pattern,
  34335. dict, operatorList, task);
  34336. } else if (typeNum === SHADING_PATTERN) {
  34337. var shading = dict.get('Shading');
  34338. var matrix = dict.get('Matrix');
  34339. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  34340. this.handler);
  34341. operatorList.addOp(fn, pattern.getIR());
  34342. return Promise.resolve();
  34343. } else {
  34344. return Promise.reject('Unknown PatternType: ' + typeNum);
  34345. }
  34346. }
  34347. // TODO shall we fail here?
  34348. operatorList.addOp(fn, args);
  34349. return Promise.resolve();
  34350. },
  34351. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  34352. task,
  34353. resources,
  34354. operatorList,
  34355. initialState) {
  34356. var self = this;
  34357. var xref = this.xref;
  34358. var imageCache = {};
  34359. assert(operatorList);
  34360. resources = (resources || Dict.empty);
  34361. var xobjs = (resources.get('XObject') || Dict.empty);
  34362. var patterns = (resources.get('Pattern') || Dict.empty);
  34363. var stateManager = new StateManager(initialState || new EvalState());
  34364. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34365. var timeSlotManager = new TimeSlotManager();
  34366. return new Promise(function next(resolve, reject) {
  34367. task.ensureNotTerminated();
  34368. timeSlotManager.reset();
  34369. var stop, operation = {}, i, ii, cs;
  34370. while (!(stop = timeSlotManager.check())) {
  34371. // The arguments parsed by read() are used beyond this loop, so we
  34372. // cannot reuse the same array on each iteration. Therefore we pass
  34373. // in |null| as the initial value (see the comment on
  34374. // EvaluatorPreprocessor_read() for why).
  34375. operation.args = null;
  34376. if (!(preprocessor.read(operation))) {
  34377. break;
  34378. }
  34379. var args = operation.args;
  34380. var fn = operation.fn;
  34381. switch (fn | 0) {
  34382. case OPS.paintXObject:
  34383. if (args[0].code) {
  34384. break;
  34385. }
  34386. // eagerly compile XForm objects
  34387. var name = args[0].name;
  34388. if (!name) {
  34389. warn('XObject must be referred to by name.');
  34390. continue;
  34391. }
  34392. if (imageCache[name] !== undefined) {
  34393. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  34394. args = null;
  34395. continue;
  34396. }
  34397. var xobj = xobjs.get(name);
  34398. if (xobj) {
  34399. assert(isStream(xobj), 'XObject should be a stream');
  34400. var type = xobj.dict.get('Subtype');
  34401. assert(isName(type),
  34402. 'XObject should have a Name subtype');
  34403. if (type.name === 'Form') {
  34404. stateManager.save();
  34405. return self.buildFormXObject(resources, xobj, null,
  34406. operatorList, task,
  34407. stateManager.state.clone()).
  34408. then(function () {
  34409. stateManager.restore();
  34410. next(resolve, reject);
  34411. }, reject);
  34412. } else if (type.name === 'Image') {
  34413. self.buildPaintImageXObject(resources, xobj, false,
  34414. operatorList, name, imageCache);
  34415. args = null;
  34416. continue;
  34417. } else if (type.name === 'PS') {
  34418. // PostScript XObjects are unused when viewing documents.
  34419. // See section 4.7.1 of Adobe's PDF reference.
  34420. info('Ignored XObject subtype PS');
  34421. continue;
  34422. } else {
  34423. error('Unhandled XObject subtype ' + type.name);
  34424. }
  34425. }
  34426. break;
  34427. case OPS.setFont:
  34428. var fontSize = args[1];
  34429. // eagerly collect all fonts
  34430. return self.handleSetFont(resources, args, null, operatorList,
  34431. task, stateManager.state).
  34432. then(function (loadedName) {
  34433. operatorList.addDependency(loadedName);
  34434. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  34435. next(resolve, reject);
  34436. }, reject);
  34437. case OPS.endInlineImage:
  34438. var cacheKey = args[0].cacheKey;
  34439. if (cacheKey) {
  34440. var cacheEntry = imageCache[cacheKey];
  34441. if (cacheEntry !== undefined) {
  34442. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  34443. args = null;
  34444. continue;
  34445. }
  34446. }
  34447. self.buildPaintImageXObject(resources, args[0], true,
  34448. operatorList, cacheKey, imageCache);
  34449. args = null;
  34450. continue;
  34451. case OPS.showText:
  34452. args[0] = self.handleText(args[0], stateManager.state);
  34453. break;
  34454. case OPS.showSpacedText:
  34455. var arr = args[0];
  34456. var combinedGlyphs = [];
  34457. var arrLength = arr.length;
  34458. var state = stateManager.state;
  34459. for (i = 0; i < arrLength; ++i) {
  34460. var arrItem = arr[i];
  34461. if (isString(arrItem)) {
  34462. Array.prototype.push.apply(combinedGlyphs,
  34463. self.handleText(arrItem, state));
  34464. } else if (isNum(arrItem)) {
  34465. combinedGlyphs.push(arrItem);
  34466. }
  34467. }
  34468. args[0] = combinedGlyphs;
  34469. fn = OPS.showText;
  34470. break;
  34471. case OPS.nextLineShowText:
  34472. operatorList.addOp(OPS.nextLine);
  34473. args[0] = self.handleText(args[0], stateManager.state);
  34474. fn = OPS.showText;
  34475. break;
  34476. case OPS.nextLineSetSpacingShowText:
  34477. operatorList.addOp(OPS.nextLine);
  34478. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  34479. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  34480. args[0] = self.handleText(args[0], stateManager.state);
  34481. fn = OPS.showText;
  34482. break;
  34483. case OPS.setTextRenderingMode:
  34484. stateManager.state.textRenderingMode = args[0];
  34485. break;
  34486. case OPS.setFillColorSpace:
  34487. stateManager.state.fillColorSpace =
  34488. ColorSpace.parse(args[0], xref, resources);
  34489. continue;
  34490. case OPS.setStrokeColorSpace:
  34491. stateManager.state.strokeColorSpace =
  34492. ColorSpace.parse(args[0], xref, resources);
  34493. continue;
  34494. case OPS.setFillColor:
  34495. cs = stateManager.state.fillColorSpace;
  34496. args = cs.getRgb(args, 0);
  34497. fn = OPS.setFillRGBColor;
  34498. break;
  34499. case OPS.setStrokeColor:
  34500. cs = stateManager.state.strokeColorSpace;
  34501. args = cs.getRgb(args, 0);
  34502. fn = OPS.setStrokeRGBColor;
  34503. break;
  34504. case OPS.setFillGray:
  34505. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  34506. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34507. fn = OPS.setFillRGBColor;
  34508. break;
  34509. case OPS.setStrokeGray:
  34510. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  34511. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34512. fn = OPS.setStrokeRGBColor;
  34513. break;
  34514. case OPS.setFillCMYKColor:
  34515. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  34516. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34517. fn = OPS.setFillRGBColor;
  34518. break;
  34519. case OPS.setStrokeCMYKColor:
  34520. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  34521. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34522. fn = OPS.setStrokeRGBColor;
  34523. break;
  34524. case OPS.setFillRGBColor:
  34525. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  34526. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34527. break;
  34528. case OPS.setStrokeRGBColor:
  34529. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  34530. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34531. break;
  34532. case OPS.setFillColorN:
  34533. cs = stateManager.state.fillColorSpace;
  34534. if (cs.name === 'Pattern') {
  34535. return self.handleColorN(operatorList, OPS.setFillColorN,
  34536. args, cs, patterns, resources, task, xref).then(function() {
  34537. next(resolve, reject);
  34538. }, reject);
  34539. }
  34540. args = cs.getRgb(args, 0);
  34541. fn = OPS.setFillRGBColor;
  34542. break;
  34543. case OPS.setStrokeColorN:
  34544. cs = stateManager.state.strokeColorSpace;
  34545. if (cs.name === 'Pattern') {
  34546. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  34547. args, cs, patterns, resources, task, xref).then(function() {
  34548. next(resolve, reject);
  34549. }, reject);
  34550. }
  34551. args = cs.getRgb(args, 0);
  34552. fn = OPS.setStrokeRGBColor;
  34553. break;
  34554. case OPS.shadingFill:
  34555. var shadingRes = resources.get('Shading');
  34556. if (!shadingRes) {
  34557. error('No shading resource found');
  34558. }
  34559. var shading = shadingRes.get(args[0].name);
  34560. if (!shading) {
  34561. error('No shading object found');
  34562. }
  34563. var shadingFill = Pattern.parseShading(shading, null, xref,
  34564. resources, self.handler);
  34565. var patternIR = shadingFill.getIR();
  34566. args = [patternIR];
  34567. fn = OPS.shadingFill;
  34568. break;
  34569. case OPS.setGState:
  34570. var dictName = args[0];
  34571. var extGState = resources.get('ExtGState');
  34572. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  34573. break;
  34574. }
  34575. var gState = extGState.get(dictName.name);
  34576. return self.setGState(resources, gState, operatorList, task,
  34577. xref, stateManager).then(function() {
  34578. next(resolve, reject);
  34579. }, reject);
  34580. case OPS.moveTo:
  34581. case OPS.lineTo:
  34582. case OPS.curveTo:
  34583. case OPS.curveTo2:
  34584. case OPS.curveTo3:
  34585. case OPS.closePath:
  34586. self.buildPath(operatorList, fn, args);
  34587. continue;
  34588. case OPS.rectangle:
  34589. self.buildPath(operatorList, fn, args);
  34590. continue;
  34591. case OPS.markPoint:
  34592. case OPS.markPointProps:
  34593. case OPS.beginMarkedContent:
  34594. case OPS.beginMarkedContentProps:
  34595. case OPS.endMarkedContent:
  34596. case OPS.beginCompat:
  34597. case OPS.endCompat:
  34598. // Ignore operators where the corresponding handlers are known to
  34599. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  34600. // serialization errors and is also a bit more efficient.
  34601. // We could also try to serialize all objects in a general way,
  34602. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  34603. // but doing so is meaningless without knowing the semantics.
  34604. continue;
  34605. default:
  34606. // Note: Let's hope that the ignored operator does not have any
  34607. // non-serializable arguments, otherwise postMessage will throw
  34608. // "An object could not be cloned.".
  34609. }
  34610. operatorList.addOp(fn, args);
  34611. }
  34612. if (stop) {
  34613. deferred.then(function () {
  34614. next(resolve, reject);
  34615. }, reject);
  34616. return;
  34617. }
  34618. // Some PDFs don't close all restores inside object/form.
  34619. // Closing those for them.
  34620. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  34621. operatorList.addOp(OPS.restore, []);
  34622. }
  34623. resolve();
  34624. });
  34625. },
  34626. getTextContent:
  34627. function PartialEvaluator_getTextContent(stream, task, resources,
  34628. stateManager,
  34629. normalizeWhitespace) {
  34630. stateManager = (stateManager || new StateManager(new TextState()));
  34631. var WhitespaceRegexp = /\s/g;
  34632. var textContent = {
  34633. items: [],
  34634. styles: Object.create(null)
  34635. };
  34636. var textContentItem = {
  34637. initialized: false,
  34638. str: [],
  34639. width: 0,
  34640. height: 0,
  34641. vertical: false,
  34642. lastAdvanceWidth: 0,
  34643. lastAdvanceHeight: 0,
  34644. textAdvanceScale: 0,
  34645. spaceWidth: 0,
  34646. fakeSpaceMin: Infinity,
  34647. fakeMultiSpaceMin: Infinity,
  34648. fakeMultiSpaceMax: -0,
  34649. textRunBreakAllowed: false,
  34650. transform: null,
  34651. fontName: null
  34652. };
  34653. var SPACE_FACTOR = 0.3;
  34654. var MULTI_SPACE_FACTOR = 1.5;
  34655. var MULTI_SPACE_FACTOR_MAX = 4;
  34656. var self = this;
  34657. var xref = this.xref;
  34658. resources = (xref.fetchIfRef(resources) || Dict.empty);
  34659. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  34660. var xobjs = null;
  34661. var xobjsCache = {};
  34662. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34663. var textState;
  34664. function ensureTextContentItem() {
  34665. if (textContentItem.initialized) {
  34666. return textContentItem;
  34667. }
  34668. var font = textState.font;
  34669. if (!(font.loadedName in textContent.styles)) {
  34670. textContent.styles[font.loadedName] = {
  34671. fontFamily: font.fallbackName,
  34672. ascent: font.ascent,
  34673. descent: font.descent,
  34674. vertical: font.vertical
  34675. };
  34676. }
  34677. textContentItem.fontName = font.loadedName;
  34678. // 9.4.4 Text Space Details
  34679. var tsm = [textState.fontSize * textState.textHScale, 0,
  34680. 0, textState.fontSize,
  34681. 0, textState.textRise];
  34682. if (font.isType3Font &&
  34683. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  34684. textState.fontSize === 1) {
  34685. var glyphHeight = font.bbox[3] - font.bbox[1];
  34686. if (glyphHeight > 0) {
  34687. glyphHeight = glyphHeight * textState.fontMatrix[3];
  34688. tsm[3] *= glyphHeight;
  34689. }
  34690. }
  34691. var trm = Util.transform(textState.ctm,
  34692. Util.transform(textState.textMatrix, tsm));
  34693. textContentItem.transform = trm;
  34694. if (!font.vertical) {
  34695. textContentItem.width = 0;
  34696. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  34697. textContentItem.vertical = false;
  34698. } else {
  34699. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  34700. textContentItem.height = 0;
  34701. textContentItem.vertical = true;
  34702. }
  34703. var a = textState.textLineMatrix[0];
  34704. var b = textState.textLineMatrix[1];
  34705. var scaleLineX = Math.sqrt(a * a + b * b);
  34706. a = textState.ctm[0];
  34707. b = textState.ctm[1];
  34708. var scaleCtmX = Math.sqrt(a * a + b * b);
  34709. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  34710. textContentItem.lastAdvanceWidth = 0;
  34711. textContentItem.lastAdvanceHeight = 0;
  34712. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  34713. if (spaceWidth) {
  34714. textContentItem.spaceWidth = spaceWidth;
  34715. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  34716. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  34717. textContentItem.fakeMultiSpaceMax =
  34718. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  34719. // It's okay for monospace fonts to fake as much space as needed.
  34720. textContentItem.textRunBreakAllowed = !font.isMonospace;
  34721. } else {
  34722. textContentItem.spaceWidth = 0;
  34723. textContentItem.fakeSpaceMin = Infinity;
  34724. textContentItem.fakeMultiSpaceMin = Infinity;
  34725. textContentItem.fakeMultiSpaceMax = 0;
  34726. textContentItem.textRunBreakAllowed = false;
  34727. }
  34728. textContentItem.initialized = true;
  34729. return textContentItem;
  34730. }
  34731. function replaceWhitespace(str) {
  34732. // Replaces all whitespaces with standard spaces (0x20), to avoid
  34733. // alignment issues between the textLayer and the canvas if the text
  34734. // contains e.g. tabs (fixes issue6612.pdf).
  34735. var i = 0, ii = str.length, code;
  34736. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  34737. i++;
  34738. }
  34739. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  34740. }
  34741. function runBidiTransform(textChunk) {
  34742. var str = textChunk.str.join('');
  34743. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  34744. return {
  34745. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  34746. bidiResult.str),
  34747. dir: bidiResult.dir,
  34748. width: textChunk.width,
  34749. height: textChunk.height,
  34750. transform: textChunk.transform,
  34751. fontName: textChunk.fontName
  34752. };
  34753. }
  34754. function handleSetFont(fontName, fontRef) {
  34755. return self.loadFont(fontName, fontRef, xref, resources).
  34756. then(function (translated) {
  34757. textState.font = translated.font;
  34758. textState.fontMatrix = translated.font.fontMatrix ||
  34759. FONT_IDENTITY_MATRIX;
  34760. });
  34761. }
  34762. function buildTextContentItem(chars) {
  34763. var font = textState.font;
  34764. var textChunk = ensureTextContentItem();
  34765. var width = 0;
  34766. var height = 0;
  34767. var glyphs = font.charsToGlyphs(chars);
  34768. var defaultVMetrics = font.defaultVMetrics;
  34769. for (var i = 0; i < glyphs.length; i++) {
  34770. var glyph = glyphs[i];
  34771. var vMetricX = null;
  34772. var vMetricY = null;
  34773. var glyphWidth = null;
  34774. if (font.vertical) {
  34775. if (glyph.vmetric) {
  34776. glyphWidth = glyph.vmetric[0];
  34777. vMetricX = glyph.vmetric[1];
  34778. vMetricY = glyph.vmetric[2];
  34779. } else {
  34780. glyphWidth = glyph.width;
  34781. vMetricX = glyph.width * 0.5;
  34782. vMetricY = defaultVMetrics[2];
  34783. }
  34784. } else {
  34785. glyphWidth = glyph.width;
  34786. }
  34787. var glyphUnicode = glyph.unicode;
  34788. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  34789. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  34790. }
  34791. glyphUnicode = reverseIfRtl(glyphUnicode);
  34792. // The following will calculate the x and y of the individual glyphs.
  34793. // if (font.vertical) {
  34794. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  34795. // textState.fontMatrix[0];
  34796. // tsm[5] -= vMetricY * textState.fontSize *
  34797. // textState.fontMatrix[0];
  34798. // }
  34799. // var trm = Util.transform(textState.textMatrix, tsm);
  34800. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  34801. // var x = pt[0];
  34802. // var y = pt[1];
  34803. var charSpacing = textState.charSpacing;
  34804. if (glyph.isSpace) {
  34805. var wordSpacing = textState.wordSpacing;
  34806. charSpacing += wordSpacing;
  34807. if (wordSpacing > 0) {
  34808. addFakeSpaces(wordSpacing, textChunk.str);
  34809. }
  34810. }
  34811. var tx = 0;
  34812. var ty = 0;
  34813. if (!font.vertical) {
  34814. var w0 = glyphWidth * textState.fontMatrix[0];
  34815. tx = (w0 * textState.fontSize + charSpacing) *
  34816. textState.textHScale;
  34817. width += tx;
  34818. } else {
  34819. var w1 = glyphWidth * textState.fontMatrix[0];
  34820. ty = w1 * textState.fontSize + charSpacing;
  34821. height += ty;
  34822. }
  34823. textState.translateTextMatrix(tx, ty);
  34824. textChunk.str.push(glyphUnicode);
  34825. }
  34826. if (!font.vertical) {
  34827. textChunk.lastAdvanceWidth = width;
  34828. textChunk.width += width * textChunk.textAdvanceScale;
  34829. } else {
  34830. textChunk.lastAdvanceHeight = height;
  34831. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  34832. }
  34833. return textChunk;
  34834. }
  34835. function addFakeSpaces(width, strBuf) {
  34836. if (width < textContentItem.fakeSpaceMin) {
  34837. return;
  34838. }
  34839. if (width < textContentItem.fakeMultiSpaceMin) {
  34840. strBuf.push(' ');
  34841. return;
  34842. }
  34843. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  34844. while (fakeSpaces-- > 0) {
  34845. strBuf.push(' ');
  34846. }
  34847. }
  34848. function flushTextContentItem() {
  34849. if (!textContentItem.initialized) {
  34850. return;
  34851. }
  34852. textContent.items.push(runBidiTransform(textContentItem));
  34853. textContentItem.initialized = false;
  34854. textContentItem.str.length = 0;
  34855. }
  34856. var timeSlotManager = new TimeSlotManager();
  34857. return new Promise(function next(resolve, reject) {
  34858. task.ensureNotTerminated();
  34859. timeSlotManager.reset();
  34860. var stop, operation = {}, args = [];
  34861. while (!(stop = timeSlotManager.check())) {
  34862. // The arguments parsed by read() are not used beyond this loop, so
  34863. // we can reuse the same array on every iteration, thus avoiding
  34864. // unnecessary allocations.
  34865. args.length = 0;
  34866. operation.args = args;
  34867. if (!(preprocessor.read(operation))) {
  34868. break;
  34869. }
  34870. textState = stateManager.state;
  34871. var fn = operation.fn;
  34872. args = operation.args;
  34873. var advance;
  34874. switch (fn | 0) {
  34875. case OPS.setFont:
  34876. flushTextContentItem();
  34877. textState.fontSize = args[1];
  34878. return handleSetFont(args[0].name).then(function() {
  34879. next(resolve, reject);
  34880. }, reject);
  34881. case OPS.setTextRise:
  34882. flushTextContentItem();
  34883. textState.textRise = args[0];
  34884. break;
  34885. case OPS.setHScale:
  34886. flushTextContentItem();
  34887. textState.textHScale = args[0] / 100;
  34888. break;
  34889. case OPS.setLeading:
  34890. flushTextContentItem();
  34891. textState.leading = args[0];
  34892. break;
  34893. case OPS.moveText:
  34894. // Optimization to treat same line movement as advance
  34895. var isSameTextLine = !textState.font ? false :
  34896. ((textState.font.vertical ? args[0] : args[1]) === 0);
  34897. advance = args[0] - args[1];
  34898. if (isSameTextLine && textContentItem.initialized &&
  34899. advance > 0 &&
  34900. advance <= textContentItem.fakeMultiSpaceMax) {
  34901. textState.translateTextLineMatrix(args[0], args[1]);
  34902. textContentItem.width +=
  34903. (args[0] - textContentItem.lastAdvanceWidth);
  34904. textContentItem.height +=
  34905. (args[1] - textContentItem.lastAdvanceHeight);
  34906. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  34907. (args[1] - textContentItem.lastAdvanceHeight);
  34908. addFakeSpaces(diff, textContentItem.str);
  34909. break;
  34910. }
  34911. flushTextContentItem();
  34912. textState.translateTextLineMatrix(args[0], args[1]);
  34913. textState.textMatrix = textState.textLineMatrix.slice();
  34914. break;
  34915. case OPS.setLeadingMoveText:
  34916. flushTextContentItem();
  34917. textState.leading = -args[1];
  34918. textState.translateTextLineMatrix(args[0], args[1]);
  34919. textState.textMatrix = textState.textLineMatrix.slice();
  34920. break;
  34921. case OPS.nextLine:
  34922. flushTextContentItem();
  34923. textState.carriageReturn();
  34924. break;
  34925. case OPS.setTextMatrix:
  34926. flushTextContentItem();
  34927. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  34928. args[4], args[5]);
  34929. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  34930. args[4], args[5]);
  34931. break;
  34932. case OPS.setCharSpacing:
  34933. textState.charSpacing = args[0];
  34934. break;
  34935. case OPS.setWordSpacing:
  34936. textState.wordSpacing = args[0];
  34937. break;
  34938. case OPS.beginText:
  34939. flushTextContentItem();
  34940. textState.textMatrix = IDENTITY_MATRIX.slice();
  34941. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  34942. break;
  34943. case OPS.showSpacedText:
  34944. var items = args[0];
  34945. var offset;
  34946. for (var j = 0, jj = items.length; j < jj; j++) {
  34947. if (typeof items[j] === 'string') {
  34948. buildTextContentItem(items[j]);
  34949. } else {
  34950. ensureTextContentItem();
  34951. // PDF Specification 5.3.2 states:
  34952. // The number is expressed in thousandths of a unit of text
  34953. // space.
  34954. // This amount is subtracted from the current horizontal or
  34955. // vertical coordinate, depending on the writing mode.
  34956. // In the default coordinate system, a positive adjustment
  34957. // has the effect of moving the next glyph painted either to
  34958. // the left or down by the given amount.
  34959. advance = items[j] * textState.fontSize / 1000;
  34960. var breakTextRun = false;
  34961. if (textState.font.vertical) {
  34962. offset = advance *
  34963. (textState.textHScale * textState.textMatrix[2] +
  34964. textState.textMatrix[3]);
  34965. textState.translateTextMatrix(0, advance);
  34966. breakTextRun = textContentItem.textRunBreakAllowed &&
  34967. advance > textContentItem.fakeMultiSpaceMax;
  34968. if (!breakTextRun) {
  34969. // Value needs to be added to height to paint down.
  34970. textContentItem.height += offset;
  34971. }
  34972. } else {
  34973. advance = -advance;
  34974. offset = advance * (
  34975. textState.textHScale * textState.textMatrix[0] +
  34976. textState.textMatrix[1]);
  34977. textState.translateTextMatrix(advance, 0);
  34978. breakTextRun = textContentItem.textRunBreakAllowed &&
  34979. advance > textContentItem.fakeMultiSpaceMax;
  34980. if (!breakTextRun) {
  34981. // Value needs to be subtracted from width to paint left.
  34982. textContentItem.width += offset;
  34983. }
  34984. }
  34985. if (breakTextRun) {
  34986. flushTextContentItem();
  34987. } else if (advance > 0) {
  34988. addFakeSpaces(advance, textContentItem.str);
  34989. }
  34990. }
  34991. }
  34992. break;
  34993. case OPS.showText:
  34994. buildTextContentItem(args[0]);
  34995. break;
  34996. case OPS.nextLineShowText:
  34997. flushTextContentItem();
  34998. textState.carriageReturn();
  34999. buildTextContentItem(args[0]);
  35000. break;
  35001. case OPS.nextLineSetSpacingShowText:
  35002. flushTextContentItem();
  35003. textState.wordSpacing = args[0];
  35004. textState.charSpacing = args[1];
  35005. textState.carriageReturn();
  35006. buildTextContentItem(args[2]);
  35007. break;
  35008. case OPS.paintXObject:
  35009. flushTextContentItem();
  35010. if (args[0].code) {
  35011. break;
  35012. }
  35013. if (!xobjs) {
  35014. xobjs = (resources.get('XObject') || Dict.empty);
  35015. }
  35016. var name = args[0].name;
  35017. if (xobjsCache.key === name) {
  35018. if (xobjsCache.texts) {
  35019. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35020. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35021. }
  35022. break;
  35023. }
  35024. var xobj = xobjs.get(name);
  35025. if (!xobj) {
  35026. break;
  35027. }
  35028. assert(isStream(xobj), 'XObject should be a stream');
  35029. var type = xobj.dict.get('Subtype');
  35030. assert(isName(type),
  35031. 'XObject should have a Name subtype');
  35032. if ('Form' !== type.name) {
  35033. xobjsCache.key = name;
  35034. xobjsCache.texts = null;
  35035. break;
  35036. }
  35037. stateManager.save();
  35038. var matrix = xobj.dict.get('Matrix');
  35039. if (isArray(matrix) && matrix.length === 6) {
  35040. stateManager.transform(matrix);
  35041. }
  35042. return self.getTextContent(xobj, task,
  35043. xobj.dict.get('Resources') || resources, stateManager,
  35044. normalizeWhitespace).then(function (formTextContent) {
  35045. Util.appendToArray(textContent.items, formTextContent.items);
  35046. Util.extendObj(textContent.styles, formTextContent.styles);
  35047. stateManager.restore();
  35048. xobjsCache.key = name;
  35049. xobjsCache.texts = formTextContent;
  35050. next(resolve, reject);
  35051. }, reject);
  35052. case OPS.setGState:
  35053. flushTextContentItem();
  35054. var dictName = args[0];
  35055. var extGState = resources.get('ExtGState');
  35056. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35057. break;
  35058. }
  35059. var gsStateMap = extGState.get(dictName.name);
  35060. var gsStateFont = null;
  35061. for (var key in gsStateMap) {
  35062. if (key === 'Font') {
  35063. assert(!gsStateFont);
  35064. gsStateFont = gsStateMap[key];
  35065. }
  35066. }
  35067. if (gsStateFont) {
  35068. textState.fontSize = gsStateFont[1];
  35069. return handleSetFont(gsStateFont[0]).then(function() {
  35070. next(resolve, reject);
  35071. }, reject);
  35072. }
  35073. break;
  35074. } // switch
  35075. } // while
  35076. if (stop) {
  35077. deferred.then(function () {
  35078. next(resolve, reject);
  35079. }, reject);
  35080. return;
  35081. }
  35082. flushTextContentItem();
  35083. resolve(textContent);
  35084. });
  35085. },
  35086. extractDataStructures: function
  35087. partialEvaluatorExtractDataStructures(dict, baseDict,
  35088. xref, properties) {
  35089. // 9.10.2
  35090. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  35091. if (toUnicode) {
  35092. properties.toUnicode = this.readToUnicode(toUnicode);
  35093. }
  35094. if (properties.composite) {
  35095. // CIDSystemInfo helps to match CID to glyphs
  35096. var cidSystemInfo = dict.get('CIDSystemInfo');
  35097. if (isDict(cidSystemInfo)) {
  35098. properties.cidSystemInfo = {
  35099. registry: cidSystemInfo.get('Registry'),
  35100. ordering: cidSystemInfo.get('Ordering'),
  35101. supplement: cidSystemInfo.get('Supplement')
  35102. };
  35103. }
  35104. var cidToGidMap = dict.get('CIDToGIDMap');
  35105. if (isStream(cidToGidMap)) {
  35106. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  35107. }
  35108. }
  35109. // Based on 9.6.6 of the spec the encoding can come from multiple places
  35110. // and depends on the font type. The base encoding and differences are
  35111. // read here, but the encoding that is actually used is chosen during
  35112. // glyph mapping in the font.
  35113. // TODO: Loading the built in encoding in the font would allow the
  35114. // differences to be merged in here not require us to hold on to it.
  35115. var differences = [];
  35116. var baseEncodingName = null;
  35117. var encoding;
  35118. if (dict.has('Encoding')) {
  35119. encoding = dict.get('Encoding');
  35120. if (isDict(encoding)) {
  35121. baseEncodingName = encoding.get('BaseEncoding');
  35122. baseEncodingName = (isName(baseEncodingName) ?
  35123. baseEncodingName.name : null);
  35124. // Load the differences between the base and original
  35125. if (encoding.has('Differences')) {
  35126. var diffEncoding = encoding.get('Differences');
  35127. var index = 0;
  35128. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  35129. var data = diffEncoding[j];
  35130. if (isNum(data)) {
  35131. index = data;
  35132. } else if (isName(data)) {
  35133. differences[index++] = data.name;
  35134. } else if (isRef(data)) {
  35135. diffEncoding[j--] = xref.fetch(data);
  35136. continue;
  35137. } else {
  35138. error('Invalid entry in \'Differences\' array: ' + data);
  35139. }
  35140. }
  35141. }
  35142. } else if (isName(encoding)) {
  35143. baseEncodingName = encoding.name;
  35144. } else {
  35145. error('Encoding is not a Name nor a Dict');
  35146. }
  35147. // According to table 114 if the encoding is a named encoding it must be
  35148. // one of these predefined encodings.
  35149. if ((baseEncodingName !== 'MacRomanEncoding' &&
  35150. baseEncodingName !== 'MacExpertEncoding' &&
  35151. baseEncodingName !== 'WinAnsiEncoding')) {
  35152. baseEncodingName = null;
  35153. }
  35154. }
  35155. if (baseEncodingName) {
  35156. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  35157. } else {
  35158. encoding = (properties.type === 'TrueType' ?
  35159. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  35160. // The Symbolic attribute can be misused for regular fonts
  35161. // Heuristic: we have to check if the font is a standard one also
  35162. if (!!(properties.flags & FontFlags.Symbolic)) {
  35163. encoding = Encodings.MacRomanEncoding;
  35164. if (!properties.file) {
  35165. if (/Symbol/i.test(properties.name)) {
  35166. encoding = Encodings.SymbolSetEncoding;
  35167. } else if (/Dingbats/i.test(properties.name)) {
  35168. encoding = Encodings.ZapfDingbatsEncoding;
  35169. }
  35170. }
  35171. }
  35172. properties.defaultEncoding = encoding;
  35173. }
  35174. properties.differences = differences;
  35175. properties.baseEncodingName = baseEncodingName;
  35176. properties.dict = dict;
  35177. },
  35178. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  35179. var cmap, cmapObj = toUnicode;
  35180. if (isName(cmapObj)) {
  35181. cmap = CMapFactory.create(cmapObj,
  35182. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35183. if (cmap instanceof IdentityCMap) {
  35184. return new IdentityToUnicodeMap(0, 0xFFFF);
  35185. }
  35186. return new ToUnicodeMap(cmap.getMap());
  35187. } else if (isStream(cmapObj)) {
  35188. cmap = CMapFactory.create(cmapObj,
  35189. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35190. if (cmap instanceof IdentityCMap) {
  35191. return new IdentityToUnicodeMap(0, 0xFFFF);
  35192. }
  35193. var map = new Array(cmap.length);
  35194. // Convert UTF-16BE
  35195. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  35196. // to iterate over all keys.
  35197. cmap.forEach(function(charCode, token) {
  35198. var str = [];
  35199. for (var k = 0; k < token.length; k += 2) {
  35200. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35201. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  35202. str.push(w1);
  35203. continue;
  35204. }
  35205. k += 2;
  35206. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35207. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  35208. }
  35209. map[charCode] = String.fromCharCode.apply(String, str);
  35210. });
  35211. return new ToUnicodeMap(map);
  35212. }
  35213. return null;
  35214. },
  35215. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  35216. // Extract the encoding from the CIDToGIDMap
  35217. var glyphsData = cidToGidStream.getBytes();
  35218. // Set encoding 0 to later verify the font has an encoding
  35219. var result = [];
  35220. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  35221. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  35222. if (glyphID === 0) {
  35223. continue;
  35224. }
  35225. var code = j >> 1;
  35226. result[code] = glyphID;
  35227. }
  35228. return result;
  35229. },
  35230. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  35231. descriptor,
  35232. properties) {
  35233. var glyphsWidths = [];
  35234. var defaultWidth = 0;
  35235. var glyphsVMetrics = [];
  35236. var defaultVMetrics;
  35237. var i, ii, j, jj, start, code, widths;
  35238. if (properties.composite) {
  35239. defaultWidth = dict.get('DW') || 1000;
  35240. widths = dict.get('W');
  35241. if (widths) {
  35242. for (i = 0, ii = widths.length; i < ii; i++) {
  35243. start = widths[i++];
  35244. code = xref.fetchIfRef(widths[i]);
  35245. if (isArray(code)) {
  35246. for (j = 0, jj = code.length; j < jj; j++) {
  35247. glyphsWidths[start++] = code[j];
  35248. }
  35249. } else {
  35250. var width = widths[++i];
  35251. for (j = start; j <= code; j++) {
  35252. glyphsWidths[j] = width;
  35253. }
  35254. }
  35255. }
  35256. }
  35257. if (properties.vertical) {
  35258. var vmetrics = (dict.get('DW2') || [880, -1000]);
  35259. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  35260. vmetrics = dict.get('W2');
  35261. if (vmetrics) {
  35262. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  35263. start = vmetrics[i++];
  35264. code = xref.fetchIfRef(vmetrics[i]);
  35265. if (isArray(code)) {
  35266. for (j = 0, jj = code.length; j < jj; j++) {
  35267. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  35268. }
  35269. } else {
  35270. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  35271. for (j = start; j <= code; j++) {
  35272. glyphsVMetrics[j] = vmetric;
  35273. }
  35274. }
  35275. }
  35276. }
  35277. }
  35278. } else {
  35279. var firstChar = properties.firstChar;
  35280. widths = dict.get('Widths');
  35281. if (widths) {
  35282. j = firstChar;
  35283. for (i = 0, ii = widths.length; i < ii; i++) {
  35284. glyphsWidths[j++] = widths[i];
  35285. }
  35286. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  35287. } else {
  35288. // Trying get the BaseFont metrics (see comment above).
  35289. var baseFontName = dict.get('BaseFont');
  35290. if (isName(baseFontName)) {
  35291. var metrics = this.getBaseFontMetrics(baseFontName.name);
  35292. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  35293. properties);
  35294. defaultWidth = metrics.defaultWidth;
  35295. }
  35296. }
  35297. }
  35298. // Heuristic: detection of monospace font by checking all non-zero widths
  35299. var isMonospace = true;
  35300. var firstWidth = defaultWidth;
  35301. for (var glyph in glyphsWidths) {
  35302. var glyphWidth = glyphsWidths[glyph];
  35303. if (!glyphWidth) {
  35304. continue;
  35305. }
  35306. if (!firstWidth) {
  35307. firstWidth = glyphWidth;
  35308. continue;
  35309. }
  35310. if (firstWidth !== glyphWidth) {
  35311. isMonospace = false;
  35312. break;
  35313. }
  35314. }
  35315. if (isMonospace) {
  35316. properties.flags |= FontFlags.FixedPitch;
  35317. }
  35318. properties.defaultWidth = defaultWidth;
  35319. properties.widths = glyphsWidths;
  35320. properties.defaultVMetrics = defaultVMetrics;
  35321. properties.vmetrics = glyphsVMetrics;
  35322. },
  35323. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  35324. // Simulating descriptor flags attribute
  35325. var fontNameWoStyle = baseFontName.split('-')[0];
  35326. return (fontNameWoStyle in serifFonts) ||
  35327. (fontNameWoStyle.search(/serif/gi) !== -1);
  35328. },
  35329. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  35330. var defaultWidth = 0;
  35331. var widths = [];
  35332. var monospace = false;
  35333. var lookupName = (stdFontMap[name] || name);
  35334. if (!(lookupName in Metrics)) {
  35335. // Use default fonts for looking up font metrics if the passed
  35336. // font is not a base font
  35337. if (this.isSerifFont(name)) {
  35338. lookupName = 'Times-Roman';
  35339. } else {
  35340. lookupName = 'Helvetica';
  35341. }
  35342. }
  35343. var glyphWidths = Metrics[lookupName];
  35344. if (isNum(glyphWidths)) {
  35345. defaultWidth = glyphWidths;
  35346. monospace = true;
  35347. } else {
  35348. widths = glyphWidths;
  35349. }
  35350. return {
  35351. defaultWidth: defaultWidth,
  35352. monospace: monospace,
  35353. widths: widths
  35354. };
  35355. },
  35356. buildCharCodeToWidth:
  35357. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  35358. properties) {
  35359. var widths = Object.create(null);
  35360. var differences = properties.differences;
  35361. var encoding = properties.defaultEncoding;
  35362. for (var charCode = 0; charCode < 256; charCode++) {
  35363. if (charCode in differences &&
  35364. widthsByGlyphName[differences[charCode]]) {
  35365. widths[charCode] = widthsByGlyphName[differences[charCode]];
  35366. continue;
  35367. }
  35368. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  35369. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  35370. continue;
  35371. }
  35372. }
  35373. return widths;
  35374. },
  35375. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  35376. var baseDict = dict;
  35377. var type = dict.get('Subtype');
  35378. assert(isName(type), 'invalid font Subtype');
  35379. var composite = false;
  35380. var uint8array;
  35381. if (type.name === 'Type0') {
  35382. // If font is a composite
  35383. // - get the descendant font
  35384. // - set the type according to the descendant font
  35385. // - get the FontDescriptor from the descendant font
  35386. var df = dict.get('DescendantFonts');
  35387. if (!df) {
  35388. error('Descendant fonts are not specified');
  35389. }
  35390. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  35391. type = dict.get('Subtype');
  35392. assert(isName(type), 'invalid font Subtype');
  35393. composite = true;
  35394. }
  35395. var descriptor = dict.get('FontDescriptor');
  35396. if (descriptor) {
  35397. var hash = new MurmurHash3_64();
  35398. var encoding = baseDict.getRaw('Encoding');
  35399. if (isName(encoding)) {
  35400. hash.update(encoding.name);
  35401. } else if (isRef(encoding)) {
  35402. hash.update(encoding.num + '_' + encoding.gen);
  35403. } else if (isDict(encoding)) {
  35404. var keys = encoding.getKeys();
  35405. for (var i = 0, ii = keys.length; i < ii; i++) {
  35406. var entry = encoding.getRaw(keys[i]);
  35407. if (isName(entry)) {
  35408. hash.update(entry.name);
  35409. } else if (isRef(entry)) {
  35410. hash.update(entry.num + '_' + entry.gen);
  35411. } else if (isArray(entry)) { // 'Differences' entry.
  35412. // Ideally we should check the contents of the array, but to avoid
  35413. // parsing it here and then again in |extractDataStructures|,
  35414. // we only use the array length for now (fixes bug1157493.pdf).
  35415. hash.update(entry.length.toString());
  35416. }
  35417. }
  35418. }
  35419. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  35420. if (isStream(toUnicode)) {
  35421. var stream = toUnicode.str || toUnicode;
  35422. uint8array = stream.buffer ?
  35423. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  35424. new Uint8Array(stream.bytes.buffer,
  35425. stream.start, stream.end - stream.start);
  35426. hash.update(uint8array);
  35427. } else if (isName(toUnicode)) {
  35428. hash.update(toUnicode.name);
  35429. }
  35430. var widths = dict.get('Widths') || baseDict.get('Widths');
  35431. if (widths) {
  35432. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  35433. hash.update(uint8array);
  35434. }
  35435. }
  35436. return {
  35437. descriptor: descriptor,
  35438. dict: dict,
  35439. baseDict: baseDict,
  35440. composite: composite,
  35441. type: type.name,
  35442. hash: hash ? hash.hexdigest() : ''
  35443. };
  35444. },
  35445. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  35446. xref) {
  35447. var baseDict = preEvaluatedFont.baseDict;
  35448. var dict = preEvaluatedFont.dict;
  35449. var composite = preEvaluatedFont.composite;
  35450. var descriptor = preEvaluatedFont.descriptor;
  35451. var type = preEvaluatedFont.type;
  35452. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  35453. var properties;
  35454. if (!descriptor) {
  35455. if (type === 'Type3') {
  35456. // FontDescriptor is only required for Type3 fonts when the document
  35457. // is a tagged pdf. Create a barbebones one to get by.
  35458. descriptor = new Dict(null);
  35459. descriptor.set('FontName', Name.get(type));
  35460. descriptor.set('FontBBox', dict.get('FontBBox'));
  35461. } else {
  35462. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  35463. // FontDescriptor was not required.
  35464. // This case is here for compatibility.
  35465. var baseFontName = dict.get('BaseFont');
  35466. if (!isName(baseFontName)) {
  35467. error('Base font is not specified');
  35468. }
  35469. // Using base font name as a font name.
  35470. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  35471. var metrics = this.getBaseFontMetrics(baseFontName);
  35472. // Simulating descriptor flags attribute
  35473. var fontNameWoStyle = baseFontName.split('-')[0];
  35474. var flags =
  35475. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  35476. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  35477. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  35478. FontFlags.Nonsymbolic);
  35479. properties = {
  35480. type: type,
  35481. name: baseFontName,
  35482. widths: metrics.widths,
  35483. defaultWidth: metrics.defaultWidth,
  35484. flags: flags,
  35485. firstChar: 0,
  35486. lastChar: maxCharIndex
  35487. };
  35488. this.extractDataStructures(dict, dict, xref, properties);
  35489. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  35490. properties);
  35491. return new Font(baseFontName, null, properties);
  35492. }
  35493. }
  35494. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  35495. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  35496. // to ignore this rule when a variant of a standart font is used.
  35497. // TODO Fill the width array depending on which of the base font this is
  35498. // a variant.
  35499. var firstChar = (dict.get('FirstChar') || 0);
  35500. var lastChar = (dict.get('LastChar') || maxCharIndex);
  35501. var fontName = descriptor.get('FontName');
  35502. var baseFont = dict.get('BaseFont');
  35503. // Some bad PDFs have a string as the font name.
  35504. if (isString(fontName)) {
  35505. fontName = Name.get(fontName);
  35506. }
  35507. if (isString(baseFont)) {
  35508. baseFont = Name.get(baseFont);
  35509. }
  35510. if (type !== 'Type3') {
  35511. var fontNameStr = fontName && fontName.name;
  35512. var baseFontStr = baseFont && baseFont.name;
  35513. if (fontNameStr !== baseFontStr) {
  35514. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  35515. '" but should be the same as the Font\'s BaseFont "' +
  35516. baseFontStr + '"');
  35517. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  35518. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  35519. if (fontNameStr && baseFontStr &&
  35520. baseFontStr.indexOf(fontNameStr) === 0) {
  35521. fontName = baseFont;
  35522. }
  35523. }
  35524. }
  35525. fontName = (fontName || baseFont);
  35526. assert(isName(fontName), 'invalid font name');
  35527. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  35528. if (fontFile) {
  35529. if (fontFile.dict) {
  35530. var subtype = fontFile.dict.get('Subtype');
  35531. if (subtype) {
  35532. subtype = subtype.name;
  35533. }
  35534. var length1 = fontFile.dict.get('Length1');
  35535. var length2 = fontFile.dict.get('Length2');
  35536. }
  35537. }
  35538. properties = {
  35539. type: type,
  35540. name: fontName.name,
  35541. subtype: subtype,
  35542. file: fontFile,
  35543. length1: length1,
  35544. length2: length2,
  35545. loadedName: baseDict.loadedName,
  35546. composite: composite,
  35547. wideChars: composite,
  35548. fixedPitch: false,
  35549. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  35550. firstChar: firstChar || 0,
  35551. lastChar: (lastChar || maxCharIndex),
  35552. bbox: descriptor.get('FontBBox'),
  35553. ascent: descriptor.get('Ascent'),
  35554. descent: descriptor.get('Descent'),
  35555. xHeight: descriptor.get('XHeight'),
  35556. capHeight: descriptor.get('CapHeight'),
  35557. flags: descriptor.get('Flags'),
  35558. italicAngle: descriptor.get('ItalicAngle'),
  35559. coded: false
  35560. };
  35561. if (composite) {
  35562. var cidEncoding = baseDict.get('Encoding');
  35563. if (isName(cidEncoding)) {
  35564. properties.cidEncoding = cidEncoding.name;
  35565. }
  35566. properties.cMap = CMapFactory.create(cidEncoding,
  35567. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35568. properties.vertical = properties.cMap.vertical;
  35569. }
  35570. this.extractDataStructures(dict, baseDict, xref, properties);
  35571. this.extractWidths(dict, xref, descriptor, properties);
  35572. if (type === 'Type3') {
  35573. properties.isType3Font = true;
  35574. }
  35575. return new Font(fontName.name, fontFile, properties);
  35576. }
  35577. };
  35578. return PartialEvaluator;
  35579. })();
  35580. var TranslatedFont = (function TranslatedFontClosure() {
  35581. function TranslatedFont(loadedName, font, dict) {
  35582. this.loadedName = loadedName;
  35583. this.font = font;
  35584. this.dict = dict;
  35585. this.type3Loaded = null;
  35586. this.sent = false;
  35587. }
  35588. TranslatedFont.prototype = {
  35589. send: function (handler) {
  35590. if (this.sent) {
  35591. return;
  35592. }
  35593. var fontData = this.font.exportData();
  35594. handler.send('commonobj', [
  35595. this.loadedName,
  35596. 'Font',
  35597. fontData
  35598. ]);
  35599. this.sent = true;
  35600. },
  35601. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  35602. assert(this.font.isType3Font);
  35603. if (this.type3Loaded) {
  35604. return this.type3Loaded;
  35605. }
  35606. var translatedFont = this.font;
  35607. var loadCharProcsPromise = Promise.resolve();
  35608. var charProcs = this.dict.get('CharProcs').getAll();
  35609. var fontResources = this.dict.get('Resources') || resources;
  35610. var charProcKeys = Object.keys(charProcs);
  35611. var charProcOperatorList = {};
  35612. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  35613. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  35614. var glyphStream = charProcs[key];
  35615. var operatorList = new OperatorList();
  35616. return evaluator.getOperatorList(glyphStream, task, fontResources,
  35617. operatorList).then(function () {
  35618. charProcOperatorList[key] = operatorList.getIR();
  35619. // Add the dependencies to the parent operator list so they are
  35620. // resolved before sub operator list is executed synchronously.
  35621. parentOperatorList.addDependencies(operatorList.dependencies);
  35622. }, function (reason) {
  35623. warn('Type3 font resource \"' + key + '\" is not available');
  35624. var operatorList = new OperatorList();
  35625. charProcOperatorList[key] = operatorList.getIR();
  35626. });
  35627. }.bind(this, charProcKeys[i]));
  35628. }
  35629. this.type3Loaded = loadCharProcsPromise.then(function () {
  35630. translatedFont.charProcOperatorList = charProcOperatorList;
  35631. });
  35632. return this.type3Loaded;
  35633. }
  35634. };
  35635. return TranslatedFont;
  35636. })();
  35637. var OperatorList = (function OperatorListClosure() {
  35638. var CHUNK_SIZE = 1000;
  35639. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  35640. function getTransfers(queue) {
  35641. var transfers = [];
  35642. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  35643. for (var i = 0, ii = queue.length; i < ii; i++) {
  35644. switch (fnArray[i]) {
  35645. case OPS.paintInlineImageXObject:
  35646. case OPS.paintInlineImageXObjectGroup:
  35647. case OPS.paintImageMaskXObject:
  35648. var arg = argsArray[i][0]; // first param in imgData
  35649. if (!arg.cached) {
  35650. transfers.push(arg.data.buffer);
  35651. }
  35652. break;
  35653. }
  35654. }
  35655. return transfers;
  35656. }
  35657. function OperatorList(intent, messageHandler, pageIndex) {
  35658. this.messageHandler = messageHandler;
  35659. this.fnArray = [];
  35660. this.argsArray = [];
  35661. this.dependencies = {};
  35662. this._totalLength = 0;
  35663. this.pageIndex = pageIndex;
  35664. this.intent = intent;
  35665. }
  35666. OperatorList.prototype = {
  35667. get length() {
  35668. return this.argsArray.length;
  35669. },
  35670. /**
  35671. * @returns {number} The total length of the entire operator list,
  35672. * since `this.length === 0` after flushing.
  35673. */
  35674. get totalLength() {
  35675. return (this._totalLength + this.length);
  35676. },
  35677. addOp: function(fn, args) {
  35678. this.fnArray.push(fn);
  35679. this.argsArray.push(args);
  35680. if (this.messageHandler) {
  35681. if (this.fnArray.length >= CHUNK_SIZE) {
  35682. this.flush();
  35683. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  35684. (fn === OPS.restore || fn === OPS.endText)) {
  35685. // heuristic to flush on boundary of restore or endText
  35686. this.flush();
  35687. }
  35688. }
  35689. },
  35690. addDependency: function(dependency) {
  35691. if (dependency in this.dependencies) {
  35692. return;
  35693. }
  35694. this.dependencies[dependency] = true;
  35695. this.addOp(OPS.dependency, [dependency]);
  35696. },
  35697. addDependencies: function(dependencies) {
  35698. for (var key in dependencies) {
  35699. this.addDependency(key);
  35700. }
  35701. },
  35702. addOpList: function(opList) {
  35703. Util.extendObj(this.dependencies, opList.dependencies);
  35704. for (var i = 0, ii = opList.length; i < ii; i++) {
  35705. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  35706. }
  35707. },
  35708. getIR: function() {
  35709. return {
  35710. fnArray: this.fnArray,
  35711. argsArray: this.argsArray,
  35712. length: this.length
  35713. };
  35714. },
  35715. flush: function(lastChunk) {
  35716. if (this.intent !== 'oplist') {
  35717. new QueueOptimizer().optimize(this);
  35718. }
  35719. var transfers = getTransfers(this);
  35720. var length = this.length;
  35721. this._totalLength += length;
  35722. this.messageHandler.send('RenderPageChunk', {
  35723. operatorList: {
  35724. fnArray: this.fnArray,
  35725. argsArray: this.argsArray,
  35726. lastChunk: lastChunk,
  35727. length: length
  35728. },
  35729. pageIndex: this.pageIndex,
  35730. intent: this.intent
  35731. }, transfers);
  35732. this.dependencies = {};
  35733. this.fnArray.length = 0;
  35734. this.argsArray.length = 0;
  35735. }
  35736. };
  35737. return OperatorList;
  35738. })();
  35739. var StateManager = (function StateManagerClosure() {
  35740. function StateManager(initialState) {
  35741. this.state = initialState;
  35742. this.stateStack = [];
  35743. }
  35744. StateManager.prototype = {
  35745. save: function () {
  35746. var old = this.state;
  35747. this.stateStack.push(this.state);
  35748. this.state = old.clone();
  35749. },
  35750. restore: function () {
  35751. var prev = this.stateStack.pop();
  35752. if (prev) {
  35753. this.state = prev;
  35754. }
  35755. },
  35756. transform: function (args) {
  35757. this.state.ctm = Util.transform(this.state.ctm, args);
  35758. }
  35759. };
  35760. return StateManager;
  35761. })();
  35762. var TextState = (function TextStateClosure() {
  35763. function TextState() {
  35764. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35765. this.fontSize = 0;
  35766. this.font = null;
  35767. this.fontMatrix = FONT_IDENTITY_MATRIX;
  35768. this.textMatrix = IDENTITY_MATRIX.slice();
  35769. this.textLineMatrix = IDENTITY_MATRIX.slice();
  35770. this.charSpacing = 0;
  35771. this.wordSpacing = 0;
  35772. this.leading = 0;
  35773. this.textHScale = 1;
  35774. this.textRise = 0;
  35775. }
  35776. TextState.prototype = {
  35777. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35778. var m = this.textMatrix;
  35779. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35780. },
  35781. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35782. var m = this.textLineMatrix;
  35783. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35784. },
  35785. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  35786. var m = this.textMatrix;
  35787. m[4] = m[0] * x + m[2] * y + m[4];
  35788. m[5] = m[1] * x + m[3] * y + m[5];
  35789. },
  35790. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  35791. var m = this.textLineMatrix;
  35792. m[4] = m[0] * x + m[2] * y + m[4];
  35793. m[5] = m[1] * x + m[3] * y + m[5];
  35794. },
  35795. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  35796. // 9.4.4 Text Space Details
  35797. var tsm = [this.fontSize * this.textHScale, 0,
  35798. 0, this.fontSize,
  35799. 0, this.textRise];
  35800. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  35801. },
  35802. carriageReturn: function TextState_carriageReturn() {
  35803. this.translateTextLineMatrix(0, -this.leading);
  35804. this.textMatrix = this.textLineMatrix.slice();
  35805. },
  35806. clone: function TextState_clone() {
  35807. var clone = Object.create(this);
  35808. clone.textMatrix = this.textMatrix.slice();
  35809. clone.textLineMatrix = this.textLineMatrix.slice();
  35810. clone.fontMatrix = this.fontMatrix.slice();
  35811. return clone;
  35812. }
  35813. };
  35814. return TextState;
  35815. })();
  35816. var EvalState = (function EvalStateClosure() {
  35817. function EvalState() {
  35818. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35819. this.font = null;
  35820. this.textRenderingMode = TextRenderingMode.FILL;
  35821. this.fillColorSpace = ColorSpace.singletons.gray;
  35822. this.strokeColorSpace = ColorSpace.singletons.gray;
  35823. }
  35824. EvalState.prototype = {
  35825. clone: function CanvasExtraState_clone() {
  35826. return Object.create(this);
  35827. },
  35828. };
  35829. return EvalState;
  35830. })();
  35831. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  35832. // Specifies properties for each command
  35833. //
  35834. // If variableArgs === true: [0, `numArgs`] expected
  35835. // If variableArgs === false: exactly `numArgs` expected
  35836. var OP_MAP = {
  35837. // Graphic state
  35838. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  35839. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  35840. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  35841. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  35842. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  35843. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  35844. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  35845. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  35846. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  35847. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  35848. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  35849. // Path
  35850. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  35851. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  35852. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  35853. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  35854. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  35855. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  35856. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  35857. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  35858. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  35859. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35860. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35861. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  35862. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  35863. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  35864. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  35865. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  35866. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  35867. // Clipping
  35868. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  35869. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  35870. // Text
  35871. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  35872. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  35873. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  35874. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  35875. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  35876. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  35877. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  35878. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  35879. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  35880. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  35881. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  35882. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  35883. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  35884. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  35885. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  35886. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  35887. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  35888. variableArgs: false },
  35889. // Type3 fonts
  35890. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  35891. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  35892. // Color
  35893. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  35894. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  35895. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  35896. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  35897. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  35898. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  35899. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  35900. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  35901. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  35902. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  35903. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  35904. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  35905. // Shading
  35906. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  35907. // Images
  35908. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  35909. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  35910. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  35911. // XObjects
  35912. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  35913. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  35914. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  35915. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  35916. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  35917. variableArgs: false },
  35918. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  35919. // Compatibility
  35920. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  35921. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  35922. // (reserved partial commands for the lexer)
  35923. BM: null,
  35924. BD: null,
  35925. 'true': null,
  35926. fa: null,
  35927. fal: null,
  35928. fals: null,
  35929. 'false': null,
  35930. nu: null,
  35931. nul: null,
  35932. 'null': null
  35933. };
  35934. function EvaluatorPreprocessor(stream, xref, stateManager) {
  35935. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  35936. // dictionary
  35937. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  35938. this.stateManager = stateManager;
  35939. this.nonProcessedArgs = [];
  35940. }
  35941. EvaluatorPreprocessor.prototype = {
  35942. get savedStatesDepth() {
  35943. return this.stateManager.stateStack.length;
  35944. },
  35945. // |operation| is an object with two fields:
  35946. //
  35947. // - |fn| is an out param.
  35948. //
  35949. // - |args| is an inout param. On entry, it should have one of two values.
  35950. //
  35951. // - An empty array. This indicates that the caller is providing the
  35952. // array in which the args will be stored in. The caller should use
  35953. // this value if it can reuse a single array for each call to read().
  35954. //
  35955. // - |null|. This indicates that the caller needs this function to create
  35956. // the array in which any args are stored in. If there are zero args,
  35957. // this function will leave |operation.args| as |null| (thus avoiding
  35958. // allocations that would occur if we used an empty array to represent
  35959. // zero arguments). Otherwise, it will replace |null| with a new array
  35960. // containing the arguments. The caller should use this value if it
  35961. // cannot reuse an array for each call to read().
  35962. //
  35963. // These two modes are present because this function is very hot and so
  35964. // avoiding allocations where possible is worthwhile.
  35965. //
  35966. read: function EvaluatorPreprocessor_read(operation) {
  35967. var args = operation.args;
  35968. while (true) {
  35969. var obj = this.parser.getObj();
  35970. if (isCmd(obj)) {
  35971. var cmd = obj.cmd;
  35972. // Check that the command is valid
  35973. var opSpec = OP_MAP[cmd];
  35974. if (!opSpec) {
  35975. warn('Unknown command "' + cmd + '"');
  35976. continue;
  35977. }
  35978. var fn = opSpec.id;
  35979. var numArgs = opSpec.numArgs;
  35980. var argsLength = args !== null ? args.length : 0;
  35981. if (!opSpec.variableArgs) {
  35982. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  35983. if (argsLength !== numArgs) {
  35984. var nonProcessedArgs = this.nonProcessedArgs;
  35985. while (argsLength > numArgs) {
  35986. nonProcessedArgs.push(args.shift());
  35987. argsLength--;
  35988. }
  35989. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  35990. if (!args) {
  35991. args = [];
  35992. }
  35993. args.unshift(nonProcessedArgs.pop());
  35994. argsLength++;
  35995. }
  35996. }
  35997. if (argsLength < numArgs) {
  35998. // If we receive too few args, it's not possible to possible
  35999. // to execute the command, so skip the command
  36000. info('Command ' + fn + ': because expected ' +
  36001. numArgs + ' args, but received ' + argsLength +
  36002. ' args; skipping');
  36003. args = null;
  36004. continue;
  36005. }
  36006. } else if (argsLength > numArgs) {
  36007. info('Command ' + fn + ': expected [0,' + numArgs +
  36008. '] args, but received ' + argsLength + ' args');
  36009. }
  36010. // TODO figure out how to type-check vararg functions
  36011. this.preprocessCommand(fn, args);
  36012. operation.fn = fn;
  36013. operation.args = args;
  36014. return true;
  36015. } else {
  36016. if (isEOF(obj)) {
  36017. return false; // no more commands
  36018. }
  36019. // argument
  36020. if (obj !== null) {
  36021. if (!args) {
  36022. args = [];
  36023. }
  36024. args.push((obj instanceof Dict ? obj.getAll() : obj));
  36025. assert(args.length <= 33, 'Too many arguments');
  36026. }
  36027. }
  36028. }
  36029. },
  36030. preprocessCommand:
  36031. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36032. switch (fn | 0) {
  36033. case OPS.save:
  36034. this.stateManager.save();
  36035. break;
  36036. case OPS.restore:
  36037. this.stateManager.restore();
  36038. break;
  36039. case OPS.transform:
  36040. this.stateManager.transform(args);
  36041. break;
  36042. }
  36043. }
  36044. };
  36045. return EvaluatorPreprocessor;
  36046. })();
  36047. var QueueOptimizer = (function QueueOptimizerClosure() {
  36048. function addState(parentState, pattern, fn) {
  36049. var state = parentState;
  36050. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  36051. var item = pattern[i];
  36052. state = (state[item] || (state[item] = []));
  36053. }
  36054. state[pattern[pattern.length - 1]] = fn;
  36055. }
  36056. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36057. argsArray) {
  36058. // Handles special case of mainly LaTeX documents which use image masks to
  36059. // draw lines with the current fill style.
  36060. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  36061. // have been found at iFirstSave.
  36062. var iFirstPIMXO = iFirstSave + 2;
  36063. for (var i = 0; i < count; i++) {
  36064. var arg = argsArray[iFirstPIMXO + 4 * i];
  36065. var imageMask = arg.length === 1 && arg[0];
  36066. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  36067. (!imageMask.data.length ||
  36068. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  36069. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  36070. continue;
  36071. }
  36072. break;
  36073. }
  36074. return count - i;
  36075. }
  36076. var InitialState = [];
  36077. // This replaces (save, transform, paintInlineImageXObject, restore)+
  36078. // sequences with one |paintInlineImageXObjectGroup| operation.
  36079. addState(InitialState,
  36080. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  36081. function foundInlineImageGroup(context) {
  36082. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  36083. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  36084. var MAX_WIDTH = 1000;
  36085. var IMAGE_PADDING = 1;
  36086. var fnArray = context.fnArray, argsArray = context.argsArray;
  36087. var curr = context.iCurr;
  36088. var iFirstSave = curr - 3;
  36089. var iFirstTransform = curr - 2;
  36090. var iFirstPIIXO = curr - 1;
  36091. // Look for the quartets.
  36092. var i = iFirstSave + 4;
  36093. var ii = fnArray.length;
  36094. while (i + 3 < ii) {
  36095. if (fnArray[i] !== OPS.save ||
  36096. fnArray[i + 1] !== OPS.transform ||
  36097. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  36098. fnArray[i + 3] !== OPS.restore) {
  36099. break; // ops don't match
  36100. }
  36101. i += 4;
  36102. }
  36103. // At this point, i is the index of the first op past the last valid
  36104. // quartet.
  36105. var count = Math.min((i - iFirstSave) / 4,
  36106. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  36107. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  36108. return i;
  36109. }
  36110. // assuming that heights of those image is too small (~1 pixel)
  36111. // packing as much as possible by lines
  36112. var maxX = 0;
  36113. var map = [], maxLineHeight = 0;
  36114. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  36115. var q;
  36116. for (q = 0; q < count; q++) {
  36117. var transform = argsArray[iFirstTransform + (q << 2)];
  36118. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  36119. if (currentX + img.width > MAX_WIDTH) {
  36120. // starting new line
  36121. maxX = Math.max(maxX, currentX);
  36122. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  36123. currentX = 0;
  36124. maxLineHeight = 0;
  36125. }
  36126. map.push({
  36127. transform: transform,
  36128. x: currentX, y: currentY,
  36129. w: img.width, h: img.height
  36130. });
  36131. currentX += img.width + 2 * IMAGE_PADDING;
  36132. maxLineHeight = Math.max(maxLineHeight, img.height);
  36133. }
  36134. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  36135. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  36136. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  36137. var imgRowSize = imgWidth << 2;
  36138. for (q = 0; q < count; q++) {
  36139. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  36140. // Copy image by lines and extends pixels into padding.
  36141. var rowSize = map[q].w << 2;
  36142. var dataOffset = 0;
  36143. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  36144. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  36145. for (var k = 0, kk = map[q].h; k < kk; k++) {
  36146. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  36147. dataOffset += rowSize;
  36148. offset += imgRowSize;
  36149. }
  36150. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  36151. while (offset >= 0) {
  36152. data[offset - 4] = data[offset];
  36153. data[offset - 3] = data[offset + 1];
  36154. data[offset - 2] = data[offset + 2];
  36155. data[offset - 1] = data[offset + 3];
  36156. data[offset + rowSize] = data[offset + rowSize - 4];
  36157. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  36158. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  36159. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  36160. offset -= imgRowSize;
  36161. }
  36162. }
  36163. // Replace queue items.
  36164. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  36165. argsArray.splice(iFirstSave, count * 4,
  36166. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  36167. data: imgData }, map]);
  36168. return iFirstSave + 1;
  36169. });
  36170. // This replaces (save, transform, paintImageMaskXObject, restore)+
  36171. // sequences with one |paintImageMaskXObjectGroup| or one
  36172. // |paintImageMaskXObjectRepeat| operation.
  36173. addState(InitialState,
  36174. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  36175. function foundImageMaskGroup(context) {
  36176. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  36177. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  36178. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  36179. var fnArray = context.fnArray, argsArray = context.argsArray;
  36180. var curr = context.iCurr;
  36181. var iFirstSave = curr - 3;
  36182. var iFirstTransform = curr - 2;
  36183. var iFirstPIMXO = curr - 1;
  36184. // Look for the quartets.
  36185. var i = iFirstSave + 4;
  36186. var ii = fnArray.length;
  36187. while (i + 3 < ii) {
  36188. if (fnArray[i] !== OPS.save ||
  36189. fnArray[i + 1] !== OPS.transform ||
  36190. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  36191. fnArray[i + 3] !== OPS.restore) {
  36192. break; // ops don't match
  36193. }
  36194. i += 4;
  36195. }
  36196. // At this point, i is the index of the first op past the last valid
  36197. // quartet.
  36198. var count = (i - iFirstSave) / 4;
  36199. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36200. argsArray);
  36201. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  36202. return i;
  36203. }
  36204. var q;
  36205. var isSameImage = false;
  36206. var iTransform, transformArgs;
  36207. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  36208. if (argsArray[iFirstTransform][1] === 0 &&
  36209. argsArray[iFirstTransform][2] === 0) {
  36210. isSameImage = true;
  36211. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36212. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36213. iTransform = iFirstTransform + 4;
  36214. var iPIMXO = iFirstPIMXO + 4;
  36215. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  36216. transformArgs = argsArray[iTransform];
  36217. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  36218. transformArgs[0] !== firstTransformArg0 ||
  36219. transformArgs[1] !== 0 ||
  36220. transformArgs[2] !== 0 ||
  36221. transformArgs[3] !== firstTransformArg3) {
  36222. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  36223. isSameImage = false;
  36224. } else {
  36225. count = q;
  36226. }
  36227. break; // different image or transform
  36228. }
  36229. }
  36230. }
  36231. if (isSameImage) {
  36232. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  36233. var positions = new Float32Array(count * 2);
  36234. iTransform = iFirstTransform;
  36235. for (q = 0; q < count; q++, iTransform += 4) {
  36236. transformArgs = argsArray[iTransform];
  36237. positions[(q << 1)] = transformArgs[4];
  36238. positions[(q << 1) + 1] = transformArgs[5];
  36239. }
  36240. // Replace queue items.
  36241. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  36242. argsArray.splice(iFirstSave, count * 4,
  36243. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  36244. } else {
  36245. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  36246. var images = [];
  36247. for (q = 0; q < count; q++) {
  36248. transformArgs = argsArray[iFirstTransform + (q << 2)];
  36249. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  36250. images.push({ data: maskParams.data, width: maskParams.width,
  36251. height: maskParams.height,
  36252. transform: transformArgs });
  36253. }
  36254. // Replace queue items.
  36255. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  36256. argsArray.splice(iFirstSave, count * 4, [images]);
  36257. }
  36258. return iFirstSave + 1;
  36259. });
  36260. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  36261. // with one paintImageXObjectRepeat operation, if the |transform| and
  36262. // |paintImageXObjectRepeat| ops are appropriate.
  36263. addState(InitialState,
  36264. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  36265. function (context) {
  36266. var MIN_IMAGES_IN_BLOCK = 3;
  36267. var MAX_IMAGES_IN_BLOCK = 1000;
  36268. var fnArray = context.fnArray, argsArray = context.argsArray;
  36269. var curr = context.iCurr;
  36270. var iFirstSave = curr - 3;
  36271. var iFirstTransform = curr - 2;
  36272. var iFirstPIXO = curr - 1;
  36273. var iFirstRestore = curr;
  36274. if (argsArray[iFirstTransform][1] !== 0 ||
  36275. argsArray[iFirstTransform][2] !== 0) {
  36276. return iFirstRestore + 1; // transform has the wrong form
  36277. }
  36278. // Look for the quartets.
  36279. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  36280. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36281. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36282. var i = iFirstSave + 4;
  36283. var ii = fnArray.length;
  36284. while (i + 3 < ii) {
  36285. if (fnArray[i] !== OPS.save ||
  36286. fnArray[i + 1] !== OPS.transform ||
  36287. fnArray[i + 2] !== OPS.paintImageXObject ||
  36288. fnArray[i + 3] !== OPS.restore) {
  36289. break; // ops don't match
  36290. }
  36291. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  36292. argsArray[i + 1][1] !== 0 ||
  36293. argsArray[i + 1][2] !== 0 ||
  36294. argsArray[i + 1][3] !== firstTransformArg3) {
  36295. break; // transforms don't match
  36296. }
  36297. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  36298. break; // images don't match
  36299. }
  36300. i += 4;
  36301. }
  36302. // At this point, i is the index of the first op past the last valid
  36303. // quartet.
  36304. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  36305. if (count < MIN_IMAGES_IN_BLOCK) {
  36306. return i;
  36307. }
  36308. // Extract the (x,y) positions from all of the matching transforms.
  36309. var positions = new Float32Array(count * 2);
  36310. var iTransform = iFirstTransform;
  36311. for (var q = 0; q < count; q++, iTransform += 4) {
  36312. var transformArgs = argsArray[iTransform];
  36313. positions[(q << 1)] = transformArgs[4];
  36314. positions[(q << 1) + 1] = transformArgs[5];
  36315. }
  36316. // Replace queue items.
  36317. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  36318. positions];
  36319. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  36320. argsArray.splice(iFirstSave, count * 4, args);
  36321. return iFirstSave + 1;
  36322. });
  36323. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  36324. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  36325. // sequences, if the font for each one is the same.
  36326. addState(InitialState,
  36327. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  36328. function (context) {
  36329. var MIN_CHARS_IN_BLOCK = 3;
  36330. var MAX_CHARS_IN_BLOCK = 1000;
  36331. var fnArray = context.fnArray, argsArray = context.argsArray;
  36332. var curr = context.iCurr;
  36333. var iFirstBeginText = curr - 4;
  36334. var iFirstSetFont = curr - 3;
  36335. var iFirstSetTextMatrix = curr - 2;
  36336. var iFirstShowText = curr - 1;
  36337. var iFirstEndText = curr;
  36338. // Look for the quintets.
  36339. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  36340. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  36341. var i = iFirstBeginText + 5;
  36342. var ii = fnArray.length;
  36343. while (i + 4 < ii) {
  36344. if (fnArray[i] !== OPS.beginText ||
  36345. fnArray[i + 1] !== OPS.setFont ||
  36346. fnArray[i + 2] !== OPS.setTextMatrix ||
  36347. fnArray[i + 3] !== OPS.showText ||
  36348. fnArray[i + 4] !== OPS.endText) {
  36349. break; // ops don't match
  36350. }
  36351. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  36352. argsArray[i + 1][1] !== firstSetFontArg1) {
  36353. break; // fonts don't match
  36354. }
  36355. i += 5;
  36356. }
  36357. // At this point, i is the index of the first op past the last valid
  36358. // quintet.
  36359. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  36360. if (count < MIN_CHARS_IN_BLOCK) {
  36361. return i;
  36362. }
  36363. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  36364. // showText, endText), include that as well. (E.g. <something> might be
  36365. // |dependency|.)
  36366. var iFirst = iFirstBeginText;
  36367. if (iFirstBeginText >= 4 &&
  36368. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  36369. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  36370. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  36371. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  36372. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  36373. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  36374. count++;
  36375. iFirst -= 5;
  36376. }
  36377. // Remove (endText, beginText, setFont) trios.
  36378. var iEndText = iFirst + 4;
  36379. for (var q = 1; q < count; q++) {
  36380. fnArray.splice(iEndText, 3);
  36381. argsArray.splice(iEndText, 3);
  36382. iEndText += 2;
  36383. }
  36384. return iEndText + 1;
  36385. });
  36386. function QueueOptimizer() {}
  36387. QueueOptimizer.prototype = {
  36388. optimize: function QueueOptimizer_optimize(queue) {
  36389. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36390. var context = {
  36391. iCurr: 0,
  36392. fnArray: fnArray,
  36393. argsArray: argsArray
  36394. };
  36395. var state;
  36396. var i = 0, ii = fnArray.length;
  36397. while (i < ii) {
  36398. state = (state || InitialState)[fnArray[i]];
  36399. if (typeof state === 'function') { // we found some handler
  36400. context.iCurr = i;
  36401. // state() returns the index of the first non-matching op (if we
  36402. // didn't match) or the first op past the modified ops (if we did
  36403. // match and replace).
  36404. i = state(context);
  36405. state = undefined; // reset the state machine
  36406. ii = context.fnArray.length;
  36407. } else {
  36408. i++;
  36409. }
  36410. }
  36411. }
  36412. };
  36413. return QueueOptimizer;
  36414. })();
  36415. exports.OperatorList = OperatorList;
  36416. exports.PartialEvaluator = PartialEvaluator;
  36417. }));
  36418. (function (root, factory) {
  36419. {
  36420. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  36421. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  36422. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  36423. }
  36424. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  36425. coreColorSpace, coreObj, coreEvaluator) {
  36426. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  36427. var AnnotationFlag = sharedUtil.AnnotationFlag;
  36428. var AnnotationType = sharedUtil.AnnotationType;
  36429. var OPS = sharedUtil.OPS;
  36430. var Util = sharedUtil.Util;
  36431. var isArray = sharedUtil.isArray;
  36432. var isInt = sharedUtil.isInt;
  36433. var isValidUrl = sharedUtil.isValidUrl;
  36434. var stringToBytes = sharedUtil.stringToBytes;
  36435. var stringToPDFString = sharedUtil.stringToPDFString;
  36436. var stringToUTF8String = sharedUtil.stringToUTF8String;
  36437. var warn = sharedUtil.warn;
  36438. var Dict = corePrimitives.Dict;
  36439. var isDict = corePrimitives.isDict;
  36440. var isName = corePrimitives.isName;
  36441. var Stream = coreStream.Stream;
  36442. var ColorSpace = coreColorSpace.ColorSpace;
  36443. var ObjectLoader = coreObj.ObjectLoader;
  36444. var OperatorList = coreEvaluator.OperatorList;
  36445. /**
  36446. * @class
  36447. * @alias AnnotationFactory
  36448. */
  36449. function AnnotationFactory() {}
  36450. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  36451. /**
  36452. * @param {XRef} xref
  36453. * @param {Object} ref
  36454. * @returns {Annotation}
  36455. */
  36456. create: function AnnotationFactory_create(xref, ref) {
  36457. var dict = xref.fetchIfRef(ref);
  36458. if (!isDict(dict)) {
  36459. return;
  36460. }
  36461. // Determine the annotation's subtype.
  36462. var subtype = dict.get('Subtype');
  36463. subtype = isName(subtype) ? subtype.name : '';
  36464. // Return the right annotation object based on the subtype and field type.
  36465. var parameters = {
  36466. dict: dict,
  36467. ref: ref
  36468. };
  36469. switch (subtype) {
  36470. case 'Link':
  36471. return new LinkAnnotation(parameters);
  36472. case 'Text':
  36473. return new TextAnnotation(parameters);
  36474. case 'Widget':
  36475. var fieldType = Util.getInheritableProperty(dict, 'FT');
  36476. if (isName(fieldType) && fieldType.name === 'Tx') {
  36477. return new TextWidgetAnnotation(parameters);
  36478. }
  36479. return new WidgetAnnotation(parameters);
  36480. case 'Popup':
  36481. return new PopupAnnotation(parameters);
  36482. default:
  36483. warn('Unimplemented annotation type "' + subtype + '", ' +
  36484. 'falling back to base annotation');
  36485. return new Annotation(parameters);
  36486. }
  36487. }
  36488. };
  36489. var Annotation = (function AnnotationClosure() {
  36490. // 12.5.5: Algorithm: Appearance streams
  36491. function getTransformMatrix(rect, bbox, matrix) {
  36492. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  36493. var minX = bounds[0];
  36494. var minY = bounds[1];
  36495. var maxX = bounds[2];
  36496. var maxY = bounds[3];
  36497. if (minX === maxX || minY === maxY) {
  36498. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  36499. // just apply the transform for rect
  36500. return [1, 0, 0, 1, rect[0], rect[1]];
  36501. }
  36502. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  36503. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  36504. return [
  36505. xRatio,
  36506. 0,
  36507. 0,
  36508. yRatio,
  36509. rect[0] - minX * xRatio,
  36510. rect[1] - minY * yRatio
  36511. ];
  36512. }
  36513. function getDefaultAppearance(dict) {
  36514. var appearanceState = dict.get('AP');
  36515. if (!isDict(appearanceState)) {
  36516. return;
  36517. }
  36518. var appearance;
  36519. var appearances = appearanceState.get('N');
  36520. if (isDict(appearances)) {
  36521. var as = dict.get('AS');
  36522. if (as && appearances.has(as.name)) {
  36523. appearance = appearances.get(as.name);
  36524. }
  36525. } else {
  36526. appearance = appearances;
  36527. }
  36528. return appearance;
  36529. }
  36530. function Annotation(params) {
  36531. var dict = params.dict;
  36532. this.setFlags(dict.get('F'));
  36533. this.setRectangle(dict.get('Rect'));
  36534. this.setColor(dict.get('C'));
  36535. this.setBorderStyle(dict);
  36536. this.appearance = getDefaultAppearance(dict);
  36537. // Expose public properties using a data object.
  36538. this.data = {};
  36539. this.data.id = params.ref.toString();
  36540. this.data.subtype = dict.get('Subtype').name;
  36541. this.data.annotationFlags = this.flags;
  36542. this.data.rect = this.rectangle;
  36543. this.data.color = this.color;
  36544. this.data.borderStyle = this.borderStyle;
  36545. this.data.hasAppearance = !!this.appearance;
  36546. }
  36547. Annotation.prototype = {
  36548. /**
  36549. * @return {boolean}
  36550. */
  36551. get viewable() {
  36552. if (this.flags) {
  36553. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36554. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  36555. !this.hasFlag(AnnotationFlag.NOVIEW);
  36556. }
  36557. return true;
  36558. },
  36559. /**
  36560. * @return {boolean}
  36561. */
  36562. get printable() {
  36563. if (this.flags) {
  36564. return this.hasFlag(AnnotationFlag.PRINT) &&
  36565. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36566. !this.hasFlag(AnnotationFlag.HIDDEN);
  36567. }
  36568. return false;
  36569. },
  36570. /**
  36571. * Set the flags.
  36572. *
  36573. * @public
  36574. * @memberof Annotation
  36575. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  36576. * characteristics
  36577. * @see {@link shared/util.js}
  36578. */
  36579. setFlags: function Annotation_setFlags(flags) {
  36580. if (isInt(flags)) {
  36581. this.flags = flags;
  36582. } else {
  36583. this.flags = 0;
  36584. }
  36585. },
  36586. /**
  36587. * Check if a provided flag is set.
  36588. *
  36589. * @public
  36590. * @memberof Annotation
  36591. * @param {number} flag - Hexadecimal representation for an annotation
  36592. * characteristic
  36593. * @return {boolean}
  36594. * @see {@link shared/util.js}
  36595. */
  36596. hasFlag: function Annotation_hasFlag(flag) {
  36597. if (this.flags) {
  36598. return (this.flags & flag) > 0;
  36599. }
  36600. return false;
  36601. },
  36602. /**
  36603. * Set the rectangle.
  36604. *
  36605. * @public
  36606. * @memberof Annotation
  36607. * @param {Array} rectangle - The rectangle array with exactly four entries
  36608. */
  36609. setRectangle: function Annotation_setRectangle(rectangle) {
  36610. if (isArray(rectangle) && rectangle.length === 4) {
  36611. this.rectangle = Util.normalizeRect(rectangle);
  36612. } else {
  36613. this.rectangle = [0, 0, 0, 0];
  36614. }
  36615. },
  36616. /**
  36617. * Set the color and take care of color space conversion.
  36618. *
  36619. * @public
  36620. * @memberof Annotation
  36621. * @param {Array} color - The color array containing either 0
  36622. * (transparent), 1 (grayscale), 3 (RGB) or
  36623. * 4 (CMYK) elements
  36624. */
  36625. setColor: function Annotation_setColor(color) {
  36626. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  36627. if (!isArray(color)) {
  36628. this.color = rgbColor;
  36629. return;
  36630. }
  36631. switch (color.length) {
  36632. case 0: // Transparent, which we indicate with a null value
  36633. this.color = null;
  36634. break;
  36635. case 1: // Convert grayscale to RGB
  36636. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  36637. this.color = rgbColor;
  36638. break;
  36639. case 3: // Convert RGB percentages to RGB
  36640. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  36641. this.color = rgbColor;
  36642. break;
  36643. case 4: // Convert CMYK to RGB
  36644. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  36645. this.color = rgbColor;
  36646. break;
  36647. default:
  36648. this.color = rgbColor;
  36649. break;
  36650. }
  36651. },
  36652. /**
  36653. * Set the border style (as AnnotationBorderStyle object).
  36654. *
  36655. * @public
  36656. * @memberof Annotation
  36657. * @param {Dict} borderStyle - The border style dictionary
  36658. */
  36659. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  36660. this.borderStyle = new AnnotationBorderStyle();
  36661. if (!isDict(borderStyle)) {
  36662. return;
  36663. }
  36664. if (borderStyle.has('BS')) {
  36665. var dict = borderStyle.get('BS');
  36666. var dictType;
  36667. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  36668. dictType.name === 'Border')) {
  36669. this.borderStyle.setWidth(dict.get('W'));
  36670. this.borderStyle.setStyle(dict.get('S'));
  36671. this.borderStyle.setDashArray(dict.get('D'));
  36672. }
  36673. } else if (borderStyle.has('Border')) {
  36674. var array = borderStyle.get('Border');
  36675. if (isArray(array) && array.length >= 3) {
  36676. this.borderStyle.setHorizontalCornerRadius(array[0]);
  36677. this.borderStyle.setVerticalCornerRadius(array[1]);
  36678. this.borderStyle.setWidth(array[2]);
  36679. if (array.length === 4) { // Dash array available
  36680. this.borderStyle.setDashArray(array[3]);
  36681. }
  36682. }
  36683. } else {
  36684. // There are no border entries in the dictionary. According to the
  36685. // specification, we should draw a solid border of width 1 in that
  36686. // case, but Adobe Reader did not implement that part of the
  36687. // specification and instead draws no border at all, so we do the same.
  36688. // See also https://github.com/mozilla/pdf.js/issues/6179.
  36689. this.borderStyle.setWidth(0);
  36690. }
  36691. },
  36692. loadResources: function Annotation_loadResources(keys) {
  36693. return new Promise(function (resolve, reject) {
  36694. this.appearance.dict.getAsync('Resources').then(function (resources) {
  36695. if (!resources) {
  36696. resolve();
  36697. return;
  36698. }
  36699. var objectLoader = new ObjectLoader(resources.map,
  36700. keys,
  36701. resources.xref);
  36702. objectLoader.load().then(function() {
  36703. resolve(resources);
  36704. }, reject);
  36705. }, reject);
  36706. }.bind(this));
  36707. },
  36708. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  36709. if (!this.appearance) {
  36710. return Promise.resolve(new OperatorList());
  36711. }
  36712. var data = this.data;
  36713. var appearanceDict = this.appearance.dict;
  36714. var resourcesPromise = this.loadResources([
  36715. 'ExtGState',
  36716. 'ColorSpace',
  36717. 'Pattern',
  36718. 'Shading',
  36719. 'XObject',
  36720. 'Font'
  36721. // ProcSet
  36722. // Properties
  36723. ]);
  36724. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  36725. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  36726. var transform = getTransformMatrix(data.rect, bbox, matrix);
  36727. var self = this;
  36728. return resourcesPromise.then(function(resources) {
  36729. var opList = new OperatorList();
  36730. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  36731. return evaluator.getOperatorList(self.appearance, task,
  36732. resources, opList).
  36733. then(function () {
  36734. opList.addOp(OPS.endAnnotation, []);
  36735. self.appearance.reset();
  36736. return opList;
  36737. });
  36738. });
  36739. }
  36740. };
  36741. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  36742. annotations, opList, partialEvaluator, task, intent) {
  36743. var annotationPromises = [];
  36744. for (var i = 0, n = annotations.length; i < n; ++i) {
  36745. if ((intent === 'display' && annotations[i].viewable) ||
  36746. (intent === 'print' && annotations[i].printable)) {
  36747. annotationPromises.push(
  36748. annotations[i].getOperatorList(partialEvaluator, task));
  36749. }
  36750. }
  36751. return Promise.all(annotationPromises).then(function(operatorLists) {
  36752. opList.addOp(OPS.beginAnnotations, []);
  36753. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  36754. opList.addOpList(operatorLists[i]);
  36755. }
  36756. opList.addOp(OPS.endAnnotations, []);
  36757. });
  36758. };
  36759. return Annotation;
  36760. })();
  36761. /**
  36762. * Contains all data regarding an annotation's border style.
  36763. *
  36764. * @class
  36765. */
  36766. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  36767. /**
  36768. * @constructor
  36769. * @private
  36770. */
  36771. function AnnotationBorderStyle() {
  36772. this.width = 1;
  36773. this.style = AnnotationBorderStyleType.SOLID;
  36774. this.dashArray = [3];
  36775. this.horizontalCornerRadius = 0;
  36776. this.verticalCornerRadius = 0;
  36777. }
  36778. AnnotationBorderStyle.prototype = {
  36779. /**
  36780. * Set the width.
  36781. *
  36782. * @public
  36783. * @memberof AnnotationBorderStyle
  36784. * @param {integer} width - The width
  36785. */
  36786. setWidth: function AnnotationBorderStyle_setWidth(width) {
  36787. if (width === (width | 0)) {
  36788. this.width = width;
  36789. }
  36790. },
  36791. /**
  36792. * Set the style.
  36793. *
  36794. * @public
  36795. * @memberof AnnotationBorderStyle
  36796. * @param {Object} style - The style object
  36797. * @see {@link shared/util.js}
  36798. */
  36799. setStyle: function AnnotationBorderStyle_setStyle(style) {
  36800. if (!style) {
  36801. return;
  36802. }
  36803. switch (style.name) {
  36804. case 'S':
  36805. this.style = AnnotationBorderStyleType.SOLID;
  36806. break;
  36807. case 'D':
  36808. this.style = AnnotationBorderStyleType.DASHED;
  36809. break;
  36810. case 'B':
  36811. this.style = AnnotationBorderStyleType.BEVELED;
  36812. break;
  36813. case 'I':
  36814. this.style = AnnotationBorderStyleType.INSET;
  36815. break;
  36816. case 'U':
  36817. this.style = AnnotationBorderStyleType.UNDERLINE;
  36818. break;
  36819. default:
  36820. break;
  36821. }
  36822. },
  36823. /**
  36824. * Set the dash array.
  36825. *
  36826. * @public
  36827. * @memberof AnnotationBorderStyle
  36828. * @param {Array} dashArray - The dash array with at least one element
  36829. */
  36830. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  36831. // We validate the dash array, but we do not use it because CSS does not
  36832. // allow us to change spacing of dashes. For more information, visit
  36833. // http://www.w3.org/TR/css3-background/#the-border-style.
  36834. if (isArray(dashArray) && dashArray.length > 0) {
  36835. // According to the PDF specification: the elements in a dashArray
  36836. // shall be numbers that are nonnegative and not all equal to zero.
  36837. var isValid = true;
  36838. var allZeros = true;
  36839. for (var i = 0, len = dashArray.length; i < len; i++) {
  36840. var element = dashArray[i];
  36841. var validNumber = (+element >= 0);
  36842. if (!validNumber) {
  36843. isValid = false;
  36844. break;
  36845. } else if (element > 0) {
  36846. allZeros = false;
  36847. }
  36848. }
  36849. if (isValid && !allZeros) {
  36850. this.dashArray = dashArray;
  36851. } else {
  36852. this.width = 0; // Adobe behavior when the array is invalid.
  36853. }
  36854. } else if (dashArray) {
  36855. this.width = 0; // Adobe behavior when the array is invalid.
  36856. }
  36857. },
  36858. /**
  36859. * Set the horizontal corner radius (from a Border dictionary).
  36860. *
  36861. * @public
  36862. * @memberof AnnotationBorderStyle
  36863. * @param {integer} radius - The horizontal corner radius
  36864. */
  36865. setHorizontalCornerRadius:
  36866. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  36867. if (radius === (radius | 0)) {
  36868. this.horizontalCornerRadius = radius;
  36869. }
  36870. },
  36871. /**
  36872. * Set the vertical corner radius (from a Border dictionary).
  36873. *
  36874. * @public
  36875. * @memberof AnnotationBorderStyle
  36876. * @param {integer} radius - The vertical corner radius
  36877. */
  36878. setVerticalCornerRadius:
  36879. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  36880. if (radius === (radius | 0)) {
  36881. this.verticalCornerRadius = radius;
  36882. }
  36883. }
  36884. };
  36885. return AnnotationBorderStyle;
  36886. })();
  36887. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  36888. function WidgetAnnotation(params) {
  36889. Annotation.call(this, params);
  36890. var dict = params.dict;
  36891. var data = this.data;
  36892. data.annotationType = AnnotationType.WIDGET;
  36893. data.fieldValue = stringToPDFString(
  36894. Util.getInheritableProperty(dict, 'V') || '');
  36895. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  36896. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  36897. var fieldType = Util.getInheritableProperty(dict, 'FT');
  36898. data.fieldType = isName(fieldType) ? fieldType.name : '';
  36899. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  36900. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  36901. // Hide unsupported Widget signatures.
  36902. if (data.fieldType === 'Sig') {
  36903. warn('unimplemented annotation type: Widget signature');
  36904. this.setFlags(AnnotationFlag.HIDDEN);
  36905. }
  36906. // Building the full field name by collecting the field and
  36907. // its ancestors 'T' data and joining them using '.'.
  36908. var fieldName = [];
  36909. var namedItem = dict;
  36910. var ref = params.ref;
  36911. while (namedItem) {
  36912. var parent = namedItem.get('Parent');
  36913. var parentRef = namedItem.getRaw('Parent');
  36914. var name = namedItem.get('T');
  36915. if (name) {
  36916. fieldName.unshift(stringToPDFString(name));
  36917. } else if (parent && ref) {
  36918. // The field name is absent, that means more than one field
  36919. // with the same name may exist. Replacing the empty name
  36920. // with the '`' plus index in the parent's 'Kids' array.
  36921. // This is not in the PDF spec but necessary to id the
  36922. // the input controls.
  36923. var kids = parent.get('Kids');
  36924. var j, jj;
  36925. for (j = 0, jj = kids.length; j < jj; j++) {
  36926. var kidRef = kids[j];
  36927. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  36928. break;
  36929. }
  36930. }
  36931. fieldName.unshift('`' + j);
  36932. }
  36933. namedItem = parent;
  36934. ref = parentRef;
  36935. }
  36936. data.fullName = fieldName.join('.');
  36937. }
  36938. Util.inherit(WidgetAnnotation, Annotation, {});
  36939. return WidgetAnnotation;
  36940. })();
  36941. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  36942. function TextWidgetAnnotation(params) {
  36943. WidgetAnnotation.call(this, params);
  36944. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  36945. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  36946. }
  36947. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  36948. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  36949. task) {
  36950. if (this.appearance) {
  36951. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  36952. }
  36953. var opList = new OperatorList();
  36954. var data = this.data;
  36955. // Even if there is an appearance stream, ignore it. This is the
  36956. // behaviour used by Adobe Reader.
  36957. if (!data.defaultAppearance) {
  36958. return Promise.resolve(opList);
  36959. }
  36960. var stream = new Stream(stringToBytes(data.defaultAppearance));
  36961. return evaluator.getOperatorList(stream, task,
  36962. this.fieldResources, opList).
  36963. then(function () {
  36964. return opList;
  36965. });
  36966. }
  36967. });
  36968. return TextWidgetAnnotation;
  36969. })();
  36970. var TextAnnotation = (function TextAnnotationClosure() {
  36971. var DEFAULT_ICON_SIZE = 22; // px
  36972. function TextAnnotation(parameters) {
  36973. Annotation.call(this, parameters);
  36974. this.data.annotationType = AnnotationType.TEXT;
  36975. this.data.hasHtml = true;
  36976. var dict = parameters.dict;
  36977. if (this.data.hasAppearance) {
  36978. this.data.name = 'NoIcon';
  36979. } else {
  36980. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  36981. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  36982. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  36983. }
  36984. if (!dict.has('C')) {
  36985. // Fall back to the default background color.
  36986. this.data.color = null;
  36987. }
  36988. this.data.hasPopup = dict.has('Popup');
  36989. if (!this.data.hasPopup) {
  36990. // There is no associated Popup annotation, so the Text annotation
  36991. // must create its own popup.
  36992. this.data.title = stringToPDFString(dict.get('T') || '');
  36993. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  36994. this.data.hasHtml = (this.data.title || this.data.contents);
  36995. }
  36996. }
  36997. Util.inherit(TextAnnotation, Annotation, {});
  36998. return TextAnnotation;
  36999. })();
  37000. var LinkAnnotation = (function LinkAnnotationClosure() {
  37001. function LinkAnnotation(params) {
  37002. Annotation.call(this, params);
  37003. var dict = params.dict;
  37004. var data = this.data;
  37005. data.annotationType = AnnotationType.LINK;
  37006. data.hasHtml = true;
  37007. var action = dict.get('A');
  37008. if (action && isDict(action)) {
  37009. var linkType = action.get('S').name;
  37010. if (linkType === 'URI') {
  37011. var url = action.get('URI');
  37012. if (isName(url)) {
  37013. // Some bad PDFs do not put parentheses around relative URLs.
  37014. url = '/' + url.name;
  37015. } else if (url) {
  37016. url = addDefaultProtocolToUrl(url);
  37017. }
  37018. // TODO: pdf spec mentions urls can be relative to a Base
  37019. // entry in the dictionary.
  37020. if (!isValidUrl(url, false)) {
  37021. url = '';
  37022. }
  37023. // According to ISO 32000-1:2008, section 12.6.4.7,
  37024. // URI should to be encoded in 7-bit ASCII.
  37025. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37026. try {
  37027. data.url = stringToUTF8String(url);
  37028. } catch (e) {
  37029. // Fall back to a simple copy.
  37030. data.url = url;
  37031. }
  37032. } else if (linkType === 'GoTo') {
  37033. data.dest = action.get('D');
  37034. } else if (linkType === 'GoToR') {
  37035. var urlDict = action.get('F');
  37036. if (isDict(urlDict)) {
  37037. // We assume that the 'url' is a Filspec dictionary
  37038. // and fetch the url without checking any further
  37039. url = urlDict.get('F') || '';
  37040. }
  37041. // TODO: pdf reference says that GoToR
  37042. // can also have 'NewWindow' attribute
  37043. if (!isValidUrl(url, false)) {
  37044. url = '';
  37045. }
  37046. data.url = url;
  37047. data.dest = action.get('D');
  37048. } else if (linkType === 'Named') {
  37049. data.action = action.get('N').name;
  37050. } else {
  37051. warn('unrecognized link type: ' + linkType);
  37052. }
  37053. } else if (dict.has('Dest')) {
  37054. // simple destination link
  37055. var dest = dict.get('Dest');
  37056. data.dest = isName(dest) ? dest.name : dest;
  37057. }
  37058. }
  37059. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  37060. function addDefaultProtocolToUrl(url) {
  37061. if (url && url.indexOf('www.') === 0) {
  37062. return ('http://' + url);
  37063. }
  37064. return url;
  37065. }
  37066. Util.inherit(LinkAnnotation, Annotation, {});
  37067. return LinkAnnotation;
  37068. })();
  37069. var PopupAnnotation = (function PopupAnnotationClosure() {
  37070. function PopupAnnotation(parameters) {
  37071. Annotation.call(this, parameters);
  37072. this.data.annotationType = AnnotationType.POPUP;
  37073. var dict = parameters.dict;
  37074. var parentItem = dict.get('Parent');
  37075. if (!parentItem) {
  37076. warn('Popup annotation has a missing or invalid parent annotation.');
  37077. return;
  37078. }
  37079. this.data.parentId = dict.getRaw('Parent').toString();
  37080. this.data.title = stringToPDFString(parentItem.get('T') || '');
  37081. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  37082. if (!parentItem.has('C')) {
  37083. // Fall back to the default background color.
  37084. this.data.color = null;
  37085. } else {
  37086. this.setColor(parentItem.get('C'));
  37087. this.data.color = this.color;
  37088. }
  37089. this.data.hasHtml = (this.data.title || this.data.contents);
  37090. }
  37091. Util.inherit(PopupAnnotation, Annotation, {});
  37092. return PopupAnnotation;
  37093. })();
  37094. exports.Annotation = Annotation;
  37095. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  37096. exports.AnnotationFactory = AnnotationFactory;
  37097. }));
  37098. (function (root, factory) {
  37099. {
  37100. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  37101. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  37102. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  37103. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  37104. }
  37105. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  37106. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  37107. var MissingDataException = sharedUtil.MissingDataException;
  37108. var Util = sharedUtil.Util;
  37109. var assert = sharedUtil.assert;
  37110. var error = sharedUtil.error;
  37111. var info = sharedUtil.info;
  37112. var isArray = sharedUtil.isArray;
  37113. var isArrayBuffer = sharedUtil.isArrayBuffer;
  37114. var isString = sharedUtil.isString;
  37115. var shadow = sharedUtil.shadow;
  37116. var stringToBytes = sharedUtil.stringToBytes;
  37117. var stringToPDFString = sharedUtil.stringToPDFString;
  37118. var warn = sharedUtil.warn;
  37119. var Dict = corePrimitives.Dict;
  37120. var isDict = corePrimitives.isDict;
  37121. var isName = corePrimitives.isName;
  37122. var isStream = corePrimitives.isStream;
  37123. var NullStream = coreStream.NullStream;
  37124. var Stream = coreStream.Stream;
  37125. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  37126. var Catalog = coreObj.Catalog;
  37127. var ObjectLoader = coreObj.ObjectLoader;
  37128. var XRef = coreObj.XRef;
  37129. var Lexer = coreParser.Lexer;
  37130. var Linearization = coreParser.Linearization;
  37131. var calculateMD5 = coreCrypto.calculateMD5;
  37132. var OperatorList = coreEvaluator.OperatorList;
  37133. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  37134. var Annotation = coreAnnotation.Annotation;
  37135. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  37136. var Page = (function PageClosure() {
  37137. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  37138. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  37139. this.pdfManager = pdfManager;
  37140. this.pageIndex = pageIndex;
  37141. this.pageDict = pageDict;
  37142. this.xref = xref;
  37143. this.ref = ref;
  37144. this.fontCache = fontCache;
  37145. this.idCounters = {
  37146. obj: 0
  37147. };
  37148. this.resourcesPromise = null;
  37149. }
  37150. Page.prototype = {
  37151. getPageProp: function Page_getPageProp(key) {
  37152. return this.pageDict.get(key);
  37153. },
  37154. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  37155. var dict = this.pageDict, valueArray = null, loopCount = 0;
  37156. var MAX_LOOP_COUNT = 100;
  37157. // Always walk up the entire parent chain, to be able to find
  37158. // e.g. \Resources placed on multiple levels of the tree.
  37159. while (dict) {
  37160. var value = dict.get(key);
  37161. if (value) {
  37162. if (!valueArray) {
  37163. valueArray = [];
  37164. }
  37165. valueArray.push(value);
  37166. }
  37167. if (++loopCount > MAX_LOOP_COUNT) {
  37168. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  37169. break;
  37170. }
  37171. dict = dict.get('Parent');
  37172. }
  37173. if (!valueArray) {
  37174. return Dict.empty;
  37175. }
  37176. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  37177. loopCount > MAX_LOOP_COUNT) {
  37178. return valueArray[0];
  37179. }
  37180. return Dict.merge(this.xref, valueArray);
  37181. },
  37182. get content() {
  37183. return this.getPageProp('Contents');
  37184. },
  37185. get resources() {
  37186. // For robustness: The spec states that a \Resources entry has to be
  37187. // present, but can be empty. Some document omit it still, in this case
  37188. // we return an empty dictionary.
  37189. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  37190. },
  37191. get mediaBox() {
  37192. var obj = this.getInheritedPageProp('MediaBox');
  37193. // Reset invalid media box to letter size.
  37194. if (!isArray(obj) || obj.length !== 4) {
  37195. obj = LETTER_SIZE_MEDIABOX;
  37196. }
  37197. return shadow(this, 'mediaBox', obj);
  37198. },
  37199. get view() {
  37200. var mediaBox = this.mediaBox;
  37201. var cropBox = this.getInheritedPageProp('CropBox');
  37202. if (!isArray(cropBox) || cropBox.length !== 4) {
  37203. return shadow(this, 'view', mediaBox);
  37204. }
  37205. // From the spec, 6th ed., p.963:
  37206. // "The crop, bleed, trim, and art boxes should not ordinarily
  37207. // extend beyond the boundaries of the media box. If they do, they are
  37208. // effectively reduced to their intersection with the media box."
  37209. cropBox = Util.intersect(cropBox, mediaBox);
  37210. if (!cropBox) {
  37211. return shadow(this, 'view', mediaBox);
  37212. }
  37213. return shadow(this, 'view', cropBox);
  37214. },
  37215. get rotate() {
  37216. var rotate = this.getInheritedPageProp('Rotate') || 0;
  37217. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  37218. if (rotate % 90 !== 0) {
  37219. rotate = 0;
  37220. } else if (rotate >= 360) {
  37221. rotate = rotate % 360;
  37222. } else if (rotate < 0) {
  37223. // The spec doesn't cover negatives, assume its counterclockwise
  37224. // rotation. The following is the other implementation of modulo.
  37225. rotate = ((rotate % 360) + 360) % 360;
  37226. }
  37227. return shadow(this, 'rotate', rotate);
  37228. },
  37229. getContentStream: function Page_getContentStream() {
  37230. var content = this.content;
  37231. var stream;
  37232. if (isArray(content)) {
  37233. // fetching items
  37234. var xref = this.xref;
  37235. var i, n = content.length;
  37236. var streams = [];
  37237. for (i = 0; i < n; ++i) {
  37238. streams.push(xref.fetchIfRef(content[i]));
  37239. }
  37240. stream = new StreamsSequenceStream(streams);
  37241. } else if (isStream(content)) {
  37242. stream = content;
  37243. } else {
  37244. // replacing non-existent page content with empty one
  37245. stream = new NullStream();
  37246. }
  37247. return stream;
  37248. },
  37249. loadResources: function Page_loadResources(keys) {
  37250. if (!this.resourcesPromise) {
  37251. // TODO: add async getInheritedPageProp and remove this.
  37252. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  37253. }
  37254. return this.resourcesPromise.then(function resourceSuccess() {
  37255. var objectLoader = new ObjectLoader(this.resources.map,
  37256. keys,
  37257. this.xref);
  37258. return objectLoader.load();
  37259. }.bind(this));
  37260. },
  37261. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  37262. var self = this;
  37263. var pdfManager = this.pdfManager;
  37264. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37265. []);
  37266. var resourcesPromise = this.loadResources([
  37267. 'ExtGState',
  37268. 'ColorSpace',
  37269. 'Pattern',
  37270. 'Shading',
  37271. 'XObject',
  37272. 'Font'
  37273. // ProcSet
  37274. // Properties
  37275. ]);
  37276. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  37277. handler, this.pageIndex,
  37278. 'p' + this.pageIndex + '_',
  37279. this.idCounters,
  37280. this.fontCache);
  37281. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  37282. var pageListPromise = dataPromises.then(function(data) {
  37283. var contentStream = data[0];
  37284. var opList = new OperatorList(intent, handler, self.pageIndex);
  37285. handler.send('StartRenderPage', {
  37286. transparency: partialEvaluator.hasBlendModes(self.resources),
  37287. pageIndex: self.pageIndex,
  37288. intent: intent
  37289. });
  37290. return partialEvaluator.getOperatorList(contentStream, task,
  37291. self.resources, opList).then(function () {
  37292. return opList;
  37293. });
  37294. });
  37295. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  37296. return Promise.all([pageListPromise, annotationsPromise]).then(
  37297. function(datas) {
  37298. var pageOpList = datas[0];
  37299. var annotations = datas[1];
  37300. if (annotations.length === 0) {
  37301. pageOpList.flush(true);
  37302. return pageOpList;
  37303. }
  37304. var annotationsReadyPromise = Annotation.appendToOperatorList(
  37305. annotations, pageOpList, partialEvaluator, task, intent);
  37306. return annotationsReadyPromise.then(function () {
  37307. pageOpList.flush(true);
  37308. return pageOpList;
  37309. });
  37310. });
  37311. },
  37312. extractTextContent: function Page_extractTextContent(task,
  37313. normalizeWhitespace) {
  37314. var handler = {
  37315. on: function nullHandlerOn() {},
  37316. send: function nullHandlerSend() {}
  37317. };
  37318. var self = this;
  37319. var pdfManager = this.pdfManager;
  37320. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37321. []);
  37322. var resourcesPromise = this.loadResources([
  37323. 'ExtGState',
  37324. 'XObject',
  37325. 'Font'
  37326. ]);
  37327. var dataPromises = Promise.all([contentStreamPromise,
  37328. resourcesPromise]);
  37329. return dataPromises.then(function(data) {
  37330. var contentStream = data[0];
  37331. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  37332. handler, self.pageIndex,
  37333. 'p' + self.pageIndex + '_',
  37334. self.idCounters,
  37335. self.fontCache);
  37336. return partialEvaluator.getTextContent(contentStream,
  37337. task,
  37338. self.resources,
  37339. /* stateManager = */ null,
  37340. normalizeWhitespace);
  37341. });
  37342. },
  37343. getAnnotationsData: function Page_getAnnotationsData(intent) {
  37344. var annotations = this.annotations;
  37345. var annotationsData = [];
  37346. for (var i = 0, n = annotations.length; i < n; ++i) {
  37347. if (intent) {
  37348. if (!(intent === 'display' && annotations[i].viewable) &&
  37349. !(intent === 'print' && annotations[i].printable)) {
  37350. continue;
  37351. }
  37352. }
  37353. annotationsData.push(annotations[i].data);
  37354. }
  37355. return annotationsData;
  37356. },
  37357. get annotations() {
  37358. var annotations = [];
  37359. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  37360. var annotationFactory = new AnnotationFactory();
  37361. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  37362. var annotationRef = annotationRefs[i];
  37363. var annotation = annotationFactory.create(this.xref, annotationRef);
  37364. if (annotation) {
  37365. annotations.push(annotation);
  37366. }
  37367. }
  37368. return shadow(this, 'annotations', annotations);
  37369. }
  37370. };
  37371. return Page;
  37372. })();
  37373. /**
  37374. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  37375. * `PDFDoc`, this one doesn't have any job management code.
  37376. * Right now there exists one PDFDocument on the main thread + one object
  37377. * for each worker. If there is no worker support enabled, there are two
  37378. * `PDFDocument` objects on the main thread created.
  37379. */
  37380. var PDFDocument = (function PDFDocumentClosure() {
  37381. var FINGERPRINT_FIRST_BYTES = 1024;
  37382. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  37383. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  37384. function PDFDocument(pdfManager, arg, password) {
  37385. if (isStream(arg)) {
  37386. init.call(this, pdfManager, arg, password);
  37387. } else if (isArrayBuffer(arg)) {
  37388. init.call(this, pdfManager, new Stream(arg), password);
  37389. } else {
  37390. error('PDFDocument: Unknown argument type');
  37391. }
  37392. }
  37393. function init(pdfManager, stream, password) {
  37394. assert(stream.length > 0, 'stream must have data');
  37395. this.pdfManager = pdfManager;
  37396. this.stream = stream;
  37397. var xref = new XRef(this.stream, password, pdfManager);
  37398. this.xref = xref;
  37399. }
  37400. function find(stream, needle, limit, backwards) {
  37401. var pos = stream.pos;
  37402. var end = stream.end;
  37403. var strBuf = [];
  37404. if (pos + limit > end) {
  37405. limit = end - pos;
  37406. }
  37407. for (var n = 0; n < limit; ++n) {
  37408. strBuf.push(String.fromCharCode(stream.getByte()));
  37409. }
  37410. var str = strBuf.join('');
  37411. stream.pos = pos;
  37412. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  37413. if (index === -1) {
  37414. return false; /* not found */
  37415. }
  37416. stream.pos += index;
  37417. return true; /* found */
  37418. }
  37419. var DocumentInfoValidators = {
  37420. get entries() {
  37421. // Lazily build this since all the validation functions below are not
  37422. // defined until after this file loads.
  37423. return shadow(this, 'entries', {
  37424. Title: isString,
  37425. Author: isString,
  37426. Subject: isString,
  37427. Keywords: isString,
  37428. Creator: isString,
  37429. Producer: isString,
  37430. CreationDate: isString,
  37431. ModDate: isString,
  37432. Trapped: isName
  37433. });
  37434. }
  37435. };
  37436. PDFDocument.prototype = {
  37437. parse: function PDFDocument_parse(recoveryMode) {
  37438. this.setup(recoveryMode);
  37439. var version = this.catalog.catDict.get('Version');
  37440. if (isName(version)) {
  37441. this.pdfFormatVersion = version.name;
  37442. }
  37443. try {
  37444. // checking if AcroForm is present
  37445. this.acroForm = this.catalog.catDict.get('AcroForm');
  37446. if (this.acroForm) {
  37447. this.xfa = this.acroForm.get('XFA');
  37448. var fields = this.acroForm.get('Fields');
  37449. if ((!fields || !isArray(fields) || fields.length === 0) &&
  37450. !this.xfa) {
  37451. // no fields and no XFA -- not a form (?)
  37452. this.acroForm = null;
  37453. }
  37454. }
  37455. } catch (ex) {
  37456. info('Something wrong with AcroForm entry');
  37457. this.acroForm = null;
  37458. }
  37459. },
  37460. get linearization() {
  37461. var linearization = null;
  37462. if (this.stream.length) {
  37463. try {
  37464. linearization = Linearization.create(this.stream);
  37465. } catch (err) {
  37466. if (err instanceof MissingDataException) {
  37467. throw err;
  37468. }
  37469. info(err);
  37470. }
  37471. }
  37472. // shadow the prototype getter with a data property
  37473. return shadow(this, 'linearization', linearization);
  37474. },
  37475. get startXRef() {
  37476. var stream = this.stream;
  37477. var startXRef = 0;
  37478. var linearization = this.linearization;
  37479. if (linearization) {
  37480. // Find end of first obj.
  37481. stream.reset();
  37482. if (find(stream, 'endobj', 1024)) {
  37483. startXRef = stream.pos + 6;
  37484. }
  37485. } else {
  37486. // Find startxref by jumping backward from the end of the file.
  37487. var step = 1024;
  37488. var found = false, pos = stream.end;
  37489. while (!found && pos > 0) {
  37490. pos -= step - 'startxref'.length;
  37491. if (pos < 0) {
  37492. pos = 0;
  37493. }
  37494. stream.pos = pos;
  37495. found = find(stream, 'startxref', step, true);
  37496. }
  37497. if (found) {
  37498. stream.skip(9);
  37499. var ch;
  37500. do {
  37501. ch = stream.getByte();
  37502. } while (Lexer.isSpace(ch));
  37503. var str = '';
  37504. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  37505. str += String.fromCharCode(ch);
  37506. ch = stream.getByte();
  37507. }
  37508. startXRef = parseInt(str, 10);
  37509. if (isNaN(startXRef)) {
  37510. startXRef = 0;
  37511. }
  37512. }
  37513. }
  37514. // shadow the prototype getter with a data property
  37515. return shadow(this, 'startXRef', startXRef);
  37516. },
  37517. get mainXRefEntriesOffset() {
  37518. var mainXRefEntriesOffset = 0;
  37519. var linearization = this.linearization;
  37520. if (linearization) {
  37521. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  37522. }
  37523. // shadow the prototype getter with a data property
  37524. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  37525. },
  37526. // Find the header, remove leading garbage and setup the stream
  37527. // starting from the header.
  37528. checkHeader: function PDFDocument_checkHeader() {
  37529. var stream = this.stream;
  37530. stream.reset();
  37531. if (find(stream, '%PDF-', 1024)) {
  37532. // Found the header, trim off any garbage before it.
  37533. stream.moveStart();
  37534. // Reading file format version
  37535. var MAX_VERSION_LENGTH = 12;
  37536. var version = '', ch;
  37537. while ((ch = stream.getByte()) > 0x20) { // SPACE
  37538. if (version.length >= MAX_VERSION_LENGTH) {
  37539. break;
  37540. }
  37541. version += String.fromCharCode(ch);
  37542. }
  37543. if (!this.pdfFormatVersion) {
  37544. // removing "%PDF-"-prefix
  37545. this.pdfFormatVersion = version.substring(5);
  37546. }
  37547. return;
  37548. }
  37549. // May not be a PDF file, continue anyway.
  37550. },
  37551. parseStartXRef: function PDFDocument_parseStartXRef() {
  37552. var startXRef = this.startXRef;
  37553. this.xref.setStartXRef(startXRef);
  37554. },
  37555. setup: function PDFDocument_setup(recoveryMode) {
  37556. this.xref.parse(recoveryMode);
  37557. var self = this;
  37558. var pageFactory = {
  37559. createPage: function (pageIndex, dict, ref, fontCache) {
  37560. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  37561. fontCache);
  37562. }
  37563. };
  37564. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  37565. },
  37566. get numPages() {
  37567. var linearization = this.linearization;
  37568. var num = linearization ? linearization.numPages : this.catalog.numPages;
  37569. // shadow the prototype getter
  37570. return shadow(this, 'numPages', num);
  37571. },
  37572. get documentInfo() {
  37573. var docInfo = {
  37574. PDFFormatVersion: this.pdfFormatVersion,
  37575. IsAcroFormPresent: !!this.acroForm,
  37576. IsXFAPresent: !!this.xfa
  37577. };
  37578. var infoDict;
  37579. try {
  37580. infoDict = this.xref.trailer.get('Info');
  37581. } catch (err) {
  37582. info('The document information dictionary is invalid.');
  37583. }
  37584. if (infoDict) {
  37585. var validEntries = DocumentInfoValidators.entries;
  37586. // Only fill the document info with valid entries from the spec.
  37587. for (var key in validEntries) {
  37588. if (infoDict.has(key)) {
  37589. var value = infoDict.get(key);
  37590. // Make sure the value conforms to the spec.
  37591. if (validEntries[key](value)) {
  37592. docInfo[key] = (typeof value !== 'string' ?
  37593. value : stringToPDFString(value));
  37594. } else {
  37595. info('Bad value in document info for "' + key + '"');
  37596. }
  37597. }
  37598. }
  37599. }
  37600. return shadow(this, 'documentInfo', docInfo);
  37601. },
  37602. get fingerprint() {
  37603. var xref = this.xref, hash, fileID = '';
  37604. var idArray = xref.trailer.get('ID');
  37605. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  37606. idArray[0] !== EMPTY_FINGERPRINT) {
  37607. hash = stringToBytes(idArray[0]);
  37608. } else {
  37609. if (this.stream.ensureRange) {
  37610. this.stream.ensureRange(0,
  37611. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  37612. }
  37613. hash = calculateMD5(this.stream.bytes.subarray(0,
  37614. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  37615. }
  37616. for (var i = 0, n = hash.length; i < n; i++) {
  37617. var hex = hash[i].toString(16);
  37618. fileID += hex.length === 1 ? '0' + hex : hex;
  37619. }
  37620. return shadow(this, 'fingerprint', fileID);
  37621. },
  37622. getPage: function PDFDocument_getPage(pageIndex) {
  37623. return this.catalog.getPage(pageIndex);
  37624. },
  37625. cleanup: function PDFDocument_cleanup() {
  37626. return this.catalog.cleanup();
  37627. }
  37628. };
  37629. return PDFDocument;
  37630. })();
  37631. exports.Page = Page;
  37632. exports.PDFDocument = PDFDocument;
  37633. }));
  37634. (function (root, factory) {
  37635. {
  37636. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  37637. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  37638. root.pdfjsCoreDocument);
  37639. }
  37640. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  37641. coreDocument) {
  37642. var NotImplementedException = sharedUtil.NotImplementedException;
  37643. var MissingDataException = sharedUtil.MissingDataException;
  37644. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37645. var Util = sharedUtil.Util;
  37646. var Stream = coreStream.Stream;
  37647. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  37648. var PDFDocument = coreDocument.PDFDocument;
  37649. var BasePdfManager = (function BasePdfManagerClosure() {
  37650. function BasePdfManager() {
  37651. throw new Error('Cannot initialize BaseManagerManager');
  37652. }
  37653. BasePdfManager.prototype = {
  37654. get docId() {
  37655. return this._docId;
  37656. },
  37657. onLoadedStream: function BasePdfManager_onLoadedStream() {
  37658. throw new NotImplementedException();
  37659. },
  37660. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  37661. return this.ensure(this.pdfDocument, prop, args);
  37662. },
  37663. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  37664. return this.ensure(this.pdfDocument.xref, prop, args);
  37665. },
  37666. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  37667. return this.ensure(this.pdfDocument.catalog, prop, args);
  37668. },
  37669. getPage: function BasePdfManager_getPage(pageIndex) {
  37670. return this.pdfDocument.getPage(pageIndex);
  37671. },
  37672. cleanup: function BasePdfManager_cleanup() {
  37673. return this.pdfDocument.cleanup();
  37674. },
  37675. ensure: function BasePdfManager_ensure(obj, prop, args) {
  37676. return new NotImplementedException();
  37677. },
  37678. requestRange: function BasePdfManager_requestRange(begin, end) {
  37679. return new NotImplementedException();
  37680. },
  37681. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  37682. return new NotImplementedException();
  37683. },
  37684. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  37685. return new NotImplementedException();
  37686. },
  37687. updatePassword: function BasePdfManager_updatePassword(password) {
  37688. this.pdfDocument.xref.password = this.password = password;
  37689. if (this._passwordChangedCapability) {
  37690. this._passwordChangedCapability.resolve();
  37691. }
  37692. },
  37693. passwordChanged: function BasePdfManager_passwordChanged() {
  37694. this._passwordChangedCapability = createPromiseCapability();
  37695. return this._passwordChangedCapability.promise;
  37696. },
  37697. terminate: function BasePdfManager_terminate() {
  37698. return new NotImplementedException();
  37699. }
  37700. };
  37701. return BasePdfManager;
  37702. })();
  37703. var LocalPdfManager = (function LocalPdfManagerClosure() {
  37704. function LocalPdfManager(docId, data, password) {
  37705. this._docId = docId;
  37706. var stream = new Stream(data);
  37707. this.pdfDocument = new PDFDocument(this, stream, password);
  37708. this._loadedStreamCapability = createPromiseCapability();
  37709. this._loadedStreamCapability.resolve(stream);
  37710. }
  37711. Util.inherit(LocalPdfManager, BasePdfManager, {
  37712. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  37713. return new Promise(function (resolve, reject) {
  37714. try {
  37715. var value = obj[prop];
  37716. var result;
  37717. if (typeof value === 'function') {
  37718. result = value.apply(obj, args);
  37719. } else {
  37720. result = value;
  37721. }
  37722. resolve(result);
  37723. } catch (e) {
  37724. reject(e);
  37725. }
  37726. });
  37727. },
  37728. requestRange: function LocalPdfManager_requestRange(begin, end) {
  37729. return Promise.resolve();
  37730. },
  37731. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  37732. return;
  37733. },
  37734. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  37735. return this._loadedStreamCapability.promise;
  37736. },
  37737. terminate: function LocalPdfManager_terminate() {
  37738. return;
  37739. }
  37740. });
  37741. return LocalPdfManager;
  37742. })();
  37743. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  37744. function NetworkPdfManager(docId, args, msgHandler) {
  37745. this._docId = docId;
  37746. this.msgHandler = msgHandler;
  37747. var params = {
  37748. msgHandler: msgHandler,
  37749. httpHeaders: args.httpHeaders,
  37750. withCredentials: args.withCredentials,
  37751. chunkedViewerLoading: args.chunkedViewerLoading,
  37752. disableAutoFetch: args.disableAutoFetch,
  37753. initialData: args.initialData
  37754. };
  37755. this.streamManager = new ChunkedStreamManager(args.length,
  37756. args.rangeChunkSize,
  37757. args.url, params);
  37758. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  37759. args.password);
  37760. }
  37761. Util.inherit(NetworkPdfManager, BasePdfManager, {
  37762. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  37763. var pdfManager = this;
  37764. return new Promise(function (resolve, reject) {
  37765. function ensureHelper() {
  37766. try {
  37767. var result;
  37768. var value = obj[prop];
  37769. if (typeof value === 'function') {
  37770. result = value.apply(obj, args);
  37771. } else {
  37772. result = value;
  37773. }
  37774. resolve(result);
  37775. } catch(e) {
  37776. if (!(e instanceof MissingDataException)) {
  37777. reject(e);
  37778. return;
  37779. }
  37780. pdfManager.streamManager.requestRange(e.begin, e.end).
  37781. then(ensureHelper, reject);
  37782. }
  37783. }
  37784. ensureHelper();
  37785. });
  37786. },
  37787. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  37788. return this.streamManager.requestRange(begin, end);
  37789. },
  37790. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  37791. this.streamManager.requestAllChunks();
  37792. },
  37793. sendProgressiveData:
  37794. function NetworkPdfManager_sendProgressiveData(chunk) {
  37795. this.streamManager.onReceiveData({ chunk: chunk });
  37796. },
  37797. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  37798. return this.streamManager.onLoadedStream();
  37799. },
  37800. terminate: function NetworkPdfManager_terminate() {
  37801. this.streamManager.abort();
  37802. }
  37803. });
  37804. return NetworkPdfManager;
  37805. })();
  37806. exports.LocalPdfManager = LocalPdfManager;
  37807. exports.NetworkPdfManager = NetworkPdfManager;
  37808. }));
  37809. (function (root, factory) {
  37810. {
  37811. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  37812. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  37813. root.pdfjsSharedGlobal);
  37814. }
  37815. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  37816. sharedGlobal) {
  37817. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  37818. var InvalidPDFException = sharedUtil.InvalidPDFException;
  37819. var MessageHandler = sharedUtil.MessageHandler;
  37820. var MissingPDFException = sharedUtil.MissingPDFException;
  37821. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  37822. var PasswordException = sharedUtil.PasswordException;
  37823. var PasswordResponses = sharedUtil.PasswordResponses;
  37824. var UnknownErrorException = sharedUtil.UnknownErrorException;
  37825. var XRefParseException = sharedUtil.XRefParseException;
  37826. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37827. var error = sharedUtil.error;
  37828. var info = sharedUtil.info;
  37829. var isInt = sharedUtil.isInt;
  37830. var warn = sharedUtil.warn;
  37831. var Ref = corePrimitives.Ref;
  37832. var LocalPdfManager = corePdfManager.LocalPdfManager;
  37833. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  37834. var globalScope = sharedGlobal.globalScope;
  37835. var PDFJS = sharedGlobal.PDFJS;
  37836. var WorkerTask = (function WorkerTaskClosure() {
  37837. function WorkerTask(name) {
  37838. this.name = name;
  37839. this.terminated = false;
  37840. this._capability = createPromiseCapability();
  37841. }
  37842. WorkerTask.prototype = {
  37843. get finished() {
  37844. return this._capability.promise;
  37845. },
  37846. finish: function () {
  37847. this._capability.resolve();
  37848. },
  37849. terminate: function () {
  37850. this.terminated = true;
  37851. },
  37852. ensureNotTerminated: function () {
  37853. if (this.terminated) {
  37854. throw new Error('Worker task was terminated');
  37855. }
  37856. }
  37857. };
  37858. return WorkerTask;
  37859. })();
  37860. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37861. setup: function wphSetup(handler, port) {
  37862. handler.on('test', function wphSetupTest(data) {
  37863. // check if Uint8Array can be sent to worker
  37864. if (!(data instanceof Uint8Array)) {
  37865. handler.send('test', 'main', false);
  37866. return;
  37867. }
  37868. // making sure postMessage transfers are working
  37869. var supportTransfers = data[0] === 255;
  37870. handler.postMessageTransfers = supportTransfers;
  37871. // check if the response property is supported by xhr
  37872. var xhr = new XMLHttpRequest();
  37873. var responseExists = 'response' in xhr;
  37874. // check if the property is actually implemented
  37875. try {
  37876. var dummy = xhr.responseType;
  37877. } catch (e) {
  37878. responseExists = false;
  37879. }
  37880. if (!responseExists) {
  37881. handler.send('test', false);
  37882. return;
  37883. }
  37884. handler.send('test', {
  37885. supportTypedArray: true,
  37886. supportTransfers: supportTransfers
  37887. });
  37888. });
  37889. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37890. return WorkerMessageHandler.createDocumentHandler(data, port);
  37891. });
  37892. },
  37893. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  37894. // This context is actually holds references on pdfManager and handler,
  37895. // until the latter is destroyed.
  37896. var pdfManager;
  37897. var terminated = false;
  37898. var cancelXHRs = null;
  37899. var WorkerTasks = [];
  37900. var docId = docParams.docId;
  37901. var workerHandlerName = docParams.docId + '_worker';
  37902. var handler = new MessageHandler(workerHandlerName, docId, port);
  37903. function ensureNotTerminated() {
  37904. if (terminated) {
  37905. throw new Error('Worker was terminated');
  37906. }
  37907. }
  37908. function startWorkerTask(task) {
  37909. WorkerTasks.push(task);
  37910. }
  37911. function finishWorkerTask(task) {
  37912. task.finish();
  37913. var i = WorkerTasks.indexOf(task);
  37914. WorkerTasks.splice(i, 1);
  37915. }
  37916. function loadDocument(recoveryMode) {
  37917. var loadDocumentCapability = createPromiseCapability();
  37918. var parseSuccess = function parseSuccess() {
  37919. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37920. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37921. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37922. Promise.all([numPagesPromise, fingerprintPromise,
  37923. encryptedPromise]).then(function onDocReady(results) {
  37924. var doc = {
  37925. numPages: results[0],
  37926. fingerprint: results[1],
  37927. encrypted: !!results[2],
  37928. };
  37929. loadDocumentCapability.resolve(doc);
  37930. },
  37931. parseFailure);
  37932. };
  37933. var parseFailure = function parseFailure(e) {
  37934. loadDocumentCapability.reject(e);
  37935. };
  37936. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37937. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37938. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37939. parseSuccess, parseFailure);
  37940. }, parseFailure);
  37941. }, parseFailure);
  37942. return loadDocumentCapability.promise;
  37943. }
  37944. function getPdfManager(data) {
  37945. var pdfManagerCapability = createPromiseCapability();
  37946. var pdfManager;
  37947. var source = data.source;
  37948. var disableRange = data.disableRange;
  37949. if (source.data) {
  37950. try {
  37951. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  37952. pdfManagerCapability.resolve(pdfManager);
  37953. } catch (ex) {
  37954. pdfManagerCapability.reject(ex);
  37955. }
  37956. return pdfManagerCapability.promise;
  37957. } else if (source.chunkedViewerLoading) {
  37958. try {
  37959. pdfManager = new NetworkPdfManager(docId, source, handler);
  37960. pdfManagerCapability.resolve(pdfManager);
  37961. } catch (ex) {
  37962. pdfManagerCapability.reject(ex);
  37963. }
  37964. return pdfManagerCapability.promise;
  37965. }
  37966. var networkManager = new NetworkManager(source.url, {
  37967. httpHeaders: source.httpHeaders,
  37968. withCredentials: source.withCredentials
  37969. });
  37970. var cachedChunks = [];
  37971. var fullRequestXhrId = networkManager.requestFull({
  37972. onHeadersReceived: function onHeadersReceived() {
  37973. if (disableRange) {
  37974. return;
  37975. }
  37976. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37977. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37978. return;
  37979. }
  37980. var contentEncoding =
  37981. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37982. if (contentEncoding !== 'identity') {
  37983. return;
  37984. }
  37985. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37986. length = parseInt(length, 10);
  37987. if (!isInt(length)) {
  37988. return;
  37989. }
  37990. source.length = length;
  37991. if (length <= 2 * source.rangeChunkSize) {
  37992. // The file size is smaller than the size of two chunks, so it does
  37993. // not make any sense to abort the request and retry with a range
  37994. // request.
  37995. return;
  37996. }
  37997. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37998. // We can continue fetching when progressive loading is enabled,
  37999. // and we don't need the autoFetch feature.
  38000. source.disableAutoFetch = true;
  38001. } else {
  38002. // NOTE: by cancelling the full request, and then issuing range
  38003. // requests, there will be an issue for sites where you can only
  38004. // request the pdf once. However, if this is the case, then the
  38005. // server should not be returning that it can support range
  38006. // requests.
  38007. networkManager.abortRequest(fullRequestXhrId);
  38008. }
  38009. try {
  38010. pdfManager = new NetworkPdfManager(docId, source, handler);
  38011. pdfManagerCapability.resolve(pdfManager);
  38012. } catch (ex) {
  38013. pdfManagerCapability.reject(ex);
  38014. }
  38015. cancelXHRs = null;
  38016. },
  38017. onProgressiveData: source.disableStream ? null :
  38018. function onProgressiveData(chunk) {
  38019. if (!pdfManager) {
  38020. cachedChunks.push(chunk);
  38021. return;
  38022. }
  38023. pdfManager.sendProgressiveData(chunk);
  38024. },
  38025. onDone: function onDone(args) {
  38026. if (pdfManager) {
  38027. return; // already processed
  38028. }
  38029. var pdfFile;
  38030. if (args === null) {
  38031. // TODO add some streaming manager, e.g. for unknown length files.
  38032. // The data was returned in the onProgressiveData, combining...
  38033. var pdfFileLength = 0, pos = 0;
  38034. cachedChunks.forEach(function (chunk) {
  38035. pdfFileLength += chunk.byteLength;
  38036. });
  38037. if (source.length && pdfFileLength !== source.length) {
  38038. warn('reported HTTP length is different from actual');
  38039. }
  38040. var pdfFileArray = new Uint8Array(pdfFileLength);
  38041. cachedChunks.forEach(function (chunk) {
  38042. pdfFileArray.set(new Uint8Array(chunk), pos);
  38043. pos += chunk.byteLength;
  38044. });
  38045. pdfFile = pdfFileArray.buffer;
  38046. } else {
  38047. pdfFile = args.chunk;
  38048. }
  38049. // the data is array, instantiating directly from it
  38050. try {
  38051. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  38052. pdfManagerCapability.resolve(pdfManager);
  38053. } catch (ex) {
  38054. pdfManagerCapability.reject(ex);
  38055. }
  38056. cancelXHRs = null;
  38057. },
  38058. onError: function onError(status) {
  38059. var exception;
  38060. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38061. exception = new MissingPDFException('Missing PDF "' +
  38062. source.url + '".');
  38063. handler.send('MissingPDF', exception);
  38064. } else {
  38065. exception = new UnexpectedResponseException(
  38066. 'Unexpected server response (' + status +
  38067. ') while retrieving PDF "' + source.url + '".', status);
  38068. handler.send('UnexpectedResponse', exception);
  38069. }
  38070. cancelXHRs = null;
  38071. },
  38072. onProgress: function onProgress(evt) {
  38073. handler.send('DocProgress', {
  38074. loaded: evt.loaded,
  38075. total: evt.lengthComputable ? evt.total : source.length
  38076. });
  38077. }
  38078. });
  38079. cancelXHRs = function () {
  38080. networkManager.abortRequest(fullRequestXhrId);
  38081. };
  38082. return pdfManagerCapability.promise;
  38083. }
  38084. var setupDoc = function(data) {
  38085. var onSuccess = function(doc) {
  38086. ensureNotTerminated();
  38087. handler.send('GetDoc', { pdfInfo: doc });
  38088. };
  38089. var onFailure = function(e) {
  38090. if (e instanceof PasswordException) {
  38091. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38092. handler.send('NeedPassword', e);
  38093. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38094. handler.send('IncorrectPassword', e);
  38095. }
  38096. } else if (e instanceof InvalidPDFException) {
  38097. handler.send('InvalidPDF', e);
  38098. } else if (e instanceof MissingPDFException) {
  38099. handler.send('MissingPDF', e);
  38100. } else if (e instanceof UnexpectedResponseException) {
  38101. handler.send('UnexpectedResponse', e);
  38102. } else {
  38103. handler.send('UnknownError',
  38104. new UnknownErrorException(e.message, e.toString()));
  38105. }
  38106. };
  38107. ensureNotTerminated();
  38108. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38109. -1 : data.maxImageSize;
  38110. PDFJS.disableFontFace = data.disableFontFace;
  38111. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38112. PDFJS.verbosity = data.verbosity;
  38113. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38114. null : data.cMapUrl;
  38115. PDFJS.cMapPacked = data.cMapPacked === true;
  38116. getPdfManager(data).then(function (newPdfManager) {
  38117. if (terminated) {
  38118. // We were in a process of setting up the manager, but it got
  38119. // terminated in the middle.
  38120. newPdfManager.terminate();
  38121. throw new Error('Worker was terminated');
  38122. }
  38123. pdfManager = newPdfManager;
  38124. handler.send('PDFManagerReady', null);
  38125. pdfManager.onLoadedStream().then(function(stream) {
  38126. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38127. });
  38128. }).then(function pdfManagerReady() {
  38129. ensureNotTerminated();
  38130. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38131. ensureNotTerminated();
  38132. // Try again with recoveryMode == true
  38133. if (!(ex instanceof XRefParseException)) {
  38134. if (ex instanceof PasswordException) {
  38135. // after password exception prepare to receive a new password
  38136. // to repeat loading
  38137. pdfManager.passwordChanged().then(pdfManagerReady);
  38138. }
  38139. onFailure(ex);
  38140. return;
  38141. }
  38142. pdfManager.requestLoadedStream();
  38143. pdfManager.onLoadedStream().then(function() {
  38144. ensureNotTerminated();
  38145. loadDocument(true).then(onSuccess, onFailure);
  38146. });
  38147. }, onFailure);
  38148. }, onFailure);
  38149. };
  38150. handler.on('GetPage', function wphSetupGetPage(data) {
  38151. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38152. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38153. var refPromise = pdfManager.ensure(page, 'ref');
  38154. var viewPromise = pdfManager.ensure(page, 'view');
  38155. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38156. function(results) {
  38157. return {
  38158. rotate: results[0],
  38159. ref: results[1],
  38160. view: results[2]
  38161. };
  38162. });
  38163. });
  38164. });
  38165. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38166. var ref = new Ref(data.ref.num, data.ref.gen);
  38167. var catalog = pdfManager.pdfDocument.catalog;
  38168. return catalog.getPageIndex(ref);
  38169. });
  38170. handler.on('GetDestinations',
  38171. function wphSetupGetDestinations(data) {
  38172. return pdfManager.ensureCatalog('destinations');
  38173. }
  38174. );
  38175. handler.on('GetDestination',
  38176. function wphSetupGetDestination(data) {
  38177. return pdfManager.ensureCatalog('getDestination', [data.id]);
  38178. }
  38179. );
  38180. handler.on('GetAttachments',
  38181. function wphSetupGetAttachments(data) {
  38182. return pdfManager.ensureCatalog('attachments');
  38183. }
  38184. );
  38185. handler.on('GetJavaScript',
  38186. function wphSetupGetJavaScript(data) {
  38187. return pdfManager.ensureCatalog('javaScript');
  38188. }
  38189. );
  38190. handler.on('GetOutline',
  38191. function wphSetupGetOutline(data) {
  38192. return pdfManager.ensureCatalog('documentOutline');
  38193. }
  38194. );
  38195. handler.on('GetMetadata',
  38196. function wphSetupGetMetadata(data) {
  38197. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38198. pdfManager.ensureCatalog('metadata')]);
  38199. }
  38200. );
  38201. handler.on('GetData', function wphSetupGetData(data) {
  38202. pdfManager.requestLoadedStream();
  38203. return pdfManager.onLoadedStream().then(function(stream) {
  38204. return stream.bytes;
  38205. });
  38206. });
  38207. handler.on('GetStats',
  38208. function wphSetupGetStats(data) {
  38209. return pdfManager.pdfDocument.xref.stats;
  38210. }
  38211. );
  38212. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38213. pdfManager.updatePassword(data);
  38214. });
  38215. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38216. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38217. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  38218. });
  38219. });
  38220. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38221. var pageIndex = data.pageIndex;
  38222. pdfManager.getPage(pageIndex).then(function(page) {
  38223. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  38224. startWorkerTask(task);
  38225. var pageNum = pageIndex + 1;
  38226. var start = Date.now();
  38227. // Pre compile the pdf page and fetch the fonts/images.
  38228. page.getOperatorList(handler, task, data.intent).then(
  38229. function(operatorList) {
  38230. finishWorkerTask(task);
  38231. info('page=' + pageNum + ' - getOperatorList: time=' +
  38232. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  38233. }, function(e) {
  38234. finishWorkerTask(task);
  38235. if (task.terminated) {
  38236. return; // ignoring errors from the terminated thread
  38237. }
  38238. // For compatibility with older behavior, generating unknown
  38239. // unsupported feature notification on errors.
  38240. handler.send('UnsupportedFeature',
  38241. {featureId: UNSUPPORTED_FEATURES.unknown});
  38242. var minimumStackMessage =
  38243. 'worker.js: while trying to getPage() and getOperatorList()';
  38244. var wrappedException;
  38245. // Turn the error into an obj that can be serialized
  38246. if (typeof e === 'string') {
  38247. wrappedException = {
  38248. message: e,
  38249. stack: minimumStackMessage
  38250. };
  38251. } else if (typeof e === 'object') {
  38252. wrappedException = {
  38253. message: e.message || e.toString(),
  38254. stack: e.stack || minimumStackMessage
  38255. };
  38256. } else {
  38257. wrappedException = {
  38258. message: 'Unknown exception type: ' + (typeof e),
  38259. stack: minimumStackMessage
  38260. };
  38261. }
  38262. handler.send('PageError', {
  38263. pageNum: pageNum,
  38264. error: wrappedException,
  38265. intent: data.intent
  38266. });
  38267. });
  38268. });
  38269. }, this);
  38270. handler.on('GetTextContent', function wphExtractText(data) {
  38271. var pageIndex = data.pageIndex;
  38272. var normalizeWhitespace = data.normalizeWhitespace;
  38273. return pdfManager.getPage(pageIndex).then(function(page) {
  38274. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  38275. startWorkerTask(task);
  38276. var pageNum = pageIndex + 1;
  38277. var start = Date.now();
  38278. return page.extractTextContent(task, normalizeWhitespace).then(
  38279. function(textContent) {
  38280. finishWorkerTask(task);
  38281. info('text indexing: page=' + pageNum + ' - time=' +
  38282. (Date.now() - start) + 'ms');
  38283. return textContent;
  38284. }, function (reason) {
  38285. finishWorkerTask(task);
  38286. if (task.terminated) {
  38287. return; // ignoring errors from the terminated thread
  38288. }
  38289. throw reason;
  38290. });
  38291. });
  38292. });
  38293. handler.on('Cleanup', function wphCleanup(data) {
  38294. return pdfManager.cleanup();
  38295. });
  38296. handler.on('Terminate', function wphTerminate(data) {
  38297. terminated = true;
  38298. if (pdfManager) {
  38299. pdfManager.terminate();
  38300. pdfManager = null;
  38301. }
  38302. if (cancelXHRs) {
  38303. cancelXHRs();
  38304. }
  38305. var waitOn = [];
  38306. WorkerTasks.forEach(function (task) {
  38307. waitOn.push(task.finished);
  38308. task.terminate();
  38309. });
  38310. return Promise.all(waitOn).then(function () {
  38311. // Notice that even if we destroying handler, resolved response promise
  38312. // must be sent back.
  38313. handler.destroy();
  38314. handler = null;
  38315. });
  38316. });
  38317. handler.on('Ready', function wphReady(data) {
  38318. setupDoc(docParams);
  38319. docParams = null; // we don't need docParams anymore -- saving memory.
  38320. });
  38321. return workerHandlerName;
  38322. }
  38323. };
  38324. var consoleTimer = {};
  38325. var workerConsole = {
  38326. log: function log() {
  38327. var args = Array.prototype.slice.call(arguments);
  38328. globalScope.postMessage({
  38329. targetName: 'main',
  38330. action: 'console_log',
  38331. data: args
  38332. });
  38333. },
  38334. error: function error() {
  38335. var args = Array.prototype.slice.call(arguments);
  38336. globalScope.postMessage({
  38337. targetName: 'main',
  38338. action: 'console_error',
  38339. data: args
  38340. });
  38341. throw 'pdf.js execution error';
  38342. },
  38343. time: function time(name) {
  38344. consoleTimer[name] = Date.now();
  38345. },
  38346. timeEnd: function timeEnd(name) {
  38347. var time = consoleTimer[name];
  38348. if (!time) {
  38349. error('Unknown timer name ' + name);
  38350. }
  38351. this.log('Timer:', name, Date.now() - time);
  38352. }
  38353. };
  38354. // Worker thread?
  38355. if (typeof window === 'undefined' &&
  38356. !(typeof module !== 'undefined' && module.require)) {
  38357. if (!('console' in globalScope)) {
  38358. globalScope.console = workerConsole;
  38359. }
  38360. var handler = new MessageHandler('worker', 'main', self);
  38361. WorkerMessageHandler.setup(handler, self);
  38362. }
  38363. exports.WorkerTask = WorkerTask;
  38364. exports.WorkerMessageHandler = WorkerMessageHandler;
  38365. }));
  38366. }).call((typeof window === 'undefined') ? this : window);
  38367. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  38368. // workerSrc is not set -- using last script url to define default location
  38369. PDFJS.workerSrc = (function () {
  38370. 'use strict';
  38371. var pdfJsSrc = document.currentScript.src;
  38372. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  38373. })();
  38374. }