pdf.worker.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.3.116';
  22. PDFJS.build = 'cfc0cc8';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. (function (root, factory) {
  27. {
  28. factory((root.pdfjsSharedGlobal = {}));
  29. }
  30. }(this, function (exports) {
  31. var globalScope = (typeof window !== 'undefined') ? window :
  32. (typeof global !== 'undefined') ? global :
  33. (typeof self !== 'undefined') ? self : this;
  34. var isWorker = (typeof window === 'undefined');
  35. // The global PDFJS object exposes the API
  36. // In production, it will be declared outside a global wrapper
  37. // In development, it will be declared here
  38. if (!globalScope.PDFJS) {
  39. globalScope.PDFJS = {};
  40. }
  41. globalScope.PDFJS.pdfBug = false;
  42. exports.globalScope = globalScope;
  43. exports.isWorker = isWorker;
  44. exports.PDFJS = globalScope.PDFJS;
  45. }));
  46. (function (root, factory) {
  47. {
  48. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  49. }
  50. }(this, function (exports, sharedGlobal) {
  51. var PDFJS = sharedGlobal.PDFJS;
  52. var globalScope = sharedGlobal.globalScope;
  53. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  54. var TextRenderingMode = {
  55. FILL: 0,
  56. STROKE: 1,
  57. FILL_STROKE: 2,
  58. INVISIBLE: 3,
  59. FILL_ADD_TO_PATH: 4,
  60. STROKE_ADD_TO_PATH: 5,
  61. FILL_STROKE_ADD_TO_PATH: 6,
  62. ADD_TO_PATH: 7,
  63. FILL_STROKE_MASK: 3,
  64. ADD_TO_PATH_FLAG: 4
  65. };
  66. var ImageKind = {
  67. GRAYSCALE_1BPP: 1,
  68. RGB_24BPP: 2,
  69. RGBA_32BPP: 3
  70. };
  71. var AnnotationType = {
  72. TEXT: 1,
  73. LINK: 2,
  74. FREETEXT: 3,
  75. LINE: 4,
  76. SQUARE: 5,
  77. CIRCLE: 6,
  78. POLYGON: 7,
  79. POLYLINE: 8,
  80. HIGHLIGHT: 9,
  81. UNDERLINE: 10,
  82. SQUIGGLY: 11,
  83. STRIKEOUT: 12,
  84. STAMP: 13,
  85. CARET: 14,
  86. INK: 15,
  87. POPUP: 16,
  88. FILEATTACHMENT: 17,
  89. SOUND: 18,
  90. MOVIE: 19,
  91. WIDGET: 20,
  92. SCREEN: 21,
  93. PRINTERMARK: 22,
  94. TRAPNET: 23,
  95. WATERMARK: 24,
  96. THREED: 25,
  97. REDACT: 26
  98. };
  99. var AnnotationFlag = {
  100. INVISIBLE: 0x01,
  101. HIDDEN: 0x02,
  102. PRINT: 0x04,
  103. NOZOOM: 0x08,
  104. NOROTATE: 0x10,
  105. NOVIEW: 0x20,
  106. READONLY: 0x40,
  107. LOCKED: 0x80,
  108. TOGGLENOVIEW: 0x100,
  109. LOCKEDCONTENTS: 0x200
  110. };
  111. var AnnotationBorderStyleType = {
  112. SOLID: 1,
  113. DASHED: 2,
  114. BEVELED: 3,
  115. INSET: 4,
  116. UNDERLINE: 5
  117. };
  118. var StreamType = {
  119. UNKNOWN: 0,
  120. FLATE: 1,
  121. LZW: 2,
  122. DCT: 3,
  123. JPX: 4,
  124. JBIG: 5,
  125. A85: 6,
  126. AHX: 7,
  127. CCF: 8,
  128. RL: 9
  129. };
  130. var FontType = {
  131. UNKNOWN: 0,
  132. TYPE1: 1,
  133. TYPE1C: 2,
  134. CIDFONTTYPE0: 3,
  135. CIDFONTTYPE0C: 4,
  136. TRUETYPE: 5,
  137. CIDFONTTYPE2: 6,
  138. TYPE3: 7,
  139. OPENTYPE: 8,
  140. TYPE0: 9,
  141. MMTYPE1: 10
  142. };
  143. PDFJS.VERBOSITY_LEVELS = {
  144. errors: 0,
  145. warnings: 1,
  146. infos: 5
  147. };
  148. // All the possible operations for an operator list.
  149. var OPS = PDFJS.OPS = {
  150. // Intentionally start from 1 so it is easy to spot bad operators that will be
  151. // 0's.
  152. dependency: 1,
  153. setLineWidth: 2,
  154. setLineCap: 3,
  155. setLineJoin: 4,
  156. setMiterLimit: 5,
  157. setDash: 6,
  158. setRenderingIntent: 7,
  159. setFlatness: 8,
  160. setGState: 9,
  161. save: 10,
  162. restore: 11,
  163. transform: 12,
  164. moveTo: 13,
  165. lineTo: 14,
  166. curveTo: 15,
  167. curveTo2: 16,
  168. curveTo3: 17,
  169. closePath: 18,
  170. rectangle: 19,
  171. stroke: 20,
  172. closeStroke: 21,
  173. fill: 22,
  174. eoFill: 23,
  175. fillStroke: 24,
  176. eoFillStroke: 25,
  177. closeFillStroke: 26,
  178. closeEOFillStroke: 27,
  179. endPath: 28,
  180. clip: 29,
  181. eoClip: 30,
  182. beginText: 31,
  183. endText: 32,
  184. setCharSpacing: 33,
  185. setWordSpacing: 34,
  186. setHScale: 35,
  187. setLeading: 36,
  188. setFont: 37,
  189. setTextRenderingMode: 38,
  190. setTextRise: 39,
  191. moveText: 40,
  192. setLeadingMoveText: 41,
  193. setTextMatrix: 42,
  194. nextLine: 43,
  195. showText: 44,
  196. showSpacedText: 45,
  197. nextLineShowText: 46,
  198. nextLineSetSpacingShowText: 47,
  199. setCharWidth: 48,
  200. setCharWidthAndBounds: 49,
  201. setStrokeColorSpace: 50,
  202. setFillColorSpace: 51,
  203. setStrokeColor: 52,
  204. setStrokeColorN: 53,
  205. setFillColor: 54,
  206. setFillColorN: 55,
  207. setStrokeGray: 56,
  208. setFillGray: 57,
  209. setStrokeRGBColor: 58,
  210. setFillRGBColor: 59,
  211. setStrokeCMYKColor: 60,
  212. setFillCMYKColor: 61,
  213. shadingFill: 62,
  214. beginInlineImage: 63,
  215. beginImageData: 64,
  216. endInlineImage: 65,
  217. paintXObject: 66,
  218. markPoint: 67,
  219. markPointProps: 68,
  220. beginMarkedContent: 69,
  221. beginMarkedContentProps: 70,
  222. endMarkedContent: 71,
  223. beginCompat: 72,
  224. endCompat: 73,
  225. paintFormXObjectBegin: 74,
  226. paintFormXObjectEnd: 75,
  227. beginGroup: 76,
  228. endGroup: 77,
  229. beginAnnotations: 78,
  230. endAnnotations: 79,
  231. beginAnnotation: 80,
  232. endAnnotation: 81,
  233. paintJpegXObject: 82,
  234. paintImageMaskXObject: 83,
  235. paintImageMaskXObjectGroup: 84,
  236. paintImageXObject: 85,
  237. paintInlineImageXObject: 86,
  238. paintInlineImageXObjectGroup: 87,
  239. paintImageXObjectRepeat: 88,
  240. paintImageMaskXObjectRepeat: 89,
  241. paintSolidColorImageMask: 90,
  242. constructPath: 91
  243. };
  244. // A notice for devs. These are good for things that are helpful to devs, such
  245. // as warning that Workers were disabled, which is important to devs but not
  246. // end users.
  247. function info(msg) {
  248. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  249. console.log('Info: ' + msg);
  250. }
  251. }
  252. // Non-fatal warnings.
  253. function warn(msg) {
  254. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  255. console.log('Warning: ' + msg);
  256. }
  257. }
  258. // Deprecated API function -- treated as warnings.
  259. function deprecated(details) {
  260. warn('Deprecated API usage: ' + details);
  261. }
  262. // Fatal errors that should trigger the fallback UI and halt execution by
  263. // throwing an exception.
  264. function error(msg) {
  265. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  266. console.log('Error: ' + msg);
  267. console.log(backtrace());
  268. }
  269. throw new Error(msg);
  270. }
  271. function backtrace() {
  272. try {
  273. throw new Error();
  274. } catch (e) {
  275. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  276. }
  277. }
  278. function assert(cond, msg) {
  279. if (!cond) {
  280. error(msg);
  281. }
  282. }
  283. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  284. unknown: 'unknown',
  285. forms: 'forms',
  286. javaScript: 'javaScript',
  287. smask: 'smask',
  288. shadingPattern: 'shadingPattern',
  289. font: 'font'
  290. };
  291. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  292. // absolute URL, it will be returned as is.
  293. function combineUrl(baseUrl, url) {
  294. if (!url) {
  295. return baseUrl;
  296. }
  297. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  298. return url;
  299. }
  300. var i;
  301. if (url.charAt(0) === '/') {
  302. // absolute path
  303. i = baseUrl.indexOf('://');
  304. if (url.charAt(1) === '/') {
  305. ++i;
  306. } else {
  307. i = baseUrl.indexOf('/', i + 3);
  308. }
  309. return baseUrl.substring(0, i) + url;
  310. } else {
  311. // relative path
  312. var pathLength = baseUrl.length;
  313. i = baseUrl.lastIndexOf('#');
  314. pathLength = i >= 0 ? i : pathLength;
  315. i = baseUrl.lastIndexOf('?', pathLength);
  316. pathLength = i >= 0 ? i : pathLength;
  317. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  318. return baseUrl.substring(0, prefixLength + 1) + url;
  319. }
  320. }
  321. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  322. function isValidUrl(url, allowRelative) {
  323. if (!url) {
  324. return false;
  325. }
  326. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  327. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  328. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  329. if (!protocol) {
  330. return allowRelative;
  331. }
  332. protocol = protocol[0].toLowerCase();
  333. switch (protocol) {
  334. case 'http':
  335. case 'https':
  336. case 'ftp':
  337. case 'mailto':
  338. case 'tel':
  339. return true;
  340. default:
  341. return false;
  342. }
  343. }
  344. PDFJS.isValidUrl = isValidUrl;
  345. function shadow(obj, prop, value) {
  346. Object.defineProperty(obj, prop, { value: value,
  347. enumerable: true,
  348. configurable: true,
  349. writable: false });
  350. return value;
  351. }
  352. PDFJS.shadow = shadow;
  353. var LinkTarget = PDFJS.LinkTarget = {
  354. NONE: 0, // Default value.
  355. SELF: 1,
  356. BLANK: 2,
  357. PARENT: 3,
  358. TOP: 4,
  359. };
  360. var LinkTargetStringMap = [
  361. '',
  362. '_self',
  363. '_blank',
  364. '_parent',
  365. '_top'
  366. ];
  367. function isExternalLinkTargetSet() {
  368. if (PDFJS.openExternalLinksInNewWindow) {
  369. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  370. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  371. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  372. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  373. }
  374. // Reset the deprecated parameter, to suppress further warnings.
  375. PDFJS.openExternalLinksInNewWindow = false;
  376. }
  377. switch (PDFJS.externalLinkTarget) {
  378. case LinkTarget.NONE:
  379. return false;
  380. case LinkTarget.SELF:
  381. case LinkTarget.BLANK:
  382. case LinkTarget.PARENT:
  383. case LinkTarget.TOP:
  384. return true;
  385. }
  386. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  387. // Reset the external link target, to suppress further warnings.
  388. PDFJS.externalLinkTarget = LinkTarget.NONE;
  389. return false;
  390. }
  391. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  392. var PasswordResponses = PDFJS.PasswordResponses = {
  393. NEED_PASSWORD: 1,
  394. INCORRECT_PASSWORD: 2
  395. };
  396. var PasswordException = (function PasswordExceptionClosure() {
  397. function PasswordException(msg, code) {
  398. this.name = 'PasswordException';
  399. this.message = msg;
  400. this.code = code;
  401. }
  402. PasswordException.prototype = new Error();
  403. PasswordException.constructor = PasswordException;
  404. return PasswordException;
  405. })();
  406. PDFJS.PasswordException = PasswordException;
  407. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  408. function UnknownErrorException(msg, details) {
  409. this.name = 'UnknownErrorException';
  410. this.message = msg;
  411. this.details = details;
  412. }
  413. UnknownErrorException.prototype = new Error();
  414. UnknownErrorException.constructor = UnknownErrorException;
  415. return UnknownErrorException;
  416. })();
  417. PDFJS.UnknownErrorException = UnknownErrorException;
  418. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  419. function InvalidPDFException(msg) {
  420. this.name = 'InvalidPDFException';
  421. this.message = msg;
  422. }
  423. InvalidPDFException.prototype = new Error();
  424. InvalidPDFException.constructor = InvalidPDFException;
  425. return InvalidPDFException;
  426. })();
  427. PDFJS.InvalidPDFException = InvalidPDFException;
  428. var MissingPDFException = (function MissingPDFExceptionClosure() {
  429. function MissingPDFException(msg) {
  430. this.name = 'MissingPDFException';
  431. this.message = msg;
  432. }
  433. MissingPDFException.prototype = new Error();
  434. MissingPDFException.constructor = MissingPDFException;
  435. return MissingPDFException;
  436. })();
  437. PDFJS.MissingPDFException = MissingPDFException;
  438. var UnexpectedResponseException =
  439. (function UnexpectedResponseExceptionClosure() {
  440. function UnexpectedResponseException(msg, status) {
  441. this.name = 'UnexpectedResponseException';
  442. this.message = msg;
  443. this.status = status;
  444. }
  445. UnexpectedResponseException.prototype = new Error();
  446. UnexpectedResponseException.constructor = UnexpectedResponseException;
  447. return UnexpectedResponseException;
  448. })();
  449. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  450. var NotImplementedException = (function NotImplementedExceptionClosure() {
  451. function NotImplementedException(msg) {
  452. this.message = msg;
  453. }
  454. NotImplementedException.prototype = new Error();
  455. NotImplementedException.prototype.name = 'NotImplementedException';
  456. NotImplementedException.constructor = NotImplementedException;
  457. return NotImplementedException;
  458. })();
  459. var MissingDataException = (function MissingDataExceptionClosure() {
  460. function MissingDataException(begin, end) {
  461. this.begin = begin;
  462. this.end = end;
  463. this.message = 'Missing data [' + begin + ', ' + end + ')';
  464. }
  465. MissingDataException.prototype = new Error();
  466. MissingDataException.prototype.name = 'MissingDataException';
  467. MissingDataException.constructor = MissingDataException;
  468. return MissingDataException;
  469. })();
  470. var XRefParseException = (function XRefParseExceptionClosure() {
  471. function XRefParseException(msg) {
  472. this.message = msg;
  473. }
  474. XRefParseException.prototype = new Error();
  475. XRefParseException.prototype.name = 'XRefParseException';
  476. XRefParseException.constructor = XRefParseException;
  477. return XRefParseException;
  478. })();
  479. function bytesToString(bytes) {
  480. assert(bytes !== null && typeof bytes === 'object' &&
  481. bytes.length !== undefined, 'Invalid argument for bytesToString');
  482. var length = bytes.length;
  483. var MAX_ARGUMENT_COUNT = 8192;
  484. if (length < MAX_ARGUMENT_COUNT) {
  485. return String.fromCharCode.apply(null, bytes);
  486. }
  487. var strBuf = [];
  488. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  489. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  490. var chunk = bytes.subarray(i, chunkEnd);
  491. strBuf.push(String.fromCharCode.apply(null, chunk));
  492. }
  493. return strBuf.join('');
  494. }
  495. function stringToBytes(str) {
  496. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  497. var length = str.length;
  498. var bytes = new Uint8Array(length);
  499. for (var i = 0; i < length; ++i) {
  500. bytes[i] = str.charCodeAt(i) & 0xFF;
  501. }
  502. return bytes;
  503. }
  504. function string32(value) {
  505. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  506. (value >> 8) & 0xff, value & 0xff);
  507. }
  508. function log2(x) {
  509. var n = 1, i = 0;
  510. while (x > n) {
  511. n <<= 1;
  512. i++;
  513. }
  514. return i;
  515. }
  516. function readInt8(data, start) {
  517. return (data[start] << 24) >> 24;
  518. }
  519. function readUint16(data, offset) {
  520. return (data[offset] << 8) | data[offset + 1];
  521. }
  522. function readUint32(data, offset) {
  523. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  524. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  525. }
  526. // Lazy test the endianness of the platform
  527. // NOTE: This will be 'true' for simulated TypedArrays
  528. function isLittleEndian() {
  529. var buffer8 = new Uint8Array(2);
  530. buffer8[0] = 1;
  531. var buffer16 = new Uint16Array(buffer8.buffer);
  532. return (buffer16[0] === 1);
  533. }
  534. Object.defineProperty(PDFJS, 'isLittleEndian', {
  535. configurable: true,
  536. get: function PDFJS_isLittleEndian() {
  537. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  538. }
  539. });
  540. // Lazy test if the userAgent support CanvasTypedArrays
  541. function hasCanvasTypedArrays() {
  542. var canvas = document.createElement('canvas');
  543. canvas.width = canvas.height = 1;
  544. var ctx = canvas.getContext('2d');
  545. var imageData = ctx.createImageData(1, 1);
  546. return (typeof imageData.data.buffer !== 'undefined');
  547. }
  548. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  549. configurable: true,
  550. get: function PDFJS_hasCanvasTypedArrays() {
  551. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  552. }
  553. });
  554. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  555. function Uint32ArrayView(buffer, length) {
  556. this.buffer = buffer;
  557. this.byteLength = buffer.length;
  558. this.length = length === undefined ? (this.byteLength >> 2) : length;
  559. ensureUint32ArrayViewProps(this.length);
  560. }
  561. Uint32ArrayView.prototype = Object.create(null);
  562. var uint32ArrayViewSetters = 0;
  563. function createUint32ArrayProp(index) {
  564. return {
  565. get: function () {
  566. var buffer = this.buffer, offset = index << 2;
  567. return (buffer[offset] | (buffer[offset + 1] << 8) |
  568. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  569. },
  570. set: function (value) {
  571. var buffer = this.buffer, offset = index << 2;
  572. buffer[offset] = value & 255;
  573. buffer[offset + 1] = (value >> 8) & 255;
  574. buffer[offset + 2] = (value >> 16) & 255;
  575. buffer[offset + 3] = (value >>> 24) & 255;
  576. }
  577. };
  578. }
  579. function ensureUint32ArrayViewProps(length) {
  580. while (uint32ArrayViewSetters < length) {
  581. Object.defineProperty(Uint32ArrayView.prototype,
  582. uint32ArrayViewSetters,
  583. createUint32ArrayProp(uint32ArrayViewSetters));
  584. uint32ArrayViewSetters++;
  585. }
  586. }
  587. return Uint32ArrayView;
  588. })();
  589. exports.Uint32ArrayView = Uint32ArrayView;
  590. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  591. var Util = PDFJS.Util = (function UtilClosure() {
  592. function Util() {}
  593. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  594. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  595. // creating many intermediate strings.
  596. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  597. rgbBuf[1] = r;
  598. rgbBuf[3] = g;
  599. rgbBuf[5] = b;
  600. return rgbBuf.join('');
  601. };
  602. // Concatenates two transformation matrices together and returns the result.
  603. Util.transform = function Util_transform(m1, m2) {
  604. return [
  605. m1[0] * m2[0] + m1[2] * m2[1],
  606. m1[1] * m2[0] + m1[3] * m2[1],
  607. m1[0] * m2[2] + m1[2] * m2[3],
  608. m1[1] * m2[2] + m1[3] * m2[3],
  609. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  610. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  611. ];
  612. };
  613. // For 2d affine transforms
  614. Util.applyTransform = function Util_applyTransform(p, m) {
  615. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  616. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  617. return [xt, yt];
  618. };
  619. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  620. var d = m[0] * m[3] - m[1] * m[2];
  621. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  622. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  623. return [xt, yt];
  624. };
  625. // Applies the transform to the rectangle and finds the minimum axially
  626. // aligned bounding box.
  627. Util.getAxialAlignedBoundingBox =
  628. function Util_getAxialAlignedBoundingBox(r, m) {
  629. var p1 = Util.applyTransform(r, m);
  630. var p2 = Util.applyTransform(r.slice(2, 4), m);
  631. var p3 = Util.applyTransform([r[0], r[3]], m);
  632. var p4 = Util.applyTransform([r[2], r[1]], m);
  633. return [
  634. Math.min(p1[0], p2[0], p3[0], p4[0]),
  635. Math.min(p1[1], p2[1], p3[1], p4[1]),
  636. Math.max(p1[0], p2[0], p3[0], p4[0]),
  637. Math.max(p1[1], p2[1], p3[1], p4[1])
  638. ];
  639. };
  640. Util.inverseTransform = function Util_inverseTransform(m) {
  641. var d = m[0] * m[3] - m[1] * m[2];
  642. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  643. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  644. };
  645. // Apply a generic 3d matrix M on a 3-vector v:
  646. // | a b c | | X |
  647. // | d e f | x | Y |
  648. // | g h i | | Z |
  649. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  650. // with v as [X,Y,Z]
  651. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  652. return [
  653. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  654. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  655. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  656. ];
  657. };
  658. // This calculation uses Singular Value Decomposition.
  659. // The SVD can be represented with formula A = USV. We are interested in the
  660. // matrix S here because it represents the scale values.
  661. Util.singularValueDecompose2dScale =
  662. function Util_singularValueDecompose2dScale(m) {
  663. var transpose = [m[0], m[2], m[1], m[3]];
  664. // Multiply matrix m with its transpose.
  665. var a = m[0] * transpose[0] + m[1] * transpose[2];
  666. var b = m[0] * transpose[1] + m[1] * transpose[3];
  667. var c = m[2] * transpose[0] + m[3] * transpose[2];
  668. var d = m[2] * transpose[1] + m[3] * transpose[3];
  669. // Solve the second degree polynomial to get roots.
  670. var first = (a + d) / 2;
  671. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  672. var sx = first + second || 1;
  673. var sy = first - second || 1;
  674. // Scale values are the square roots of the eigenvalues.
  675. return [Math.sqrt(sx), Math.sqrt(sy)];
  676. };
  677. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  678. // For coordinate systems whose origin lies in the bottom-left, this
  679. // means normalization to (BL,TR) ordering. For systems with origin in the
  680. // top-left, this means (TL,BR) ordering.
  681. Util.normalizeRect = function Util_normalizeRect(rect) {
  682. var r = rect.slice(0); // clone rect
  683. if (rect[0] > rect[2]) {
  684. r[0] = rect[2];
  685. r[2] = rect[0];
  686. }
  687. if (rect[1] > rect[3]) {
  688. r[1] = rect[3];
  689. r[3] = rect[1];
  690. }
  691. return r;
  692. };
  693. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  694. // intersection of rect1 and rect2. If no intersection, returns 'false'
  695. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  696. Util.intersect = function Util_intersect(rect1, rect2) {
  697. function compare(a, b) {
  698. return a - b;
  699. }
  700. // Order points along the axes
  701. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  702. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  703. result = [];
  704. rect1 = Util.normalizeRect(rect1);
  705. rect2 = Util.normalizeRect(rect2);
  706. // X: first and second points belong to different rectangles?
  707. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  708. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  709. // Intersection must be between second and third points
  710. result[0] = orderedX[1];
  711. result[2] = orderedX[2];
  712. } else {
  713. return false;
  714. }
  715. // Y: first and second points belong to different rectangles?
  716. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  717. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  718. // Intersection must be between second and third points
  719. result[1] = orderedY[1];
  720. result[3] = orderedY[2];
  721. } else {
  722. return false;
  723. }
  724. return result;
  725. };
  726. Util.sign = function Util_sign(num) {
  727. return num < 0 ? -1 : 1;
  728. };
  729. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  730. Array.prototype.push.apply(arr1, arr2);
  731. };
  732. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  733. Array.prototype.unshift.apply(arr1, arr2);
  734. };
  735. Util.extendObj = function extendObj(obj1, obj2) {
  736. for (var key in obj2) {
  737. obj1[key] = obj2[key];
  738. }
  739. };
  740. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  741. name) {
  742. while (dict && !dict.has(name)) {
  743. dict = dict.get('Parent');
  744. }
  745. if (!dict) {
  746. return null;
  747. }
  748. return dict.get(name);
  749. };
  750. Util.inherit = function Util_inherit(sub, base, prototype) {
  751. sub.prototype = Object.create(base.prototype);
  752. sub.prototype.constructor = sub;
  753. for (var prop in prototype) {
  754. sub.prototype[prop] = prototype[prop];
  755. }
  756. };
  757. Util.loadScript = function Util_loadScript(src, callback) {
  758. var script = document.createElement('script');
  759. var loaded = false;
  760. script.setAttribute('src', src);
  761. if (callback) {
  762. script.onload = function() {
  763. if (!loaded) {
  764. callback();
  765. }
  766. loaded = true;
  767. };
  768. }
  769. document.getElementsByTagName('head')[0].appendChild(script);
  770. };
  771. return Util;
  772. })();
  773. /**
  774. * PDF page viewport created based on scale, rotation and offset.
  775. * @class
  776. * @alias PDFJS.PageViewport
  777. */
  778. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  779. /**
  780. * @constructor
  781. * @private
  782. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  783. * @param scale {number} scale of the viewport.
  784. * @param rotation {number} rotations of the viewport in degrees.
  785. * @param offsetX {number} offset X
  786. * @param offsetY {number} offset Y
  787. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  788. */
  789. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  790. this.viewBox = viewBox;
  791. this.scale = scale;
  792. this.rotation = rotation;
  793. this.offsetX = offsetX;
  794. this.offsetY = offsetY;
  795. // creating transform to convert pdf coordinate system to the normal
  796. // canvas like coordinates taking in account scale and rotation
  797. var centerX = (viewBox[2] + viewBox[0]) / 2;
  798. var centerY = (viewBox[3] + viewBox[1]) / 2;
  799. var rotateA, rotateB, rotateC, rotateD;
  800. rotation = rotation % 360;
  801. rotation = rotation < 0 ? rotation + 360 : rotation;
  802. switch (rotation) {
  803. case 180:
  804. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  805. break;
  806. case 90:
  807. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  808. break;
  809. case 270:
  810. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  811. break;
  812. //case 0:
  813. default:
  814. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  815. break;
  816. }
  817. if (dontFlip) {
  818. rotateC = -rotateC; rotateD = -rotateD;
  819. }
  820. var offsetCanvasX, offsetCanvasY;
  821. var width, height;
  822. if (rotateA === 0) {
  823. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  824. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  825. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  826. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  827. } else {
  828. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  829. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  830. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  831. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  832. }
  833. // creating transform for the following operations:
  834. // translate(-centerX, -centerY), rotate and flip vertically,
  835. // scale, and translate(offsetCanvasX, offsetCanvasY)
  836. this.transform = [
  837. rotateA * scale,
  838. rotateB * scale,
  839. rotateC * scale,
  840. rotateD * scale,
  841. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  842. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  843. ];
  844. this.width = width;
  845. this.height = height;
  846. this.fontScale = scale;
  847. }
  848. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  849. /**
  850. * Clones viewport with additional properties.
  851. * @param args {Object} (optional) If specified, may contain the 'scale' or
  852. * 'rotation' properties to override the corresponding properties in
  853. * the cloned viewport.
  854. * @returns {PDFJS.PageViewport} Cloned viewport.
  855. */
  856. clone: function PageViewPort_clone(args) {
  857. args = args || {};
  858. var scale = 'scale' in args ? args.scale : this.scale;
  859. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  860. return new PageViewport(this.viewBox.slice(), scale, rotation,
  861. this.offsetX, this.offsetY, args.dontFlip);
  862. },
  863. /**
  864. * Converts PDF point to the viewport coordinates. For examples, useful for
  865. * converting PDF location into canvas pixel coordinates.
  866. * @param x {number} X coordinate.
  867. * @param y {number} Y coordinate.
  868. * @returns {Object} Object that contains 'x' and 'y' properties of the
  869. * point in the viewport coordinate space.
  870. * @see {@link convertToPdfPoint}
  871. * @see {@link convertToViewportRectangle}
  872. */
  873. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  874. return Util.applyTransform([x, y], this.transform);
  875. },
  876. /**
  877. * Converts PDF rectangle to the viewport coordinates.
  878. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  879. * @returns {Array} Contains corresponding coordinates of the rectangle
  880. * in the viewport coordinate space.
  881. * @see {@link convertToViewportPoint}
  882. */
  883. convertToViewportRectangle:
  884. function PageViewport_convertToViewportRectangle(rect) {
  885. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  886. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  887. return [tl[0], tl[1], br[0], br[1]];
  888. },
  889. /**
  890. * Converts viewport coordinates to the PDF location. For examples, useful
  891. * for converting canvas pixel location into PDF one.
  892. * @param x {number} X coordinate.
  893. * @param y {number} Y coordinate.
  894. * @returns {Object} Object that contains 'x' and 'y' properties of the
  895. * point in the PDF coordinate space.
  896. * @see {@link convertToViewportPoint}
  897. */
  898. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  899. return Util.applyInverseTransform([x, y], this.transform);
  900. }
  901. };
  902. return PageViewport;
  903. })();
  904. var PDFStringTranslateTable = [
  905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  906. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  907. 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,
  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, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  911. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  912. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  913. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  914. ];
  915. function stringToPDFString(str) {
  916. var i, n = str.length, strBuf = [];
  917. if (str[0] === '\xFE' && str[1] === '\xFF') {
  918. // UTF16BE BOM
  919. for (i = 2; i < n; i += 2) {
  920. strBuf.push(String.fromCharCode(
  921. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  922. }
  923. } else {
  924. for (i = 0; i < n; ++i) {
  925. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  926. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  927. }
  928. }
  929. return strBuf.join('');
  930. }
  931. function stringToUTF8String(str) {
  932. return decodeURIComponent(escape(str));
  933. }
  934. function utf8StringToString(str) {
  935. return unescape(encodeURIComponent(str));
  936. }
  937. function isEmptyObj(obj) {
  938. for (var key in obj) {
  939. return false;
  940. }
  941. return true;
  942. }
  943. function isBool(v) {
  944. return typeof v === 'boolean';
  945. }
  946. function isInt(v) {
  947. return typeof v === 'number' && ((v | 0) === v);
  948. }
  949. function isNum(v) {
  950. return typeof v === 'number';
  951. }
  952. function isString(v) {
  953. return typeof v === 'string';
  954. }
  955. function isArray(v) {
  956. return v instanceof Array;
  957. }
  958. function isArrayBuffer(v) {
  959. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  960. }
  961. /**
  962. * Promise Capability object.
  963. *
  964. * @typedef {Object} PromiseCapability
  965. * @property {Promise} promise - A promise object.
  966. * @property {function} resolve - Fullfills the promise.
  967. * @property {function} reject - Rejects the promise.
  968. */
  969. /**
  970. * Creates a promise capability object.
  971. * @alias PDFJS.createPromiseCapability
  972. *
  973. * @return {PromiseCapability} A capability object contains:
  974. * - a Promise, resolve and reject methods.
  975. */
  976. function createPromiseCapability() {
  977. var capability = {};
  978. capability.promise = new Promise(function (resolve, reject) {
  979. capability.resolve = resolve;
  980. capability.reject = reject;
  981. });
  982. return capability;
  983. }
  984. PDFJS.createPromiseCapability = createPromiseCapability;
  985. /**
  986. * Polyfill for Promises:
  987. * The following promise implementation tries to generally implement the
  988. * Promise/A+ spec. Some notable differences from other promise libaries are:
  989. * - There currently isn't a seperate deferred and promise object.
  990. * - Unhandled rejections eventually show an error if they aren't handled.
  991. *
  992. * Based off of the work in:
  993. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  994. */
  995. (function PromiseClosure() {
  996. if (globalScope.Promise) {
  997. // Promises existing in the DOM/Worker, checking presence of all/resolve
  998. if (typeof globalScope.Promise.all !== 'function') {
  999. globalScope.Promise.all = function (iterable) {
  1000. var count = 0, results = [], resolve, reject;
  1001. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1002. resolve = resolve_;
  1003. reject = reject_;
  1004. });
  1005. iterable.forEach(function (p, i) {
  1006. count++;
  1007. p.then(function (result) {
  1008. results[i] = result;
  1009. count--;
  1010. if (count === 0) {
  1011. resolve(results);
  1012. }
  1013. }, reject);
  1014. });
  1015. if (count === 0) {
  1016. resolve(results);
  1017. }
  1018. return promise;
  1019. };
  1020. }
  1021. if (typeof globalScope.Promise.resolve !== 'function') {
  1022. globalScope.Promise.resolve = function (value) {
  1023. return new globalScope.Promise(function (resolve) { resolve(value); });
  1024. };
  1025. }
  1026. if (typeof globalScope.Promise.reject !== 'function') {
  1027. globalScope.Promise.reject = function (reason) {
  1028. return new globalScope.Promise(function (resolve, reject) {
  1029. reject(reason);
  1030. });
  1031. };
  1032. }
  1033. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1034. globalScope.Promise.prototype.catch = function (onReject) {
  1035. return globalScope.Promise.prototype.then(undefined, onReject);
  1036. };
  1037. }
  1038. return;
  1039. }
  1040. var STATUS_PENDING = 0;
  1041. var STATUS_RESOLVED = 1;
  1042. var STATUS_REJECTED = 2;
  1043. // In an attempt to avoid silent exceptions, unhandled rejections are
  1044. // tracked and if they aren't handled in a certain amount of time an
  1045. // error is logged.
  1046. var REJECTION_TIMEOUT = 500;
  1047. var HandlerManager = {
  1048. handlers: [],
  1049. running: false,
  1050. unhandledRejections: [],
  1051. pendingRejectionCheck: false,
  1052. scheduleHandlers: function scheduleHandlers(promise) {
  1053. if (promise._status === STATUS_PENDING) {
  1054. return;
  1055. }
  1056. this.handlers = this.handlers.concat(promise._handlers);
  1057. promise._handlers = [];
  1058. if (this.running) {
  1059. return;
  1060. }
  1061. this.running = true;
  1062. setTimeout(this.runHandlers.bind(this), 0);
  1063. },
  1064. runHandlers: function runHandlers() {
  1065. var RUN_TIMEOUT = 1; // ms
  1066. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1067. while (this.handlers.length > 0) {
  1068. var handler = this.handlers.shift();
  1069. var nextStatus = handler.thisPromise._status;
  1070. var nextValue = handler.thisPromise._value;
  1071. try {
  1072. if (nextStatus === STATUS_RESOLVED) {
  1073. if (typeof handler.onResolve === 'function') {
  1074. nextValue = handler.onResolve(nextValue);
  1075. }
  1076. } else if (typeof handler.onReject === 'function') {
  1077. nextValue = handler.onReject(nextValue);
  1078. nextStatus = STATUS_RESOLVED;
  1079. if (handler.thisPromise._unhandledRejection) {
  1080. this.removeUnhandeledRejection(handler.thisPromise);
  1081. }
  1082. }
  1083. } catch (ex) {
  1084. nextStatus = STATUS_REJECTED;
  1085. nextValue = ex;
  1086. }
  1087. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1088. if (Date.now() >= timeoutAt) {
  1089. break;
  1090. }
  1091. }
  1092. if (this.handlers.length > 0) {
  1093. setTimeout(this.runHandlers.bind(this), 0);
  1094. return;
  1095. }
  1096. this.running = false;
  1097. },
  1098. addUnhandledRejection: function addUnhandledRejection(promise) {
  1099. this.unhandledRejections.push({
  1100. promise: promise,
  1101. time: Date.now()
  1102. });
  1103. this.scheduleRejectionCheck();
  1104. },
  1105. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1106. promise._unhandledRejection = false;
  1107. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1108. if (this.unhandledRejections[i].promise === promise) {
  1109. this.unhandledRejections.splice(i);
  1110. i--;
  1111. }
  1112. }
  1113. },
  1114. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1115. if (this.pendingRejectionCheck) {
  1116. return;
  1117. }
  1118. this.pendingRejectionCheck = true;
  1119. setTimeout(function rejectionCheck() {
  1120. this.pendingRejectionCheck = false;
  1121. var now = Date.now();
  1122. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1123. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1124. var unhandled = this.unhandledRejections[i].promise._value;
  1125. var msg = 'Unhandled rejection: ' + unhandled;
  1126. if (unhandled.stack) {
  1127. msg += '\n' + unhandled.stack;
  1128. }
  1129. warn(msg);
  1130. this.unhandledRejections.splice(i);
  1131. i--;
  1132. }
  1133. }
  1134. if (this.unhandledRejections.length) {
  1135. this.scheduleRejectionCheck();
  1136. }
  1137. }.bind(this), REJECTION_TIMEOUT);
  1138. }
  1139. };
  1140. function Promise(resolver) {
  1141. this._status = STATUS_PENDING;
  1142. this._handlers = [];
  1143. try {
  1144. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1145. } catch (e) {
  1146. this._reject(e);
  1147. }
  1148. }
  1149. /**
  1150. * Builds a promise that is resolved when all the passed in promises are
  1151. * resolved.
  1152. * @param {array} array of data and/or promises to wait for.
  1153. * @return {Promise} New dependant promise.
  1154. */
  1155. Promise.all = function Promise_all(promises) {
  1156. var resolveAll, rejectAll;
  1157. var deferred = new Promise(function (resolve, reject) {
  1158. resolveAll = resolve;
  1159. rejectAll = reject;
  1160. });
  1161. var unresolved = promises.length;
  1162. var results = [];
  1163. if (unresolved === 0) {
  1164. resolveAll(results);
  1165. return deferred;
  1166. }
  1167. function reject(reason) {
  1168. if (deferred._status === STATUS_REJECTED) {
  1169. return;
  1170. }
  1171. results = [];
  1172. rejectAll(reason);
  1173. }
  1174. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1175. var promise = promises[i];
  1176. var resolve = (function(i) {
  1177. return function(value) {
  1178. if (deferred._status === STATUS_REJECTED) {
  1179. return;
  1180. }
  1181. results[i] = value;
  1182. unresolved--;
  1183. if (unresolved === 0) {
  1184. resolveAll(results);
  1185. }
  1186. };
  1187. })(i);
  1188. if (Promise.isPromise(promise)) {
  1189. promise.then(resolve, reject);
  1190. } else {
  1191. resolve(promise);
  1192. }
  1193. }
  1194. return deferred;
  1195. };
  1196. /**
  1197. * Checks if the value is likely a promise (has a 'then' function).
  1198. * @return {boolean} true if value is thenable
  1199. */
  1200. Promise.isPromise = function Promise_isPromise(value) {
  1201. return value && typeof value.then === 'function';
  1202. };
  1203. /**
  1204. * Creates resolved promise
  1205. * @param value resolve value
  1206. * @returns {Promise}
  1207. */
  1208. Promise.resolve = function Promise_resolve(value) {
  1209. return new Promise(function (resolve) { resolve(value); });
  1210. };
  1211. /**
  1212. * Creates rejected promise
  1213. * @param reason rejection value
  1214. * @returns {Promise}
  1215. */
  1216. Promise.reject = function Promise_reject(reason) {
  1217. return new Promise(function (resolve, reject) { reject(reason); });
  1218. };
  1219. Promise.prototype = {
  1220. _status: null,
  1221. _value: null,
  1222. _handlers: null,
  1223. _unhandledRejection: null,
  1224. _updateStatus: function Promise__updateStatus(status, value) {
  1225. if (this._status === STATUS_RESOLVED ||
  1226. this._status === STATUS_REJECTED) {
  1227. return;
  1228. }
  1229. if (status === STATUS_RESOLVED &&
  1230. Promise.isPromise(value)) {
  1231. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1232. this._updateStatus.bind(this, STATUS_REJECTED));
  1233. return;
  1234. }
  1235. this._status = status;
  1236. this._value = value;
  1237. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1238. this._unhandledRejection = true;
  1239. HandlerManager.addUnhandledRejection(this);
  1240. }
  1241. HandlerManager.scheduleHandlers(this);
  1242. },
  1243. _resolve: function Promise_resolve(value) {
  1244. this._updateStatus(STATUS_RESOLVED, value);
  1245. },
  1246. _reject: function Promise_reject(reason) {
  1247. this._updateStatus(STATUS_REJECTED, reason);
  1248. },
  1249. then: function Promise_then(onResolve, onReject) {
  1250. var nextPromise = new Promise(function (resolve, reject) {
  1251. this.resolve = resolve;
  1252. this.reject = reject;
  1253. });
  1254. this._handlers.push({
  1255. thisPromise: this,
  1256. onResolve: onResolve,
  1257. onReject: onReject,
  1258. nextPromise: nextPromise
  1259. });
  1260. HandlerManager.scheduleHandlers(this);
  1261. return nextPromise;
  1262. },
  1263. catch: function Promise_catch(onReject) {
  1264. return this.then(undefined, onReject);
  1265. }
  1266. };
  1267. globalScope.Promise = Promise;
  1268. })();
  1269. var StatTimer = (function StatTimerClosure() {
  1270. function rpad(str, pad, length) {
  1271. while (str.length < length) {
  1272. str += pad;
  1273. }
  1274. return str;
  1275. }
  1276. function StatTimer() {
  1277. this.started = {};
  1278. this.times = [];
  1279. this.enabled = true;
  1280. }
  1281. StatTimer.prototype = {
  1282. time: function StatTimer_time(name) {
  1283. if (!this.enabled) {
  1284. return;
  1285. }
  1286. if (name in this.started) {
  1287. warn('Timer is already running for ' + name);
  1288. }
  1289. this.started[name] = Date.now();
  1290. },
  1291. timeEnd: function StatTimer_timeEnd(name) {
  1292. if (!this.enabled) {
  1293. return;
  1294. }
  1295. if (!(name in this.started)) {
  1296. warn('Timer has not been started for ' + name);
  1297. }
  1298. this.times.push({
  1299. 'name': name,
  1300. 'start': this.started[name],
  1301. 'end': Date.now()
  1302. });
  1303. // Remove timer from started so it can be called again.
  1304. delete this.started[name];
  1305. },
  1306. toString: function StatTimer_toString() {
  1307. var i, ii;
  1308. var times = this.times;
  1309. var out = '';
  1310. // Find the longest name for padding purposes.
  1311. var longest = 0;
  1312. for (i = 0, ii = times.length; i < ii; ++i) {
  1313. var name = times[i]['name'];
  1314. if (name.length > longest) {
  1315. longest = name.length;
  1316. }
  1317. }
  1318. for (i = 0, ii = times.length; i < ii; ++i) {
  1319. var span = times[i];
  1320. var duration = span.end - span.start;
  1321. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1322. }
  1323. return out;
  1324. }
  1325. };
  1326. return StatTimer;
  1327. })();
  1328. PDFJS.createBlob = function createBlob(data, contentType) {
  1329. if (typeof Blob !== 'undefined') {
  1330. return new Blob([data], { type: contentType });
  1331. }
  1332. // Blob builder is deprecated in FF14 and removed in FF18.
  1333. var bb = new MozBlobBuilder();
  1334. bb.append(data);
  1335. return bb.getBlob(contentType);
  1336. };
  1337. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1338. // Blob/createObjectURL is not available, falling back to data schema.
  1339. var digits =
  1340. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1341. return function createObjectURL(data, contentType) {
  1342. if (!PDFJS.disableCreateObjectURL &&
  1343. typeof URL !== 'undefined' && URL.createObjectURL) {
  1344. var blob = PDFJS.createBlob(data, contentType);
  1345. return URL.createObjectURL(blob);
  1346. }
  1347. var buffer = 'data:' + contentType + ';base64,';
  1348. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1349. var b1 = data[i] & 0xFF;
  1350. var b2 = data[i + 1] & 0xFF;
  1351. var b3 = data[i + 2] & 0xFF;
  1352. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1353. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1354. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1355. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1356. }
  1357. return buffer;
  1358. };
  1359. })();
  1360. function MessageHandler(sourceName, targetName, comObj) {
  1361. this.sourceName = sourceName;
  1362. this.targetName = targetName;
  1363. this.comObj = comObj;
  1364. this.callbackIndex = 1;
  1365. this.postMessageTransfers = true;
  1366. var callbacksCapabilities = this.callbacksCapabilities = {};
  1367. var ah = this.actionHandler = {};
  1368. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1369. var data = event.data;
  1370. if (data.targetName !== this.sourceName) {
  1371. return;
  1372. }
  1373. if (data.isReply) {
  1374. var callbackId = data.callbackId;
  1375. if (data.callbackId in callbacksCapabilities) {
  1376. var callback = callbacksCapabilities[callbackId];
  1377. delete callbacksCapabilities[callbackId];
  1378. if ('error' in data) {
  1379. callback.reject(data.error);
  1380. } else {
  1381. callback.resolve(data.data);
  1382. }
  1383. } else {
  1384. error('Cannot resolve callback ' + callbackId);
  1385. }
  1386. } else if (data.action in ah) {
  1387. var action = ah[data.action];
  1388. if (data.callbackId) {
  1389. var sourceName = this.sourceName;
  1390. var targetName = data.sourceName;
  1391. Promise.resolve().then(function () {
  1392. return action[0].call(action[1], data.data);
  1393. }).then(function (result) {
  1394. comObj.postMessage({
  1395. sourceName: sourceName,
  1396. targetName: targetName,
  1397. isReply: true,
  1398. callbackId: data.callbackId,
  1399. data: result
  1400. });
  1401. }, function (reason) {
  1402. if (reason instanceof Error) {
  1403. // Serialize error to avoid "DataCloneError"
  1404. reason = reason + '';
  1405. }
  1406. comObj.postMessage({
  1407. sourceName: sourceName,
  1408. targetName: targetName,
  1409. isReply: true,
  1410. callbackId: data.callbackId,
  1411. error: reason
  1412. });
  1413. });
  1414. } else {
  1415. action[0].call(action[1], data.data);
  1416. }
  1417. } else {
  1418. error('Unknown action from worker: ' + data.action);
  1419. }
  1420. }.bind(this);
  1421. comObj.addEventListener('message', this._onComObjOnMessage);
  1422. }
  1423. MessageHandler.prototype = {
  1424. on: function messageHandlerOn(actionName, handler, scope) {
  1425. var ah = this.actionHandler;
  1426. if (ah[actionName]) {
  1427. error('There is already an actionName called "' + actionName + '"');
  1428. }
  1429. ah[actionName] = [handler, scope];
  1430. },
  1431. /**
  1432. * Sends a message to the comObj to invoke the action with the supplied data.
  1433. * @param {String} actionName Action to call.
  1434. * @param {JSON} data JSON data to send.
  1435. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1436. */
  1437. send: function messageHandlerSend(actionName, data, transfers) {
  1438. var message = {
  1439. sourceName: this.sourceName,
  1440. targetName: this.targetName,
  1441. action: actionName,
  1442. data: data
  1443. };
  1444. this.postMessage(message, transfers);
  1445. },
  1446. /**
  1447. * Sends a message to the comObj to invoke the action with the supplied data.
  1448. * Expects that other side will callback with the response.
  1449. * @param {String} actionName Action to call.
  1450. * @param {JSON} data JSON data to send.
  1451. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1452. * @returns {Promise} Promise to be resolved with response data.
  1453. */
  1454. sendWithPromise:
  1455. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1456. var callbackId = this.callbackIndex++;
  1457. var message = {
  1458. sourceName: this.sourceName,
  1459. targetName: this.targetName,
  1460. action: actionName,
  1461. data: data,
  1462. callbackId: callbackId
  1463. };
  1464. var capability = createPromiseCapability();
  1465. this.callbacksCapabilities[callbackId] = capability;
  1466. try {
  1467. this.postMessage(message, transfers);
  1468. } catch (e) {
  1469. capability.reject(e);
  1470. }
  1471. return capability.promise;
  1472. },
  1473. /**
  1474. * Sends raw message to the comObj.
  1475. * @private
  1476. * @param message {Object} Raw message.
  1477. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1478. */
  1479. postMessage: function (message, transfers) {
  1480. if (transfers && this.postMessageTransfers) {
  1481. this.comObj.postMessage(message, transfers);
  1482. } else {
  1483. this.comObj.postMessage(message);
  1484. }
  1485. },
  1486. destroy: function () {
  1487. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1488. }
  1489. };
  1490. function loadJpegStream(id, imageUrl, objs) {
  1491. var img = new Image();
  1492. img.onload = (function loadJpegStream_onloadClosure() {
  1493. objs.resolve(id, img);
  1494. });
  1495. img.onerror = (function loadJpegStream_onerrorClosure() {
  1496. objs.resolve(id, null);
  1497. warn('Error during JPEG image loading');
  1498. });
  1499. img.src = imageUrl;
  1500. }
  1501. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1502. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1503. exports.OPS = OPS;
  1504. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1505. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1506. exports.AnnotationFlag = AnnotationFlag;
  1507. exports.AnnotationType = AnnotationType;
  1508. exports.FontType = FontType;
  1509. exports.ImageKind = ImageKind;
  1510. exports.InvalidPDFException = InvalidPDFException;
  1511. exports.LinkTarget = LinkTarget;
  1512. exports.LinkTargetStringMap = LinkTargetStringMap;
  1513. exports.MessageHandler = MessageHandler;
  1514. exports.MissingDataException = MissingDataException;
  1515. exports.MissingPDFException = MissingPDFException;
  1516. exports.NotImplementedException = NotImplementedException;
  1517. exports.PasswordException = PasswordException;
  1518. exports.PasswordResponses = PasswordResponses;
  1519. exports.StatTimer = StatTimer;
  1520. exports.StreamType = StreamType;
  1521. exports.TextRenderingMode = TextRenderingMode;
  1522. exports.UnexpectedResponseException = UnexpectedResponseException;
  1523. exports.UnknownErrorException = UnknownErrorException;
  1524. exports.Util = Util;
  1525. exports.XRefParseException = XRefParseException;
  1526. exports.assert = assert;
  1527. exports.bytesToString = bytesToString;
  1528. exports.combineUrl = combineUrl;
  1529. exports.createPromiseCapability = createPromiseCapability;
  1530. exports.deprecated = deprecated;
  1531. exports.error = error;
  1532. exports.info = info;
  1533. exports.isArray = isArray;
  1534. exports.isArrayBuffer = isArrayBuffer;
  1535. exports.isBool = isBool;
  1536. exports.isEmptyObj = isEmptyObj;
  1537. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1538. exports.isInt = isInt;
  1539. exports.isNum = isNum;
  1540. exports.isString = isString;
  1541. exports.isValidUrl = isValidUrl;
  1542. exports.loadJpegStream = loadJpegStream;
  1543. exports.log2 = log2;
  1544. exports.readInt8 = readInt8;
  1545. exports.readUint16 = readUint16;
  1546. exports.readUint32 = readUint32;
  1547. exports.shadow = shadow;
  1548. exports.string32 = string32;
  1549. exports.stringToBytes = stringToBytes;
  1550. exports.stringToPDFString = stringToPDFString;
  1551. exports.stringToUTF8String = stringToUTF8String;
  1552. exports.utf8StringToString = utf8StringToString;
  1553. exports.warn = warn;
  1554. }));
  1555. var NetworkManager = (function NetworkManagerClosure() {
  1556. var OK_RESPONSE = 200;
  1557. var PARTIAL_CONTENT_RESPONSE = 206;
  1558. function NetworkManager(url, args) {
  1559. this.url = url;
  1560. args = args || {};
  1561. this.isHttp = /^https?:/i.test(url);
  1562. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1563. this.withCredentials = args.withCredentials || false;
  1564. this.getXhr = args.getXhr ||
  1565. function NetworkManager_getXhr() {
  1566. return new XMLHttpRequest();
  1567. };
  1568. this.currXhrId = 0;
  1569. this.pendingRequests = {};
  1570. this.loadedRequests = {};
  1571. }
  1572. function getArrayBuffer(xhr) {
  1573. var data = xhr.response;
  1574. if (typeof data !== 'string') {
  1575. return data;
  1576. }
  1577. var length = data.length;
  1578. var array = new Uint8Array(length);
  1579. for (var i = 0; i < length; i++) {
  1580. array[i] = data.charCodeAt(i) & 0xFF;
  1581. }
  1582. return array.buffer;
  1583. }
  1584. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1585. try {
  1586. var x = new XMLHttpRequest();
  1587. // Firefox 37- required .open() to be called before setting responseType.
  1588. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1589. // Even though the URL is not visited, .open() could fail if the URL is
  1590. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1591. // When this error occurs, this feature detection method will mistakenly
  1592. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1593. x.open('GET', 'https://example.com');
  1594. x.responseType = 'moz-chunked-arraybuffer';
  1595. return x.responseType === 'moz-chunked-arraybuffer';
  1596. } catch (e) {
  1597. return false;
  1598. }
  1599. })();
  1600. NetworkManager.prototype = {
  1601. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1602. var args = {
  1603. begin: begin,
  1604. end: end
  1605. };
  1606. for (var prop in listeners) {
  1607. args[prop] = listeners[prop];
  1608. }
  1609. return this.request(args);
  1610. },
  1611. requestFull: function NetworkManager_requestFull(listeners) {
  1612. return this.request(listeners);
  1613. },
  1614. request: function NetworkManager_request(args) {
  1615. var xhr = this.getXhr();
  1616. var xhrId = this.currXhrId++;
  1617. var pendingRequest = this.pendingRequests[xhrId] = {
  1618. xhr: xhr
  1619. };
  1620. xhr.open('GET', this.url);
  1621. xhr.withCredentials = this.withCredentials;
  1622. for (var property in this.httpHeaders) {
  1623. var value = this.httpHeaders[property];
  1624. if (typeof value === 'undefined') {
  1625. continue;
  1626. }
  1627. xhr.setRequestHeader(property, value);
  1628. }
  1629. if (this.isHttp && 'begin' in args && 'end' in args) {
  1630. var rangeStr = args.begin + '-' + (args.end - 1);
  1631. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1632. pendingRequest.expectedStatus = 206;
  1633. } else {
  1634. pendingRequest.expectedStatus = 200;
  1635. }
  1636. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1637. if (useMozChunkedLoading) {
  1638. xhr.responseType = 'moz-chunked-arraybuffer';
  1639. pendingRequest.onProgressiveData = args.onProgressiveData;
  1640. pendingRequest.mozChunked = true;
  1641. } else {
  1642. xhr.responseType = 'arraybuffer';
  1643. }
  1644. if (args.onError) {
  1645. xhr.onerror = function(evt) {
  1646. args.onError(xhr.status);
  1647. };
  1648. }
  1649. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1650. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1651. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1652. pendingRequest.onDone = args.onDone;
  1653. pendingRequest.onError = args.onError;
  1654. pendingRequest.onProgress = args.onProgress;
  1655. xhr.send(null);
  1656. return xhrId;
  1657. },
  1658. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1659. var pendingRequest = this.pendingRequests[xhrId];
  1660. if (!pendingRequest) {
  1661. // Maybe abortRequest was called...
  1662. return;
  1663. }
  1664. if (pendingRequest.mozChunked) {
  1665. var chunk = getArrayBuffer(pendingRequest.xhr);
  1666. pendingRequest.onProgressiveData(chunk);
  1667. }
  1668. var onProgress = pendingRequest.onProgress;
  1669. if (onProgress) {
  1670. onProgress(evt);
  1671. }
  1672. },
  1673. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1674. var pendingRequest = this.pendingRequests[xhrId];
  1675. if (!pendingRequest) {
  1676. // Maybe abortRequest was called...
  1677. return;
  1678. }
  1679. var xhr = pendingRequest.xhr;
  1680. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1681. pendingRequest.onHeadersReceived();
  1682. delete pendingRequest.onHeadersReceived;
  1683. }
  1684. if (xhr.readyState !== 4) {
  1685. return;
  1686. }
  1687. if (!(xhrId in this.pendingRequests)) {
  1688. // The XHR request might have been aborted in onHeadersReceived()
  1689. // callback, in which case we should abort request
  1690. return;
  1691. }
  1692. delete this.pendingRequests[xhrId];
  1693. // success status == 0 can be on ftp, file and other protocols
  1694. if (xhr.status === 0 && this.isHttp) {
  1695. if (pendingRequest.onError) {
  1696. pendingRequest.onError(xhr.status);
  1697. }
  1698. return;
  1699. }
  1700. var xhrStatus = xhr.status || OK_RESPONSE;
  1701. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1702. // "A server MAY ignore the Range header". This means it's possible to
  1703. // get a 200 rather than a 206 response from a range request.
  1704. var ok_response_on_range_request =
  1705. xhrStatus === OK_RESPONSE &&
  1706. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1707. if (!ok_response_on_range_request &&
  1708. xhrStatus !== pendingRequest.expectedStatus) {
  1709. if (pendingRequest.onError) {
  1710. pendingRequest.onError(xhr.status);
  1711. }
  1712. return;
  1713. }
  1714. this.loadedRequests[xhrId] = true;
  1715. var chunk = getArrayBuffer(xhr);
  1716. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1717. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1718. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1719. var begin = parseInt(matches[1], 10);
  1720. pendingRequest.onDone({
  1721. begin: begin,
  1722. chunk: chunk
  1723. });
  1724. } else if (pendingRequest.onProgressiveData) {
  1725. pendingRequest.onDone(null);
  1726. } else if (chunk) {
  1727. pendingRequest.onDone({
  1728. begin: 0,
  1729. chunk: chunk
  1730. });
  1731. } else if (pendingRequest.onError) {
  1732. pendingRequest.onError(xhr.status);
  1733. }
  1734. },
  1735. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1736. for (var xhrId in this.pendingRequests) {
  1737. return true;
  1738. }
  1739. return false;
  1740. },
  1741. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1742. return this.pendingRequests[xhrId].xhr;
  1743. },
  1744. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1745. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1746. },
  1747. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1748. return xhrId in this.pendingRequests;
  1749. },
  1750. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1751. return xhrId in this.loadedRequests;
  1752. },
  1753. abortAllRequests: function NetworkManager_abortAllRequests() {
  1754. for (var xhrId in this.pendingRequests) {
  1755. this.abortRequest(xhrId | 0);
  1756. }
  1757. },
  1758. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1759. var xhr = this.pendingRequests[xhrId].xhr;
  1760. delete this.pendingRequests[xhrId];
  1761. xhr.abort();
  1762. }
  1763. };
  1764. return NetworkManager;
  1765. })();
  1766. (function (root, factory) {
  1767. {
  1768. factory((root.pdfjsCoreArithmeticDecoder = {}));
  1769. }
  1770. }(this, function (exports) {
  1771. /* This class implements the QM Coder decoding as defined in
  1772. * JPEG 2000 Part I Final Committee Draft Version 1.0
  1773. * Annex C.3 Arithmetic decoding procedure
  1774. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  1775. *
  1776. * The arithmetic decoder is used in conjunction with context models to decode
  1777. * JPEG2000 and JBIG2 streams.
  1778. */
  1779. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  1780. // Table C-2
  1781. var QeTable = [
  1782. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  1783. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  1784. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  1785. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  1786. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  1787. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  1788. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  1789. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  1790. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  1791. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  1792. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  1793. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  1794. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  1795. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  1796. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  1797. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  1798. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  1799. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  1800. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  1801. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  1802. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  1803. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  1804. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  1805. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  1806. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  1807. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  1808. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  1809. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  1810. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  1811. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  1812. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  1813. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  1814. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  1815. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  1816. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  1817. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  1818. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  1819. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  1820. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  1821. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  1822. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  1823. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  1824. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  1825. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  1826. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  1827. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  1828. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  1829. ];
  1830. // C.3.5 Initialisation of the decoder (INITDEC)
  1831. function ArithmeticDecoder(data, start, end) {
  1832. this.data = data;
  1833. this.bp = start;
  1834. this.dataEnd = end;
  1835. this.chigh = data[start];
  1836. this.clow = 0;
  1837. this.byteIn();
  1838. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  1839. this.clow = (this.clow << 7) & 0xFFFF;
  1840. this.ct -= 7;
  1841. this.a = 0x8000;
  1842. }
  1843. ArithmeticDecoder.prototype = {
  1844. // C.3.4 Compressed data input (BYTEIN)
  1845. byteIn: function ArithmeticDecoder_byteIn() {
  1846. var data = this.data;
  1847. var bp = this.bp;
  1848. if (data[bp] === 0xFF) {
  1849. var b1 = data[bp + 1];
  1850. if (b1 > 0x8F) {
  1851. this.clow += 0xFF00;
  1852. this.ct = 8;
  1853. } else {
  1854. bp++;
  1855. this.clow += (data[bp] << 9);
  1856. this.ct = 7;
  1857. this.bp = bp;
  1858. }
  1859. } else {
  1860. bp++;
  1861. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  1862. this.ct = 8;
  1863. this.bp = bp;
  1864. }
  1865. if (this.clow > 0xFFFF) {
  1866. this.chigh += (this.clow >> 16);
  1867. this.clow &= 0xFFFF;
  1868. }
  1869. },
  1870. // C.3.2 Decoding a decision (DECODE)
  1871. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  1872. // contexts are packed into 1 byte:
  1873. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  1874. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  1875. var qeTableIcx = QeTable[cx_index];
  1876. var qeIcx = qeTableIcx.qe;
  1877. var d;
  1878. var a = this.a - qeIcx;
  1879. if (this.chigh < qeIcx) {
  1880. // exchangeLps
  1881. if (a < qeIcx) {
  1882. a = qeIcx;
  1883. d = cx_mps;
  1884. cx_index = qeTableIcx.nmps;
  1885. } else {
  1886. a = qeIcx;
  1887. d = 1 ^ cx_mps;
  1888. if (qeTableIcx.switchFlag === 1) {
  1889. cx_mps = d;
  1890. }
  1891. cx_index = qeTableIcx.nlps;
  1892. }
  1893. } else {
  1894. this.chigh -= qeIcx;
  1895. if ((a & 0x8000) !== 0) {
  1896. this.a = a;
  1897. return cx_mps;
  1898. }
  1899. // exchangeMps
  1900. if (a < qeIcx) {
  1901. d = 1 ^ cx_mps;
  1902. if (qeTableIcx.switchFlag === 1) {
  1903. cx_mps = d;
  1904. }
  1905. cx_index = qeTableIcx.nlps;
  1906. } else {
  1907. d = cx_mps;
  1908. cx_index = qeTableIcx.nmps;
  1909. }
  1910. }
  1911. // C.3.3 renormD;
  1912. do {
  1913. if (this.ct === 0) {
  1914. this.byteIn();
  1915. }
  1916. a <<= 1;
  1917. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  1918. this.clow = (this.clow << 1) & 0xFFFF;
  1919. this.ct--;
  1920. } while ((a & 0x8000) === 0);
  1921. this.a = a;
  1922. contexts[pos] = cx_index << 1 | cx_mps;
  1923. return d;
  1924. }
  1925. };
  1926. return ArithmeticDecoder;
  1927. })();
  1928. exports.ArithmeticDecoder = ArithmeticDecoder;
  1929. }));
  1930. (function (root, factory) {
  1931. {
  1932. factory((root.pdfjsCoreCharsets = {}));
  1933. }
  1934. }(this, function (exports) {
  1935. var ISOAdobeCharset = [
  1936. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  1937. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  1938. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  1939. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  1940. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  1941. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  1942. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  1943. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  1944. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  1945. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  1946. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  1947. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  1948. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  1949. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  1950. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  1951. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  1952. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  1953. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  1954. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  1955. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  1956. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  1957. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  1958. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  1959. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  1960. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  1961. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  1962. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  1963. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  1964. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  1965. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  1966. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  1967. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  1968. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  1969. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  1970. ];
  1971. var ExpertCharset = [
  1972. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  1973. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  1974. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  1975. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  1976. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  1977. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  1978. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  1979. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  1980. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  1981. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  1982. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  1983. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  1984. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  1985. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  1986. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  1987. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  1988. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  1989. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  1990. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  1991. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  1992. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  1993. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  1994. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  1995. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  1996. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  1997. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  1998. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  1999. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2000. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  2001. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  2002. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  2003. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  2004. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  2005. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  2006. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  2007. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  2008. 'Ydieresissmall'
  2009. ];
  2010. var ExpertSubsetCharset = [
  2011. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  2012. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  2013. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  2014. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  2015. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  2016. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  2017. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  2018. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  2019. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  2020. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  2021. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  2022. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  2023. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  2024. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  2025. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  2026. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  2027. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  2028. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  2029. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2030. 'periodinferior', 'commainferior'
  2031. ];
  2032. exports.ISOAdobeCharset = ISOAdobeCharset;
  2033. exports.ExpertCharset = ExpertCharset;
  2034. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  2035. }));
  2036. (function (root, factory) {
  2037. {
  2038. factory((root.pdfjsCoreGlyphList = {}));
  2039. }
  2040. }(this, function (exports) {
  2041. var GlyphsUnicode = {
  2042. A: 0x0041,
  2043. AE: 0x00C6,
  2044. AEacute: 0x01FC,
  2045. AEmacron: 0x01E2,
  2046. AEsmall: 0xF7E6,
  2047. Aacute: 0x00C1,
  2048. Aacutesmall: 0xF7E1,
  2049. Abreve: 0x0102,
  2050. Abreveacute: 0x1EAE,
  2051. Abrevecyrillic: 0x04D0,
  2052. Abrevedotbelow: 0x1EB6,
  2053. Abrevegrave: 0x1EB0,
  2054. Abrevehookabove: 0x1EB2,
  2055. Abrevetilde: 0x1EB4,
  2056. Acaron: 0x01CD,
  2057. Acircle: 0x24B6,
  2058. Acircumflex: 0x00C2,
  2059. Acircumflexacute: 0x1EA4,
  2060. Acircumflexdotbelow: 0x1EAC,
  2061. Acircumflexgrave: 0x1EA6,
  2062. Acircumflexhookabove: 0x1EA8,
  2063. Acircumflexsmall: 0xF7E2,
  2064. Acircumflextilde: 0x1EAA,
  2065. Acute: 0xF6C9,
  2066. Acutesmall: 0xF7B4,
  2067. Acyrillic: 0x0410,
  2068. Adblgrave: 0x0200,
  2069. Adieresis: 0x00C4,
  2070. Adieresiscyrillic: 0x04D2,
  2071. Adieresismacron: 0x01DE,
  2072. Adieresissmall: 0xF7E4,
  2073. Adotbelow: 0x1EA0,
  2074. Adotmacron: 0x01E0,
  2075. Agrave: 0x00C0,
  2076. Agravesmall: 0xF7E0,
  2077. Ahookabove: 0x1EA2,
  2078. Aiecyrillic: 0x04D4,
  2079. Ainvertedbreve: 0x0202,
  2080. Alpha: 0x0391,
  2081. Alphatonos: 0x0386,
  2082. Amacron: 0x0100,
  2083. Amonospace: 0xFF21,
  2084. Aogonek: 0x0104,
  2085. Aring: 0x00C5,
  2086. Aringacute: 0x01FA,
  2087. Aringbelow: 0x1E00,
  2088. Aringsmall: 0xF7E5,
  2089. Asmall: 0xF761,
  2090. Atilde: 0x00C3,
  2091. Atildesmall: 0xF7E3,
  2092. Aybarmenian: 0x0531,
  2093. B: 0x0042,
  2094. Bcircle: 0x24B7,
  2095. Bdotaccent: 0x1E02,
  2096. Bdotbelow: 0x1E04,
  2097. Becyrillic: 0x0411,
  2098. Benarmenian: 0x0532,
  2099. Beta: 0x0392,
  2100. Bhook: 0x0181,
  2101. Blinebelow: 0x1E06,
  2102. Bmonospace: 0xFF22,
  2103. Brevesmall: 0xF6F4,
  2104. Bsmall: 0xF762,
  2105. Btopbar: 0x0182,
  2106. C: 0x0043,
  2107. Caarmenian: 0x053E,
  2108. Cacute: 0x0106,
  2109. Caron: 0xF6CA,
  2110. Caronsmall: 0xF6F5,
  2111. Ccaron: 0x010C,
  2112. Ccedilla: 0x00C7,
  2113. Ccedillaacute: 0x1E08,
  2114. Ccedillasmall: 0xF7E7,
  2115. Ccircle: 0x24B8,
  2116. Ccircumflex: 0x0108,
  2117. Cdot: 0x010A,
  2118. Cdotaccent: 0x010A,
  2119. Cedillasmall: 0xF7B8,
  2120. Chaarmenian: 0x0549,
  2121. Cheabkhasiancyrillic: 0x04BC,
  2122. Checyrillic: 0x0427,
  2123. Chedescenderabkhasiancyrillic: 0x04BE,
  2124. Chedescendercyrillic: 0x04B6,
  2125. Chedieresiscyrillic: 0x04F4,
  2126. Cheharmenian: 0x0543,
  2127. Chekhakassiancyrillic: 0x04CB,
  2128. Cheverticalstrokecyrillic: 0x04B8,
  2129. Chi: 0x03A7,
  2130. Chook: 0x0187,
  2131. Circumflexsmall: 0xF6F6,
  2132. Cmonospace: 0xFF23,
  2133. Coarmenian: 0x0551,
  2134. Csmall: 0xF763,
  2135. D: 0x0044,
  2136. DZ: 0x01F1,
  2137. DZcaron: 0x01C4,
  2138. Daarmenian: 0x0534,
  2139. Dafrican: 0x0189,
  2140. Dcaron: 0x010E,
  2141. Dcedilla: 0x1E10,
  2142. Dcircle: 0x24B9,
  2143. Dcircumflexbelow: 0x1E12,
  2144. Dcroat: 0x0110,
  2145. Ddotaccent: 0x1E0A,
  2146. Ddotbelow: 0x1E0C,
  2147. Decyrillic: 0x0414,
  2148. Deicoptic: 0x03EE,
  2149. Delta: 0x2206,
  2150. Deltagreek: 0x0394,
  2151. Dhook: 0x018A,
  2152. Dieresis: 0xF6CB,
  2153. DieresisAcute: 0xF6CC,
  2154. DieresisGrave: 0xF6CD,
  2155. Dieresissmall: 0xF7A8,
  2156. Digammagreek: 0x03DC,
  2157. Djecyrillic: 0x0402,
  2158. Dlinebelow: 0x1E0E,
  2159. Dmonospace: 0xFF24,
  2160. Dotaccentsmall: 0xF6F7,
  2161. Dslash: 0x0110,
  2162. Dsmall: 0xF764,
  2163. Dtopbar: 0x018B,
  2164. Dz: 0x01F2,
  2165. Dzcaron: 0x01C5,
  2166. Dzeabkhasiancyrillic: 0x04E0,
  2167. Dzecyrillic: 0x0405,
  2168. Dzhecyrillic: 0x040F,
  2169. E: 0x0045,
  2170. Eacute: 0x00C9,
  2171. Eacutesmall: 0xF7E9,
  2172. Ebreve: 0x0114,
  2173. Ecaron: 0x011A,
  2174. Ecedillabreve: 0x1E1C,
  2175. Echarmenian: 0x0535,
  2176. Ecircle: 0x24BA,
  2177. Ecircumflex: 0x00CA,
  2178. Ecircumflexacute: 0x1EBE,
  2179. Ecircumflexbelow: 0x1E18,
  2180. Ecircumflexdotbelow: 0x1EC6,
  2181. Ecircumflexgrave: 0x1EC0,
  2182. Ecircumflexhookabove: 0x1EC2,
  2183. Ecircumflexsmall: 0xF7EA,
  2184. Ecircumflextilde: 0x1EC4,
  2185. Ecyrillic: 0x0404,
  2186. Edblgrave: 0x0204,
  2187. Edieresis: 0x00CB,
  2188. Edieresissmall: 0xF7EB,
  2189. Edot: 0x0116,
  2190. Edotaccent: 0x0116,
  2191. Edotbelow: 0x1EB8,
  2192. Efcyrillic: 0x0424,
  2193. Egrave: 0x00C8,
  2194. Egravesmall: 0xF7E8,
  2195. Eharmenian: 0x0537,
  2196. Ehookabove: 0x1EBA,
  2197. Eightroman: 0x2167,
  2198. Einvertedbreve: 0x0206,
  2199. Eiotifiedcyrillic: 0x0464,
  2200. Elcyrillic: 0x041B,
  2201. Elevenroman: 0x216A,
  2202. Emacron: 0x0112,
  2203. Emacronacute: 0x1E16,
  2204. Emacrongrave: 0x1E14,
  2205. Emcyrillic: 0x041C,
  2206. Emonospace: 0xFF25,
  2207. Encyrillic: 0x041D,
  2208. Endescendercyrillic: 0x04A2,
  2209. Eng: 0x014A,
  2210. Enghecyrillic: 0x04A4,
  2211. Enhookcyrillic: 0x04C7,
  2212. Eogonek: 0x0118,
  2213. Eopen: 0x0190,
  2214. Epsilon: 0x0395,
  2215. Epsilontonos: 0x0388,
  2216. Ercyrillic: 0x0420,
  2217. Ereversed: 0x018E,
  2218. Ereversedcyrillic: 0x042D,
  2219. Escyrillic: 0x0421,
  2220. Esdescendercyrillic: 0x04AA,
  2221. Esh: 0x01A9,
  2222. Esmall: 0xF765,
  2223. Eta: 0x0397,
  2224. Etarmenian: 0x0538,
  2225. Etatonos: 0x0389,
  2226. Eth: 0x00D0,
  2227. Ethsmall: 0xF7F0,
  2228. Etilde: 0x1EBC,
  2229. Etildebelow: 0x1E1A,
  2230. Euro: 0x20AC,
  2231. Ezh: 0x01B7,
  2232. Ezhcaron: 0x01EE,
  2233. Ezhreversed: 0x01B8,
  2234. F: 0x0046,
  2235. Fcircle: 0x24BB,
  2236. Fdotaccent: 0x1E1E,
  2237. Feharmenian: 0x0556,
  2238. Feicoptic: 0x03E4,
  2239. Fhook: 0x0191,
  2240. Fitacyrillic: 0x0472,
  2241. Fiveroman: 0x2164,
  2242. Fmonospace: 0xFF26,
  2243. Fourroman: 0x2163,
  2244. Fsmall: 0xF766,
  2245. G: 0x0047,
  2246. GBsquare: 0x3387,
  2247. Gacute: 0x01F4,
  2248. Gamma: 0x0393,
  2249. Gammaafrican: 0x0194,
  2250. Gangiacoptic: 0x03EA,
  2251. Gbreve: 0x011E,
  2252. Gcaron: 0x01E6,
  2253. Gcedilla: 0x0122,
  2254. Gcircle: 0x24BC,
  2255. Gcircumflex: 0x011C,
  2256. Gcommaaccent: 0x0122,
  2257. Gdot: 0x0120,
  2258. Gdotaccent: 0x0120,
  2259. Gecyrillic: 0x0413,
  2260. Ghadarmenian: 0x0542,
  2261. Ghemiddlehookcyrillic: 0x0494,
  2262. Ghestrokecyrillic: 0x0492,
  2263. Gheupturncyrillic: 0x0490,
  2264. Ghook: 0x0193,
  2265. Gimarmenian: 0x0533,
  2266. Gjecyrillic: 0x0403,
  2267. Gmacron: 0x1E20,
  2268. Gmonospace: 0xFF27,
  2269. Grave: 0xF6CE,
  2270. Gravesmall: 0xF760,
  2271. Gsmall: 0xF767,
  2272. Gsmallhook: 0x029B,
  2273. Gstroke: 0x01E4,
  2274. H: 0x0048,
  2275. H18533: 0x25CF,
  2276. H18543: 0x25AA,
  2277. H18551: 0x25AB,
  2278. H22073: 0x25A1,
  2279. HPsquare: 0x33CB,
  2280. Haabkhasiancyrillic: 0x04A8,
  2281. Hadescendercyrillic: 0x04B2,
  2282. Hardsigncyrillic: 0x042A,
  2283. Hbar: 0x0126,
  2284. Hbrevebelow: 0x1E2A,
  2285. Hcedilla: 0x1E28,
  2286. Hcircle: 0x24BD,
  2287. Hcircumflex: 0x0124,
  2288. Hdieresis: 0x1E26,
  2289. Hdotaccent: 0x1E22,
  2290. Hdotbelow: 0x1E24,
  2291. Hmonospace: 0xFF28,
  2292. Hoarmenian: 0x0540,
  2293. Horicoptic: 0x03E8,
  2294. Hsmall: 0xF768,
  2295. Hungarumlaut: 0xF6CF,
  2296. Hungarumlautsmall: 0xF6F8,
  2297. Hzsquare: 0x3390,
  2298. I: 0x0049,
  2299. IAcyrillic: 0x042F,
  2300. IJ: 0x0132,
  2301. IUcyrillic: 0x042E,
  2302. Iacute: 0x00CD,
  2303. Iacutesmall: 0xF7ED,
  2304. Ibreve: 0x012C,
  2305. Icaron: 0x01CF,
  2306. Icircle: 0x24BE,
  2307. Icircumflex: 0x00CE,
  2308. Icircumflexsmall: 0xF7EE,
  2309. Icyrillic: 0x0406,
  2310. Idblgrave: 0x0208,
  2311. Idieresis: 0x00CF,
  2312. Idieresisacute: 0x1E2E,
  2313. Idieresiscyrillic: 0x04E4,
  2314. Idieresissmall: 0xF7EF,
  2315. Idot: 0x0130,
  2316. Idotaccent: 0x0130,
  2317. Idotbelow: 0x1ECA,
  2318. Iebrevecyrillic: 0x04D6,
  2319. Iecyrillic: 0x0415,
  2320. Ifraktur: 0x2111,
  2321. Igrave: 0x00CC,
  2322. Igravesmall: 0xF7EC,
  2323. Ihookabove: 0x1EC8,
  2324. Iicyrillic: 0x0418,
  2325. Iinvertedbreve: 0x020A,
  2326. Iishortcyrillic: 0x0419,
  2327. Imacron: 0x012A,
  2328. Imacroncyrillic: 0x04E2,
  2329. Imonospace: 0xFF29,
  2330. Iniarmenian: 0x053B,
  2331. Iocyrillic: 0x0401,
  2332. Iogonek: 0x012E,
  2333. Iota: 0x0399,
  2334. Iotaafrican: 0x0196,
  2335. Iotadieresis: 0x03AA,
  2336. Iotatonos: 0x038A,
  2337. Ismall: 0xF769,
  2338. Istroke: 0x0197,
  2339. Itilde: 0x0128,
  2340. Itildebelow: 0x1E2C,
  2341. Izhitsacyrillic: 0x0474,
  2342. Izhitsadblgravecyrillic: 0x0476,
  2343. J: 0x004A,
  2344. Jaarmenian: 0x0541,
  2345. Jcircle: 0x24BF,
  2346. Jcircumflex: 0x0134,
  2347. Jecyrillic: 0x0408,
  2348. Jheharmenian: 0x054B,
  2349. Jmonospace: 0xFF2A,
  2350. Jsmall: 0xF76A,
  2351. K: 0x004B,
  2352. KBsquare: 0x3385,
  2353. KKsquare: 0x33CD,
  2354. Kabashkircyrillic: 0x04A0,
  2355. Kacute: 0x1E30,
  2356. Kacyrillic: 0x041A,
  2357. Kadescendercyrillic: 0x049A,
  2358. Kahookcyrillic: 0x04C3,
  2359. Kappa: 0x039A,
  2360. Kastrokecyrillic: 0x049E,
  2361. Kaverticalstrokecyrillic: 0x049C,
  2362. Kcaron: 0x01E8,
  2363. Kcedilla: 0x0136,
  2364. Kcircle: 0x24C0,
  2365. Kcommaaccent: 0x0136,
  2366. Kdotbelow: 0x1E32,
  2367. Keharmenian: 0x0554,
  2368. Kenarmenian: 0x053F,
  2369. Khacyrillic: 0x0425,
  2370. Kheicoptic: 0x03E6,
  2371. Khook: 0x0198,
  2372. Kjecyrillic: 0x040C,
  2373. Klinebelow: 0x1E34,
  2374. Kmonospace: 0xFF2B,
  2375. Koppacyrillic: 0x0480,
  2376. Koppagreek: 0x03DE,
  2377. Ksicyrillic: 0x046E,
  2378. Ksmall: 0xF76B,
  2379. L: 0x004C,
  2380. LJ: 0x01C7,
  2381. LL: 0xF6BF,
  2382. Lacute: 0x0139,
  2383. Lambda: 0x039B,
  2384. Lcaron: 0x013D,
  2385. Lcedilla: 0x013B,
  2386. Lcircle: 0x24C1,
  2387. Lcircumflexbelow: 0x1E3C,
  2388. Lcommaaccent: 0x013B,
  2389. Ldot: 0x013F,
  2390. Ldotaccent: 0x013F,
  2391. Ldotbelow: 0x1E36,
  2392. Ldotbelowmacron: 0x1E38,
  2393. Liwnarmenian: 0x053C,
  2394. Lj: 0x01C8,
  2395. Ljecyrillic: 0x0409,
  2396. Llinebelow: 0x1E3A,
  2397. Lmonospace: 0xFF2C,
  2398. Lslash: 0x0141,
  2399. Lslashsmall: 0xF6F9,
  2400. Lsmall: 0xF76C,
  2401. M: 0x004D,
  2402. MBsquare: 0x3386,
  2403. Macron: 0xF6D0,
  2404. Macronsmall: 0xF7AF,
  2405. Macute: 0x1E3E,
  2406. Mcircle: 0x24C2,
  2407. Mdotaccent: 0x1E40,
  2408. Mdotbelow: 0x1E42,
  2409. Menarmenian: 0x0544,
  2410. Mmonospace: 0xFF2D,
  2411. Msmall: 0xF76D,
  2412. Mturned: 0x019C,
  2413. Mu: 0x039C,
  2414. N: 0x004E,
  2415. NJ: 0x01CA,
  2416. Nacute: 0x0143,
  2417. Ncaron: 0x0147,
  2418. Ncedilla: 0x0145,
  2419. Ncircle: 0x24C3,
  2420. Ncircumflexbelow: 0x1E4A,
  2421. Ncommaaccent: 0x0145,
  2422. Ndotaccent: 0x1E44,
  2423. Ndotbelow: 0x1E46,
  2424. Nhookleft: 0x019D,
  2425. Nineroman: 0x2168,
  2426. Nj: 0x01CB,
  2427. Njecyrillic: 0x040A,
  2428. Nlinebelow: 0x1E48,
  2429. Nmonospace: 0xFF2E,
  2430. Nowarmenian: 0x0546,
  2431. Nsmall: 0xF76E,
  2432. Ntilde: 0x00D1,
  2433. Ntildesmall: 0xF7F1,
  2434. Nu: 0x039D,
  2435. O: 0x004F,
  2436. OE: 0x0152,
  2437. OEsmall: 0xF6FA,
  2438. Oacute: 0x00D3,
  2439. Oacutesmall: 0xF7F3,
  2440. Obarredcyrillic: 0x04E8,
  2441. Obarreddieresiscyrillic: 0x04EA,
  2442. Obreve: 0x014E,
  2443. Ocaron: 0x01D1,
  2444. Ocenteredtilde: 0x019F,
  2445. Ocircle: 0x24C4,
  2446. Ocircumflex: 0x00D4,
  2447. Ocircumflexacute: 0x1ED0,
  2448. Ocircumflexdotbelow: 0x1ED8,
  2449. Ocircumflexgrave: 0x1ED2,
  2450. Ocircumflexhookabove: 0x1ED4,
  2451. Ocircumflexsmall: 0xF7F4,
  2452. Ocircumflextilde: 0x1ED6,
  2453. Ocyrillic: 0x041E,
  2454. Odblacute: 0x0150,
  2455. Odblgrave: 0x020C,
  2456. Odieresis: 0x00D6,
  2457. Odieresiscyrillic: 0x04E6,
  2458. Odieresissmall: 0xF7F6,
  2459. Odotbelow: 0x1ECC,
  2460. Ogoneksmall: 0xF6FB,
  2461. Ograve: 0x00D2,
  2462. Ogravesmall: 0xF7F2,
  2463. Oharmenian: 0x0555,
  2464. Ohm: 0x2126,
  2465. Ohookabove: 0x1ECE,
  2466. Ohorn: 0x01A0,
  2467. Ohornacute: 0x1EDA,
  2468. Ohorndotbelow: 0x1EE2,
  2469. Ohorngrave: 0x1EDC,
  2470. Ohornhookabove: 0x1EDE,
  2471. Ohorntilde: 0x1EE0,
  2472. Ohungarumlaut: 0x0150,
  2473. Oi: 0x01A2,
  2474. Oinvertedbreve: 0x020E,
  2475. Omacron: 0x014C,
  2476. Omacronacute: 0x1E52,
  2477. Omacrongrave: 0x1E50,
  2478. Omega: 0x2126,
  2479. Omegacyrillic: 0x0460,
  2480. Omegagreek: 0x03A9,
  2481. Omegaroundcyrillic: 0x047A,
  2482. Omegatitlocyrillic: 0x047C,
  2483. Omegatonos: 0x038F,
  2484. Omicron: 0x039F,
  2485. Omicrontonos: 0x038C,
  2486. Omonospace: 0xFF2F,
  2487. Oneroman: 0x2160,
  2488. Oogonek: 0x01EA,
  2489. Oogonekmacron: 0x01EC,
  2490. Oopen: 0x0186,
  2491. Oslash: 0x00D8,
  2492. Oslashacute: 0x01FE,
  2493. Oslashsmall: 0xF7F8,
  2494. Osmall: 0xF76F,
  2495. Ostrokeacute: 0x01FE,
  2496. Otcyrillic: 0x047E,
  2497. Otilde: 0x00D5,
  2498. Otildeacute: 0x1E4C,
  2499. Otildedieresis: 0x1E4E,
  2500. Otildesmall: 0xF7F5,
  2501. P: 0x0050,
  2502. Pacute: 0x1E54,
  2503. Pcircle: 0x24C5,
  2504. Pdotaccent: 0x1E56,
  2505. Pecyrillic: 0x041F,
  2506. Peharmenian: 0x054A,
  2507. Pemiddlehookcyrillic: 0x04A6,
  2508. Phi: 0x03A6,
  2509. Phook: 0x01A4,
  2510. Pi: 0x03A0,
  2511. Piwrarmenian: 0x0553,
  2512. Pmonospace: 0xFF30,
  2513. Psi: 0x03A8,
  2514. Psicyrillic: 0x0470,
  2515. Psmall: 0xF770,
  2516. Q: 0x0051,
  2517. Qcircle: 0x24C6,
  2518. Qmonospace: 0xFF31,
  2519. Qsmall: 0xF771,
  2520. R: 0x0052,
  2521. Raarmenian: 0x054C,
  2522. Racute: 0x0154,
  2523. Rcaron: 0x0158,
  2524. Rcedilla: 0x0156,
  2525. Rcircle: 0x24C7,
  2526. Rcommaaccent: 0x0156,
  2527. Rdblgrave: 0x0210,
  2528. Rdotaccent: 0x1E58,
  2529. Rdotbelow: 0x1E5A,
  2530. Rdotbelowmacron: 0x1E5C,
  2531. Reharmenian: 0x0550,
  2532. Rfraktur: 0x211C,
  2533. Rho: 0x03A1,
  2534. Ringsmall: 0xF6FC,
  2535. Rinvertedbreve: 0x0212,
  2536. Rlinebelow: 0x1E5E,
  2537. Rmonospace: 0xFF32,
  2538. Rsmall: 0xF772,
  2539. Rsmallinverted: 0x0281,
  2540. Rsmallinvertedsuperior: 0x02B6,
  2541. S: 0x0053,
  2542. SF010000: 0x250C,
  2543. SF020000: 0x2514,
  2544. SF030000: 0x2510,
  2545. SF040000: 0x2518,
  2546. SF050000: 0x253C,
  2547. SF060000: 0x252C,
  2548. SF070000: 0x2534,
  2549. SF080000: 0x251C,
  2550. SF090000: 0x2524,
  2551. SF100000: 0x2500,
  2552. SF110000: 0x2502,
  2553. SF190000: 0x2561,
  2554. SF200000: 0x2562,
  2555. SF210000: 0x2556,
  2556. SF220000: 0x2555,
  2557. SF230000: 0x2563,
  2558. SF240000: 0x2551,
  2559. SF250000: 0x2557,
  2560. SF260000: 0x255D,
  2561. SF270000: 0x255C,
  2562. SF280000: 0x255B,
  2563. SF360000: 0x255E,
  2564. SF370000: 0x255F,
  2565. SF380000: 0x255A,
  2566. SF390000: 0x2554,
  2567. SF400000: 0x2569,
  2568. SF410000: 0x2566,
  2569. SF420000: 0x2560,
  2570. SF430000: 0x2550,
  2571. SF440000: 0x256C,
  2572. SF450000: 0x2567,
  2573. SF460000: 0x2568,
  2574. SF470000: 0x2564,
  2575. SF480000: 0x2565,
  2576. SF490000: 0x2559,
  2577. SF500000: 0x2558,
  2578. SF510000: 0x2552,
  2579. SF520000: 0x2553,
  2580. SF530000: 0x256B,
  2581. SF540000: 0x256A,
  2582. Sacute: 0x015A,
  2583. Sacutedotaccent: 0x1E64,
  2584. Sampigreek: 0x03E0,
  2585. Scaron: 0x0160,
  2586. Scarondotaccent: 0x1E66,
  2587. Scaronsmall: 0xF6FD,
  2588. Scedilla: 0x015E,
  2589. Schwa: 0x018F,
  2590. Schwacyrillic: 0x04D8,
  2591. Schwadieresiscyrillic: 0x04DA,
  2592. Scircle: 0x24C8,
  2593. Scircumflex: 0x015C,
  2594. Scommaaccent: 0x0218,
  2595. Sdotaccent: 0x1E60,
  2596. Sdotbelow: 0x1E62,
  2597. Sdotbelowdotaccent: 0x1E68,
  2598. Seharmenian: 0x054D,
  2599. Sevenroman: 0x2166,
  2600. Shaarmenian: 0x0547,
  2601. Shacyrillic: 0x0428,
  2602. Shchacyrillic: 0x0429,
  2603. Sheicoptic: 0x03E2,
  2604. Shhacyrillic: 0x04BA,
  2605. Shimacoptic: 0x03EC,
  2606. Sigma: 0x03A3,
  2607. Sixroman: 0x2165,
  2608. Smonospace: 0xFF33,
  2609. Softsigncyrillic: 0x042C,
  2610. Ssmall: 0xF773,
  2611. Stigmagreek: 0x03DA,
  2612. T: 0x0054,
  2613. Tau: 0x03A4,
  2614. Tbar: 0x0166,
  2615. Tcaron: 0x0164,
  2616. Tcedilla: 0x0162,
  2617. Tcircle: 0x24C9,
  2618. Tcircumflexbelow: 0x1E70,
  2619. Tcommaaccent: 0x0162,
  2620. Tdotaccent: 0x1E6A,
  2621. Tdotbelow: 0x1E6C,
  2622. Tecyrillic: 0x0422,
  2623. Tedescendercyrillic: 0x04AC,
  2624. Tenroman: 0x2169,
  2625. Tetsecyrillic: 0x04B4,
  2626. Theta: 0x0398,
  2627. Thook: 0x01AC,
  2628. Thorn: 0x00DE,
  2629. Thornsmall: 0xF7FE,
  2630. Threeroman: 0x2162,
  2631. Tildesmall: 0xF6FE,
  2632. Tiwnarmenian: 0x054F,
  2633. Tlinebelow: 0x1E6E,
  2634. Tmonospace: 0xFF34,
  2635. Toarmenian: 0x0539,
  2636. Tonefive: 0x01BC,
  2637. Tonesix: 0x0184,
  2638. Tonetwo: 0x01A7,
  2639. Tretroflexhook: 0x01AE,
  2640. Tsecyrillic: 0x0426,
  2641. Tshecyrillic: 0x040B,
  2642. Tsmall: 0xF774,
  2643. Twelveroman: 0x216B,
  2644. Tworoman: 0x2161,
  2645. U: 0x0055,
  2646. Uacute: 0x00DA,
  2647. Uacutesmall: 0xF7FA,
  2648. Ubreve: 0x016C,
  2649. Ucaron: 0x01D3,
  2650. Ucircle: 0x24CA,
  2651. Ucircumflex: 0x00DB,
  2652. Ucircumflexbelow: 0x1E76,
  2653. Ucircumflexsmall: 0xF7FB,
  2654. Ucyrillic: 0x0423,
  2655. Udblacute: 0x0170,
  2656. Udblgrave: 0x0214,
  2657. Udieresis: 0x00DC,
  2658. Udieresisacute: 0x01D7,
  2659. Udieresisbelow: 0x1E72,
  2660. Udieresiscaron: 0x01D9,
  2661. Udieresiscyrillic: 0x04F0,
  2662. Udieresisgrave: 0x01DB,
  2663. Udieresismacron: 0x01D5,
  2664. Udieresissmall: 0xF7FC,
  2665. Udotbelow: 0x1EE4,
  2666. Ugrave: 0x00D9,
  2667. Ugravesmall: 0xF7F9,
  2668. Uhookabove: 0x1EE6,
  2669. Uhorn: 0x01AF,
  2670. Uhornacute: 0x1EE8,
  2671. Uhorndotbelow: 0x1EF0,
  2672. Uhorngrave: 0x1EEA,
  2673. Uhornhookabove: 0x1EEC,
  2674. Uhorntilde: 0x1EEE,
  2675. Uhungarumlaut: 0x0170,
  2676. Uhungarumlautcyrillic: 0x04F2,
  2677. Uinvertedbreve: 0x0216,
  2678. Ukcyrillic: 0x0478,
  2679. Umacron: 0x016A,
  2680. Umacroncyrillic: 0x04EE,
  2681. Umacrondieresis: 0x1E7A,
  2682. Umonospace: 0xFF35,
  2683. Uogonek: 0x0172,
  2684. Upsilon: 0x03A5,
  2685. Upsilon1: 0x03D2,
  2686. Upsilonacutehooksymbolgreek: 0x03D3,
  2687. Upsilonafrican: 0x01B1,
  2688. Upsilondieresis: 0x03AB,
  2689. Upsilondieresishooksymbolgreek: 0x03D4,
  2690. Upsilonhooksymbol: 0x03D2,
  2691. Upsilontonos: 0x038E,
  2692. Uring: 0x016E,
  2693. Ushortcyrillic: 0x040E,
  2694. Usmall: 0xF775,
  2695. Ustraightcyrillic: 0x04AE,
  2696. Ustraightstrokecyrillic: 0x04B0,
  2697. Utilde: 0x0168,
  2698. Utildeacute: 0x1E78,
  2699. Utildebelow: 0x1E74,
  2700. V: 0x0056,
  2701. Vcircle: 0x24CB,
  2702. Vdotbelow: 0x1E7E,
  2703. Vecyrillic: 0x0412,
  2704. Vewarmenian: 0x054E,
  2705. Vhook: 0x01B2,
  2706. Vmonospace: 0xFF36,
  2707. Voarmenian: 0x0548,
  2708. Vsmall: 0xF776,
  2709. Vtilde: 0x1E7C,
  2710. W: 0x0057,
  2711. Wacute: 0x1E82,
  2712. Wcircle: 0x24CC,
  2713. Wcircumflex: 0x0174,
  2714. Wdieresis: 0x1E84,
  2715. Wdotaccent: 0x1E86,
  2716. Wdotbelow: 0x1E88,
  2717. Wgrave: 0x1E80,
  2718. Wmonospace: 0xFF37,
  2719. Wsmall: 0xF777,
  2720. X: 0x0058,
  2721. Xcircle: 0x24CD,
  2722. Xdieresis: 0x1E8C,
  2723. Xdotaccent: 0x1E8A,
  2724. Xeharmenian: 0x053D,
  2725. Xi: 0x039E,
  2726. Xmonospace: 0xFF38,
  2727. Xsmall: 0xF778,
  2728. Y: 0x0059,
  2729. Yacute: 0x00DD,
  2730. Yacutesmall: 0xF7FD,
  2731. Yatcyrillic: 0x0462,
  2732. Ycircle: 0x24CE,
  2733. Ycircumflex: 0x0176,
  2734. Ydieresis: 0x0178,
  2735. Ydieresissmall: 0xF7FF,
  2736. Ydotaccent: 0x1E8E,
  2737. Ydotbelow: 0x1EF4,
  2738. Yericyrillic: 0x042B,
  2739. Yerudieresiscyrillic: 0x04F8,
  2740. Ygrave: 0x1EF2,
  2741. Yhook: 0x01B3,
  2742. Yhookabove: 0x1EF6,
  2743. Yiarmenian: 0x0545,
  2744. Yicyrillic: 0x0407,
  2745. Yiwnarmenian: 0x0552,
  2746. Ymonospace: 0xFF39,
  2747. Ysmall: 0xF779,
  2748. Ytilde: 0x1EF8,
  2749. Yusbigcyrillic: 0x046A,
  2750. Yusbigiotifiedcyrillic: 0x046C,
  2751. Yuslittlecyrillic: 0x0466,
  2752. Yuslittleiotifiedcyrillic: 0x0468,
  2753. Z: 0x005A,
  2754. Zaarmenian: 0x0536,
  2755. Zacute: 0x0179,
  2756. Zcaron: 0x017D,
  2757. Zcaronsmall: 0xF6FF,
  2758. Zcircle: 0x24CF,
  2759. Zcircumflex: 0x1E90,
  2760. Zdot: 0x017B,
  2761. Zdotaccent: 0x017B,
  2762. Zdotbelow: 0x1E92,
  2763. Zecyrillic: 0x0417,
  2764. Zedescendercyrillic: 0x0498,
  2765. Zedieresiscyrillic: 0x04DE,
  2766. Zeta: 0x0396,
  2767. Zhearmenian: 0x053A,
  2768. Zhebrevecyrillic: 0x04C1,
  2769. Zhecyrillic: 0x0416,
  2770. Zhedescendercyrillic: 0x0496,
  2771. Zhedieresiscyrillic: 0x04DC,
  2772. Zlinebelow: 0x1E94,
  2773. Zmonospace: 0xFF3A,
  2774. Zsmall: 0xF77A,
  2775. Zstroke: 0x01B5,
  2776. a: 0x0061,
  2777. aabengali: 0x0986,
  2778. aacute: 0x00E1,
  2779. aadeva: 0x0906,
  2780. aagujarati: 0x0A86,
  2781. aagurmukhi: 0x0A06,
  2782. aamatragurmukhi: 0x0A3E,
  2783. aarusquare: 0x3303,
  2784. aavowelsignbengali: 0x09BE,
  2785. aavowelsigndeva: 0x093E,
  2786. aavowelsigngujarati: 0x0ABE,
  2787. abbreviationmarkarmenian: 0x055F,
  2788. abbreviationsigndeva: 0x0970,
  2789. abengali: 0x0985,
  2790. abopomofo: 0x311A,
  2791. abreve: 0x0103,
  2792. abreveacute: 0x1EAF,
  2793. abrevecyrillic: 0x04D1,
  2794. abrevedotbelow: 0x1EB7,
  2795. abrevegrave: 0x1EB1,
  2796. abrevehookabove: 0x1EB3,
  2797. abrevetilde: 0x1EB5,
  2798. acaron: 0x01CE,
  2799. acircle: 0x24D0,
  2800. acircumflex: 0x00E2,
  2801. acircumflexacute: 0x1EA5,
  2802. acircumflexdotbelow: 0x1EAD,
  2803. acircumflexgrave: 0x1EA7,
  2804. acircumflexhookabove: 0x1EA9,
  2805. acircumflextilde: 0x1EAB,
  2806. acute: 0x00B4,
  2807. acutebelowcmb: 0x0317,
  2808. acutecmb: 0x0301,
  2809. acutecomb: 0x0301,
  2810. acutedeva: 0x0954,
  2811. acutelowmod: 0x02CF,
  2812. acutetonecmb: 0x0341,
  2813. acyrillic: 0x0430,
  2814. adblgrave: 0x0201,
  2815. addakgurmukhi: 0x0A71,
  2816. adeva: 0x0905,
  2817. adieresis: 0x00E4,
  2818. adieresiscyrillic: 0x04D3,
  2819. adieresismacron: 0x01DF,
  2820. adotbelow: 0x1EA1,
  2821. adotmacron: 0x01E1,
  2822. ae: 0x00E6,
  2823. aeacute: 0x01FD,
  2824. aekorean: 0x3150,
  2825. aemacron: 0x01E3,
  2826. afii00208: 0x2015,
  2827. afii08941: 0x20A4,
  2828. afii10017: 0x0410,
  2829. afii10018: 0x0411,
  2830. afii10019: 0x0412,
  2831. afii10020: 0x0413,
  2832. afii10021: 0x0414,
  2833. afii10022: 0x0415,
  2834. afii10023: 0x0401,
  2835. afii10024: 0x0416,
  2836. afii10025: 0x0417,
  2837. afii10026: 0x0418,
  2838. afii10027: 0x0419,
  2839. afii10028: 0x041A,
  2840. afii10029: 0x041B,
  2841. afii10030: 0x041C,
  2842. afii10031: 0x041D,
  2843. afii10032: 0x041E,
  2844. afii10033: 0x041F,
  2845. afii10034: 0x0420,
  2846. afii10035: 0x0421,
  2847. afii10036: 0x0422,
  2848. afii10037: 0x0423,
  2849. afii10038: 0x0424,
  2850. afii10039: 0x0425,
  2851. afii10040: 0x0426,
  2852. afii10041: 0x0427,
  2853. afii10042: 0x0428,
  2854. afii10043: 0x0429,
  2855. afii10044: 0x042A,
  2856. afii10045: 0x042B,
  2857. afii10046: 0x042C,
  2858. afii10047: 0x042D,
  2859. afii10048: 0x042E,
  2860. afii10049: 0x042F,
  2861. afii10050: 0x0490,
  2862. afii10051: 0x0402,
  2863. afii10052: 0x0403,
  2864. afii10053: 0x0404,
  2865. afii10054: 0x0405,
  2866. afii10055: 0x0406,
  2867. afii10056: 0x0407,
  2868. afii10057: 0x0408,
  2869. afii10058: 0x0409,
  2870. afii10059: 0x040A,
  2871. afii10060: 0x040B,
  2872. afii10061: 0x040C,
  2873. afii10062: 0x040E,
  2874. afii10063: 0xF6C4,
  2875. afii10064: 0xF6C5,
  2876. afii10065: 0x0430,
  2877. afii10066: 0x0431,
  2878. afii10067: 0x0432,
  2879. afii10068: 0x0433,
  2880. afii10069: 0x0434,
  2881. afii10070: 0x0435,
  2882. afii10071: 0x0451,
  2883. afii10072: 0x0436,
  2884. afii10073: 0x0437,
  2885. afii10074: 0x0438,
  2886. afii10075: 0x0439,
  2887. afii10076: 0x043A,
  2888. afii10077: 0x043B,
  2889. afii10078: 0x043C,
  2890. afii10079: 0x043D,
  2891. afii10080: 0x043E,
  2892. afii10081: 0x043F,
  2893. afii10082: 0x0440,
  2894. afii10083: 0x0441,
  2895. afii10084: 0x0442,
  2896. afii10085: 0x0443,
  2897. afii10086: 0x0444,
  2898. afii10087: 0x0445,
  2899. afii10088: 0x0446,
  2900. afii10089: 0x0447,
  2901. afii10090: 0x0448,
  2902. afii10091: 0x0449,
  2903. afii10092: 0x044A,
  2904. afii10093: 0x044B,
  2905. afii10094: 0x044C,
  2906. afii10095: 0x044D,
  2907. afii10096: 0x044E,
  2908. afii10097: 0x044F,
  2909. afii10098: 0x0491,
  2910. afii10099: 0x0452,
  2911. afii10100: 0x0453,
  2912. afii10101: 0x0454,
  2913. afii10102: 0x0455,
  2914. afii10103: 0x0456,
  2915. afii10104: 0x0457,
  2916. afii10105: 0x0458,
  2917. afii10106: 0x0459,
  2918. afii10107: 0x045A,
  2919. afii10108: 0x045B,
  2920. afii10109: 0x045C,
  2921. afii10110: 0x045E,
  2922. afii10145: 0x040F,
  2923. afii10146: 0x0462,
  2924. afii10147: 0x0472,
  2925. afii10148: 0x0474,
  2926. afii10192: 0xF6C6,
  2927. afii10193: 0x045F,
  2928. afii10194: 0x0463,
  2929. afii10195: 0x0473,
  2930. afii10196: 0x0475,
  2931. afii10831: 0xF6C7,
  2932. afii10832: 0xF6C8,
  2933. afii10846: 0x04D9,
  2934. afii299: 0x200E,
  2935. afii300: 0x200F,
  2936. afii301: 0x200D,
  2937. afii57381: 0x066A,
  2938. afii57388: 0x060C,
  2939. afii57392: 0x0660,
  2940. afii57393: 0x0661,
  2941. afii57394: 0x0662,
  2942. afii57395: 0x0663,
  2943. afii57396: 0x0664,
  2944. afii57397: 0x0665,
  2945. afii57398: 0x0666,
  2946. afii57399: 0x0667,
  2947. afii57400: 0x0668,
  2948. afii57401: 0x0669,
  2949. afii57403: 0x061B,
  2950. afii57407: 0x061F,
  2951. afii57409: 0x0621,
  2952. afii57410: 0x0622,
  2953. afii57411: 0x0623,
  2954. afii57412: 0x0624,
  2955. afii57413: 0x0625,
  2956. afii57414: 0x0626,
  2957. afii57415: 0x0627,
  2958. afii57416: 0x0628,
  2959. afii57417: 0x0629,
  2960. afii57418: 0x062A,
  2961. afii57419: 0x062B,
  2962. afii57420: 0x062C,
  2963. afii57421: 0x062D,
  2964. afii57422: 0x062E,
  2965. afii57423: 0x062F,
  2966. afii57424: 0x0630,
  2967. afii57425: 0x0631,
  2968. afii57426: 0x0632,
  2969. afii57427: 0x0633,
  2970. afii57428: 0x0634,
  2971. afii57429: 0x0635,
  2972. afii57430: 0x0636,
  2973. afii57431: 0x0637,
  2974. afii57432: 0x0638,
  2975. afii57433: 0x0639,
  2976. afii57434: 0x063A,
  2977. afii57440: 0x0640,
  2978. afii57441: 0x0641,
  2979. afii57442: 0x0642,
  2980. afii57443: 0x0643,
  2981. afii57444: 0x0644,
  2982. afii57445: 0x0645,
  2983. afii57446: 0x0646,
  2984. afii57448: 0x0648,
  2985. afii57449: 0x0649,
  2986. afii57450: 0x064A,
  2987. afii57451: 0x064B,
  2988. afii57452: 0x064C,
  2989. afii57453: 0x064D,
  2990. afii57454: 0x064E,
  2991. afii57455: 0x064F,
  2992. afii57456: 0x0650,
  2993. afii57457: 0x0651,
  2994. afii57458: 0x0652,
  2995. afii57470: 0x0647,
  2996. afii57505: 0x06A4,
  2997. afii57506: 0x067E,
  2998. afii57507: 0x0686,
  2999. afii57508: 0x0698,
  3000. afii57509: 0x06AF,
  3001. afii57511: 0x0679,
  3002. afii57512: 0x0688,
  3003. afii57513: 0x0691,
  3004. afii57514: 0x06BA,
  3005. afii57519: 0x06D2,
  3006. afii57534: 0x06D5,
  3007. afii57636: 0x20AA,
  3008. afii57645: 0x05BE,
  3009. afii57658: 0x05C3,
  3010. afii57664: 0x05D0,
  3011. afii57665: 0x05D1,
  3012. afii57666: 0x05D2,
  3013. afii57667: 0x05D3,
  3014. afii57668: 0x05D4,
  3015. afii57669: 0x05D5,
  3016. afii57670: 0x05D6,
  3017. afii57671: 0x05D7,
  3018. afii57672: 0x05D8,
  3019. afii57673: 0x05D9,
  3020. afii57674: 0x05DA,
  3021. afii57675: 0x05DB,
  3022. afii57676: 0x05DC,
  3023. afii57677: 0x05DD,
  3024. afii57678: 0x05DE,
  3025. afii57679: 0x05DF,
  3026. afii57680: 0x05E0,
  3027. afii57681: 0x05E1,
  3028. afii57682: 0x05E2,
  3029. afii57683: 0x05E3,
  3030. afii57684: 0x05E4,
  3031. afii57685: 0x05E5,
  3032. afii57686: 0x05E6,
  3033. afii57687: 0x05E7,
  3034. afii57688: 0x05E8,
  3035. afii57689: 0x05E9,
  3036. afii57690: 0x05EA,
  3037. afii57694: 0xFB2A,
  3038. afii57695: 0xFB2B,
  3039. afii57700: 0xFB4B,
  3040. afii57705: 0xFB1F,
  3041. afii57716: 0x05F0,
  3042. afii57717: 0x05F1,
  3043. afii57718: 0x05F2,
  3044. afii57723: 0xFB35,
  3045. afii57793: 0x05B4,
  3046. afii57794: 0x05B5,
  3047. afii57795: 0x05B6,
  3048. afii57796: 0x05BB,
  3049. afii57797: 0x05B8,
  3050. afii57798: 0x05B7,
  3051. afii57799: 0x05B0,
  3052. afii57800: 0x05B2,
  3053. afii57801: 0x05B1,
  3054. afii57802: 0x05B3,
  3055. afii57803: 0x05C2,
  3056. afii57804: 0x05C1,
  3057. afii57806: 0x05B9,
  3058. afii57807: 0x05BC,
  3059. afii57839: 0x05BD,
  3060. afii57841: 0x05BF,
  3061. afii57842: 0x05C0,
  3062. afii57929: 0x02BC,
  3063. afii61248: 0x2105,
  3064. afii61289: 0x2113,
  3065. afii61352: 0x2116,
  3066. afii61573: 0x202C,
  3067. afii61574: 0x202D,
  3068. afii61575: 0x202E,
  3069. afii61664: 0x200C,
  3070. afii63167: 0x066D,
  3071. afii64937: 0x02BD,
  3072. agrave: 0x00E0,
  3073. agujarati: 0x0A85,
  3074. agurmukhi: 0x0A05,
  3075. ahiragana: 0x3042,
  3076. ahookabove: 0x1EA3,
  3077. aibengali: 0x0990,
  3078. aibopomofo: 0x311E,
  3079. aideva: 0x0910,
  3080. aiecyrillic: 0x04D5,
  3081. aigujarati: 0x0A90,
  3082. aigurmukhi: 0x0A10,
  3083. aimatragurmukhi: 0x0A48,
  3084. ainarabic: 0x0639,
  3085. ainfinalarabic: 0xFECA,
  3086. aininitialarabic: 0xFECB,
  3087. ainmedialarabic: 0xFECC,
  3088. ainvertedbreve: 0x0203,
  3089. aivowelsignbengali: 0x09C8,
  3090. aivowelsigndeva: 0x0948,
  3091. aivowelsigngujarati: 0x0AC8,
  3092. akatakana: 0x30A2,
  3093. akatakanahalfwidth: 0xFF71,
  3094. akorean: 0x314F,
  3095. alef: 0x05D0,
  3096. alefarabic: 0x0627,
  3097. alefdageshhebrew: 0xFB30,
  3098. aleffinalarabic: 0xFE8E,
  3099. alefhamzaabovearabic: 0x0623,
  3100. alefhamzaabovefinalarabic: 0xFE84,
  3101. alefhamzabelowarabic: 0x0625,
  3102. alefhamzabelowfinalarabic: 0xFE88,
  3103. alefhebrew: 0x05D0,
  3104. aleflamedhebrew: 0xFB4F,
  3105. alefmaddaabovearabic: 0x0622,
  3106. alefmaddaabovefinalarabic: 0xFE82,
  3107. alefmaksuraarabic: 0x0649,
  3108. alefmaksurafinalarabic: 0xFEF0,
  3109. alefmaksurainitialarabic: 0xFEF3,
  3110. alefmaksuramedialarabic: 0xFEF4,
  3111. alefpatahhebrew: 0xFB2E,
  3112. alefqamatshebrew: 0xFB2F,
  3113. aleph: 0x2135,
  3114. allequal: 0x224C,
  3115. alpha: 0x03B1,
  3116. alphatonos: 0x03AC,
  3117. amacron: 0x0101,
  3118. amonospace: 0xFF41,
  3119. ampersand: 0x0026,
  3120. ampersandmonospace: 0xFF06,
  3121. ampersandsmall: 0xF726,
  3122. amsquare: 0x33C2,
  3123. anbopomofo: 0x3122,
  3124. angbopomofo: 0x3124,
  3125. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  3126. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  3127. angkhankhuthai: 0x0E5A,
  3128. angle: 0x2220,
  3129. anglebracketleft: 0x3008,
  3130. anglebracketleftvertical: 0xFE3F,
  3131. anglebracketright: 0x3009,
  3132. anglebracketrightvertical: 0xFE40,
  3133. angleleft: 0x2329,
  3134. angleright: 0x232A,
  3135. angstrom: 0x212B,
  3136. anoteleia: 0x0387,
  3137. anudattadeva: 0x0952,
  3138. anusvarabengali: 0x0982,
  3139. anusvaradeva: 0x0902,
  3140. anusvaragujarati: 0x0A82,
  3141. aogonek: 0x0105,
  3142. apaatosquare: 0x3300,
  3143. aparen: 0x249C,
  3144. apostrophearmenian: 0x055A,
  3145. apostrophemod: 0x02BC,
  3146. apple: 0xF8FF,
  3147. approaches: 0x2250,
  3148. approxequal: 0x2248,
  3149. approxequalorimage: 0x2252,
  3150. approximatelyequal: 0x2245,
  3151. araeaekorean: 0x318E,
  3152. araeakorean: 0x318D,
  3153. arc: 0x2312,
  3154. arighthalfring: 0x1E9A,
  3155. aring: 0x00E5,
  3156. aringacute: 0x01FB,
  3157. aringbelow: 0x1E01,
  3158. arrowboth: 0x2194,
  3159. arrowdashdown: 0x21E3,
  3160. arrowdashleft: 0x21E0,
  3161. arrowdashright: 0x21E2,
  3162. arrowdashup: 0x21E1,
  3163. arrowdblboth: 0x21D4,
  3164. arrowdbldown: 0x21D3,
  3165. arrowdblleft: 0x21D0,
  3166. arrowdblright: 0x21D2,
  3167. arrowdblup: 0x21D1,
  3168. arrowdown: 0x2193,
  3169. arrowdownleft: 0x2199,
  3170. arrowdownright: 0x2198,
  3171. arrowdownwhite: 0x21E9,
  3172. arrowheaddownmod: 0x02C5,
  3173. arrowheadleftmod: 0x02C2,
  3174. arrowheadrightmod: 0x02C3,
  3175. arrowheadupmod: 0x02C4,
  3176. arrowhorizex: 0xF8E7,
  3177. arrowleft: 0x2190,
  3178. arrowleftdbl: 0x21D0,
  3179. arrowleftdblstroke: 0x21CD,
  3180. arrowleftoverright: 0x21C6,
  3181. arrowleftwhite: 0x21E6,
  3182. arrowright: 0x2192,
  3183. arrowrightdblstroke: 0x21CF,
  3184. arrowrightheavy: 0x279E,
  3185. arrowrightoverleft: 0x21C4,
  3186. arrowrightwhite: 0x21E8,
  3187. arrowtableft: 0x21E4,
  3188. arrowtabright: 0x21E5,
  3189. arrowup: 0x2191,
  3190. arrowupdn: 0x2195,
  3191. arrowupdnbse: 0x21A8,
  3192. arrowupdownbase: 0x21A8,
  3193. arrowupleft: 0x2196,
  3194. arrowupleftofdown: 0x21C5,
  3195. arrowupright: 0x2197,
  3196. arrowupwhite: 0x21E7,
  3197. arrowvertex: 0xF8E6,
  3198. asciicircum: 0x005E,
  3199. asciicircummonospace: 0xFF3E,
  3200. asciitilde: 0x007E,
  3201. asciitildemonospace: 0xFF5E,
  3202. ascript: 0x0251,
  3203. ascriptturned: 0x0252,
  3204. asmallhiragana: 0x3041,
  3205. asmallkatakana: 0x30A1,
  3206. asmallkatakanahalfwidth: 0xFF67,
  3207. asterisk: 0x002A,
  3208. asteriskaltonearabic: 0x066D,
  3209. asteriskarabic: 0x066D,
  3210. asteriskmath: 0x2217,
  3211. asteriskmonospace: 0xFF0A,
  3212. asterisksmall: 0xFE61,
  3213. asterism: 0x2042,
  3214. asuperior: 0xF6E9,
  3215. asymptoticallyequal: 0x2243,
  3216. at: 0x0040,
  3217. atilde: 0x00E3,
  3218. atmonospace: 0xFF20,
  3219. atsmall: 0xFE6B,
  3220. aturned: 0x0250,
  3221. aubengali: 0x0994,
  3222. aubopomofo: 0x3120,
  3223. audeva: 0x0914,
  3224. augujarati: 0x0A94,
  3225. augurmukhi: 0x0A14,
  3226. aulengthmarkbengali: 0x09D7,
  3227. aumatragurmukhi: 0x0A4C,
  3228. auvowelsignbengali: 0x09CC,
  3229. auvowelsigndeva: 0x094C,
  3230. auvowelsigngujarati: 0x0ACC,
  3231. avagrahadeva: 0x093D,
  3232. aybarmenian: 0x0561,
  3233. ayin: 0x05E2,
  3234. ayinaltonehebrew: 0xFB20,
  3235. ayinhebrew: 0x05E2,
  3236. b: 0x0062,
  3237. babengali: 0x09AC,
  3238. backslash: 0x005C,
  3239. backslashmonospace: 0xFF3C,
  3240. badeva: 0x092C,
  3241. bagujarati: 0x0AAC,
  3242. bagurmukhi: 0x0A2C,
  3243. bahiragana: 0x3070,
  3244. bahtthai: 0x0E3F,
  3245. bakatakana: 0x30D0,
  3246. bar: 0x007C,
  3247. barmonospace: 0xFF5C,
  3248. bbopomofo: 0x3105,
  3249. bcircle: 0x24D1,
  3250. bdotaccent: 0x1E03,
  3251. bdotbelow: 0x1E05,
  3252. beamedsixteenthnotes: 0x266C,
  3253. because: 0x2235,
  3254. becyrillic: 0x0431,
  3255. beharabic: 0x0628,
  3256. behfinalarabic: 0xFE90,
  3257. behinitialarabic: 0xFE91,
  3258. behiragana: 0x3079,
  3259. behmedialarabic: 0xFE92,
  3260. behmeeminitialarabic: 0xFC9F,
  3261. behmeemisolatedarabic: 0xFC08,
  3262. behnoonfinalarabic: 0xFC6D,
  3263. bekatakana: 0x30D9,
  3264. benarmenian: 0x0562,
  3265. bet: 0x05D1,
  3266. beta: 0x03B2,
  3267. betasymbolgreek: 0x03D0,
  3268. betdagesh: 0xFB31,
  3269. betdageshhebrew: 0xFB31,
  3270. bethebrew: 0x05D1,
  3271. betrafehebrew: 0xFB4C,
  3272. bhabengali: 0x09AD,
  3273. bhadeva: 0x092D,
  3274. bhagujarati: 0x0AAD,
  3275. bhagurmukhi: 0x0A2D,
  3276. bhook: 0x0253,
  3277. bihiragana: 0x3073,
  3278. bikatakana: 0x30D3,
  3279. bilabialclick: 0x0298,
  3280. bindigurmukhi: 0x0A02,
  3281. birusquare: 0x3331,
  3282. blackcircle: 0x25CF,
  3283. blackdiamond: 0x25C6,
  3284. blackdownpointingtriangle: 0x25BC,
  3285. blackleftpointingpointer: 0x25C4,
  3286. blackleftpointingtriangle: 0x25C0,
  3287. blacklenticularbracketleft: 0x3010,
  3288. blacklenticularbracketleftvertical: 0xFE3B,
  3289. blacklenticularbracketright: 0x3011,
  3290. blacklenticularbracketrightvertical: 0xFE3C,
  3291. blacklowerlefttriangle: 0x25E3,
  3292. blacklowerrighttriangle: 0x25E2,
  3293. blackrectangle: 0x25AC,
  3294. blackrightpointingpointer: 0x25BA,
  3295. blackrightpointingtriangle: 0x25B6,
  3296. blacksmallsquare: 0x25AA,
  3297. blacksmilingface: 0x263B,
  3298. blacksquare: 0x25A0,
  3299. blackstar: 0x2605,
  3300. blackupperlefttriangle: 0x25E4,
  3301. blackupperrighttriangle: 0x25E5,
  3302. blackuppointingsmalltriangle: 0x25B4,
  3303. blackuppointingtriangle: 0x25B2,
  3304. blank: 0x2423,
  3305. blinebelow: 0x1E07,
  3306. block: 0x2588,
  3307. bmonospace: 0xFF42,
  3308. bobaimaithai: 0x0E1A,
  3309. bohiragana: 0x307C,
  3310. bokatakana: 0x30DC,
  3311. bparen: 0x249D,
  3312. bqsquare: 0x33C3,
  3313. braceex: 0xF8F4,
  3314. braceleft: 0x007B,
  3315. braceleftbt: 0xF8F3,
  3316. braceleftmid: 0xF8F2,
  3317. braceleftmonospace: 0xFF5B,
  3318. braceleftsmall: 0xFE5B,
  3319. bracelefttp: 0xF8F1,
  3320. braceleftvertical: 0xFE37,
  3321. braceright: 0x007D,
  3322. bracerightbt: 0xF8FE,
  3323. bracerightmid: 0xF8FD,
  3324. bracerightmonospace: 0xFF5D,
  3325. bracerightsmall: 0xFE5C,
  3326. bracerighttp: 0xF8FC,
  3327. bracerightvertical: 0xFE38,
  3328. bracketleft: 0x005B,
  3329. bracketleftbt: 0xF8F0,
  3330. bracketleftex: 0xF8EF,
  3331. bracketleftmonospace: 0xFF3B,
  3332. bracketlefttp: 0xF8EE,
  3333. bracketright: 0x005D,
  3334. bracketrightbt: 0xF8FB,
  3335. bracketrightex: 0xF8FA,
  3336. bracketrightmonospace: 0xFF3D,
  3337. bracketrighttp: 0xF8F9,
  3338. breve: 0x02D8,
  3339. brevebelowcmb: 0x032E,
  3340. brevecmb: 0x0306,
  3341. breveinvertedbelowcmb: 0x032F,
  3342. breveinvertedcmb: 0x0311,
  3343. breveinverteddoublecmb: 0x0361,
  3344. bridgebelowcmb: 0x032A,
  3345. bridgeinvertedbelowcmb: 0x033A,
  3346. brokenbar: 0x00A6,
  3347. bstroke: 0x0180,
  3348. bsuperior: 0xF6EA,
  3349. btopbar: 0x0183,
  3350. buhiragana: 0x3076,
  3351. bukatakana: 0x30D6,
  3352. bullet: 0x2022,
  3353. bulletinverse: 0x25D8,
  3354. bulletoperator: 0x2219,
  3355. bullseye: 0x25CE,
  3356. c: 0x0063,
  3357. caarmenian: 0x056E,
  3358. cabengali: 0x099A,
  3359. cacute: 0x0107,
  3360. cadeva: 0x091A,
  3361. cagujarati: 0x0A9A,
  3362. cagurmukhi: 0x0A1A,
  3363. calsquare: 0x3388,
  3364. candrabindubengali: 0x0981,
  3365. candrabinducmb: 0x0310,
  3366. candrabindudeva: 0x0901,
  3367. candrabindugujarati: 0x0A81,
  3368. capslock: 0x21EA,
  3369. careof: 0x2105,
  3370. caron: 0x02C7,
  3371. caronbelowcmb: 0x032C,
  3372. caroncmb: 0x030C,
  3373. carriagereturn: 0x21B5,
  3374. cbopomofo: 0x3118,
  3375. ccaron: 0x010D,
  3376. ccedilla: 0x00E7,
  3377. ccedillaacute: 0x1E09,
  3378. ccircle: 0x24D2,
  3379. ccircumflex: 0x0109,
  3380. ccurl: 0x0255,
  3381. cdot: 0x010B,
  3382. cdotaccent: 0x010B,
  3383. cdsquare: 0x33C5,
  3384. cedilla: 0x00B8,
  3385. cedillacmb: 0x0327,
  3386. cent: 0x00A2,
  3387. centigrade: 0x2103,
  3388. centinferior: 0xF6DF,
  3389. centmonospace: 0xFFE0,
  3390. centoldstyle: 0xF7A2,
  3391. centsuperior: 0xF6E0,
  3392. chaarmenian: 0x0579,
  3393. chabengali: 0x099B,
  3394. chadeva: 0x091B,
  3395. chagujarati: 0x0A9B,
  3396. chagurmukhi: 0x0A1B,
  3397. chbopomofo: 0x3114,
  3398. cheabkhasiancyrillic: 0x04BD,
  3399. checkmark: 0x2713,
  3400. checyrillic: 0x0447,
  3401. chedescenderabkhasiancyrillic: 0x04BF,
  3402. chedescendercyrillic: 0x04B7,
  3403. chedieresiscyrillic: 0x04F5,
  3404. cheharmenian: 0x0573,
  3405. chekhakassiancyrillic: 0x04CC,
  3406. cheverticalstrokecyrillic: 0x04B9,
  3407. chi: 0x03C7,
  3408. chieuchacirclekorean: 0x3277,
  3409. chieuchaparenkorean: 0x3217,
  3410. chieuchcirclekorean: 0x3269,
  3411. chieuchkorean: 0x314A,
  3412. chieuchparenkorean: 0x3209,
  3413. chochangthai: 0x0E0A,
  3414. chochanthai: 0x0E08,
  3415. chochingthai: 0x0E09,
  3416. chochoethai: 0x0E0C,
  3417. chook: 0x0188,
  3418. cieucacirclekorean: 0x3276,
  3419. cieucaparenkorean: 0x3216,
  3420. cieuccirclekorean: 0x3268,
  3421. cieuckorean: 0x3148,
  3422. cieucparenkorean: 0x3208,
  3423. cieucuparenkorean: 0x321C,
  3424. circle: 0x25CB,
  3425. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  3426. circlemultiply: 0x2297,
  3427. circleot: 0x2299,
  3428. circleplus: 0x2295,
  3429. circlepostalmark: 0x3036,
  3430. circlewithlefthalfblack: 0x25D0,
  3431. circlewithrighthalfblack: 0x25D1,
  3432. circumflex: 0x02C6,
  3433. circumflexbelowcmb: 0x032D,
  3434. circumflexcmb: 0x0302,
  3435. clear: 0x2327,
  3436. clickalveolar: 0x01C2,
  3437. clickdental: 0x01C0,
  3438. clicklateral: 0x01C1,
  3439. clickretroflex: 0x01C3,
  3440. club: 0x2663,
  3441. clubsuitblack: 0x2663,
  3442. clubsuitwhite: 0x2667,
  3443. cmcubedsquare: 0x33A4,
  3444. cmonospace: 0xFF43,
  3445. cmsquaredsquare: 0x33A0,
  3446. coarmenian: 0x0581,
  3447. colon: 0x003A,
  3448. colonmonetary: 0x20A1,
  3449. colonmonospace: 0xFF1A,
  3450. colonsign: 0x20A1,
  3451. colonsmall: 0xFE55,
  3452. colontriangularhalfmod: 0x02D1,
  3453. colontriangularmod: 0x02D0,
  3454. comma: 0x002C,
  3455. commaabovecmb: 0x0313,
  3456. commaaboverightcmb: 0x0315,
  3457. commaaccent: 0xF6C3,
  3458. commaarabic: 0x060C,
  3459. commaarmenian: 0x055D,
  3460. commainferior: 0xF6E1,
  3461. commamonospace: 0xFF0C,
  3462. commareversedabovecmb: 0x0314,
  3463. commareversedmod: 0x02BD,
  3464. commasmall: 0xFE50,
  3465. commasuperior: 0xF6E2,
  3466. commaturnedabovecmb: 0x0312,
  3467. commaturnedmod: 0x02BB,
  3468. compass: 0x263C,
  3469. congruent: 0x2245,
  3470. contourintegral: 0x222E,
  3471. control: 0x2303,
  3472. controlACK: 0x0006,
  3473. controlBEL: 0x0007,
  3474. controlBS: 0x0008,
  3475. controlCAN: 0x0018,
  3476. controlCR: 0x000D,
  3477. controlDC1: 0x0011,
  3478. controlDC2: 0x0012,
  3479. controlDC3: 0x0013,
  3480. controlDC4: 0x0014,
  3481. controlDEL: 0x007F,
  3482. controlDLE: 0x0010,
  3483. controlEM: 0x0019,
  3484. controlENQ: 0x0005,
  3485. controlEOT: 0x0004,
  3486. controlESC: 0x001B,
  3487. controlETB: 0x0017,
  3488. controlETX: 0x0003,
  3489. controlFF: 0x000C,
  3490. controlFS: 0x001C,
  3491. controlGS: 0x001D,
  3492. controlHT: 0x0009,
  3493. controlLF: 0x000A,
  3494. controlNAK: 0x0015,
  3495. controlRS: 0x001E,
  3496. controlSI: 0x000F,
  3497. controlSO: 0x000E,
  3498. controlSOT: 0x0002,
  3499. controlSTX: 0x0001,
  3500. controlSUB: 0x001A,
  3501. controlSYN: 0x0016,
  3502. controlUS: 0x001F,
  3503. controlVT: 0x000B,
  3504. copyright: 0x00A9,
  3505. copyrightsans: 0xF8E9,
  3506. copyrightserif: 0xF6D9,
  3507. cornerbracketleft: 0x300C,
  3508. cornerbracketlefthalfwidth: 0xFF62,
  3509. cornerbracketleftvertical: 0xFE41,
  3510. cornerbracketright: 0x300D,
  3511. cornerbracketrighthalfwidth: 0xFF63,
  3512. cornerbracketrightvertical: 0xFE42,
  3513. corporationsquare: 0x337F,
  3514. cosquare: 0x33C7,
  3515. coverkgsquare: 0x33C6,
  3516. cparen: 0x249E,
  3517. cruzeiro: 0x20A2,
  3518. cstretched: 0x0297,
  3519. curlyand: 0x22CF,
  3520. curlyor: 0x22CE,
  3521. currency: 0x00A4,
  3522. cyrBreve: 0xF6D1,
  3523. cyrFlex: 0xF6D2,
  3524. cyrbreve: 0xF6D4,
  3525. cyrflex: 0xF6D5,
  3526. d: 0x0064,
  3527. daarmenian: 0x0564,
  3528. dabengali: 0x09A6,
  3529. dadarabic: 0x0636,
  3530. dadeva: 0x0926,
  3531. dadfinalarabic: 0xFEBE,
  3532. dadinitialarabic: 0xFEBF,
  3533. dadmedialarabic: 0xFEC0,
  3534. dagesh: 0x05BC,
  3535. dageshhebrew: 0x05BC,
  3536. dagger: 0x2020,
  3537. daggerdbl: 0x2021,
  3538. dagujarati: 0x0AA6,
  3539. dagurmukhi: 0x0A26,
  3540. dahiragana: 0x3060,
  3541. dakatakana: 0x30C0,
  3542. dalarabic: 0x062F,
  3543. dalet: 0x05D3,
  3544. daletdagesh: 0xFB33,
  3545. daletdageshhebrew: 0xFB33,
  3546. dalethebrew: 0x05D3,
  3547. dalfinalarabic: 0xFEAA,
  3548. dammaarabic: 0x064F,
  3549. dammalowarabic: 0x064F,
  3550. dammatanaltonearabic: 0x064C,
  3551. dammatanarabic: 0x064C,
  3552. danda: 0x0964,
  3553. dargahebrew: 0x05A7,
  3554. dargalefthebrew: 0x05A7,
  3555. dasiapneumatacyrilliccmb: 0x0485,
  3556. dblGrave: 0xF6D3,
  3557. dblanglebracketleft: 0x300A,
  3558. dblanglebracketleftvertical: 0xFE3D,
  3559. dblanglebracketright: 0x300B,
  3560. dblanglebracketrightvertical: 0xFE3E,
  3561. dblarchinvertedbelowcmb: 0x032B,
  3562. dblarrowleft: 0x21D4,
  3563. dblarrowright: 0x21D2,
  3564. dbldanda: 0x0965,
  3565. dblgrave: 0xF6D6,
  3566. dblgravecmb: 0x030F,
  3567. dblintegral: 0x222C,
  3568. dbllowline: 0x2017,
  3569. dbllowlinecmb: 0x0333,
  3570. dbloverlinecmb: 0x033F,
  3571. dblprimemod: 0x02BA,
  3572. dblverticalbar: 0x2016,
  3573. dblverticallineabovecmb: 0x030E,
  3574. dbopomofo: 0x3109,
  3575. dbsquare: 0x33C8,
  3576. dcaron: 0x010F,
  3577. dcedilla: 0x1E11,
  3578. dcircle: 0x24D3,
  3579. dcircumflexbelow: 0x1E13,
  3580. dcroat: 0x0111,
  3581. ddabengali: 0x09A1,
  3582. ddadeva: 0x0921,
  3583. ddagujarati: 0x0AA1,
  3584. ddagurmukhi: 0x0A21,
  3585. ddalarabic: 0x0688,
  3586. ddalfinalarabic: 0xFB89,
  3587. dddhadeva: 0x095C,
  3588. ddhabengali: 0x09A2,
  3589. ddhadeva: 0x0922,
  3590. ddhagujarati: 0x0AA2,
  3591. ddhagurmukhi: 0x0A22,
  3592. ddotaccent: 0x1E0B,
  3593. ddotbelow: 0x1E0D,
  3594. decimalseparatorarabic: 0x066B,
  3595. decimalseparatorpersian: 0x066B,
  3596. decyrillic: 0x0434,
  3597. degree: 0x00B0,
  3598. dehihebrew: 0x05AD,
  3599. dehiragana: 0x3067,
  3600. deicoptic: 0x03EF,
  3601. dekatakana: 0x30C7,
  3602. deleteleft: 0x232B,
  3603. deleteright: 0x2326,
  3604. delta: 0x03B4,
  3605. deltaturned: 0x018D,
  3606. denominatorminusonenumeratorbengali: 0x09F8,
  3607. dezh: 0x02A4,
  3608. dhabengali: 0x09A7,
  3609. dhadeva: 0x0927,
  3610. dhagujarati: 0x0AA7,
  3611. dhagurmukhi: 0x0A27,
  3612. dhook: 0x0257,
  3613. dialytikatonos: 0x0385,
  3614. dialytikatonoscmb: 0x0344,
  3615. diamond: 0x2666,
  3616. diamondsuitwhite: 0x2662,
  3617. dieresis: 0x00A8,
  3618. dieresisacute: 0xF6D7,
  3619. dieresisbelowcmb: 0x0324,
  3620. dieresiscmb: 0x0308,
  3621. dieresisgrave: 0xF6D8,
  3622. dieresistonos: 0x0385,
  3623. dihiragana: 0x3062,
  3624. dikatakana: 0x30C2,
  3625. dittomark: 0x3003,
  3626. divide: 0x00F7,
  3627. divides: 0x2223,
  3628. divisionslash: 0x2215,
  3629. djecyrillic: 0x0452,
  3630. dkshade: 0x2593,
  3631. dlinebelow: 0x1E0F,
  3632. dlsquare: 0x3397,
  3633. dmacron: 0x0111,
  3634. dmonospace: 0xFF44,
  3635. dnblock: 0x2584,
  3636. dochadathai: 0x0E0E,
  3637. dodekthai: 0x0E14,
  3638. dohiragana: 0x3069,
  3639. dokatakana: 0x30C9,
  3640. dollar: 0x0024,
  3641. dollarinferior: 0xF6E3,
  3642. dollarmonospace: 0xFF04,
  3643. dollaroldstyle: 0xF724,
  3644. dollarsmall: 0xFE69,
  3645. dollarsuperior: 0xF6E4,
  3646. dong: 0x20AB,
  3647. dorusquare: 0x3326,
  3648. dotaccent: 0x02D9,
  3649. dotaccentcmb: 0x0307,
  3650. dotbelowcmb: 0x0323,
  3651. dotbelowcomb: 0x0323,
  3652. dotkatakana: 0x30FB,
  3653. dotlessi: 0x0131,
  3654. dotlessj: 0xF6BE,
  3655. dotlessjstrokehook: 0x0284,
  3656. dotmath: 0x22C5,
  3657. dottedcircle: 0x25CC,
  3658. doubleyodpatah: 0xFB1F,
  3659. doubleyodpatahhebrew: 0xFB1F,
  3660. downtackbelowcmb: 0x031E,
  3661. downtackmod: 0x02D5,
  3662. dparen: 0x249F,
  3663. dsuperior: 0xF6EB,
  3664. dtail: 0x0256,
  3665. dtopbar: 0x018C,
  3666. duhiragana: 0x3065,
  3667. dukatakana: 0x30C5,
  3668. dz: 0x01F3,
  3669. dzaltone: 0x02A3,
  3670. dzcaron: 0x01C6,
  3671. dzcurl: 0x02A5,
  3672. dzeabkhasiancyrillic: 0x04E1,
  3673. dzecyrillic: 0x0455,
  3674. dzhecyrillic: 0x045F,
  3675. e: 0x0065,
  3676. eacute: 0x00E9,
  3677. earth: 0x2641,
  3678. ebengali: 0x098F,
  3679. ebopomofo: 0x311C,
  3680. ebreve: 0x0115,
  3681. ecandradeva: 0x090D,
  3682. ecandragujarati: 0x0A8D,
  3683. ecandravowelsigndeva: 0x0945,
  3684. ecandravowelsigngujarati: 0x0AC5,
  3685. ecaron: 0x011B,
  3686. ecedillabreve: 0x1E1D,
  3687. echarmenian: 0x0565,
  3688. echyiwnarmenian: 0x0587,
  3689. ecircle: 0x24D4,
  3690. ecircumflex: 0x00EA,
  3691. ecircumflexacute: 0x1EBF,
  3692. ecircumflexbelow: 0x1E19,
  3693. ecircumflexdotbelow: 0x1EC7,
  3694. ecircumflexgrave: 0x1EC1,
  3695. ecircumflexhookabove: 0x1EC3,
  3696. ecircumflextilde: 0x1EC5,
  3697. ecyrillic: 0x0454,
  3698. edblgrave: 0x0205,
  3699. edeva: 0x090F,
  3700. edieresis: 0x00EB,
  3701. edot: 0x0117,
  3702. edotaccent: 0x0117,
  3703. edotbelow: 0x1EB9,
  3704. eegurmukhi: 0x0A0F,
  3705. eematragurmukhi: 0x0A47,
  3706. efcyrillic: 0x0444,
  3707. egrave: 0x00E8,
  3708. egujarati: 0x0A8F,
  3709. eharmenian: 0x0567,
  3710. ehbopomofo: 0x311D,
  3711. ehiragana: 0x3048,
  3712. ehookabove: 0x1EBB,
  3713. eibopomofo: 0x311F,
  3714. eight: 0x0038,
  3715. eightarabic: 0x0668,
  3716. eightbengali: 0x09EE,
  3717. eightcircle: 0x2467,
  3718. eightcircleinversesansserif: 0x2791,
  3719. eightdeva: 0x096E,
  3720. eighteencircle: 0x2471,
  3721. eighteenparen: 0x2485,
  3722. eighteenperiod: 0x2499,
  3723. eightgujarati: 0x0AEE,
  3724. eightgurmukhi: 0x0A6E,
  3725. eighthackarabic: 0x0668,
  3726. eighthangzhou: 0x3028,
  3727. eighthnotebeamed: 0x266B,
  3728. eightideographicparen: 0x3227,
  3729. eightinferior: 0x2088,
  3730. eightmonospace: 0xFF18,
  3731. eightoldstyle: 0xF738,
  3732. eightparen: 0x247B,
  3733. eightperiod: 0x248F,
  3734. eightpersian: 0x06F8,
  3735. eightroman: 0x2177,
  3736. eightsuperior: 0x2078,
  3737. eightthai: 0x0E58,
  3738. einvertedbreve: 0x0207,
  3739. eiotifiedcyrillic: 0x0465,
  3740. ekatakana: 0x30A8,
  3741. ekatakanahalfwidth: 0xFF74,
  3742. ekonkargurmukhi: 0x0A74,
  3743. ekorean: 0x3154,
  3744. elcyrillic: 0x043B,
  3745. element: 0x2208,
  3746. elevencircle: 0x246A,
  3747. elevenparen: 0x247E,
  3748. elevenperiod: 0x2492,
  3749. elevenroman: 0x217A,
  3750. ellipsis: 0x2026,
  3751. ellipsisvertical: 0x22EE,
  3752. emacron: 0x0113,
  3753. emacronacute: 0x1E17,
  3754. emacrongrave: 0x1E15,
  3755. emcyrillic: 0x043C,
  3756. emdash: 0x2014,
  3757. emdashvertical: 0xFE31,
  3758. emonospace: 0xFF45,
  3759. emphasismarkarmenian: 0x055B,
  3760. emptyset: 0x2205,
  3761. enbopomofo: 0x3123,
  3762. encyrillic: 0x043D,
  3763. endash: 0x2013,
  3764. endashvertical: 0xFE32,
  3765. endescendercyrillic: 0x04A3,
  3766. eng: 0x014B,
  3767. engbopomofo: 0x3125,
  3768. enghecyrillic: 0x04A5,
  3769. enhookcyrillic: 0x04C8,
  3770. enspace: 0x2002,
  3771. eogonek: 0x0119,
  3772. eokorean: 0x3153,
  3773. eopen: 0x025B,
  3774. eopenclosed: 0x029A,
  3775. eopenreversed: 0x025C,
  3776. eopenreversedclosed: 0x025E,
  3777. eopenreversedhook: 0x025D,
  3778. eparen: 0x24A0,
  3779. epsilon: 0x03B5,
  3780. epsilontonos: 0x03AD,
  3781. equal: 0x003D,
  3782. equalmonospace: 0xFF1D,
  3783. equalsmall: 0xFE66,
  3784. equalsuperior: 0x207C,
  3785. equivalence: 0x2261,
  3786. erbopomofo: 0x3126,
  3787. ercyrillic: 0x0440,
  3788. ereversed: 0x0258,
  3789. ereversedcyrillic: 0x044D,
  3790. escyrillic: 0x0441,
  3791. esdescendercyrillic: 0x04AB,
  3792. esh: 0x0283,
  3793. eshcurl: 0x0286,
  3794. eshortdeva: 0x090E,
  3795. eshortvowelsigndeva: 0x0946,
  3796. eshreversedloop: 0x01AA,
  3797. eshsquatreversed: 0x0285,
  3798. esmallhiragana: 0x3047,
  3799. esmallkatakana: 0x30A7,
  3800. esmallkatakanahalfwidth: 0xFF6A,
  3801. estimated: 0x212E,
  3802. esuperior: 0xF6EC,
  3803. eta: 0x03B7,
  3804. etarmenian: 0x0568,
  3805. etatonos: 0x03AE,
  3806. eth: 0x00F0,
  3807. etilde: 0x1EBD,
  3808. etildebelow: 0x1E1B,
  3809. etnahtafoukhhebrew: 0x0591,
  3810. etnahtafoukhlefthebrew: 0x0591,
  3811. etnahtahebrew: 0x0591,
  3812. etnahtalefthebrew: 0x0591,
  3813. eturned: 0x01DD,
  3814. eukorean: 0x3161,
  3815. euro: 0x20AC,
  3816. evowelsignbengali: 0x09C7,
  3817. evowelsigndeva: 0x0947,
  3818. evowelsigngujarati: 0x0AC7,
  3819. exclam: 0x0021,
  3820. exclamarmenian: 0x055C,
  3821. exclamdbl: 0x203C,
  3822. exclamdown: 0x00A1,
  3823. exclamdownsmall: 0xF7A1,
  3824. exclammonospace: 0xFF01,
  3825. exclamsmall: 0xF721,
  3826. existential: 0x2203,
  3827. ezh: 0x0292,
  3828. ezhcaron: 0x01EF,
  3829. ezhcurl: 0x0293,
  3830. ezhreversed: 0x01B9,
  3831. ezhtail: 0x01BA,
  3832. f: 0x0066,
  3833. fadeva: 0x095E,
  3834. fagurmukhi: 0x0A5E,
  3835. fahrenheit: 0x2109,
  3836. fathaarabic: 0x064E,
  3837. fathalowarabic: 0x064E,
  3838. fathatanarabic: 0x064B,
  3839. fbopomofo: 0x3108,
  3840. fcircle: 0x24D5,
  3841. fdotaccent: 0x1E1F,
  3842. feharabic: 0x0641,
  3843. feharmenian: 0x0586,
  3844. fehfinalarabic: 0xFED2,
  3845. fehinitialarabic: 0xFED3,
  3846. fehmedialarabic: 0xFED4,
  3847. feicoptic: 0x03E5,
  3848. female: 0x2640,
  3849. ff: 0xFB00,
  3850. ffi: 0xFB03,
  3851. ffl: 0xFB04,
  3852. fi: 0xFB01,
  3853. fifteencircle: 0x246E,
  3854. fifteenparen: 0x2482,
  3855. fifteenperiod: 0x2496,
  3856. figuredash: 0x2012,
  3857. filledbox: 0x25A0,
  3858. filledrect: 0x25AC,
  3859. finalkaf: 0x05DA,
  3860. finalkafdagesh: 0xFB3A,
  3861. finalkafdageshhebrew: 0xFB3A,
  3862. finalkafhebrew: 0x05DA,
  3863. finalmem: 0x05DD,
  3864. finalmemhebrew: 0x05DD,
  3865. finalnun: 0x05DF,
  3866. finalnunhebrew: 0x05DF,
  3867. finalpe: 0x05E3,
  3868. finalpehebrew: 0x05E3,
  3869. finaltsadi: 0x05E5,
  3870. finaltsadihebrew: 0x05E5,
  3871. firsttonechinese: 0x02C9,
  3872. fisheye: 0x25C9,
  3873. fitacyrillic: 0x0473,
  3874. five: 0x0035,
  3875. fivearabic: 0x0665,
  3876. fivebengali: 0x09EB,
  3877. fivecircle: 0x2464,
  3878. fivecircleinversesansserif: 0x278E,
  3879. fivedeva: 0x096B,
  3880. fiveeighths: 0x215D,
  3881. fivegujarati: 0x0AEB,
  3882. fivegurmukhi: 0x0A6B,
  3883. fivehackarabic: 0x0665,
  3884. fivehangzhou: 0x3025,
  3885. fiveideographicparen: 0x3224,
  3886. fiveinferior: 0x2085,
  3887. fivemonospace: 0xFF15,
  3888. fiveoldstyle: 0xF735,
  3889. fiveparen: 0x2478,
  3890. fiveperiod: 0x248C,
  3891. fivepersian: 0x06F5,
  3892. fiveroman: 0x2174,
  3893. fivesuperior: 0x2075,
  3894. fivethai: 0x0E55,
  3895. fl: 0xFB02,
  3896. florin: 0x0192,
  3897. fmonospace: 0xFF46,
  3898. fmsquare: 0x3399,
  3899. fofanthai: 0x0E1F,
  3900. fofathai: 0x0E1D,
  3901. fongmanthai: 0x0E4F,
  3902. forall: 0x2200,
  3903. four: 0x0034,
  3904. fourarabic: 0x0664,
  3905. fourbengali: 0x09EA,
  3906. fourcircle: 0x2463,
  3907. fourcircleinversesansserif: 0x278D,
  3908. fourdeva: 0x096A,
  3909. fourgujarati: 0x0AEA,
  3910. fourgurmukhi: 0x0A6A,
  3911. fourhackarabic: 0x0664,
  3912. fourhangzhou: 0x3024,
  3913. fourideographicparen: 0x3223,
  3914. fourinferior: 0x2084,
  3915. fourmonospace: 0xFF14,
  3916. fournumeratorbengali: 0x09F7,
  3917. fouroldstyle: 0xF734,
  3918. fourparen: 0x2477,
  3919. fourperiod: 0x248B,
  3920. fourpersian: 0x06F4,
  3921. fourroman: 0x2173,
  3922. foursuperior: 0x2074,
  3923. fourteencircle: 0x246D,
  3924. fourteenparen: 0x2481,
  3925. fourteenperiod: 0x2495,
  3926. fourthai: 0x0E54,
  3927. fourthtonechinese: 0x02CB,
  3928. fparen: 0x24A1,
  3929. fraction: 0x2044,
  3930. franc: 0x20A3,
  3931. g: 0x0067,
  3932. gabengali: 0x0997,
  3933. gacute: 0x01F5,
  3934. gadeva: 0x0917,
  3935. gafarabic: 0x06AF,
  3936. gaffinalarabic: 0xFB93,
  3937. gafinitialarabic: 0xFB94,
  3938. gafmedialarabic: 0xFB95,
  3939. gagujarati: 0x0A97,
  3940. gagurmukhi: 0x0A17,
  3941. gahiragana: 0x304C,
  3942. gakatakana: 0x30AC,
  3943. gamma: 0x03B3,
  3944. gammalatinsmall: 0x0263,
  3945. gammasuperior: 0x02E0,
  3946. gangiacoptic: 0x03EB,
  3947. gbopomofo: 0x310D,
  3948. gbreve: 0x011F,
  3949. gcaron: 0x01E7,
  3950. gcedilla: 0x0123,
  3951. gcircle: 0x24D6,
  3952. gcircumflex: 0x011D,
  3953. gcommaaccent: 0x0123,
  3954. gdot: 0x0121,
  3955. gdotaccent: 0x0121,
  3956. gecyrillic: 0x0433,
  3957. gehiragana: 0x3052,
  3958. gekatakana: 0x30B2,
  3959. geometricallyequal: 0x2251,
  3960. gereshaccenthebrew: 0x059C,
  3961. gereshhebrew: 0x05F3,
  3962. gereshmuqdamhebrew: 0x059D,
  3963. germandbls: 0x00DF,
  3964. gershayimaccenthebrew: 0x059E,
  3965. gershayimhebrew: 0x05F4,
  3966. getamark: 0x3013,
  3967. ghabengali: 0x0998,
  3968. ghadarmenian: 0x0572,
  3969. ghadeva: 0x0918,
  3970. ghagujarati: 0x0A98,
  3971. ghagurmukhi: 0x0A18,
  3972. ghainarabic: 0x063A,
  3973. ghainfinalarabic: 0xFECE,
  3974. ghaininitialarabic: 0xFECF,
  3975. ghainmedialarabic: 0xFED0,
  3976. ghemiddlehookcyrillic: 0x0495,
  3977. ghestrokecyrillic: 0x0493,
  3978. gheupturncyrillic: 0x0491,
  3979. ghhadeva: 0x095A,
  3980. ghhagurmukhi: 0x0A5A,
  3981. ghook: 0x0260,
  3982. ghzsquare: 0x3393,
  3983. gihiragana: 0x304E,
  3984. gikatakana: 0x30AE,
  3985. gimarmenian: 0x0563,
  3986. gimel: 0x05D2,
  3987. gimeldagesh: 0xFB32,
  3988. gimeldageshhebrew: 0xFB32,
  3989. gimelhebrew: 0x05D2,
  3990. gjecyrillic: 0x0453,
  3991. glottalinvertedstroke: 0x01BE,
  3992. glottalstop: 0x0294,
  3993. glottalstopinverted: 0x0296,
  3994. glottalstopmod: 0x02C0,
  3995. glottalstopreversed: 0x0295,
  3996. glottalstopreversedmod: 0x02C1,
  3997. glottalstopreversedsuperior: 0x02E4,
  3998. glottalstopstroke: 0x02A1,
  3999. glottalstopstrokereversed: 0x02A2,
  4000. gmacron: 0x1E21,
  4001. gmonospace: 0xFF47,
  4002. gohiragana: 0x3054,
  4003. gokatakana: 0x30B4,
  4004. gparen: 0x24A2,
  4005. gpasquare: 0x33AC,
  4006. gradient: 0x2207,
  4007. grave: 0x0060,
  4008. gravebelowcmb: 0x0316,
  4009. gravecmb: 0x0300,
  4010. gravecomb: 0x0300,
  4011. gravedeva: 0x0953,
  4012. gravelowmod: 0x02CE,
  4013. gravemonospace: 0xFF40,
  4014. gravetonecmb: 0x0340,
  4015. greater: 0x003E,
  4016. greaterequal: 0x2265,
  4017. greaterequalorless: 0x22DB,
  4018. greatermonospace: 0xFF1E,
  4019. greaterorequivalent: 0x2273,
  4020. greaterorless: 0x2277,
  4021. greateroverequal: 0x2267,
  4022. greatersmall: 0xFE65,
  4023. gscript: 0x0261,
  4024. gstroke: 0x01E5,
  4025. guhiragana: 0x3050,
  4026. guillemotleft: 0x00AB,
  4027. guillemotright: 0x00BB,
  4028. guilsinglleft: 0x2039,
  4029. guilsinglright: 0x203A,
  4030. gukatakana: 0x30B0,
  4031. guramusquare: 0x3318,
  4032. gysquare: 0x33C9,
  4033. h: 0x0068,
  4034. haabkhasiancyrillic: 0x04A9,
  4035. haaltonearabic: 0x06C1,
  4036. habengali: 0x09B9,
  4037. hadescendercyrillic: 0x04B3,
  4038. hadeva: 0x0939,
  4039. hagujarati: 0x0AB9,
  4040. hagurmukhi: 0x0A39,
  4041. haharabic: 0x062D,
  4042. hahfinalarabic: 0xFEA2,
  4043. hahinitialarabic: 0xFEA3,
  4044. hahiragana: 0x306F,
  4045. hahmedialarabic: 0xFEA4,
  4046. haitusquare: 0x332A,
  4047. hakatakana: 0x30CF,
  4048. hakatakanahalfwidth: 0xFF8A,
  4049. halantgurmukhi: 0x0A4D,
  4050. hamzaarabic: 0x0621,
  4051. hamzalowarabic: 0x0621,
  4052. hangulfiller: 0x3164,
  4053. hardsigncyrillic: 0x044A,
  4054. harpoonleftbarbup: 0x21BC,
  4055. harpoonrightbarbup: 0x21C0,
  4056. hasquare: 0x33CA,
  4057. hatafpatah: 0x05B2,
  4058. hatafpatah16: 0x05B2,
  4059. hatafpatah23: 0x05B2,
  4060. hatafpatah2f: 0x05B2,
  4061. hatafpatahhebrew: 0x05B2,
  4062. hatafpatahnarrowhebrew: 0x05B2,
  4063. hatafpatahquarterhebrew: 0x05B2,
  4064. hatafpatahwidehebrew: 0x05B2,
  4065. hatafqamats: 0x05B3,
  4066. hatafqamats1b: 0x05B3,
  4067. hatafqamats28: 0x05B3,
  4068. hatafqamats34: 0x05B3,
  4069. hatafqamatshebrew: 0x05B3,
  4070. hatafqamatsnarrowhebrew: 0x05B3,
  4071. hatafqamatsquarterhebrew: 0x05B3,
  4072. hatafqamatswidehebrew: 0x05B3,
  4073. hatafsegol: 0x05B1,
  4074. hatafsegol17: 0x05B1,
  4075. hatafsegol24: 0x05B1,
  4076. hatafsegol30: 0x05B1,
  4077. hatafsegolhebrew: 0x05B1,
  4078. hatafsegolnarrowhebrew: 0x05B1,
  4079. hatafsegolquarterhebrew: 0x05B1,
  4080. hatafsegolwidehebrew: 0x05B1,
  4081. hbar: 0x0127,
  4082. hbopomofo: 0x310F,
  4083. hbrevebelow: 0x1E2B,
  4084. hcedilla: 0x1E29,
  4085. hcircle: 0x24D7,
  4086. hcircumflex: 0x0125,
  4087. hdieresis: 0x1E27,
  4088. hdotaccent: 0x1E23,
  4089. hdotbelow: 0x1E25,
  4090. he: 0x05D4,
  4091. heart: 0x2665,
  4092. heartsuitblack: 0x2665,
  4093. heartsuitwhite: 0x2661,
  4094. hedagesh: 0xFB34,
  4095. hedageshhebrew: 0xFB34,
  4096. hehaltonearabic: 0x06C1,
  4097. heharabic: 0x0647,
  4098. hehebrew: 0x05D4,
  4099. hehfinalaltonearabic: 0xFBA7,
  4100. hehfinalalttwoarabic: 0xFEEA,
  4101. hehfinalarabic: 0xFEEA,
  4102. hehhamzaabovefinalarabic: 0xFBA5,
  4103. hehhamzaaboveisolatedarabic: 0xFBA4,
  4104. hehinitialaltonearabic: 0xFBA8,
  4105. hehinitialarabic: 0xFEEB,
  4106. hehiragana: 0x3078,
  4107. hehmedialaltonearabic: 0xFBA9,
  4108. hehmedialarabic: 0xFEEC,
  4109. heiseierasquare: 0x337B,
  4110. hekatakana: 0x30D8,
  4111. hekatakanahalfwidth: 0xFF8D,
  4112. hekutaarusquare: 0x3336,
  4113. henghook: 0x0267,
  4114. herutusquare: 0x3339,
  4115. het: 0x05D7,
  4116. hethebrew: 0x05D7,
  4117. hhook: 0x0266,
  4118. hhooksuperior: 0x02B1,
  4119. hieuhacirclekorean: 0x327B,
  4120. hieuhaparenkorean: 0x321B,
  4121. hieuhcirclekorean: 0x326D,
  4122. hieuhkorean: 0x314E,
  4123. hieuhparenkorean: 0x320D,
  4124. hihiragana: 0x3072,
  4125. hikatakana: 0x30D2,
  4126. hikatakanahalfwidth: 0xFF8B,
  4127. hiriq: 0x05B4,
  4128. hiriq14: 0x05B4,
  4129. hiriq21: 0x05B4,
  4130. hiriq2d: 0x05B4,
  4131. hiriqhebrew: 0x05B4,
  4132. hiriqnarrowhebrew: 0x05B4,
  4133. hiriqquarterhebrew: 0x05B4,
  4134. hiriqwidehebrew: 0x05B4,
  4135. hlinebelow: 0x1E96,
  4136. hmonospace: 0xFF48,
  4137. hoarmenian: 0x0570,
  4138. hohipthai: 0x0E2B,
  4139. hohiragana: 0x307B,
  4140. hokatakana: 0x30DB,
  4141. hokatakanahalfwidth: 0xFF8E,
  4142. holam: 0x05B9,
  4143. holam19: 0x05B9,
  4144. holam26: 0x05B9,
  4145. holam32: 0x05B9,
  4146. holamhebrew: 0x05B9,
  4147. holamnarrowhebrew: 0x05B9,
  4148. holamquarterhebrew: 0x05B9,
  4149. holamwidehebrew: 0x05B9,
  4150. honokhukthai: 0x0E2E,
  4151. hookabovecomb: 0x0309,
  4152. hookcmb: 0x0309,
  4153. hookpalatalizedbelowcmb: 0x0321,
  4154. hookretroflexbelowcmb: 0x0322,
  4155. hoonsquare: 0x3342,
  4156. horicoptic: 0x03E9,
  4157. horizontalbar: 0x2015,
  4158. horncmb: 0x031B,
  4159. hotsprings: 0x2668,
  4160. house: 0x2302,
  4161. hparen: 0x24A3,
  4162. hsuperior: 0x02B0,
  4163. hturned: 0x0265,
  4164. huhiragana: 0x3075,
  4165. huiitosquare: 0x3333,
  4166. hukatakana: 0x30D5,
  4167. hukatakanahalfwidth: 0xFF8C,
  4168. hungarumlaut: 0x02DD,
  4169. hungarumlautcmb: 0x030B,
  4170. hv: 0x0195,
  4171. hyphen: 0x002D,
  4172. hypheninferior: 0xF6E5,
  4173. hyphenmonospace: 0xFF0D,
  4174. hyphensmall: 0xFE63,
  4175. hyphensuperior: 0xF6E6,
  4176. hyphentwo: 0x2010,
  4177. i: 0x0069,
  4178. iacute: 0x00ED,
  4179. iacyrillic: 0x044F,
  4180. ibengali: 0x0987,
  4181. ibopomofo: 0x3127,
  4182. ibreve: 0x012D,
  4183. icaron: 0x01D0,
  4184. icircle: 0x24D8,
  4185. icircumflex: 0x00EE,
  4186. icyrillic: 0x0456,
  4187. idblgrave: 0x0209,
  4188. ideographearthcircle: 0x328F,
  4189. ideographfirecircle: 0x328B,
  4190. ideographicallianceparen: 0x323F,
  4191. ideographiccallparen: 0x323A,
  4192. ideographiccentrecircle: 0x32A5,
  4193. ideographicclose: 0x3006,
  4194. ideographiccomma: 0x3001,
  4195. ideographiccommaleft: 0xFF64,
  4196. ideographiccongratulationparen: 0x3237,
  4197. ideographiccorrectcircle: 0x32A3,
  4198. ideographicearthparen: 0x322F,
  4199. ideographicenterpriseparen: 0x323D,
  4200. ideographicexcellentcircle: 0x329D,
  4201. ideographicfestivalparen: 0x3240,
  4202. ideographicfinancialcircle: 0x3296,
  4203. ideographicfinancialparen: 0x3236,
  4204. ideographicfireparen: 0x322B,
  4205. ideographichaveparen: 0x3232,
  4206. ideographichighcircle: 0x32A4,
  4207. ideographiciterationmark: 0x3005,
  4208. ideographiclaborcircle: 0x3298,
  4209. ideographiclaborparen: 0x3238,
  4210. ideographicleftcircle: 0x32A7,
  4211. ideographiclowcircle: 0x32A6,
  4212. ideographicmedicinecircle: 0x32A9,
  4213. ideographicmetalparen: 0x322E,
  4214. ideographicmoonparen: 0x322A,
  4215. ideographicnameparen: 0x3234,
  4216. ideographicperiod: 0x3002,
  4217. ideographicprintcircle: 0x329E,
  4218. ideographicreachparen: 0x3243,
  4219. ideographicrepresentparen: 0x3239,
  4220. ideographicresourceparen: 0x323E,
  4221. ideographicrightcircle: 0x32A8,
  4222. ideographicsecretcircle: 0x3299,
  4223. ideographicselfparen: 0x3242,
  4224. ideographicsocietyparen: 0x3233,
  4225. ideographicspace: 0x3000,
  4226. ideographicspecialparen: 0x3235,
  4227. ideographicstockparen: 0x3231,
  4228. ideographicstudyparen: 0x323B,
  4229. ideographicsunparen: 0x3230,
  4230. ideographicsuperviseparen: 0x323C,
  4231. ideographicwaterparen: 0x322C,
  4232. ideographicwoodparen: 0x322D,
  4233. ideographiczero: 0x3007,
  4234. ideographmetalcircle: 0x328E,
  4235. ideographmooncircle: 0x328A,
  4236. ideographnamecircle: 0x3294,
  4237. ideographsuncircle: 0x3290,
  4238. ideographwatercircle: 0x328C,
  4239. ideographwoodcircle: 0x328D,
  4240. ideva: 0x0907,
  4241. idieresis: 0x00EF,
  4242. idieresisacute: 0x1E2F,
  4243. idieresiscyrillic: 0x04E5,
  4244. idotbelow: 0x1ECB,
  4245. iebrevecyrillic: 0x04D7,
  4246. iecyrillic: 0x0435,
  4247. ieungacirclekorean: 0x3275,
  4248. ieungaparenkorean: 0x3215,
  4249. ieungcirclekorean: 0x3267,
  4250. ieungkorean: 0x3147,
  4251. ieungparenkorean: 0x3207,
  4252. igrave: 0x00EC,
  4253. igujarati: 0x0A87,
  4254. igurmukhi: 0x0A07,
  4255. ihiragana: 0x3044,
  4256. ihookabove: 0x1EC9,
  4257. iibengali: 0x0988,
  4258. iicyrillic: 0x0438,
  4259. iideva: 0x0908,
  4260. iigujarati: 0x0A88,
  4261. iigurmukhi: 0x0A08,
  4262. iimatragurmukhi: 0x0A40,
  4263. iinvertedbreve: 0x020B,
  4264. iishortcyrillic: 0x0439,
  4265. iivowelsignbengali: 0x09C0,
  4266. iivowelsigndeva: 0x0940,
  4267. iivowelsigngujarati: 0x0AC0,
  4268. ij: 0x0133,
  4269. ikatakana: 0x30A4,
  4270. ikatakanahalfwidth: 0xFF72,
  4271. ikorean: 0x3163,
  4272. ilde: 0x02DC,
  4273. iluyhebrew: 0x05AC,
  4274. imacron: 0x012B,
  4275. imacroncyrillic: 0x04E3,
  4276. imageorapproximatelyequal: 0x2253,
  4277. imatragurmukhi: 0x0A3F,
  4278. imonospace: 0xFF49,
  4279. increment: 0x2206,
  4280. infinity: 0x221E,
  4281. iniarmenian: 0x056B,
  4282. integral: 0x222B,
  4283. integralbottom: 0x2321,
  4284. integralbt: 0x2321,
  4285. integralex: 0xF8F5,
  4286. integraltop: 0x2320,
  4287. integraltp: 0x2320,
  4288. intersection: 0x2229,
  4289. intisquare: 0x3305,
  4290. invbullet: 0x25D8,
  4291. invcircle: 0x25D9,
  4292. invsmileface: 0x263B,
  4293. iocyrillic: 0x0451,
  4294. iogonek: 0x012F,
  4295. iota: 0x03B9,
  4296. iotadieresis: 0x03CA,
  4297. iotadieresistonos: 0x0390,
  4298. iotalatin: 0x0269,
  4299. iotatonos: 0x03AF,
  4300. iparen: 0x24A4,
  4301. irigurmukhi: 0x0A72,
  4302. ismallhiragana: 0x3043,
  4303. ismallkatakana: 0x30A3,
  4304. ismallkatakanahalfwidth: 0xFF68,
  4305. issharbengali: 0x09FA,
  4306. istroke: 0x0268,
  4307. isuperior: 0xF6ED,
  4308. iterationhiragana: 0x309D,
  4309. iterationkatakana: 0x30FD,
  4310. itilde: 0x0129,
  4311. itildebelow: 0x1E2D,
  4312. iubopomofo: 0x3129,
  4313. iucyrillic: 0x044E,
  4314. ivowelsignbengali: 0x09BF,
  4315. ivowelsigndeva: 0x093F,
  4316. ivowelsigngujarati: 0x0ABF,
  4317. izhitsacyrillic: 0x0475,
  4318. izhitsadblgravecyrillic: 0x0477,
  4319. j: 0x006A,
  4320. jaarmenian: 0x0571,
  4321. jabengali: 0x099C,
  4322. jadeva: 0x091C,
  4323. jagujarati: 0x0A9C,
  4324. jagurmukhi: 0x0A1C,
  4325. jbopomofo: 0x3110,
  4326. jcaron: 0x01F0,
  4327. jcircle: 0x24D9,
  4328. jcircumflex: 0x0135,
  4329. jcrossedtail: 0x029D,
  4330. jdotlessstroke: 0x025F,
  4331. jecyrillic: 0x0458,
  4332. jeemarabic: 0x062C,
  4333. jeemfinalarabic: 0xFE9E,
  4334. jeeminitialarabic: 0xFE9F,
  4335. jeemmedialarabic: 0xFEA0,
  4336. jeharabic: 0x0698,
  4337. jehfinalarabic: 0xFB8B,
  4338. jhabengali: 0x099D,
  4339. jhadeva: 0x091D,
  4340. jhagujarati: 0x0A9D,
  4341. jhagurmukhi: 0x0A1D,
  4342. jheharmenian: 0x057B,
  4343. jis: 0x3004,
  4344. jmonospace: 0xFF4A,
  4345. jparen: 0x24A5,
  4346. jsuperior: 0x02B2,
  4347. k: 0x006B,
  4348. kabashkircyrillic: 0x04A1,
  4349. kabengali: 0x0995,
  4350. kacute: 0x1E31,
  4351. kacyrillic: 0x043A,
  4352. kadescendercyrillic: 0x049B,
  4353. kadeva: 0x0915,
  4354. kaf: 0x05DB,
  4355. kafarabic: 0x0643,
  4356. kafdagesh: 0xFB3B,
  4357. kafdageshhebrew: 0xFB3B,
  4358. kaffinalarabic: 0xFEDA,
  4359. kafhebrew: 0x05DB,
  4360. kafinitialarabic: 0xFEDB,
  4361. kafmedialarabic: 0xFEDC,
  4362. kafrafehebrew: 0xFB4D,
  4363. kagujarati: 0x0A95,
  4364. kagurmukhi: 0x0A15,
  4365. kahiragana: 0x304B,
  4366. kahookcyrillic: 0x04C4,
  4367. kakatakana: 0x30AB,
  4368. kakatakanahalfwidth: 0xFF76,
  4369. kappa: 0x03BA,
  4370. kappasymbolgreek: 0x03F0,
  4371. kapyeounmieumkorean: 0x3171,
  4372. kapyeounphieuphkorean: 0x3184,
  4373. kapyeounpieupkorean: 0x3178,
  4374. kapyeounssangpieupkorean: 0x3179,
  4375. karoriisquare: 0x330D,
  4376. kashidaautoarabic: 0x0640,
  4377. kashidaautonosidebearingarabic: 0x0640,
  4378. kasmallkatakana: 0x30F5,
  4379. kasquare: 0x3384,
  4380. kasraarabic: 0x0650,
  4381. kasratanarabic: 0x064D,
  4382. kastrokecyrillic: 0x049F,
  4383. katahiraprolongmarkhalfwidth: 0xFF70,
  4384. kaverticalstrokecyrillic: 0x049D,
  4385. kbopomofo: 0x310E,
  4386. kcalsquare: 0x3389,
  4387. kcaron: 0x01E9,
  4388. kcedilla: 0x0137,
  4389. kcircle: 0x24DA,
  4390. kcommaaccent: 0x0137,
  4391. kdotbelow: 0x1E33,
  4392. keharmenian: 0x0584,
  4393. kehiragana: 0x3051,
  4394. kekatakana: 0x30B1,
  4395. kekatakanahalfwidth: 0xFF79,
  4396. kenarmenian: 0x056F,
  4397. kesmallkatakana: 0x30F6,
  4398. kgreenlandic: 0x0138,
  4399. khabengali: 0x0996,
  4400. khacyrillic: 0x0445,
  4401. khadeva: 0x0916,
  4402. khagujarati: 0x0A96,
  4403. khagurmukhi: 0x0A16,
  4404. khaharabic: 0x062E,
  4405. khahfinalarabic: 0xFEA6,
  4406. khahinitialarabic: 0xFEA7,
  4407. khahmedialarabic: 0xFEA8,
  4408. kheicoptic: 0x03E7,
  4409. khhadeva: 0x0959,
  4410. khhagurmukhi: 0x0A59,
  4411. khieukhacirclekorean: 0x3278,
  4412. khieukhaparenkorean: 0x3218,
  4413. khieukhcirclekorean: 0x326A,
  4414. khieukhkorean: 0x314B,
  4415. khieukhparenkorean: 0x320A,
  4416. khokhaithai: 0x0E02,
  4417. khokhonthai: 0x0E05,
  4418. khokhuatthai: 0x0E03,
  4419. khokhwaithai: 0x0E04,
  4420. khomutthai: 0x0E5B,
  4421. khook: 0x0199,
  4422. khorakhangthai: 0x0E06,
  4423. khzsquare: 0x3391,
  4424. kihiragana: 0x304D,
  4425. kikatakana: 0x30AD,
  4426. kikatakanahalfwidth: 0xFF77,
  4427. kiroguramusquare: 0x3315,
  4428. kiromeetorusquare: 0x3316,
  4429. kirosquare: 0x3314,
  4430. kiyeokacirclekorean: 0x326E,
  4431. kiyeokaparenkorean: 0x320E,
  4432. kiyeokcirclekorean: 0x3260,
  4433. kiyeokkorean: 0x3131,
  4434. kiyeokparenkorean: 0x3200,
  4435. kiyeoksioskorean: 0x3133,
  4436. kjecyrillic: 0x045C,
  4437. klinebelow: 0x1E35,
  4438. klsquare: 0x3398,
  4439. kmcubedsquare: 0x33A6,
  4440. kmonospace: 0xFF4B,
  4441. kmsquaredsquare: 0x33A2,
  4442. kohiragana: 0x3053,
  4443. kohmsquare: 0x33C0,
  4444. kokaithai: 0x0E01,
  4445. kokatakana: 0x30B3,
  4446. kokatakanahalfwidth: 0xFF7A,
  4447. kooposquare: 0x331E,
  4448. koppacyrillic: 0x0481,
  4449. koreanstandardsymbol: 0x327F,
  4450. koroniscmb: 0x0343,
  4451. kparen: 0x24A6,
  4452. kpasquare: 0x33AA,
  4453. ksicyrillic: 0x046F,
  4454. ktsquare: 0x33CF,
  4455. kturned: 0x029E,
  4456. kuhiragana: 0x304F,
  4457. kukatakana: 0x30AF,
  4458. kukatakanahalfwidth: 0xFF78,
  4459. kvsquare: 0x33B8,
  4460. kwsquare: 0x33BE,
  4461. l: 0x006C,
  4462. labengali: 0x09B2,
  4463. lacute: 0x013A,
  4464. ladeva: 0x0932,
  4465. lagujarati: 0x0AB2,
  4466. lagurmukhi: 0x0A32,
  4467. lakkhangyaothai: 0x0E45,
  4468. lamaleffinalarabic: 0xFEFC,
  4469. lamalefhamzaabovefinalarabic: 0xFEF8,
  4470. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  4471. lamalefhamzabelowfinalarabic: 0xFEFA,
  4472. lamalefhamzabelowisolatedarabic: 0xFEF9,
  4473. lamalefisolatedarabic: 0xFEFB,
  4474. lamalefmaddaabovefinalarabic: 0xFEF6,
  4475. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  4476. lamarabic: 0x0644,
  4477. lambda: 0x03BB,
  4478. lambdastroke: 0x019B,
  4479. lamed: 0x05DC,
  4480. lameddagesh: 0xFB3C,
  4481. lameddageshhebrew: 0xFB3C,
  4482. lamedhebrew: 0x05DC,
  4483. lamfinalarabic: 0xFEDE,
  4484. lamhahinitialarabic: 0xFCCA,
  4485. laminitialarabic: 0xFEDF,
  4486. lamjeeminitialarabic: 0xFCC9,
  4487. lamkhahinitialarabic: 0xFCCB,
  4488. lamlamhehisolatedarabic: 0xFDF2,
  4489. lammedialarabic: 0xFEE0,
  4490. lammeemhahinitialarabic: 0xFD88,
  4491. lammeeminitialarabic: 0xFCCC,
  4492. largecircle: 0x25EF,
  4493. lbar: 0x019A,
  4494. lbelt: 0x026C,
  4495. lbopomofo: 0x310C,
  4496. lcaron: 0x013E,
  4497. lcedilla: 0x013C,
  4498. lcircle: 0x24DB,
  4499. lcircumflexbelow: 0x1E3D,
  4500. lcommaaccent: 0x013C,
  4501. ldot: 0x0140,
  4502. ldotaccent: 0x0140,
  4503. ldotbelow: 0x1E37,
  4504. ldotbelowmacron: 0x1E39,
  4505. leftangleabovecmb: 0x031A,
  4506. lefttackbelowcmb: 0x0318,
  4507. less: 0x003C,
  4508. lessequal: 0x2264,
  4509. lessequalorgreater: 0x22DA,
  4510. lessmonospace: 0xFF1C,
  4511. lessorequivalent: 0x2272,
  4512. lessorgreater: 0x2276,
  4513. lessoverequal: 0x2266,
  4514. lesssmall: 0xFE64,
  4515. lezh: 0x026E,
  4516. lfblock: 0x258C,
  4517. lhookretroflex: 0x026D,
  4518. lira: 0x20A4,
  4519. liwnarmenian: 0x056C,
  4520. lj: 0x01C9,
  4521. ljecyrillic: 0x0459,
  4522. ll: 0xF6C0,
  4523. lladeva: 0x0933,
  4524. llagujarati: 0x0AB3,
  4525. llinebelow: 0x1E3B,
  4526. llladeva: 0x0934,
  4527. llvocalicbengali: 0x09E1,
  4528. llvocalicdeva: 0x0961,
  4529. llvocalicvowelsignbengali: 0x09E3,
  4530. llvocalicvowelsigndeva: 0x0963,
  4531. lmiddletilde: 0x026B,
  4532. lmonospace: 0xFF4C,
  4533. lmsquare: 0x33D0,
  4534. lochulathai: 0x0E2C,
  4535. logicaland: 0x2227,
  4536. logicalnot: 0x00AC,
  4537. logicalnotreversed: 0x2310,
  4538. logicalor: 0x2228,
  4539. lolingthai: 0x0E25,
  4540. longs: 0x017F,
  4541. lowlinecenterline: 0xFE4E,
  4542. lowlinecmb: 0x0332,
  4543. lowlinedashed: 0xFE4D,
  4544. lozenge: 0x25CA,
  4545. lparen: 0x24A7,
  4546. lslash: 0x0142,
  4547. lsquare: 0x2113,
  4548. lsuperior: 0xF6EE,
  4549. ltshade: 0x2591,
  4550. luthai: 0x0E26,
  4551. lvocalicbengali: 0x098C,
  4552. lvocalicdeva: 0x090C,
  4553. lvocalicvowelsignbengali: 0x09E2,
  4554. lvocalicvowelsigndeva: 0x0962,
  4555. lxsquare: 0x33D3,
  4556. m: 0x006D,
  4557. mabengali: 0x09AE,
  4558. macron: 0x00AF,
  4559. macronbelowcmb: 0x0331,
  4560. macroncmb: 0x0304,
  4561. macronlowmod: 0x02CD,
  4562. macronmonospace: 0xFFE3,
  4563. macute: 0x1E3F,
  4564. madeva: 0x092E,
  4565. magujarati: 0x0AAE,
  4566. magurmukhi: 0x0A2E,
  4567. mahapakhhebrew: 0x05A4,
  4568. mahapakhlefthebrew: 0x05A4,
  4569. mahiragana: 0x307E,
  4570. maichattawalowleftthai: 0xF895,
  4571. maichattawalowrightthai: 0xF894,
  4572. maichattawathai: 0x0E4B,
  4573. maichattawaupperleftthai: 0xF893,
  4574. maieklowleftthai: 0xF88C,
  4575. maieklowrightthai: 0xF88B,
  4576. maiekthai: 0x0E48,
  4577. maiekupperleftthai: 0xF88A,
  4578. maihanakatleftthai: 0xF884,
  4579. maihanakatthai: 0x0E31,
  4580. maitaikhuleftthai: 0xF889,
  4581. maitaikhuthai: 0x0E47,
  4582. maitholowleftthai: 0xF88F,
  4583. maitholowrightthai: 0xF88E,
  4584. maithothai: 0x0E49,
  4585. maithoupperleftthai: 0xF88D,
  4586. maitrilowleftthai: 0xF892,
  4587. maitrilowrightthai: 0xF891,
  4588. maitrithai: 0x0E4A,
  4589. maitriupperleftthai: 0xF890,
  4590. maiyamokthai: 0x0E46,
  4591. makatakana: 0x30DE,
  4592. makatakanahalfwidth: 0xFF8F,
  4593. male: 0x2642,
  4594. mansyonsquare: 0x3347,
  4595. maqafhebrew: 0x05BE,
  4596. mars: 0x2642,
  4597. masoracirclehebrew: 0x05AF,
  4598. masquare: 0x3383,
  4599. mbopomofo: 0x3107,
  4600. mbsquare: 0x33D4,
  4601. mcircle: 0x24DC,
  4602. mcubedsquare: 0x33A5,
  4603. mdotaccent: 0x1E41,
  4604. mdotbelow: 0x1E43,
  4605. meemarabic: 0x0645,
  4606. meemfinalarabic: 0xFEE2,
  4607. meeminitialarabic: 0xFEE3,
  4608. meemmedialarabic: 0xFEE4,
  4609. meemmeeminitialarabic: 0xFCD1,
  4610. meemmeemisolatedarabic: 0xFC48,
  4611. meetorusquare: 0x334D,
  4612. mehiragana: 0x3081,
  4613. meizierasquare: 0x337E,
  4614. mekatakana: 0x30E1,
  4615. mekatakanahalfwidth: 0xFF92,
  4616. mem: 0x05DE,
  4617. memdagesh: 0xFB3E,
  4618. memdageshhebrew: 0xFB3E,
  4619. memhebrew: 0x05DE,
  4620. menarmenian: 0x0574,
  4621. merkhahebrew: 0x05A5,
  4622. merkhakefulahebrew: 0x05A6,
  4623. merkhakefulalefthebrew: 0x05A6,
  4624. merkhalefthebrew: 0x05A5,
  4625. mhook: 0x0271,
  4626. mhzsquare: 0x3392,
  4627. middledotkatakanahalfwidth: 0xFF65,
  4628. middot: 0x00B7,
  4629. mieumacirclekorean: 0x3272,
  4630. mieumaparenkorean: 0x3212,
  4631. mieumcirclekorean: 0x3264,
  4632. mieumkorean: 0x3141,
  4633. mieumpansioskorean: 0x3170,
  4634. mieumparenkorean: 0x3204,
  4635. mieumpieupkorean: 0x316E,
  4636. mieumsioskorean: 0x316F,
  4637. mihiragana: 0x307F,
  4638. mikatakana: 0x30DF,
  4639. mikatakanahalfwidth: 0xFF90,
  4640. minus: 0x2212,
  4641. minusbelowcmb: 0x0320,
  4642. minuscircle: 0x2296,
  4643. minusmod: 0x02D7,
  4644. minusplus: 0x2213,
  4645. minute: 0x2032,
  4646. miribaarusquare: 0x334A,
  4647. mirisquare: 0x3349,
  4648. mlonglegturned: 0x0270,
  4649. mlsquare: 0x3396,
  4650. mmcubedsquare: 0x33A3,
  4651. mmonospace: 0xFF4D,
  4652. mmsquaredsquare: 0x339F,
  4653. mohiragana: 0x3082,
  4654. mohmsquare: 0x33C1,
  4655. mokatakana: 0x30E2,
  4656. mokatakanahalfwidth: 0xFF93,
  4657. molsquare: 0x33D6,
  4658. momathai: 0x0E21,
  4659. moverssquare: 0x33A7,
  4660. moverssquaredsquare: 0x33A8,
  4661. mparen: 0x24A8,
  4662. mpasquare: 0x33AB,
  4663. mssquare: 0x33B3,
  4664. msuperior: 0xF6EF,
  4665. mturned: 0x026F,
  4666. mu: 0x00B5,
  4667. mu1: 0x00B5,
  4668. muasquare: 0x3382,
  4669. muchgreater: 0x226B,
  4670. muchless: 0x226A,
  4671. mufsquare: 0x338C,
  4672. mugreek: 0x03BC,
  4673. mugsquare: 0x338D,
  4674. muhiragana: 0x3080,
  4675. mukatakana: 0x30E0,
  4676. mukatakanahalfwidth: 0xFF91,
  4677. mulsquare: 0x3395,
  4678. multiply: 0x00D7,
  4679. mumsquare: 0x339B,
  4680. munahhebrew: 0x05A3,
  4681. munahlefthebrew: 0x05A3,
  4682. musicalnote: 0x266A,
  4683. musicalnotedbl: 0x266B,
  4684. musicflatsign: 0x266D,
  4685. musicsharpsign: 0x266F,
  4686. mussquare: 0x33B2,
  4687. muvsquare: 0x33B6,
  4688. muwsquare: 0x33BC,
  4689. mvmegasquare: 0x33B9,
  4690. mvsquare: 0x33B7,
  4691. mwmegasquare: 0x33BF,
  4692. mwsquare: 0x33BD,
  4693. n: 0x006E,
  4694. nabengali: 0x09A8,
  4695. nabla: 0x2207,
  4696. nacute: 0x0144,
  4697. nadeva: 0x0928,
  4698. nagujarati: 0x0AA8,
  4699. nagurmukhi: 0x0A28,
  4700. nahiragana: 0x306A,
  4701. nakatakana: 0x30CA,
  4702. nakatakanahalfwidth: 0xFF85,
  4703. napostrophe: 0x0149,
  4704. nasquare: 0x3381,
  4705. nbopomofo: 0x310B,
  4706. nbspace: 0x00A0,
  4707. ncaron: 0x0148,
  4708. ncedilla: 0x0146,
  4709. ncircle: 0x24DD,
  4710. ncircumflexbelow: 0x1E4B,
  4711. ncommaaccent: 0x0146,
  4712. ndotaccent: 0x1E45,
  4713. ndotbelow: 0x1E47,
  4714. nehiragana: 0x306D,
  4715. nekatakana: 0x30CD,
  4716. nekatakanahalfwidth: 0xFF88,
  4717. newsheqelsign: 0x20AA,
  4718. nfsquare: 0x338B,
  4719. ngabengali: 0x0999,
  4720. ngadeva: 0x0919,
  4721. ngagujarati: 0x0A99,
  4722. ngagurmukhi: 0x0A19,
  4723. ngonguthai: 0x0E07,
  4724. nhiragana: 0x3093,
  4725. nhookleft: 0x0272,
  4726. nhookretroflex: 0x0273,
  4727. nieunacirclekorean: 0x326F,
  4728. nieunaparenkorean: 0x320F,
  4729. nieuncieuckorean: 0x3135,
  4730. nieuncirclekorean: 0x3261,
  4731. nieunhieuhkorean: 0x3136,
  4732. nieunkorean: 0x3134,
  4733. nieunpansioskorean: 0x3168,
  4734. nieunparenkorean: 0x3201,
  4735. nieunsioskorean: 0x3167,
  4736. nieuntikeutkorean: 0x3166,
  4737. nihiragana: 0x306B,
  4738. nikatakana: 0x30CB,
  4739. nikatakanahalfwidth: 0xFF86,
  4740. nikhahitleftthai: 0xF899,
  4741. nikhahitthai: 0x0E4D,
  4742. nine: 0x0039,
  4743. ninearabic: 0x0669,
  4744. ninebengali: 0x09EF,
  4745. ninecircle: 0x2468,
  4746. ninecircleinversesansserif: 0x2792,
  4747. ninedeva: 0x096F,
  4748. ninegujarati: 0x0AEF,
  4749. ninegurmukhi: 0x0A6F,
  4750. ninehackarabic: 0x0669,
  4751. ninehangzhou: 0x3029,
  4752. nineideographicparen: 0x3228,
  4753. nineinferior: 0x2089,
  4754. ninemonospace: 0xFF19,
  4755. nineoldstyle: 0xF739,
  4756. nineparen: 0x247C,
  4757. nineperiod: 0x2490,
  4758. ninepersian: 0x06F9,
  4759. nineroman: 0x2178,
  4760. ninesuperior: 0x2079,
  4761. nineteencircle: 0x2472,
  4762. nineteenparen: 0x2486,
  4763. nineteenperiod: 0x249A,
  4764. ninethai: 0x0E59,
  4765. nj: 0x01CC,
  4766. njecyrillic: 0x045A,
  4767. nkatakana: 0x30F3,
  4768. nkatakanahalfwidth: 0xFF9D,
  4769. nlegrightlong: 0x019E,
  4770. nlinebelow: 0x1E49,
  4771. nmonospace: 0xFF4E,
  4772. nmsquare: 0x339A,
  4773. nnabengali: 0x09A3,
  4774. nnadeva: 0x0923,
  4775. nnagujarati: 0x0AA3,
  4776. nnagurmukhi: 0x0A23,
  4777. nnnadeva: 0x0929,
  4778. nohiragana: 0x306E,
  4779. nokatakana: 0x30CE,
  4780. nokatakanahalfwidth: 0xFF89,
  4781. nonbreakingspace: 0x00A0,
  4782. nonenthai: 0x0E13,
  4783. nonuthai: 0x0E19,
  4784. noonarabic: 0x0646,
  4785. noonfinalarabic: 0xFEE6,
  4786. noonghunnaarabic: 0x06BA,
  4787. noonghunnafinalarabic: 0xFB9F,
  4788. nooninitialarabic: 0xFEE7,
  4789. noonjeeminitialarabic: 0xFCD2,
  4790. noonjeemisolatedarabic: 0xFC4B,
  4791. noonmedialarabic: 0xFEE8,
  4792. noonmeeminitialarabic: 0xFCD5,
  4793. noonmeemisolatedarabic: 0xFC4E,
  4794. noonnoonfinalarabic: 0xFC8D,
  4795. notcontains: 0x220C,
  4796. notelement: 0x2209,
  4797. notelementof: 0x2209,
  4798. notequal: 0x2260,
  4799. notgreater: 0x226F,
  4800. notgreaternorequal: 0x2271,
  4801. notgreaternorless: 0x2279,
  4802. notidentical: 0x2262,
  4803. notless: 0x226E,
  4804. notlessnorequal: 0x2270,
  4805. notparallel: 0x2226,
  4806. notprecedes: 0x2280,
  4807. notsubset: 0x2284,
  4808. notsucceeds: 0x2281,
  4809. notsuperset: 0x2285,
  4810. nowarmenian: 0x0576,
  4811. nparen: 0x24A9,
  4812. nssquare: 0x33B1,
  4813. nsuperior: 0x207F,
  4814. ntilde: 0x00F1,
  4815. nu: 0x03BD,
  4816. nuhiragana: 0x306C,
  4817. nukatakana: 0x30CC,
  4818. nukatakanahalfwidth: 0xFF87,
  4819. nuktabengali: 0x09BC,
  4820. nuktadeva: 0x093C,
  4821. nuktagujarati: 0x0ABC,
  4822. nuktagurmukhi: 0x0A3C,
  4823. numbersign: 0x0023,
  4824. numbersignmonospace: 0xFF03,
  4825. numbersignsmall: 0xFE5F,
  4826. numeralsigngreek: 0x0374,
  4827. numeralsignlowergreek: 0x0375,
  4828. numero: 0x2116,
  4829. nun: 0x05E0,
  4830. nundagesh: 0xFB40,
  4831. nundageshhebrew: 0xFB40,
  4832. nunhebrew: 0x05E0,
  4833. nvsquare: 0x33B5,
  4834. nwsquare: 0x33BB,
  4835. nyabengali: 0x099E,
  4836. nyadeva: 0x091E,
  4837. nyagujarati: 0x0A9E,
  4838. nyagurmukhi: 0x0A1E,
  4839. o: 0x006F,
  4840. oacute: 0x00F3,
  4841. oangthai: 0x0E2D,
  4842. obarred: 0x0275,
  4843. obarredcyrillic: 0x04E9,
  4844. obarreddieresiscyrillic: 0x04EB,
  4845. obengali: 0x0993,
  4846. obopomofo: 0x311B,
  4847. obreve: 0x014F,
  4848. ocandradeva: 0x0911,
  4849. ocandragujarati: 0x0A91,
  4850. ocandravowelsigndeva: 0x0949,
  4851. ocandravowelsigngujarati: 0x0AC9,
  4852. ocaron: 0x01D2,
  4853. ocircle: 0x24DE,
  4854. ocircumflex: 0x00F4,
  4855. ocircumflexacute: 0x1ED1,
  4856. ocircumflexdotbelow: 0x1ED9,
  4857. ocircumflexgrave: 0x1ED3,
  4858. ocircumflexhookabove: 0x1ED5,
  4859. ocircumflextilde: 0x1ED7,
  4860. ocyrillic: 0x043E,
  4861. odblacute: 0x0151,
  4862. odblgrave: 0x020D,
  4863. odeva: 0x0913,
  4864. odieresis: 0x00F6,
  4865. odieresiscyrillic: 0x04E7,
  4866. odotbelow: 0x1ECD,
  4867. oe: 0x0153,
  4868. oekorean: 0x315A,
  4869. ogonek: 0x02DB,
  4870. ogonekcmb: 0x0328,
  4871. ograve: 0x00F2,
  4872. ogujarati: 0x0A93,
  4873. oharmenian: 0x0585,
  4874. ohiragana: 0x304A,
  4875. ohookabove: 0x1ECF,
  4876. ohorn: 0x01A1,
  4877. ohornacute: 0x1EDB,
  4878. ohorndotbelow: 0x1EE3,
  4879. ohorngrave: 0x1EDD,
  4880. ohornhookabove: 0x1EDF,
  4881. ohorntilde: 0x1EE1,
  4882. ohungarumlaut: 0x0151,
  4883. oi: 0x01A3,
  4884. oinvertedbreve: 0x020F,
  4885. okatakana: 0x30AA,
  4886. okatakanahalfwidth: 0xFF75,
  4887. okorean: 0x3157,
  4888. olehebrew: 0x05AB,
  4889. omacron: 0x014D,
  4890. omacronacute: 0x1E53,
  4891. omacrongrave: 0x1E51,
  4892. omdeva: 0x0950,
  4893. omega: 0x03C9,
  4894. omega1: 0x03D6,
  4895. omegacyrillic: 0x0461,
  4896. omegalatinclosed: 0x0277,
  4897. omegaroundcyrillic: 0x047B,
  4898. omegatitlocyrillic: 0x047D,
  4899. omegatonos: 0x03CE,
  4900. omgujarati: 0x0AD0,
  4901. omicron: 0x03BF,
  4902. omicrontonos: 0x03CC,
  4903. omonospace: 0xFF4F,
  4904. one: 0x0031,
  4905. onearabic: 0x0661,
  4906. onebengali: 0x09E7,
  4907. onecircle: 0x2460,
  4908. onecircleinversesansserif: 0x278A,
  4909. onedeva: 0x0967,
  4910. onedotenleader: 0x2024,
  4911. oneeighth: 0x215B,
  4912. onefitted: 0xF6DC,
  4913. onegujarati: 0x0AE7,
  4914. onegurmukhi: 0x0A67,
  4915. onehackarabic: 0x0661,
  4916. onehalf: 0x00BD,
  4917. onehangzhou: 0x3021,
  4918. oneideographicparen: 0x3220,
  4919. oneinferior: 0x2081,
  4920. onemonospace: 0xFF11,
  4921. onenumeratorbengali: 0x09F4,
  4922. oneoldstyle: 0xF731,
  4923. oneparen: 0x2474,
  4924. oneperiod: 0x2488,
  4925. onepersian: 0x06F1,
  4926. onequarter: 0x00BC,
  4927. oneroman: 0x2170,
  4928. onesuperior: 0x00B9,
  4929. onethai: 0x0E51,
  4930. onethird: 0x2153,
  4931. oogonek: 0x01EB,
  4932. oogonekmacron: 0x01ED,
  4933. oogurmukhi: 0x0A13,
  4934. oomatragurmukhi: 0x0A4B,
  4935. oopen: 0x0254,
  4936. oparen: 0x24AA,
  4937. openbullet: 0x25E6,
  4938. option: 0x2325,
  4939. ordfeminine: 0x00AA,
  4940. ordmasculine: 0x00BA,
  4941. orthogonal: 0x221F,
  4942. oshortdeva: 0x0912,
  4943. oshortvowelsigndeva: 0x094A,
  4944. oslash: 0x00F8,
  4945. oslashacute: 0x01FF,
  4946. osmallhiragana: 0x3049,
  4947. osmallkatakana: 0x30A9,
  4948. osmallkatakanahalfwidth: 0xFF6B,
  4949. ostrokeacute: 0x01FF,
  4950. osuperior: 0xF6F0,
  4951. otcyrillic: 0x047F,
  4952. otilde: 0x00F5,
  4953. otildeacute: 0x1E4D,
  4954. otildedieresis: 0x1E4F,
  4955. oubopomofo: 0x3121,
  4956. overline: 0x203E,
  4957. overlinecenterline: 0xFE4A,
  4958. overlinecmb: 0x0305,
  4959. overlinedashed: 0xFE49,
  4960. overlinedblwavy: 0xFE4C,
  4961. overlinewavy: 0xFE4B,
  4962. overscore: 0x00AF,
  4963. ovowelsignbengali: 0x09CB,
  4964. ovowelsigndeva: 0x094B,
  4965. ovowelsigngujarati: 0x0ACB,
  4966. p: 0x0070,
  4967. paampssquare: 0x3380,
  4968. paasentosquare: 0x332B,
  4969. pabengali: 0x09AA,
  4970. pacute: 0x1E55,
  4971. padeva: 0x092A,
  4972. pagedown: 0x21DF,
  4973. pageup: 0x21DE,
  4974. pagujarati: 0x0AAA,
  4975. pagurmukhi: 0x0A2A,
  4976. pahiragana: 0x3071,
  4977. paiyannoithai: 0x0E2F,
  4978. pakatakana: 0x30D1,
  4979. palatalizationcyrilliccmb: 0x0484,
  4980. palochkacyrillic: 0x04C0,
  4981. pansioskorean: 0x317F,
  4982. paragraph: 0x00B6,
  4983. parallel: 0x2225,
  4984. parenleft: 0x0028,
  4985. parenleftaltonearabic: 0xFD3E,
  4986. parenleftbt: 0xF8ED,
  4987. parenleftex: 0xF8EC,
  4988. parenleftinferior: 0x208D,
  4989. parenleftmonospace: 0xFF08,
  4990. parenleftsmall: 0xFE59,
  4991. parenleftsuperior: 0x207D,
  4992. parenlefttp: 0xF8EB,
  4993. parenleftvertical: 0xFE35,
  4994. parenright: 0x0029,
  4995. parenrightaltonearabic: 0xFD3F,
  4996. parenrightbt: 0xF8F8,
  4997. parenrightex: 0xF8F7,
  4998. parenrightinferior: 0x208E,
  4999. parenrightmonospace: 0xFF09,
  5000. parenrightsmall: 0xFE5A,
  5001. parenrightsuperior: 0x207E,
  5002. parenrighttp: 0xF8F6,
  5003. parenrightvertical: 0xFE36,
  5004. partialdiff: 0x2202,
  5005. paseqhebrew: 0x05C0,
  5006. pashtahebrew: 0x0599,
  5007. pasquare: 0x33A9,
  5008. patah: 0x05B7,
  5009. patah11: 0x05B7,
  5010. patah1d: 0x05B7,
  5011. patah2a: 0x05B7,
  5012. patahhebrew: 0x05B7,
  5013. patahnarrowhebrew: 0x05B7,
  5014. patahquarterhebrew: 0x05B7,
  5015. patahwidehebrew: 0x05B7,
  5016. pazerhebrew: 0x05A1,
  5017. pbopomofo: 0x3106,
  5018. pcircle: 0x24DF,
  5019. pdotaccent: 0x1E57,
  5020. pe: 0x05E4,
  5021. pecyrillic: 0x043F,
  5022. pedagesh: 0xFB44,
  5023. pedageshhebrew: 0xFB44,
  5024. peezisquare: 0x333B,
  5025. pefinaldageshhebrew: 0xFB43,
  5026. peharabic: 0x067E,
  5027. peharmenian: 0x057A,
  5028. pehebrew: 0x05E4,
  5029. pehfinalarabic: 0xFB57,
  5030. pehinitialarabic: 0xFB58,
  5031. pehiragana: 0x307A,
  5032. pehmedialarabic: 0xFB59,
  5033. pekatakana: 0x30DA,
  5034. pemiddlehookcyrillic: 0x04A7,
  5035. perafehebrew: 0xFB4E,
  5036. percent: 0x0025,
  5037. percentarabic: 0x066A,
  5038. percentmonospace: 0xFF05,
  5039. percentsmall: 0xFE6A,
  5040. period: 0x002E,
  5041. periodarmenian: 0x0589,
  5042. periodcentered: 0x00B7,
  5043. periodhalfwidth: 0xFF61,
  5044. periodinferior: 0xF6E7,
  5045. periodmonospace: 0xFF0E,
  5046. periodsmall: 0xFE52,
  5047. periodsuperior: 0xF6E8,
  5048. perispomenigreekcmb: 0x0342,
  5049. perpendicular: 0x22A5,
  5050. perthousand: 0x2030,
  5051. peseta: 0x20A7,
  5052. pfsquare: 0x338A,
  5053. phabengali: 0x09AB,
  5054. phadeva: 0x092B,
  5055. phagujarati: 0x0AAB,
  5056. phagurmukhi: 0x0A2B,
  5057. phi: 0x03C6,
  5058. phi1: 0x03D5,
  5059. phieuphacirclekorean: 0x327A,
  5060. phieuphaparenkorean: 0x321A,
  5061. phieuphcirclekorean: 0x326C,
  5062. phieuphkorean: 0x314D,
  5063. phieuphparenkorean: 0x320C,
  5064. philatin: 0x0278,
  5065. phinthuthai: 0x0E3A,
  5066. phisymbolgreek: 0x03D5,
  5067. phook: 0x01A5,
  5068. phophanthai: 0x0E1E,
  5069. phophungthai: 0x0E1C,
  5070. phosamphaothai: 0x0E20,
  5071. pi: 0x03C0,
  5072. pieupacirclekorean: 0x3273,
  5073. pieupaparenkorean: 0x3213,
  5074. pieupcieuckorean: 0x3176,
  5075. pieupcirclekorean: 0x3265,
  5076. pieupkiyeokkorean: 0x3172,
  5077. pieupkorean: 0x3142,
  5078. pieupparenkorean: 0x3205,
  5079. pieupsioskiyeokkorean: 0x3174,
  5080. pieupsioskorean: 0x3144,
  5081. pieupsiostikeutkorean: 0x3175,
  5082. pieupthieuthkorean: 0x3177,
  5083. pieuptikeutkorean: 0x3173,
  5084. pihiragana: 0x3074,
  5085. pikatakana: 0x30D4,
  5086. pisymbolgreek: 0x03D6,
  5087. piwrarmenian: 0x0583,
  5088. plus: 0x002B,
  5089. plusbelowcmb: 0x031F,
  5090. pluscircle: 0x2295,
  5091. plusminus: 0x00B1,
  5092. plusmod: 0x02D6,
  5093. plusmonospace: 0xFF0B,
  5094. plussmall: 0xFE62,
  5095. plussuperior: 0x207A,
  5096. pmonospace: 0xFF50,
  5097. pmsquare: 0x33D8,
  5098. pohiragana: 0x307D,
  5099. pointingindexdownwhite: 0x261F,
  5100. pointingindexleftwhite: 0x261C,
  5101. pointingindexrightwhite: 0x261E,
  5102. pointingindexupwhite: 0x261D,
  5103. pokatakana: 0x30DD,
  5104. poplathai: 0x0E1B,
  5105. postalmark: 0x3012,
  5106. postalmarkface: 0x3020,
  5107. pparen: 0x24AB,
  5108. precedes: 0x227A,
  5109. prescription: 0x211E,
  5110. primemod: 0x02B9,
  5111. primereversed: 0x2035,
  5112. product: 0x220F,
  5113. projective: 0x2305,
  5114. prolongedkana: 0x30FC,
  5115. propellor: 0x2318,
  5116. propersubset: 0x2282,
  5117. propersuperset: 0x2283,
  5118. proportion: 0x2237,
  5119. proportional: 0x221D,
  5120. psi: 0x03C8,
  5121. psicyrillic: 0x0471,
  5122. psilipneumatacyrilliccmb: 0x0486,
  5123. pssquare: 0x33B0,
  5124. puhiragana: 0x3077,
  5125. pukatakana: 0x30D7,
  5126. pvsquare: 0x33B4,
  5127. pwsquare: 0x33BA,
  5128. q: 0x0071,
  5129. qadeva: 0x0958,
  5130. qadmahebrew: 0x05A8,
  5131. qafarabic: 0x0642,
  5132. qaffinalarabic: 0xFED6,
  5133. qafinitialarabic: 0xFED7,
  5134. qafmedialarabic: 0xFED8,
  5135. qamats: 0x05B8,
  5136. qamats10: 0x05B8,
  5137. qamats1a: 0x05B8,
  5138. qamats1c: 0x05B8,
  5139. qamats27: 0x05B8,
  5140. qamats29: 0x05B8,
  5141. qamats33: 0x05B8,
  5142. qamatsde: 0x05B8,
  5143. qamatshebrew: 0x05B8,
  5144. qamatsnarrowhebrew: 0x05B8,
  5145. qamatsqatanhebrew: 0x05B8,
  5146. qamatsqatannarrowhebrew: 0x05B8,
  5147. qamatsqatanquarterhebrew: 0x05B8,
  5148. qamatsqatanwidehebrew: 0x05B8,
  5149. qamatsquarterhebrew: 0x05B8,
  5150. qamatswidehebrew: 0x05B8,
  5151. qarneyparahebrew: 0x059F,
  5152. qbopomofo: 0x3111,
  5153. qcircle: 0x24E0,
  5154. qhook: 0x02A0,
  5155. qmonospace: 0xFF51,
  5156. qof: 0x05E7,
  5157. qofdagesh: 0xFB47,
  5158. qofdageshhebrew: 0xFB47,
  5159. qofhebrew: 0x05E7,
  5160. qparen: 0x24AC,
  5161. quarternote: 0x2669,
  5162. qubuts: 0x05BB,
  5163. qubuts18: 0x05BB,
  5164. qubuts25: 0x05BB,
  5165. qubuts31: 0x05BB,
  5166. qubutshebrew: 0x05BB,
  5167. qubutsnarrowhebrew: 0x05BB,
  5168. qubutsquarterhebrew: 0x05BB,
  5169. qubutswidehebrew: 0x05BB,
  5170. question: 0x003F,
  5171. questionarabic: 0x061F,
  5172. questionarmenian: 0x055E,
  5173. questiondown: 0x00BF,
  5174. questiondownsmall: 0xF7BF,
  5175. questiongreek: 0x037E,
  5176. questionmonospace: 0xFF1F,
  5177. questionsmall: 0xF73F,
  5178. quotedbl: 0x0022,
  5179. quotedblbase: 0x201E,
  5180. quotedblleft: 0x201C,
  5181. quotedblmonospace: 0xFF02,
  5182. quotedblprime: 0x301E,
  5183. quotedblprimereversed: 0x301D,
  5184. quotedblright: 0x201D,
  5185. quoteleft: 0x2018,
  5186. quoteleftreversed: 0x201B,
  5187. quotereversed: 0x201B,
  5188. quoteright: 0x2019,
  5189. quoterightn: 0x0149,
  5190. quotesinglbase: 0x201A,
  5191. quotesingle: 0x0027,
  5192. quotesinglemonospace: 0xFF07,
  5193. r: 0x0072,
  5194. raarmenian: 0x057C,
  5195. rabengali: 0x09B0,
  5196. racute: 0x0155,
  5197. radeva: 0x0930,
  5198. radical: 0x221A,
  5199. radicalex: 0xF8E5,
  5200. radoverssquare: 0x33AE,
  5201. radoverssquaredsquare: 0x33AF,
  5202. radsquare: 0x33AD,
  5203. rafe: 0x05BF,
  5204. rafehebrew: 0x05BF,
  5205. ragujarati: 0x0AB0,
  5206. ragurmukhi: 0x0A30,
  5207. rahiragana: 0x3089,
  5208. rakatakana: 0x30E9,
  5209. rakatakanahalfwidth: 0xFF97,
  5210. ralowerdiagonalbengali: 0x09F1,
  5211. ramiddlediagonalbengali: 0x09F0,
  5212. ramshorn: 0x0264,
  5213. ratio: 0x2236,
  5214. rbopomofo: 0x3116,
  5215. rcaron: 0x0159,
  5216. rcedilla: 0x0157,
  5217. rcircle: 0x24E1,
  5218. rcommaaccent: 0x0157,
  5219. rdblgrave: 0x0211,
  5220. rdotaccent: 0x1E59,
  5221. rdotbelow: 0x1E5B,
  5222. rdotbelowmacron: 0x1E5D,
  5223. referencemark: 0x203B,
  5224. reflexsubset: 0x2286,
  5225. reflexsuperset: 0x2287,
  5226. registered: 0x00AE,
  5227. registersans: 0xF8E8,
  5228. registerserif: 0xF6DA,
  5229. reharabic: 0x0631,
  5230. reharmenian: 0x0580,
  5231. rehfinalarabic: 0xFEAE,
  5232. rehiragana: 0x308C,
  5233. rekatakana: 0x30EC,
  5234. rekatakanahalfwidth: 0xFF9A,
  5235. resh: 0x05E8,
  5236. reshdageshhebrew: 0xFB48,
  5237. reshhebrew: 0x05E8,
  5238. reversedtilde: 0x223D,
  5239. reviahebrew: 0x0597,
  5240. reviamugrashhebrew: 0x0597,
  5241. revlogicalnot: 0x2310,
  5242. rfishhook: 0x027E,
  5243. rfishhookreversed: 0x027F,
  5244. rhabengali: 0x09DD,
  5245. rhadeva: 0x095D,
  5246. rho: 0x03C1,
  5247. rhook: 0x027D,
  5248. rhookturned: 0x027B,
  5249. rhookturnedsuperior: 0x02B5,
  5250. rhosymbolgreek: 0x03F1,
  5251. rhotichookmod: 0x02DE,
  5252. rieulacirclekorean: 0x3271,
  5253. rieulaparenkorean: 0x3211,
  5254. rieulcirclekorean: 0x3263,
  5255. rieulhieuhkorean: 0x3140,
  5256. rieulkiyeokkorean: 0x313A,
  5257. rieulkiyeoksioskorean: 0x3169,
  5258. rieulkorean: 0x3139,
  5259. rieulmieumkorean: 0x313B,
  5260. rieulpansioskorean: 0x316C,
  5261. rieulparenkorean: 0x3203,
  5262. rieulphieuphkorean: 0x313F,
  5263. rieulpieupkorean: 0x313C,
  5264. rieulpieupsioskorean: 0x316B,
  5265. rieulsioskorean: 0x313D,
  5266. rieulthieuthkorean: 0x313E,
  5267. rieultikeutkorean: 0x316A,
  5268. rieulyeorinhieuhkorean: 0x316D,
  5269. rightangle: 0x221F,
  5270. righttackbelowcmb: 0x0319,
  5271. righttriangle: 0x22BF,
  5272. rihiragana: 0x308A,
  5273. rikatakana: 0x30EA,
  5274. rikatakanahalfwidth: 0xFF98,
  5275. ring: 0x02DA,
  5276. ringbelowcmb: 0x0325,
  5277. ringcmb: 0x030A,
  5278. ringhalfleft: 0x02BF,
  5279. ringhalfleftarmenian: 0x0559,
  5280. ringhalfleftbelowcmb: 0x031C,
  5281. ringhalfleftcentered: 0x02D3,
  5282. ringhalfright: 0x02BE,
  5283. ringhalfrightbelowcmb: 0x0339,
  5284. ringhalfrightcentered: 0x02D2,
  5285. rinvertedbreve: 0x0213,
  5286. rittorusquare: 0x3351,
  5287. rlinebelow: 0x1E5F,
  5288. rlongleg: 0x027C,
  5289. rlonglegturned: 0x027A,
  5290. rmonospace: 0xFF52,
  5291. rohiragana: 0x308D,
  5292. rokatakana: 0x30ED,
  5293. rokatakanahalfwidth: 0xFF9B,
  5294. roruathai: 0x0E23,
  5295. rparen: 0x24AD,
  5296. rrabengali: 0x09DC,
  5297. rradeva: 0x0931,
  5298. rragurmukhi: 0x0A5C,
  5299. rreharabic: 0x0691,
  5300. rrehfinalarabic: 0xFB8D,
  5301. rrvocalicbengali: 0x09E0,
  5302. rrvocalicdeva: 0x0960,
  5303. rrvocalicgujarati: 0x0AE0,
  5304. rrvocalicvowelsignbengali: 0x09C4,
  5305. rrvocalicvowelsigndeva: 0x0944,
  5306. rrvocalicvowelsigngujarati: 0x0AC4,
  5307. rsuperior: 0xF6F1,
  5308. rtblock: 0x2590,
  5309. rturned: 0x0279,
  5310. rturnedsuperior: 0x02B4,
  5311. ruhiragana: 0x308B,
  5312. rukatakana: 0x30EB,
  5313. rukatakanahalfwidth: 0xFF99,
  5314. rupeemarkbengali: 0x09F2,
  5315. rupeesignbengali: 0x09F3,
  5316. rupiah: 0xF6DD,
  5317. ruthai: 0x0E24,
  5318. rvocalicbengali: 0x098B,
  5319. rvocalicdeva: 0x090B,
  5320. rvocalicgujarati: 0x0A8B,
  5321. rvocalicvowelsignbengali: 0x09C3,
  5322. rvocalicvowelsigndeva: 0x0943,
  5323. rvocalicvowelsigngujarati: 0x0AC3,
  5324. s: 0x0073,
  5325. sabengali: 0x09B8,
  5326. sacute: 0x015B,
  5327. sacutedotaccent: 0x1E65,
  5328. sadarabic: 0x0635,
  5329. sadeva: 0x0938,
  5330. sadfinalarabic: 0xFEBA,
  5331. sadinitialarabic: 0xFEBB,
  5332. sadmedialarabic: 0xFEBC,
  5333. sagujarati: 0x0AB8,
  5334. sagurmukhi: 0x0A38,
  5335. sahiragana: 0x3055,
  5336. sakatakana: 0x30B5,
  5337. sakatakanahalfwidth: 0xFF7B,
  5338. sallallahoualayhewasallamarabic: 0xFDFA,
  5339. samekh: 0x05E1,
  5340. samekhdagesh: 0xFB41,
  5341. samekhdageshhebrew: 0xFB41,
  5342. samekhhebrew: 0x05E1,
  5343. saraaathai: 0x0E32,
  5344. saraaethai: 0x0E41,
  5345. saraaimaimalaithai: 0x0E44,
  5346. saraaimaimuanthai: 0x0E43,
  5347. saraamthai: 0x0E33,
  5348. saraathai: 0x0E30,
  5349. saraethai: 0x0E40,
  5350. saraiileftthai: 0xF886,
  5351. saraiithai: 0x0E35,
  5352. saraileftthai: 0xF885,
  5353. saraithai: 0x0E34,
  5354. saraothai: 0x0E42,
  5355. saraueeleftthai: 0xF888,
  5356. saraueethai: 0x0E37,
  5357. saraueleftthai: 0xF887,
  5358. sarauethai: 0x0E36,
  5359. sarauthai: 0x0E38,
  5360. sarauuthai: 0x0E39,
  5361. sbopomofo: 0x3119,
  5362. scaron: 0x0161,
  5363. scarondotaccent: 0x1E67,
  5364. scedilla: 0x015F,
  5365. schwa: 0x0259,
  5366. schwacyrillic: 0x04D9,
  5367. schwadieresiscyrillic: 0x04DB,
  5368. schwahook: 0x025A,
  5369. scircle: 0x24E2,
  5370. scircumflex: 0x015D,
  5371. scommaaccent: 0x0219,
  5372. sdotaccent: 0x1E61,
  5373. sdotbelow: 0x1E63,
  5374. sdotbelowdotaccent: 0x1E69,
  5375. seagullbelowcmb: 0x033C,
  5376. second: 0x2033,
  5377. secondtonechinese: 0x02CA,
  5378. section: 0x00A7,
  5379. seenarabic: 0x0633,
  5380. seenfinalarabic: 0xFEB2,
  5381. seeninitialarabic: 0xFEB3,
  5382. seenmedialarabic: 0xFEB4,
  5383. segol: 0x05B6,
  5384. segol13: 0x05B6,
  5385. segol1f: 0x05B6,
  5386. segol2c: 0x05B6,
  5387. segolhebrew: 0x05B6,
  5388. segolnarrowhebrew: 0x05B6,
  5389. segolquarterhebrew: 0x05B6,
  5390. segoltahebrew: 0x0592,
  5391. segolwidehebrew: 0x05B6,
  5392. seharmenian: 0x057D,
  5393. sehiragana: 0x305B,
  5394. sekatakana: 0x30BB,
  5395. sekatakanahalfwidth: 0xFF7E,
  5396. semicolon: 0x003B,
  5397. semicolonarabic: 0x061B,
  5398. semicolonmonospace: 0xFF1B,
  5399. semicolonsmall: 0xFE54,
  5400. semivoicedmarkkana: 0x309C,
  5401. semivoicedmarkkanahalfwidth: 0xFF9F,
  5402. sentisquare: 0x3322,
  5403. sentosquare: 0x3323,
  5404. seven: 0x0037,
  5405. sevenarabic: 0x0667,
  5406. sevenbengali: 0x09ED,
  5407. sevencircle: 0x2466,
  5408. sevencircleinversesansserif: 0x2790,
  5409. sevendeva: 0x096D,
  5410. seveneighths: 0x215E,
  5411. sevengujarati: 0x0AED,
  5412. sevengurmukhi: 0x0A6D,
  5413. sevenhackarabic: 0x0667,
  5414. sevenhangzhou: 0x3027,
  5415. sevenideographicparen: 0x3226,
  5416. seveninferior: 0x2087,
  5417. sevenmonospace: 0xFF17,
  5418. sevenoldstyle: 0xF737,
  5419. sevenparen: 0x247A,
  5420. sevenperiod: 0x248E,
  5421. sevenpersian: 0x06F7,
  5422. sevenroman: 0x2176,
  5423. sevensuperior: 0x2077,
  5424. seventeencircle: 0x2470,
  5425. seventeenparen: 0x2484,
  5426. seventeenperiod: 0x2498,
  5427. seventhai: 0x0E57,
  5428. sfthyphen: 0x00AD,
  5429. shaarmenian: 0x0577,
  5430. shabengali: 0x09B6,
  5431. shacyrillic: 0x0448,
  5432. shaddaarabic: 0x0651,
  5433. shaddadammaarabic: 0xFC61,
  5434. shaddadammatanarabic: 0xFC5E,
  5435. shaddafathaarabic: 0xFC60,
  5436. shaddakasraarabic: 0xFC62,
  5437. shaddakasratanarabic: 0xFC5F,
  5438. shade: 0x2592,
  5439. shadedark: 0x2593,
  5440. shadelight: 0x2591,
  5441. shademedium: 0x2592,
  5442. shadeva: 0x0936,
  5443. shagujarati: 0x0AB6,
  5444. shagurmukhi: 0x0A36,
  5445. shalshelethebrew: 0x0593,
  5446. shbopomofo: 0x3115,
  5447. shchacyrillic: 0x0449,
  5448. sheenarabic: 0x0634,
  5449. sheenfinalarabic: 0xFEB6,
  5450. sheeninitialarabic: 0xFEB7,
  5451. sheenmedialarabic: 0xFEB8,
  5452. sheicoptic: 0x03E3,
  5453. sheqel: 0x20AA,
  5454. sheqelhebrew: 0x20AA,
  5455. sheva: 0x05B0,
  5456. sheva115: 0x05B0,
  5457. sheva15: 0x05B0,
  5458. sheva22: 0x05B0,
  5459. sheva2e: 0x05B0,
  5460. shevahebrew: 0x05B0,
  5461. shevanarrowhebrew: 0x05B0,
  5462. shevaquarterhebrew: 0x05B0,
  5463. shevawidehebrew: 0x05B0,
  5464. shhacyrillic: 0x04BB,
  5465. shimacoptic: 0x03ED,
  5466. shin: 0x05E9,
  5467. shindagesh: 0xFB49,
  5468. shindageshhebrew: 0xFB49,
  5469. shindageshshindot: 0xFB2C,
  5470. shindageshshindothebrew: 0xFB2C,
  5471. shindageshsindot: 0xFB2D,
  5472. shindageshsindothebrew: 0xFB2D,
  5473. shindothebrew: 0x05C1,
  5474. shinhebrew: 0x05E9,
  5475. shinshindot: 0xFB2A,
  5476. shinshindothebrew: 0xFB2A,
  5477. shinsindot: 0xFB2B,
  5478. shinsindothebrew: 0xFB2B,
  5479. shook: 0x0282,
  5480. sigma: 0x03C3,
  5481. sigma1: 0x03C2,
  5482. sigmafinal: 0x03C2,
  5483. sigmalunatesymbolgreek: 0x03F2,
  5484. sihiragana: 0x3057,
  5485. sikatakana: 0x30B7,
  5486. sikatakanahalfwidth: 0xFF7C,
  5487. siluqhebrew: 0x05BD,
  5488. siluqlefthebrew: 0x05BD,
  5489. similar: 0x223C,
  5490. sindothebrew: 0x05C2,
  5491. siosacirclekorean: 0x3274,
  5492. siosaparenkorean: 0x3214,
  5493. sioscieuckorean: 0x317E,
  5494. sioscirclekorean: 0x3266,
  5495. sioskiyeokkorean: 0x317A,
  5496. sioskorean: 0x3145,
  5497. siosnieunkorean: 0x317B,
  5498. siosparenkorean: 0x3206,
  5499. siospieupkorean: 0x317D,
  5500. siostikeutkorean: 0x317C,
  5501. six: 0x0036,
  5502. sixarabic: 0x0666,
  5503. sixbengali: 0x09EC,
  5504. sixcircle: 0x2465,
  5505. sixcircleinversesansserif: 0x278F,
  5506. sixdeva: 0x096C,
  5507. sixgujarati: 0x0AEC,
  5508. sixgurmukhi: 0x0A6C,
  5509. sixhackarabic: 0x0666,
  5510. sixhangzhou: 0x3026,
  5511. sixideographicparen: 0x3225,
  5512. sixinferior: 0x2086,
  5513. sixmonospace: 0xFF16,
  5514. sixoldstyle: 0xF736,
  5515. sixparen: 0x2479,
  5516. sixperiod: 0x248D,
  5517. sixpersian: 0x06F6,
  5518. sixroman: 0x2175,
  5519. sixsuperior: 0x2076,
  5520. sixteencircle: 0x246F,
  5521. sixteencurrencydenominatorbengali: 0x09F9,
  5522. sixteenparen: 0x2483,
  5523. sixteenperiod: 0x2497,
  5524. sixthai: 0x0E56,
  5525. slash: 0x002F,
  5526. slashmonospace: 0xFF0F,
  5527. slong: 0x017F,
  5528. slongdotaccent: 0x1E9B,
  5529. smileface: 0x263A,
  5530. smonospace: 0xFF53,
  5531. sofpasuqhebrew: 0x05C3,
  5532. softhyphen: 0x00AD,
  5533. softsigncyrillic: 0x044C,
  5534. sohiragana: 0x305D,
  5535. sokatakana: 0x30BD,
  5536. sokatakanahalfwidth: 0xFF7F,
  5537. soliduslongoverlaycmb: 0x0338,
  5538. solidusshortoverlaycmb: 0x0337,
  5539. sorusithai: 0x0E29,
  5540. sosalathai: 0x0E28,
  5541. sosothai: 0x0E0B,
  5542. sosuathai: 0x0E2A,
  5543. space: 0x0020,
  5544. spacehackarabic: 0x0020,
  5545. spade: 0x2660,
  5546. spadesuitblack: 0x2660,
  5547. spadesuitwhite: 0x2664,
  5548. sparen: 0x24AE,
  5549. squarebelowcmb: 0x033B,
  5550. squarecc: 0x33C4,
  5551. squarecm: 0x339D,
  5552. squarediagonalcrosshatchfill: 0x25A9,
  5553. squarehorizontalfill: 0x25A4,
  5554. squarekg: 0x338F,
  5555. squarekm: 0x339E,
  5556. squarekmcapital: 0x33CE,
  5557. squareln: 0x33D1,
  5558. squarelog: 0x33D2,
  5559. squaremg: 0x338E,
  5560. squaremil: 0x33D5,
  5561. squaremm: 0x339C,
  5562. squaremsquared: 0x33A1,
  5563. squareorthogonalcrosshatchfill: 0x25A6,
  5564. squareupperlefttolowerrightfill: 0x25A7,
  5565. squareupperrighttolowerleftfill: 0x25A8,
  5566. squareverticalfill: 0x25A5,
  5567. squarewhitewithsmallblack: 0x25A3,
  5568. srsquare: 0x33DB,
  5569. ssabengali: 0x09B7,
  5570. ssadeva: 0x0937,
  5571. ssagujarati: 0x0AB7,
  5572. ssangcieuckorean: 0x3149,
  5573. ssanghieuhkorean: 0x3185,
  5574. ssangieungkorean: 0x3180,
  5575. ssangkiyeokkorean: 0x3132,
  5576. ssangnieunkorean: 0x3165,
  5577. ssangpieupkorean: 0x3143,
  5578. ssangsioskorean: 0x3146,
  5579. ssangtikeutkorean: 0x3138,
  5580. ssuperior: 0xF6F2,
  5581. sterling: 0x00A3,
  5582. sterlingmonospace: 0xFFE1,
  5583. strokelongoverlaycmb: 0x0336,
  5584. strokeshortoverlaycmb: 0x0335,
  5585. subset: 0x2282,
  5586. subsetnotequal: 0x228A,
  5587. subsetorequal: 0x2286,
  5588. succeeds: 0x227B,
  5589. suchthat: 0x220B,
  5590. suhiragana: 0x3059,
  5591. sukatakana: 0x30B9,
  5592. sukatakanahalfwidth: 0xFF7D,
  5593. sukunarabic: 0x0652,
  5594. summation: 0x2211,
  5595. sun: 0x263C,
  5596. superset: 0x2283,
  5597. supersetnotequal: 0x228B,
  5598. supersetorequal: 0x2287,
  5599. svsquare: 0x33DC,
  5600. syouwaerasquare: 0x337C,
  5601. t: 0x0074,
  5602. tabengali: 0x09A4,
  5603. tackdown: 0x22A4,
  5604. tackleft: 0x22A3,
  5605. tadeva: 0x0924,
  5606. tagujarati: 0x0AA4,
  5607. tagurmukhi: 0x0A24,
  5608. taharabic: 0x0637,
  5609. tahfinalarabic: 0xFEC2,
  5610. tahinitialarabic: 0xFEC3,
  5611. tahiragana: 0x305F,
  5612. tahmedialarabic: 0xFEC4,
  5613. taisyouerasquare: 0x337D,
  5614. takatakana: 0x30BF,
  5615. takatakanahalfwidth: 0xFF80,
  5616. tatweelarabic: 0x0640,
  5617. tau: 0x03C4,
  5618. tav: 0x05EA,
  5619. tavdages: 0xFB4A,
  5620. tavdagesh: 0xFB4A,
  5621. tavdageshhebrew: 0xFB4A,
  5622. tavhebrew: 0x05EA,
  5623. tbar: 0x0167,
  5624. tbopomofo: 0x310A,
  5625. tcaron: 0x0165,
  5626. tccurl: 0x02A8,
  5627. tcedilla: 0x0163,
  5628. tcheharabic: 0x0686,
  5629. tchehfinalarabic: 0xFB7B,
  5630. tchehinitialarabic: 0xFB7C,
  5631. tchehmedialarabic: 0xFB7D,
  5632. tcircle: 0x24E3,
  5633. tcircumflexbelow: 0x1E71,
  5634. tcommaaccent: 0x0163,
  5635. tdieresis: 0x1E97,
  5636. tdotaccent: 0x1E6B,
  5637. tdotbelow: 0x1E6D,
  5638. tecyrillic: 0x0442,
  5639. tedescendercyrillic: 0x04AD,
  5640. teharabic: 0x062A,
  5641. tehfinalarabic: 0xFE96,
  5642. tehhahinitialarabic: 0xFCA2,
  5643. tehhahisolatedarabic: 0xFC0C,
  5644. tehinitialarabic: 0xFE97,
  5645. tehiragana: 0x3066,
  5646. tehjeeminitialarabic: 0xFCA1,
  5647. tehjeemisolatedarabic: 0xFC0B,
  5648. tehmarbutaarabic: 0x0629,
  5649. tehmarbutafinalarabic: 0xFE94,
  5650. tehmedialarabic: 0xFE98,
  5651. tehmeeminitialarabic: 0xFCA4,
  5652. tehmeemisolatedarabic: 0xFC0E,
  5653. tehnoonfinalarabic: 0xFC73,
  5654. tekatakana: 0x30C6,
  5655. tekatakanahalfwidth: 0xFF83,
  5656. telephone: 0x2121,
  5657. telephoneblack: 0x260E,
  5658. telishagedolahebrew: 0x05A0,
  5659. telishaqetanahebrew: 0x05A9,
  5660. tencircle: 0x2469,
  5661. tenideographicparen: 0x3229,
  5662. tenparen: 0x247D,
  5663. tenperiod: 0x2491,
  5664. tenroman: 0x2179,
  5665. tesh: 0x02A7,
  5666. tet: 0x05D8,
  5667. tetdagesh: 0xFB38,
  5668. tetdageshhebrew: 0xFB38,
  5669. tethebrew: 0x05D8,
  5670. tetsecyrillic: 0x04B5,
  5671. tevirhebrew: 0x059B,
  5672. tevirlefthebrew: 0x059B,
  5673. thabengali: 0x09A5,
  5674. thadeva: 0x0925,
  5675. thagujarati: 0x0AA5,
  5676. thagurmukhi: 0x0A25,
  5677. thalarabic: 0x0630,
  5678. thalfinalarabic: 0xFEAC,
  5679. thanthakhatlowleftthai: 0xF898,
  5680. thanthakhatlowrightthai: 0xF897,
  5681. thanthakhatthai: 0x0E4C,
  5682. thanthakhatupperleftthai: 0xF896,
  5683. theharabic: 0x062B,
  5684. thehfinalarabic: 0xFE9A,
  5685. thehinitialarabic: 0xFE9B,
  5686. thehmedialarabic: 0xFE9C,
  5687. thereexists: 0x2203,
  5688. therefore: 0x2234,
  5689. theta: 0x03B8,
  5690. theta1: 0x03D1,
  5691. thetasymbolgreek: 0x03D1,
  5692. thieuthacirclekorean: 0x3279,
  5693. thieuthaparenkorean: 0x3219,
  5694. thieuthcirclekorean: 0x326B,
  5695. thieuthkorean: 0x314C,
  5696. thieuthparenkorean: 0x320B,
  5697. thirteencircle: 0x246C,
  5698. thirteenparen: 0x2480,
  5699. thirteenperiod: 0x2494,
  5700. thonangmonthothai: 0x0E11,
  5701. thook: 0x01AD,
  5702. thophuthaothai: 0x0E12,
  5703. thorn: 0x00FE,
  5704. thothahanthai: 0x0E17,
  5705. thothanthai: 0x0E10,
  5706. thothongthai: 0x0E18,
  5707. thothungthai: 0x0E16,
  5708. thousandcyrillic: 0x0482,
  5709. thousandsseparatorarabic: 0x066C,
  5710. thousandsseparatorpersian: 0x066C,
  5711. three: 0x0033,
  5712. threearabic: 0x0663,
  5713. threebengali: 0x09E9,
  5714. threecircle: 0x2462,
  5715. threecircleinversesansserif: 0x278C,
  5716. threedeva: 0x0969,
  5717. threeeighths: 0x215C,
  5718. threegujarati: 0x0AE9,
  5719. threegurmukhi: 0x0A69,
  5720. threehackarabic: 0x0663,
  5721. threehangzhou: 0x3023,
  5722. threeideographicparen: 0x3222,
  5723. threeinferior: 0x2083,
  5724. threemonospace: 0xFF13,
  5725. threenumeratorbengali: 0x09F6,
  5726. threeoldstyle: 0xF733,
  5727. threeparen: 0x2476,
  5728. threeperiod: 0x248A,
  5729. threepersian: 0x06F3,
  5730. threequarters: 0x00BE,
  5731. threequartersemdash: 0xF6DE,
  5732. threeroman: 0x2172,
  5733. threesuperior: 0x00B3,
  5734. threethai: 0x0E53,
  5735. thzsquare: 0x3394,
  5736. tihiragana: 0x3061,
  5737. tikatakana: 0x30C1,
  5738. tikatakanahalfwidth: 0xFF81,
  5739. tikeutacirclekorean: 0x3270,
  5740. tikeutaparenkorean: 0x3210,
  5741. tikeutcirclekorean: 0x3262,
  5742. tikeutkorean: 0x3137,
  5743. tikeutparenkorean: 0x3202,
  5744. tilde: 0x02DC,
  5745. tildebelowcmb: 0x0330,
  5746. tildecmb: 0x0303,
  5747. tildecomb: 0x0303,
  5748. tildedoublecmb: 0x0360,
  5749. tildeoperator: 0x223C,
  5750. tildeoverlaycmb: 0x0334,
  5751. tildeverticalcmb: 0x033E,
  5752. timescircle: 0x2297,
  5753. tipehahebrew: 0x0596,
  5754. tipehalefthebrew: 0x0596,
  5755. tippigurmukhi: 0x0A70,
  5756. titlocyrilliccmb: 0x0483,
  5757. tiwnarmenian: 0x057F,
  5758. tlinebelow: 0x1E6F,
  5759. tmonospace: 0xFF54,
  5760. toarmenian: 0x0569,
  5761. tohiragana: 0x3068,
  5762. tokatakana: 0x30C8,
  5763. tokatakanahalfwidth: 0xFF84,
  5764. tonebarextrahighmod: 0x02E5,
  5765. tonebarextralowmod: 0x02E9,
  5766. tonebarhighmod: 0x02E6,
  5767. tonebarlowmod: 0x02E8,
  5768. tonebarmidmod: 0x02E7,
  5769. tonefive: 0x01BD,
  5770. tonesix: 0x0185,
  5771. tonetwo: 0x01A8,
  5772. tonos: 0x0384,
  5773. tonsquare: 0x3327,
  5774. topatakthai: 0x0E0F,
  5775. tortoiseshellbracketleft: 0x3014,
  5776. tortoiseshellbracketleftsmall: 0xFE5D,
  5777. tortoiseshellbracketleftvertical: 0xFE39,
  5778. tortoiseshellbracketright: 0x3015,
  5779. tortoiseshellbracketrightsmall: 0xFE5E,
  5780. tortoiseshellbracketrightvertical: 0xFE3A,
  5781. totaothai: 0x0E15,
  5782. tpalatalhook: 0x01AB,
  5783. tparen: 0x24AF,
  5784. trademark: 0x2122,
  5785. trademarksans: 0xF8EA,
  5786. trademarkserif: 0xF6DB,
  5787. tretroflexhook: 0x0288,
  5788. triagdn: 0x25BC,
  5789. triaglf: 0x25C4,
  5790. triagrt: 0x25BA,
  5791. triagup: 0x25B2,
  5792. ts: 0x02A6,
  5793. tsadi: 0x05E6,
  5794. tsadidagesh: 0xFB46,
  5795. tsadidageshhebrew: 0xFB46,
  5796. tsadihebrew: 0x05E6,
  5797. tsecyrillic: 0x0446,
  5798. tsere: 0x05B5,
  5799. tsere12: 0x05B5,
  5800. tsere1e: 0x05B5,
  5801. tsere2b: 0x05B5,
  5802. tserehebrew: 0x05B5,
  5803. tserenarrowhebrew: 0x05B5,
  5804. tserequarterhebrew: 0x05B5,
  5805. tserewidehebrew: 0x05B5,
  5806. tshecyrillic: 0x045B,
  5807. tsuperior: 0xF6F3,
  5808. ttabengali: 0x099F,
  5809. ttadeva: 0x091F,
  5810. ttagujarati: 0x0A9F,
  5811. ttagurmukhi: 0x0A1F,
  5812. tteharabic: 0x0679,
  5813. ttehfinalarabic: 0xFB67,
  5814. ttehinitialarabic: 0xFB68,
  5815. ttehmedialarabic: 0xFB69,
  5816. tthabengali: 0x09A0,
  5817. tthadeva: 0x0920,
  5818. tthagujarati: 0x0AA0,
  5819. tthagurmukhi: 0x0A20,
  5820. tturned: 0x0287,
  5821. tuhiragana: 0x3064,
  5822. tukatakana: 0x30C4,
  5823. tukatakanahalfwidth: 0xFF82,
  5824. tusmallhiragana: 0x3063,
  5825. tusmallkatakana: 0x30C3,
  5826. tusmallkatakanahalfwidth: 0xFF6F,
  5827. twelvecircle: 0x246B,
  5828. twelveparen: 0x247F,
  5829. twelveperiod: 0x2493,
  5830. twelveroman: 0x217B,
  5831. twentycircle: 0x2473,
  5832. twentyhangzhou: 0x5344,
  5833. twentyparen: 0x2487,
  5834. twentyperiod: 0x249B,
  5835. two: 0x0032,
  5836. twoarabic: 0x0662,
  5837. twobengali: 0x09E8,
  5838. twocircle: 0x2461,
  5839. twocircleinversesansserif: 0x278B,
  5840. twodeva: 0x0968,
  5841. twodotenleader: 0x2025,
  5842. twodotleader: 0x2025,
  5843. twodotleadervertical: 0xFE30,
  5844. twogujarati: 0x0AE8,
  5845. twogurmukhi: 0x0A68,
  5846. twohackarabic: 0x0662,
  5847. twohangzhou: 0x3022,
  5848. twoideographicparen: 0x3221,
  5849. twoinferior: 0x2082,
  5850. twomonospace: 0xFF12,
  5851. twonumeratorbengali: 0x09F5,
  5852. twooldstyle: 0xF732,
  5853. twoparen: 0x2475,
  5854. twoperiod: 0x2489,
  5855. twopersian: 0x06F2,
  5856. tworoman: 0x2171,
  5857. twostroke: 0x01BB,
  5858. twosuperior: 0x00B2,
  5859. twothai: 0x0E52,
  5860. twothirds: 0x2154,
  5861. u: 0x0075,
  5862. uacute: 0x00FA,
  5863. ubar: 0x0289,
  5864. ubengali: 0x0989,
  5865. ubopomofo: 0x3128,
  5866. ubreve: 0x016D,
  5867. ucaron: 0x01D4,
  5868. ucircle: 0x24E4,
  5869. ucircumflex: 0x00FB,
  5870. ucircumflexbelow: 0x1E77,
  5871. ucyrillic: 0x0443,
  5872. udattadeva: 0x0951,
  5873. udblacute: 0x0171,
  5874. udblgrave: 0x0215,
  5875. udeva: 0x0909,
  5876. udieresis: 0x00FC,
  5877. udieresisacute: 0x01D8,
  5878. udieresisbelow: 0x1E73,
  5879. udieresiscaron: 0x01DA,
  5880. udieresiscyrillic: 0x04F1,
  5881. udieresisgrave: 0x01DC,
  5882. udieresismacron: 0x01D6,
  5883. udotbelow: 0x1EE5,
  5884. ugrave: 0x00F9,
  5885. ugujarati: 0x0A89,
  5886. ugurmukhi: 0x0A09,
  5887. uhiragana: 0x3046,
  5888. uhookabove: 0x1EE7,
  5889. uhorn: 0x01B0,
  5890. uhornacute: 0x1EE9,
  5891. uhorndotbelow: 0x1EF1,
  5892. uhorngrave: 0x1EEB,
  5893. uhornhookabove: 0x1EED,
  5894. uhorntilde: 0x1EEF,
  5895. uhungarumlaut: 0x0171,
  5896. uhungarumlautcyrillic: 0x04F3,
  5897. uinvertedbreve: 0x0217,
  5898. ukatakana: 0x30A6,
  5899. ukatakanahalfwidth: 0xFF73,
  5900. ukcyrillic: 0x0479,
  5901. ukorean: 0x315C,
  5902. umacron: 0x016B,
  5903. umacroncyrillic: 0x04EF,
  5904. umacrondieresis: 0x1E7B,
  5905. umatragurmukhi: 0x0A41,
  5906. umonospace: 0xFF55,
  5907. underscore: 0x005F,
  5908. underscoredbl: 0x2017,
  5909. underscoremonospace: 0xFF3F,
  5910. underscorevertical: 0xFE33,
  5911. underscorewavy: 0xFE4F,
  5912. union: 0x222A,
  5913. universal: 0x2200,
  5914. uogonek: 0x0173,
  5915. uparen: 0x24B0,
  5916. upblock: 0x2580,
  5917. upperdothebrew: 0x05C4,
  5918. upsilon: 0x03C5,
  5919. upsilondieresis: 0x03CB,
  5920. upsilondieresistonos: 0x03B0,
  5921. upsilonlatin: 0x028A,
  5922. upsilontonos: 0x03CD,
  5923. uptackbelowcmb: 0x031D,
  5924. uptackmod: 0x02D4,
  5925. uragurmukhi: 0x0A73,
  5926. uring: 0x016F,
  5927. ushortcyrillic: 0x045E,
  5928. usmallhiragana: 0x3045,
  5929. usmallkatakana: 0x30A5,
  5930. usmallkatakanahalfwidth: 0xFF69,
  5931. ustraightcyrillic: 0x04AF,
  5932. ustraightstrokecyrillic: 0x04B1,
  5933. utilde: 0x0169,
  5934. utildeacute: 0x1E79,
  5935. utildebelow: 0x1E75,
  5936. uubengali: 0x098A,
  5937. uudeva: 0x090A,
  5938. uugujarati: 0x0A8A,
  5939. uugurmukhi: 0x0A0A,
  5940. uumatragurmukhi: 0x0A42,
  5941. uuvowelsignbengali: 0x09C2,
  5942. uuvowelsigndeva: 0x0942,
  5943. uuvowelsigngujarati: 0x0AC2,
  5944. uvowelsignbengali: 0x09C1,
  5945. uvowelsigndeva: 0x0941,
  5946. uvowelsigngujarati: 0x0AC1,
  5947. v: 0x0076,
  5948. vadeva: 0x0935,
  5949. vagujarati: 0x0AB5,
  5950. vagurmukhi: 0x0A35,
  5951. vakatakana: 0x30F7,
  5952. vav: 0x05D5,
  5953. vavdagesh: 0xFB35,
  5954. vavdagesh65: 0xFB35,
  5955. vavdageshhebrew: 0xFB35,
  5956. vavhebrew: 0x05D5,
  5957. vavholam: 0xFB4B,
  5958. vavholamhebrew: 0xFB4B,
  5959. vavvavhebrew: 0x05F0,
  5960. vavyodhebrew: 0x05F1,
  5961. vcircle: 0x24E5,
  5962. vdotbelow: 0x1E7F,
  5963. vecyrillic: 0x0432,
  5964. veharabic: 0x06A4,
  5965. vehfinalarabic: 0xFB6B,
  5966. vehinitialarabic: 0xFB6C,
  5967. vehmedialarabic: 0xFB6D,
  5968. vekatakana: 0x30F9,
  5969. venus: 0x2640,
  5970. verticalbar: 0x007C,
  5971. verticallineabovecmb: 0x030D,
  5972. verticallinebelowcmb: 0x0329,
  5973. verticallinelowmod: 0x02CC,
  5974. verticallinemod: 0x02C8,
  5975. vewarmenian: 0x057E,
  5976. vhook: 0x028B,
  5977. vikatakana: 0x30F8,
  5978. viramabengali: 0x09CD,
  5979. viramadeva: 0x094D,
  5980. viramagujarati: 0x0ACD,
  5981. visargabengali: 0x0983,
  5982. visargadeva: 0x0903,
  5983. visargagujarati: 0x0A83,
  5984. vmonospace: 0xFF56,
  5985. voarmenian: 0x0578,
  5986. voicediterationhiragana: 0x309E,
  5987. voicediterationkatakana: 0x30FE,
  5988. voicedmarkkana: 0x309B,
  5989. voicedmarkkanahalfwidth: 0xFF9E,
  5990. vokatakana: 0x30FA,
  5991. vparen: 0x24B1,
  5992. vtilde: 0x1E7D,
  5993. vturned: 0x028C,
  5994. vuhiragana: 0x3094,
  5995. vukatakana: 0x30F4,
  5996. w: 0x0077,
  5997. wacute: 0x1E83,
  5998. waekorean: 0x3159,
  5999. wahiragana: 0x308F,
  6000. wakatakana: 0x30EF,
  6001. wakatakanahalfwidth: 0xFF9C,
  6002. wakorean: 0x3158,
  6003. wasmallhiragana: 0x308E,
  6004. wasmallkatakana: 0x30EE,
  6005. wattosquare: 0x3357,
  6006. wavedash: 0x301C,
  6007. wavyunderscorevertical: 0xFE34,
  6008. wawarabic: 0x0648,
  6009. wawfinalarabic: 0xFEEE,
  6010. wawhamzaabovearabic: 0x0624,
  6011. wawhamzaabovefinalarabic: 0xFE86,
  6012. wbsquare: 0x33DD,
  6013. wcircle: 0x24E6,
  6014. wcircumflex: 0x0175,
  6015. wdieresis: 0x1E85,
  6016. wdotaccent: 0x1E87,
  6017. wdotbelow: 0x1E89,
  6018. wehiragana: 0x3091,
  6019. weierstrass: 0x2118,
  6020. wekatakana: 0x30F1,
  6021. wekorean: 0x315E,
  6022. weokorean: 0x315D,
  6023. wgrave: 0x1E81,
  6024. whitebullet: 0x25E6,
  6025. whitecircle: 0x25CB,
  6026. whitecircleinverse: 0x25D9,
  6027. whitecornerbracketleft: 0x300E,
  6028. whitecornerbracketleftvertical: 0xFE43,
  6029. whitecornerbracketright: 0x300F,
  6030. whitecornerbracketrightvertical: 0xFE44,
  6031. whitediamond: 0x25C7,
  6032. whitediamondcontainingblacksmalldiamond: 0x25C8,
  6033. whitedownpointingsmalltriangle: 0x25BF,
  6034. whitedownpointingtriangle: 0x25BD,
  6035. whiteleftpointingsmalltriangle: 0x25C3,
  6036. whiteleftpointingtriangle: 0x25C1,
  6037. whitelenticularbracketleft: 0x3016,
  6038. whitelenticularbracketright: 0x3017,
  6039. whiterightpointingsmalltriangle: 0x25B9,
  6040. whiterightpointingtriangle: 0x25B7,
  6041. whitesmallsquare: 0x25AB,
  6042. whitesmilingface: 0x263A,
  6043. whitesquare: 0x25A1,
  6044. whitestar: 0x2606,
  6045. whitetelephone: 0x260F,
  6046. whitetortoiseshellbracketleft: 0x3018,
  6047. whitetortoiseshellbracketright: 0x3019,
  6048. whiteuppointingsmalltriangle: 0x25B5,
  6049. whiteuppointingtriangle: 0x25B3,
  6050. wihiragana: 0x3090,
  6051. wikatakana: 0x30F0,
  6052. wikorean: 0x315F,
  6053. wmonospace: 0xFF57,
  6054. wohiragana: 0x3092,
  6055. wokatakana: 0x30F2,
  6056. wokatakanahalfwidth: 0xFF66,
  6057. won: 0x20A9,
  6058. wonmonospace: 0xFFE6,
  6059. wowaenthai: 0x0E27,
  6060. wparen: 0x24B2,
  6061. wring: 0x1E98,
  6062. wsuperior: 0x02B7,
  6063. wturned: 0x028D,
  6064. wynn: 0x01BF,
  6065. x: 0x0078,
  6066. xabovecmb: 0x033D,
  6067. xbopomofo: 0x3112,
  6068. xcircle: 0x24E7,
  6069. xdieresis: 0x1E8D,
  6070. xdotaccent: 0x1E8B,
  6071. xeharmenian: 0x056D,
  6072. xi: 0x03BE,
  6073. xmonospace: 0xFF58,
  6074. xparen: 0x24B3,
  6075. xsuperior: 0x02E3,
  6076. y: 0x0079,
  6077. yaadosquare: 0x334E,
  6078. yabengali: 0x09AF,
  6079. yacute: 0x00FD,
  6080. yadeva: 0x092F,
  6081. yaekorean: 0x3152,
  6082. yagujarati: 0x0AAF,
  6083. yagurmukhi: 0x0A2F,
  6084. yahiragana: 0x3084,
  6085. yakatakana: 0x30E4,
  6086. yakatakanahalfwidth: 0xFF94,
  6087. yakorean: 0x3151,
  6088. yamakkanthai: 0x0E4E,
  6089. yasmallhiragana: 0x3083,
  6090. yasmallkatakana: 0x30E3,
  6091. yasmallkatakanahalfwidth: 0xFF6C,
  6092. yatcyrillic: 0x0463,
  6093. ycircle: 0x24E8,
  6094. ycircumflex: 0x0177,
  6095. ydieresis: 0x00FF,
  6096. ydotaccent: 0x1E8F,
  6097. ydotbelow: 0x1EF5,
  6098. yeharabic: 0x064A,
  6099. yehbarreearabic: 0x06D2,
  6100. yehbarreefinalarabic: 0xFBAF,
  6101. yehfinalarabic: 0xFEF2,
  6102. yehhamzaabovearabic: 0x0626,
  6103. yehhamzaabovefinalarabic: 0xFE8A,
  6104. yehhamzaaboveinitialarabic: 0xFE8B,
  6105. yehhamzaabovemedialarabic: 0xFE8C,
  6106. yehinitialarabic: 0xFEF3,
  6107. yehmedialarabic: 0xFEF4,
  6108. yehmeeminitialarabic: 0xFCDD,
  6109. yehmeemisolatedarabic: 0xFC58,
  6110. yehnoonfinalarabic: 0xFC94,
  6111. yehthreedotsbelowarabic: 0x06D1,
  6112. yekorean: 0x3156,
  6113. yen: 0x00A5,
  6114. yenmonospace: 0xFFE5,
  6115. yeokorean: 0x3155,
  6116. yeorinhieuhkorean: 0x3186,
  6117. yerahbenyomohebrew: 0x05AA,
  6118. yerahbenyomolefthebrew: 0x05AA,
  6119. yericyrillic: 0x044B,
  6120. yerudieresiscyrillic: 0x04F9,
  6121. yesieungkorean: 0x3181,
  6122. yesieungpansioskorean: 0x3183,
  6123. yesieungsioskorean: 0x3182,
  6124. yetivhebrew: 0x059A,
  6125. ygrave: 0x1EF3,
  6126. yhook: 0x01B4,
  6127. yhookabove: 0x1EF7,
  6128. yiarmenian: 0x0575,
  6129. yicyrillic: 0x0457,
  6130. yikorean: 0x3162,
  6131. yinyang: 0x262F,
  6132. yiwnarmenian: 0x0582,
  6133. ymonospace: 0xFF59,
  6134. yod: 0x05D9,
  6135. yoddagesh: 0xFB39,
  6136. yoddageshhebrew: 0xFB39,
  6137. yodhebrew: 0x05D9,
  6138. yodyodhebrew: 0x05F2,
  6139. yodyodpatahhebrew: 0xFB1F,
  6140. yohiragana: 0x3088,
  6141. yoikorean: 0x3189,
  6142. yokatakana: 0x30E8,
  6143. yokatakanahalfwidth: 0xFF96,
  6144. yokorean: 0x315B,
  6145. yosmallhiragana: 0x3087,
  6146. yosmallkatakana: 0x30E7,
  6147. yosmallkatakanahalfwidth: 0xFF6E,
  6148. yotgreek: 0x03F3,
  6149. yoyaekorean: 0x3188,
  6150. yoyakorean: 0x3187,
  6151. yoyakthai: 0x0E22,
  6152. yoyingthai: 0x0E0D,
  6153. yparen: 0x24B4,
  6154. ypogegrammeni: 0x037A,
  6155. ypogegrammenigreekcmb: 0x0345,
  6156. yr: 0x01A6,
  6157. yring: 0x1E99,
  6158. ysuperior: 0x02B8,
  6159. ytilde: 0x1EF9,
  6160. yturned: 0x028E,
  6161. yuhiragana: 0x3086,
  6162. yuikorean: 0x318C,
  6163. yukatakana: 0x30E6,
  6164. yukatakanahalfwidth: 0xFF95,
  6165. yukorean: 0x3160,
  6166. yusbigcyrillic: 0x046B,
  6167. yusbigiotifiedcyrillic: 0x046D,
  6168. yuslittlecyrillic: 0x0467,
  6169. yuslittleiotifiedcyrillic: 0x0469,
  6170. yusmallhiragana: 0x3085,
  6171. yusmallkatakana: 0x30E5,
  6172. yusmallkatakanahalfwidth: 0xFF6D,
  6173. yuyekorean: 0x318B,
  6174. yuyeokorean: 0x318A,
  6175. yyabengali: 0x09DF,
  6176. yyadeva: 0x095F,
  6177. z: 0x007A,
  6178. zaarmenian: 0x0566,
  6179. zacute: 0x017A,
  6180. zadeva: 0x095B,
  6181. zagurmukhi: 0x0A5B,
  6182. zaharabic: 0x0638,
  6183. zahfinalarabic: 0xFEC6,
  6184. zahinitialarabic: 0xFEC7,
  6185. zahiragana: 0x3056,
  6186. zahmedialarabic: 0xFEC8,
  6187. zainarabic: 0x0632,
  6188. zainfinalarabic: 0xFEB0,
  6189. zakatakana: 0x30B6,
  6190. zaqefgadolhebrew: 0x0595,
  6191. zaqefqatanhebrew: 0x0594,
  6192. zarqahebrew: 0x0598,
  6193. zayin: 0x05D6,
  6194. zayindagesh: 0xFB36,
  6195. zayindageshhebrew: 0xFB36,
  6196. zayinhebrew: 0x05D6,
  6197. zbopomofo: 0x3117,
  6198. zcaron: 0x017E,
  6199. zcircle: 0x24E9,
  6200. zcircumflex: 0x1E91,
  6201. zcurl: 0x0291,
  6202. zdot: 0x017C,
  6203. zdotaccent: 0x017C,
  6204. zdotbelow: 0x1E93,
  6205. zecyrillic: 0x0437,
  6206. zedescendercyrillic: 0x0499,
  6207. zedieresiscyrillic: 0x04DF,
  6208. zehiragana: 0x305C,
  6209. zekatakana: 0x30BC,
  6210. zero: 0x0030,
  6211. zeroarabic: 0x0660,
  6212. zerobengali: 0x09E6,
  6213. zerodeva: 0x0966,
  6214. zerogujarati: 0x0AE6,
  6215. zerogurmukhi: 0x0A66,
  6216. zerohackarabic: 0x0660,
  6217. zeroinferior: 0x2080,
  6218. zeromonospace: 0xFF10,
  6219. zerooldstyle: 0xF730,
  6220. zeropersian: 0x06F0,
  6221. zerosuperior: 0x2070,
  6222. zerothai: 0x0E50,
  6223. zerowidthjoiner: 0xFEFF,
  6224. zerowidthnonjoiner: 0x200C,
  6225. zerowidthspace: 0x200B,
  6226. zeta: 0x03B6,
  6227. zhbopomofo: 0x3113,
  6228. zhearmenian: 0x056A,
  6229. zhebrevecyrillic: 0x04C2,
  6230. zhecyrillic: 0x0436,
  6231. zhedescendercyrillic: 0x0497,
  6232. zhedieresiscyrillic: 0x04DD,
  6233. zihiragana: 0x3058,
  6234. zikatakana: 0x30B8,
  6235. zinorhebrew: 0x05AE,
  6236. zlinebelow: 0x1E95,
  6237. zmonospace: 0xFF5A,
  6238. zohiragana: 0x305E,
  6239. zokatakana: 0x30BE,
  6240. zparen: 0x24B5,
  6241. zretroflexhook: 0x0290,
  6242. zstroke: 0x01B6,
  6243. zuhiragana: 0x305A,
  6244. zukatakana: 0x30BA,
  6245. '.notdef': 0x0000
  6246. };
  6247. var DingbatsGlyphsUnicode = {
  6248. space: 0x0020,
  6249. a1: 0x2701,
  6250. a2: 0x2702,
  6251. a202: 0x2703,
  6252. a3: 0x2704,
  6253. a4: 0x260E,
  6254. a5: 0x2706,
  6255. a119: 0x2707,
  6256. a118: 0x2708,
  6257. a117: 0x2709,
  6258. a11: 0x261B,
  6259. a12: 0x261E,
  6260. a13: 0x270C,
  6261. a14: 0x270D,
  6262. a15: 0x270E,
  6263. a16: 0x270F,
  6264. a105: 0x2710,
  6265. a17: 0x2711,
  6266. a18: 0x2712,
  6267. a19: 0x2713,
  6268. a20: 0x2714,
  6269. a21: 0x2715,
  6270. a22: 0x2716,
  6271. a23: 0x2717,
  6272. a24: 0x2718,
  6273. a25: 0x2719,
  6274. a26: 0x271A,
  6275. a27: 0x271B,
  6276. a28: 0x271C,
  6277. a6: 0x271D,
  6278. a7: 0x271E,
  6279. a8: 0x271F,
  6280. a9: 0x2720,
  6281. a10: 0x2721,
  6282. a29: 0x2722,
  6283. a30: 0x2723,
  6284. a31: 0x2724,
  6285. a32: 0x2725,
  6286. a33: 0x2726,
  6287. a34: 0x2727,
  6288. a35: 0x2605,
  6289. a36: 0x2729,
  6290. a37: 0x272A,
  6291. a38: 0x272B,
  6292. a39: 0x272C,
  6293. a40: 0x272D,
  6294. a41: 0x272E,
  6295. a42: 0x272F,
  6296. a43: 0x2730,
  6297. a44: 0x2731,
  6298. a45: 0x2732,
  6299. a46: 0x2733,
  6300. a47: 0x2734,
  6301. a48: 0x2735,
  6302. a49: 0x2736,
  6303. a50: 0x2737,
  6304. a51: 0x2738,
  6305. a52: 0x2739,
  6306. a53: 0x273A,
  6307. a54: 0x273B,
  6308. a55: 0x273C,
  6309. a56: 0x273D,
  6310. a57: 0x273E,
  6311. a58: 0x273F,
  6312. a59: 0x2740,
  6313. a60: 0x2741,
  6314. a61: 0x2742,
  6315. a62: 0x2743,
  6316. a63: 0x2744,
  6317. a64: 0x2745,
  6318. a65: 0x2746,
  6319. a66: 0x2747,
  6320. a67: 0x2748,
  6321. a68: 0x2749,
  6322. a69: 0x274A,
  6323. a70: 0x274B,
  6324. a71: 0x25CF,
  6325. a72: 0x274D,
  6326. a73: 0x25A0,
  6327. a74: 0x274F,
  6328. a203: 0x2750,
  6329. a75: 0x2751,
  6330. a204: 0x2752,
  6331. a76: 0x25B2,
  6332. a77: 0x25BC,
  6333. a78: 0x25C6,
  6334. a79: 0x2756,
  6335. a81: 0x25D7,
  6336. a82: 0x2758,
  6337. a83: 0x2759,
  6338. a84: 0x275A,
  6339. a97: 0x275B,
  6340. a98: 0x275C,
  6341. a99: 0x275D,
  6342. a100: 0x275E,
  6343. a101: 0x2761,
  6344. a102: 0x2762,
  6345. a103: 0x2763,
  6346. a104: 0x2764,
  6347. a106: 0x2765,
  6348. a107: 0x2766,
  6349. a108: 0x2767,
  6350. a112: 0x2663,
  6351. a111: 0x2666,
  6352. a110: 0x2665,
  6353. a109: 0x2660,
  6354. a120: 0x2460,
  6355. a121: 0x2461,
  6356. a122: 0x2462,
  6357. a123: 0x2463,
  6358. a124: 0x2464,
  6359. a125: 0x2465,
  6360. a126: 0x2466,
  6361. a127: 0x2467,
  6362. a128: 0x2468,
  6363. a129: 0x2469,
  6364. a130: 0x2776,
  6365. a131: 0x2777,
  6366. a132: 0x2778,
  6367. a133: 0x2779,
  6368. a134: 0x277A,
  6369. a135: 0x277B,
  6370. a136: 0x277C,
  6371. a137: 0x277D,
  6372. a138: 0x277E,
  6373. a139: 0x277F,
  6374. a140: 0x2780,
  6375. a141: 0x2781,
  6376. a142: 0x2782,
  6377. a143: 0x2783,
  6378. a144: 0x2784,
  6379. a145: 0x2785,
  6380. a146: 0x2786,
  6381. a147: 0x2787,
  6382. a148: 0x2788,
  6383. a149: 0x2789,
  6384. a150: 0x278A,
  6385. a151: 0x278B,
  6386. a152: 0x278C,
  6387. a153: 0x278D,
  6388. a154: 0x278E,
  6389. a155: 0x278F,
  6390. a156: 0x2790,
  6391. a157: 0x2791,
  6392. a158: 0x2792,
  6393. a159: 0x2793,
  6394. a160: 0x2794,
  6395. a161: 0x2192,
  6396. a163: 0x2194,
  6397. a164: 0x2195,
  6398. a196: 0x2798,
  6399. a165: 0x2799,
  6400. a192: 0x279A,
  6401. a166: 0x279B,
  6402. a167: 0x279C,
  6403. a168: 0x279D,
  6404. a169: 0x279E,
  6405. a170: 0x279F,
  6406. a171: 0x27A0,
  6407. a172: 0x27A1,
  6408. a173: 0x27A2,
  6409. a162: 0x27A3,
  6410. a174: 0x27A4,
  6411. a175: 0x27A5,
  6412. a176: 0x27A6,
  6413. a177: 0x27A7,
  6414. a178: 0x27A8,
  6415. a179: 0x27A9,
  6416. a193: 0x27AA,
  6417. a180: 0x27AB,
  6418. a199: 0x27AC,
  6419. a181: 0x27AD,
  6420. a200: 0x27AE,
  6421. a182: 0x27AF,
  6422. a201: 0x27B1,
  6423. a183: 0x27B2,
  6424. a184: 0x27B3,
  6425. a197: 0x27B4,
  6426. a185: 0x27B5,
  6427. a194: 0x27B6,
  6428. a198: 0x27B7,
  6429. a186: 0x27B8,
  6430. a195: 0x27B9,
  6431. a187: 0x27BA,
  6432. a188: 0x27BB,
  6433. a189: 0x27BC,
  6434. a190: 0x27BD,
  6435. a191: 0x27BE,
  6436. a89: 0x2768, // 0xF8D7
  6437. a90: 0x2769, // 0xF8D8
  6438. a93: 0x276A, // 0xF8D9
  6439. a94: 0x276B, // 0xF8DA
  6440. a91: 0x276C, // 0xF8DB
  6441. a92: 0x276D, // 0xF8DC
  6442. a205: 0x276E, // 0xF8DD
  6443. a85: 0x276F, // 0xF8DE
  6444. a206: 0x2770, // 0xF8DF
  6445. a86: 0x2771, // 0xF8E0
  6446. a87: 0x2772, // 0xF8E1
  6447. a88: 0x2773, // 0xF8E2
  6448. a95: 0x2774, // 0xF8E3
  6449. a96: 0x2775, // 0xF8E4
  6450. '.notdef': 0x0000
  6451. };
  6452. exports.GlyphsUnicode = GlyphsUnicode;
  6453. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  6454. }));
  6455. (function (root, factory) {
  6456. {
  6457. factory((root.pdfjsCoreJpg = {}));
  6458. }
  6459. }(this, function (exports) {
  6460. /*
  6461. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  6462. version was created by github user notmasteryet
  6463. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  6464. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  6465. - The JFIF specification can be found in the JPEG File Interchange Format
  6466. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  6467. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  6468. in PostScript Level 2, Technical Note #5116
  6469. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  6470. */
  6471. var JpegImage = (function jpegImage() {
  6472. var dctZigZag = new Uint8Array([
  6473. 0,
  6474. 1, 8,
  6475. 16, 9, 2,
  6476. 3, 10, 17, 24,
  6477. 32, 25, 18, 11, 4,
  6478. 5, 12, 19, 26, 33, 40,
  6479. 48, 41, 34, 27, 20, 13, 6,
  6480. 7, 14, 21, 28, 35, 42, 49, 56,
  6481. 57, 50, 43, 36, 29, 22, 15,
  6482. 23, 30, 37, 44, 51, 58,
  6483. 59, 52, 45, 38, 31,
  6484. 39, 46, 53, 60,
  6485. 61, 54, 47,
  6486. 55, 62,
  6487. 63
  6488. ]);
  6489. var dctCos1 = 4017; // cos(pi/16)
  6490. var dctSin1 = 799; // sin(pi/16)
  6491. var dctCos3 = 3406; // cos(3*pi/16)
  6492. var dctSin3 = 2276; // sin(3*pi/16)
  6493. var dctCos6 = 1567; // cos(6*pi/16)
  6494. var dctSin6 = 3784; // sin(6*pi/16)
  6495. var dctSqrt2 = 5793; // sqrt(2)
  6496. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  6497. function constructor() {
  6498. }
  6499. function buildHuffmanTable(codeLengths, values) {
  6500. var k = 0, code = [], i, j, length = 16;
  6501. while (length > 0 && !codeLengths[length - 1]) {
  6502. length--;
  6503. }
  6504. code.push({children: [], index: 0});
  6505. var p = code[0], q;
  6506. for (i = 0; i < length; i++) {
  6507. for (j = 0; j < codeLengths[i]; j++) {
  6508. p = code.pop();
  6509. p.children[p.index] = values[k];
  6510. while (p.index > 0) {
  6511. p = code.pop();
  6512. }
  6513. p.index++;
  6514. code.push(p);
  6515. while (code.length <= i) {
  6516. code.push(q = {children: [], index: 0});
  6517. p.children[p.index] = q.children;
  6518. p = q;
  6519. }
  6520. k++;
  6521. }
  6522. if (i + 1 < length) {
  6523. // p here points to last code
  6524. code.push(q = {children: [], index: 0});
  6525. p.children[p.index] = q.children;
  6526. p = q;
  6527. }
  6528. }
  6529. return code[0].children;
  6530. }
  6531. function getBlockBufferOffset(component, row, col) {
  6532. return 64 * ((component.blocksPerLine + 1) * row + col);
  6533. }
  6534. function decodeScan(data, offset, frame, components, resetInterval,
  6535. spectralStart, spectralEnd, successivePrev, successive) {
  6536. var mcusPerLine = frame.mcusPerLine;
  6537. var progressive = frame.progressive;
  6538. var startOffset = offset, bitsData = 0, bitsCount = 0;
  6539. function readBit() {
  6540. if (bitsCount > 0) {
  6541. bitsCount--;
  6542. return (bitsData >> bitsCount) & 1;
  6543. }
  6544. bitsData = data[offset++];
  6545. if (bitsData === 0xFF) {
  6546. var nextByte = data[offset++];
  6547. if (nextByte) {
  6548. throw 'unexpected marker: ' +
  6549. ((bitsData << 8) | nextByte).toString(16);
  6550. }
  6551. // unstuff 0
  6552. }
  6553. bitsCount = 7;
  6554. return bitsData >>> 7;
  6555. }
  6556. function decodeHuffman(tree) {
  6557. var node = tree;
  6558. while (true) {
  6559. node = node[readBit()];
  6560. if (typeof node === 'number') {
  6561. return node;
  6562. }
  6563. if (typeof node !== 'object') {
  6564. throw 'invalid huffman sequence';
  6565. }
  6566. }
  6567. }
  6568. function receive(length) {
  6569. var n = 0;
  6570. while (length > 0) {
  6571. n = (n << 1) | readBit();
  6572. length--;
  6573. }
  6574. return n;
  6575. }
  6576. function receiveAndExtend(length) {
  6577. if (length === 1) {
  6578. return readBit() === 1 ? 1 : -1;
  6579. }
  6580. var n = receive(length);
  6581. if (n >= 1 << (length - 1)) {
  6582. return n;
  6583. }
  6584. return n + (-1 << length) + 1;
  6585. }
  6586. function decodeBaseline(component, offset) {
  6587. var t = decodeHuffman(component.huffmanTableDC);
  6588. var diff = t === 0 ? 0 : receiveAndExtend(t);
  6589. component.blockData[offset] = (component.pred += diff);
  6590. var k = 1;
  6591. while (k < 64) {
  6592. var rs = decodeHuffman(component.huffmanTableAC);
  6593. var s = rs & 15, r = rs >> 4;
  6594. if (s === 0) {
  6595. if (r < 15) {
  6596. break;
  6597. }
  6598. k += 16;
  6599. continue;
  6600. }
  6601. k += r;
  6602. var z = dctZigZag[k];
  6603. component.blockData[offset + z] = receiveAndExtend(s);
  6604. k++;
  6605. }
  6606. }
  6607. function decodeDCFirst(component, offset) {
  6608. var t = decodeHuffman(component.huffmanTableDC);
  6609. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  6610. component.blockData[offset] = (component.pred += diff);
  6611. }
  6612. function decodeDCSuccessive(component, offset) {
  6613. component.blockData[offset] |= readBit() << successive;
  6614. }
  6615. var eobrun = 0;
  6616. function decodeACFirst(component, offset) {
  6617. if (eobrun > 0) {
  6618. eobrun--;
  6619. return;
  6620. }
  6621. var k = spectralStart, e = spectralEnd;
  6622. while (k <= e) {
  6623. var rs = decodeHuffman(component.huffmanTableAC);
  6624. var s = rs & 15, r = rs >> 4;
  6625. if (s === 0) {
  6626. if (r < 15) {
  6627. eobrun = receive(r) + (1 << r) - 1;
  6628. break;
  6629. }
  6630. k += 16;
  6631. continue;
  6632. }
  6633. k += r;
  6634. var z = dctZigZag[k];
  6635. component.blockData[offset + z] =
  6636. receiveAndExtend(s) * (1 << successive);
  6637. k++;
  6638. }
  6639. }
  6640. var successiveACState = 0, successiveACNextValue;
  6641. function decodeACSuccessive(component, offset) {
  6642. var k = spectralStart;
  6643. var e = spectralEnd;
  6644. var r = 0;
  6645. var s;
  6646. var rs;
  6647. while (k <= e) {
  6648. var z = dctZigZag[k];
  6649. switch (successiveACState) {
  6650. case 0: // initial state
  6651. rs = decodeHuffman(component.huffmanTableAC);
  6652. s = rs & 15;
  6653. r = rs >> 4;
  6654. if (s === 0) {
  6655. if (r < 15) {
  6656. eobrun = receive(r) + (1 << r);
  6657. successiveACState = 4;
  6658. } else {
  6659. r = 16;
  6660. successiveACState = 1;
  6661. }
  6662. } else {
  6663. if (s !== 1) {
  6664. throw 'invalid ACn encoding';
  6665. }
  6666. successiveACNextValue = receiveAndExtend(s);
  6667. successiveACState = r ? 2 : 3;
  6668. }
  6669. continue;
  6670. case 1: // skipping r zero items
  6671. case 2:
  6672. if (component.blockData[offset + z]) {
  6673. component.blockData[offset + z] += (readBit() << successive);
  6674. } else {
  6675. r--;
  6676. if (r === 0) {
  6677. successiveACState = successiveACState === 2 ? 3 : 0;
  6678. }
  6679. }
  6680. break;
  6681. case 3: // set value for a zero item
  6682. if (component.blockData[offset + z]) {
  6683. component.blockData[offset + z] += (readBit() << successive);
  6684. } else {
  6685. component.blockData[offset + z] =
  6686. successiveACNextValue << successive;
  6687. successiveACState = 0;
  6688. }
  6689. break;
  6690. case 4: // eob
  6691. if (component.blockData[offset + z]) {
  6692. component.blockData[offset + z] += (readBit() << successive);
  6693. }
  6694. break;
  6695. }
  6696. k++;
  6697. }
  6698. if (successiveACState === 4) {
  6699. eobrun--;
  6700. if (eobrun === 0) {
  6701. successiveACState = 0;
  6702. }
  6703. }
  6704. }
  6705. function decodeMcu(component, decode, mcu, row, col) {
  6706. var mcuRow = (mcu / mcusPerLine) | 0;
  6707. var mcuCol = mcu % mcusPerLine;
  6708. var blockRow = mcuRow * component.v + row;
  6709. var blockCol = mcuCol * component.h + col;
  6710. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6711. decode(component, offset);
  6712. }
  6713. function decodeBlock(component, decode, mcu) {
  6714. var blockRow = (mcu / component.blocksPerLine) | 0;
  6715. var blockCol = mcu % component.blocksPerLine;
  6716. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6717. decode(component, offset);
  6718. }
  6719. var componentsLength = components.length;
  6720. var component, i, j, k, n;
  6721. var decodeFn;
  6722. if (progressive) {
  6723. if (spectralStart === 0) {
  6724. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  6725. } else {
  6726. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  6727. }
  6728. } else {
  6729. decodeFn = decodeBaseline;
  6730. }
  6731. var mcu = 0, marker;
  6732. var mcuExpected;
  6733. if (componentsLength === 1) {
  6734. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  6735. } else {
  6736. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  6737. }
  6738. if (!resetInterval) {
  6739. resetInterval = mcuExpected;
  6740. }
  6741. var h, v;
  6742. while (mcu < mcuExpected) {
  6743. // reset interval stuff
  6744. for (i = 0; i < componentsLength; i++) {
  6745. components[i].pred = 0;
  6746. }
  6747. eobrun = 0;
  6748. if (componentsLength === 1) {
  6749. component = components[0];
  6750. for (n = 0; n < resetInterval; n++) {
  6751. decodeBlock(component, decodeFn, mcu);
  6752. mcu++;
  6753. }
  6754. } else {
  6755. for (n = 0; n < resetInterval; n++) {
  6756. for (i = 0; i < componentsLength; i++) {
  6757. component = components[i];
  6758. h = component.h;
  6759. v = component.v;
  6760. for (j = 0; j < v; j++) {
  6761. for (k = 0; k < h; k++) {
  6762. decodeMcu(component, decodeFn, mcu, j, k);
  6763. }
  6764. }
  6765. }
  6766. mcu++;
  6767. }
  6768. }
  6769. // find marker
  6770. bitsCount = 0;
  6771. marker = (data[offset] << 8) | data[offset + 1];
  6772. if (marker <= 0xFF00) {
  6773. throw 'marker was not found';
  6774. }
  6775. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  6776. offset += 2;
  6777. } else {
  6778. break;
  6779. }
  6780. }
  6781. return offset - startOffset;
  6782. }
  6783. // A port of poppler's IDCT method which in turn is taken from:
  6784. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  6785. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  6786. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  6787. // 988-991.
  6788. function quantizeAndInverse(component, blockBufferOffset, p) {
  6789. var qt = component.quantizationTable, blockData = component.blockData;
  6790. var v0, v1, v2, v3, v4, v5, v6, v7;
  6791. var p0, p1, p2, p3, p4, p5, p6, p7;
  6792. var t;
  6793. // inverse DCT on rows
  6794. for (var row = 0; row < 64; row += 8) {
  6795. // gather block data
  6796. p0 = blockData[blockBufferOffset + row];
  6797. p1 = blockData[blockBufferOffset + row + 1];
  6798. p2 = blockData[blockBufferOffset + row + 2];
  6799. p3 = blockData[blockBufferOffset + row + 3];
  6800. p4 = blockData[blockBufferOffset + row + 4];
  6801. p5 = blockData[blockBufferOffset + row + 5];
  6802. p6 = blockData[blockBufferOffset + row + 6];
  6803. p7 = blockData[blockBufferOffset + row + 7];
  6804. // dequant p0
  6805. p0 *= qt[row];
  6806. // check for all-zero AC coefficients
  6807. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6808. t = (dctSqrt2 * p0 + 512) >> 10;
  6809. p[row] = t;
  6810. p[row + 1] = t;
  6811. p[row + 2] = t;
  6812. p[row + 3] = t;
  6813. p[row + 4] = t;
  6814. p[row + 5] = t;
  6815. p[row + 6] = t;
  6816. p[row + 7] = t;
  6817. continue;
  6818. }
  6819. // dequant p1 ... p7
  6820. p1 *= qt[row + 1];
  6821. p2 *= qt[row + 2];
  6822. p3 *= qt[row + 3];
  6823. p4 *= qt[row + 4];
  6824. p5 *= qt[row + 5];
  6825. p6 *= qt[row + 6];
  6826. p7 *= qt[row + 7];
  6827. // stage 4
  6828. v0 = (dctSqrt2 * p0 + 128) >> 8;
  6829. v1 = (dctSqrt2 * p4 + 128) >> 8;
  6830. v2 = p2;
  6831. v3 = p6;
  6832. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  6833. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  6834. v5 = p3 << 4;
  6835. v6 = p5 << 4;
  6836. // stage 3
  6837. v0 = (v0 + v1 + 1) >> 1;
  6838. v1 = v0 - v1;
  6839. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  6840. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  6841. v3 = t;
  6842. v4 = (v4 + v6 + 1) >> 1;
  6843. v6 = v4 - v6;
  6844. v7 = (v7 + v5 + 1) >> 1;
  6845. v5 = v7 - v5;
  6846. // stage 2
  6847. v0 = (v0 + v3 + 1) >> 1;
  6848. v3 = v0 - v3;
  6849. v1 = (v1 + v2 + 1) >> 1;
  6850. v2 = v1 - v2;
  6851. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6852. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6853. v7 = t;
  6854. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6855. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6856. v6 = t;
  6857. // stage 1
  6858. p[row] = v0 + v7;
  6859. p[row + 7] = v0 - v7;
  6860. p[row + 1] = v1 + v6;
  6861. p[row + 6] = v1 - v6;
  6862. p[row + 2] = v2 + v5;
  6863. p[row + 5] = v2 - v5;
  6864. p[row + 3] = v3 + v4;
  6865. p[row + 4] = v3 - v4;
  6866. }
  6867. // inverse DCT on columns
  6868. for (var col = 0; col < 8; ++col) {
  6869. p0 = p[col];
  6870. p1 = p[col + 8];
  6871. p2 = p[col + 16];
  6872. p3 = p[col + 24];
  6873. p4 = p[col + 32];
  6874. p5 = p[col + 40];
  6875. p6 = p[col + 48];
  6876. p7 = p[col + 56];
  6877. // check for all-zero AC coefficients
  6878. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6879. t = (dctSqrt2 * p0 + 8192) >> 14;
  6880. // convert to 8 bit
  6881. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  6882. blockData[blockBufferOffset + col] = t;
  6883. blockData[blockBufferOffset + col + 8] = t;
  6884. blockData[blockBufferOffset + col + 16] = t;
  6885. blockData[blockBufferOffset + col + 24] = t;
  6886. blockData[blockBufferOffset + col + 32] = t;
  6887. blockData[blockBufferOffset + col + 40] = t;
  6888. blockData[blockBufferOffset + col + 48] = t;
  6889. blockData[blockBufferOffset + col + 56] = t;
  6890. continue;
  6891. }
  6892. // stage 4
  6893. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  6894. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  6895. v2 = p2;
  6896. v3 = p6;
  6897. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  6898. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  6899. v5 = p3;
  6900. v6 = p5;
  6901. // stage 3
  6902. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  6903. // converting to UInt8 range later.
  6904. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  6905. v1 = v0 - v1;
  6906. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  6907. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  6908. v3 = t;
  6909. v4 = (v4 + v6 + 1) >> 1;
  6910. v6 = v4 - v6;
  6911. v7 = (v7 + v5 + 1) >> 1;
  6912. v5 = v7 - v5;
  6913. // stage 2
  6914. v0 = (v0 + v3 + 1) >> 1;
  6915. v3 = v0 - v3;
  6916. v1 = (v1 + v2 + 1) >> 1;
  6917. v2 = v1 - v2;
  6918. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6919. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6920. v7 = t;
  6921. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6922. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6923. v6 = t;
  6924. // stage 1
  6925. p0 = v0 + v7;
  6926. p7 = v0 - v7;
  6927. p1 = v1 + v6;
  6928. p6 = v1 - v6;
  6929. p2 = v2 + v5;
  6930. p5 = v2 - v5;
  6931. p3 = v3 + v4;
  6932. p4 = v3 - v4;
  6933. // convert to 8-bit integers
  6934. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  6935. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  6936. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  6937. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  6938. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  6939. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  6940. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  6941. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  6942. // store block data
  6943. blockData[blockBufferOffset + col] = p0;
  6944. blockData[blockBufferOffset + col + 8] = p1;
  6945. blockData[blockBufferOffset + col + 16] = p2;
  6946. blockData[blockBufferOffset + col + 24] = p3;
  6947. blockData[blockBufferOffset + col + 32] = p4;
  6948. blockData[blockBufferOffset + col + 40] = p5;
  6949. blockData[blockBufferOffset + col + 48] = p6;
  6950. blockData[blockBufferOffset + col + 56] = p7;
  6951. }
  6952. }
  6953. function buildComponentData(frame, component) {
  6954. var blocksPerLine = component.blocksPerLine;
  6955. var blocksPerColumn = component.blocksPerColumn;
  6956. var computationBuffer = new Int16Array(64);
  6957. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  6958. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  6959. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6960. quantizeAndInverse(component, offset, computationBuffer);
  6961. }
  6962. }
  6963. return component.blockData;
  6964. }
  6965. function clamp0to255(a) {
  6966. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  6967. }
  6968. constructor.prototype = {
  6969. parse: function parse(data) {
  6970. function readUint16() {
  6971. var value = (data[offset] << 8) | data[offset + 1];
  6972. offset += 2;
  6973. return value;
  6974. }
  6975. function readDataBlock() {
  6976. var length = readUint16();
  6977. var array = data.subarray(offset, offset + length - 2);
  6978. offset += array.length;
  6979. return array;
  6980. }
  6981. function prepareComponents(frame) {
  6982. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  6983. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  6984. for (var i = 0; i < frame.components.length; i++) {
  6985. component = frame.components[i];
  6986. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  6987. component.h / frame.maxH);
  6988. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  6989. component.v / frame.maxV);
  6990. var blocksPerLineForMcu = mcusPerLine * component.h;
  6991. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  6992. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  6993. (blocksPerLineForMcu + 1);
  6994. component.blockData = new Int16Array(blocksBufferSize);
  6995. component.blocksPerLine = blocksPerLine;
  6996. component.blocksPerColumn = blocksPerColumn;
  6997. }
  6998. frame.mcusPerLine = mcusPerLine;
  6999. frame.mcusPerColumn = mcusPerColumn;
  7000. }
  7001. var offset = 0;
  7002. var jfif = null;
  7003. var adobe = null;
  7004. var frame, resetInterval;
  7005. var quantizationTables = [];
  7006. var huffmanTablesAC = [], huffmanTablesDC = [];
  7007. var fileMarker = readUint16();
  7008. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  7009. throw 'SOI not found';
  7010. }
  7011. fileMarker = readUint16();
  7012. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  7013. var i, j, l;
  7014. switch(fileMarker) {
  7015. case 0xFFE0: // APP0 (Application Specific)
  7016. case 0xFFE1: // APP1
  7017. case 0xFFE2: // APP2
  7018. case 0xFFE3: // APP3
  7019. case 0xFFE4: // APP4
  7020. case 0xFFE5: // APP5
  7021. case 0xFFE6: // APP6
  7022. case 0xFFE7: // APP7
  7023. case 0xFFE8: // APP8
  7024. case 0xFFE9: // APP9
  7025. case 0xFFEA: // APP10
  7026. case 0xFFEB: // APP11
  7027. case 0xFFEC: // APP12
  7028. case 0xFFED: // APP13
  7029. case 0xFFEE: // APP14
  7030. case 0xFFEF: // APP15
  7031. case 0xFFFE: // COM (Comment)
  7032. var appData = readDataBlock();
  7033. if (fileMarker === 0xFFE0) {
  7034. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  7035. appData[2] === 0x49 && appData[3] === 0x46 &&
  7036. appData[4] === 0) { // 'JFIF\x00'
  7037. jfif = {
  7038. version: { major: appData[5], minor: appData[6] },
  7039. densityUnits: appData[7],
  7040. xDensity: (appData[8] << 8) | appData[9],
  7041. yDensity: (appData[10] << 8) | appData[11],
  7042. thumbWidth: appData[12],
  7043. thumbHeight: appData[13],
  7044. thumbData: appData.subarray(14, 14 +
  7045. 3 * appData[12] * appData[13])
  7046. };
  7047. }
  7048. }
  7049. // TODO APP1 - Exif
  7050. if (fileMarker === 0xFFEE) {
  7051. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  7052. appData[2] === 0x6F && appData[3] === 0x62 &&
  7053. appData[4] === 0x65) { // 'Adobe'
  7054. adobe = {
  7055. version: (appData[5] << 8) | appData[6],
  7056. flags0: (appData[7] << 8) | appData[8],
  7057. flags1: (appData[9] << 8) | appData[10],
  7058. transformCode: appData[11]
  7059. };
  7060. }
  7061. }
  7062. break;
  7063. case 0xFFDB: // DQT (Define Quantization Tables)
  7064. var quantizationTablesLength = readUint16();
  7065. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  7066. var z;
  7067. while (offset < quantizationTablesEnd) {
  7068. var quantizationTableSpec = data[offset++];
  7069. var tableData = new Uint16Array(64);
  7070. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  7071. for (j = 0; j < 64; j++) {
  7072. z = dctZigZag[j];
  7073. tableData[z] = data[offset++];
  7074. }
  7075. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  7076. for (j = 0; j < 64; j++) {
  7077. z = dctZigZag[j];
  7078. tableData[z] = readUint16();
  7079. }
  7080. } else {
  7081. throw 'DQT: invalid table spec';
  7082. }
  7083. quantizationTables[quantizationTableSpec & 15] = tableData;
  7084. }
  7085. break;
  7086. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  7087. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  7088. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  7089. if (frame) {
  7090. throw 'Only single frame JPEGs supported';
  7091. }
  7092. readUint16(); // skip data length
  7093. frame = {};
  7094. frame.extended = (fileMarker === 0xFFC1);
  7095. frame.progressive = (fileMarker === 0xFFC2);
  7096. frame.precision = data[offset++];
  7097. frame.scanLines = readUint16();
  7098. frame.samplesPerLine = readUint16();
  7099. frame.components = [];
  7100. frame.componentIds = {};
  7101. var componentsCount = data[offset++], componentId;
  7102. var maxH = 0, maxV = 0;
  7103. for (i = 0; i < componentsCount; i++) {
  7104. componentId = data[offset];
  7105. var h = data[offset + 1] >> 4;
  7106. var v = data[offset + 1] & 15;
  7107. if (maxH < h) {
  7108. maxH = h;
  7109. }
  7110. if (maxV < v) {
  7111. maxV = v;
  7112. }
  7113. var qId = data[offset + 2];
  7114. l = frame.components.push({
  7115. h: h,
  7116. v: v,
  7117. quantizationTable: quantizationTables[qId]
  7118. });
  7119. frame.componentIds[componentId] = l - 1;
  7120. offset += 3;
  7121. }
  7122. frame.maxH = maxH;
  7123. frame.maxV = maxV;
  7124. prepareComponents(frame);
  7125. break;
  7126. case 0xFFC4: // DHT (Define Huffman Tables)
  7127. var huffmanLength = readUint16();
  7128. for (i = 2; i < huffmanLength;) {
  7129. var huffmanTableSpec = data[offset++];
  7130. var codeLengths = new Uint8Array(16);
  7131. var codeLengthSum = 0;
  7132. for (j = 0; j < 16; j++, offset++) {
  7133. codeLengthSum += (codeLengths[j] = data[offset]);
  7134. }
  7135. var huffmanValues = new Uint8Array(codeLengthSum);
  7136. for (j = 0; j < codeLengthSum; j++, offset++) {
  7137. huffmanValues[j] = data[offset];
  7138. }
  7139. i += 17 + codeLengthSum;
  7140. ((huffmanTableSpec >> 4) === 0 ?
  7141. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  7142. buildHuffmanTable(codeLengths, huffmanValues);
  7143. }
  7144. break;
  7145. case 0xFFDD: // DRI (Define Restart Interval)
  7146. readUint16(); // skip data length
  7147. resetInterval = readUint16();
  7148. break;
  7149. case 0xFFDA: // SOS (Start of Scan)
  7150. var scanLength = readUint16();
  7151. var selectorsCount = data[offset++];
  7152. var components = [], component;
  7153. for (i = 0; i < selectorsCount; i++) {
  7154. var componentIndex = frame.componentIds[data[offset++]];
  7155. component = frame.components[componentIndex];
  7156. var tableSpec = data[offset++];
  7157. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  7158. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  7159. components.push(component);
  7160. }
  7161. var spectralStart = data[offset++];
  7162. var spectralEnd = data[offset++];
  7163. var successiveApproximation = data[offset++];
  7164. var processed = decodeScan(data, offset,
  7165. frame, components, resetInterval,
  7166. spectralStart, spectralEnd,
  7167. successiveApproximation >> 4, successiveApproximation & 15);
  7168. offset += processed;
  7169. break;
  7170. case 0xFFFF: // Fill bytes
  7171. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  7172. offset--;
  7173. }
  7174. break;
  7175. default:
  7176. if (data[offset - 3] === 0xFF &&
  7177. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  7178. // could be incorrect encoding -- last 0xFF byte of the previous
  7179. // block was eaten by the encoder
  7180. offset -= 3;
  7181. break;
  7182. }
  7183. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  7184. }
  7185. fileMarker = readUint16();
  7186. }
  7187. this.width = frame.samplesPerLine;
  7188. this.height = frame.scanLines;
  7189. this.jfif = jfif;
  7190. this.adobe = adobe;
  7191. this.components = [];
  7192. for (i = 0; i < frame.components.length; i++) {
  7193. component = frame.components[i];
  7194. this.components.push({
  7195. output: buildComponentData(frame, component),
  7196. scaleX: component.h / frame.maxH,
  7197. scaleY: component.v / frame.maxV,
  7198. blocksPerLine: component.blocksPerLine,
  7199. blocksPerColumn: component.blocksPerColumn
  7200. });
  7201. }
  7202. this.numComponents = this.components.length;
  7203. },
  7204. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  7205. var scaleX = this.width / width, scaleY = this.height / height;
  7206. var component, componentScaleX, componentScaleY, blocksPerScanline;
  7207. var x, y, i, j, k;
  7208. var index;
  7209. var offset = 0;
  7210. var output;
  7211. var numComponents = this.components.length;
  7212. var dataLength = width * height * numComponents;
  7213. var data = new Uint8Array(dataLength);
  7214. var xScaleBlockOffset = new Uint32Array(width);
  7215. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  7216. for (i = 0; i < numComponents; i++) {
  7217. component = this.components[i];
  7218. componentScaleX = component.scaleX * scaleX;
  7219. componentScaleY = component.scaleY * scaleY;
  7220. offset = i;
  7221. output = component.output;
  7222. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  7223. // precalculate the xScaleBlockOffset
  7224. for (x = 0; x < width; x++) {
  7225. j = 0 | (x * componentScaleX);
  7226. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  7227. }
  7228. // linearize the blocks of the component
  7229. for (y = 0; y < height; y++) {
  7230. j = 0 | (y * componentScaleY);
  7231. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  7232. for (x = 0; x < width; x++) {
  7233. data[offset] = output[index + xScaleBlockOffset[x]];
  7234. offset += numComponents;
  7235. }
  7236. }
  7237. }
  7238. // decodeTransform contains pairs of multiplier (-256..256) and additive
  7239. var transform = this.decodeTransform;
  7240. if (transform) {
  7241. for (i = 0; i < dataLength;) {
  7242. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  7243. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  7244. }
  7245. }
  7246. }
  7247. return data;
  7248. },
  7249. _isColorConversionNeeded: function isColorConversionNeeded() {
  7250. if (this.adobe && this.adobe.transformCode) {
  7251. // The adobe transform marker overrides any previous setting
  7252. return true;
  7253. } else if (this.numComponents === 3) {
  7254. return true;
  7255. } else {
  7256. return false;
  7257. }
  7258. },
  7259. _convertYccToRgb: function convertYccToRgb(data) {
  7260. var Y, Cb, Cr;
  7261. for (var i = 0, length = data.length; i < length; i += 3) {
  7262. Y = data[i ];
  7263. Cb = data[i + 1];
  7264. Cr = data[i + 2];
  7265. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  7266. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  7267. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  7268. }
  7269. return data;
  7270. },
  7271. _convertYcckToRgb: function convertYcckToRgb(data) {
  7272. var Y, Cb, Cr, k;
  7273. var offset = 0;
  7274. for (var i = 0, length = data.length; i < length; i += 4) {
  7275. Y = data[i];
  7276. Cb = data[i + 1];
  7277. Cr = data[i + 2];
  7278. k = data[i + 3];
  7279. var r = -122.67195406894 +
  7280. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  7281. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  7282. 0.154362151871126) +
  7283. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  7284. 0.00477271405408747 * k + 1.53380253221734) +
  7285. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  7286. 0.48357088451265) +
  7287. k * (-0.000336197177618394 * k + 0.484791561490776);
  7288. var g = 107.268039397724 +
  7289. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  7290. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  7291. 0.176491792462875) +
  7292. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  7293. 0.000770482631801132 * k - 0.151051492775562) +
  7294. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  7295. 0.25802910206845) +
  7296. k * (-0.000318913117588328 * k - 0.213742400323665);
  7297. var b = -20.810012546947 +
  7298. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  7299. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  7300. 0.814272968359295) +
  7301. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  7302. 0.000560833691242812 * k - 0.195152027534049) +
  7303. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  7304. 0.116935020465145) +
  7305. k * (-0.000343531996510555 * k + 0.24165260232407);
  7306. data[offset++] = clamp0to255(r);
  7307. data[offset++] = clamp0to255(g);
  7308. data[offset++] = clamp0to255(b);
  7309. }
  7310. return data;
  7311. },
  7312. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  7313. var Y, Cb, Cr;
  7314. for (var i = 0, length = data.length; i < length; i += 4) {
  7315. Y = data[i];
  7316. Cb = data[i + 1];
  7317. Cr = data[i + 2];
  7318. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  7319. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  7320. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  7321. // K in data[i + 3] is unchanged
  7322. }
  7323. return data;
  7324. },
  7325. _convertCmykToRgb: function convertCmykToRgb(data) {
  7326. var c, m, y, k;
  7327. var offset = 0;
  7328. var min = -255 * 255 * 255;
  7329. var scale = 1 / 255 / 255;
  7330. for (var i = 0, length = data.length; i < length; i += 4) {
  7331. c = data[i];
  7332. m = data[i + 1];
  7333. y = data[i + 2];
  7334. k = data[i + 3];
  7335. var r =
  7336. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  7337. 18.82290502165302 * y + 212.25662451639585 * k -
  7338. 72734.4411664936) +
  7339. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  7340. 17.873870861415444 * k - 1401.7366389350734) +
  7341. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  7342. 4465.541406466231) -
  7343. k * (21.86122147463605 * k + 48317.86113160301);
  7344. var g =
  7345. c * (8.841041422036149 * c + 60.118027045597366 * m +
  7346. 6.871425592049007 * y + 31.159100130055922 * k -
  7347. 20220.756542821975) +
  7348. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  7349. 131.35250912493976 * k - 48691.05921601825) +
  7350. y * (4.444339102852739 * y + 9.8632861493405 * k -
  7351. 6341.191035517494) -
  7352. k * (20.737325471181034 * k + 47890.15695978492);
  7353. var b =
  7354. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  7355. 30.89978309703729 * y - 0.23883238689178934 * k -
  7356. 3616.812083916688) +
  7357. m * (10.49593273432072 * m + 63.02378494754052 * y +
  7358. 50.606957656360734 * k - 28620.90484698408) +
  7359. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  7360. 49363.43385999684) -
  7361. k * (22.33816807309886 * k + 45932.16563550634);
  7362. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  7363. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  7364. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  7365. }
  7366. return data;
  7367. },
  7368. getData: function getData(width, height, forceRGBoutput) {
  7369. if (this.numComponents > 4) {
  7370. throw 'Unsupported color mode';
  7371. }
  7372. // type of data: Uint8Array(width * height * numComponents)
  7373. var data = this._getLinearizedBlockData(width, height);
  7374. if (this.numComponents === 3) {
  7375. return this._convertYccToRgb(data);
  7376. } else if (this.numComponents === 4) {
  7377. if (this._isColorConversionNeeded()) {
  7378. if (forceRGBoutput) {
  7379. return this._convertYcckToRgb(data);
  7380. } else {
  7381. return this._convertYcckToCmyk(data);
  7382. }
  7383. } else if (forceRGBoutput) {
  7384. return this._convertCmykToRgb(data);
  7385. }
  7386. }
  7387. return data;
  7388. }
  7389. };
  7390. return constructor;
  7391. })();
  7392. exports.JpegImage = JpegImage;
  7393. }));
  7394. (function (root, factory) {
  7395. {
  7396. factory((root.pdfjsCoreMetrics = {}));
  7397. }
  7398. }(this, function (exports) {
  7399. // The Metrics object contains glyph widths (in glyph space units).
  7400. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  7401. // space unit corresponds to 1/1000th of text space unit.
  7402. var Metrics = {
  7403. 'Courier': 600,
  7404. 'Courier-Bold': 600,
  7405. 'Courier-BoldOblique': 600,
  7406. 'Courier-Oblique': 600,
  7407. 'Helvetica' : {
  7408. 'space': 278,
  7409. 'exclam': 278,
  7410. 'quotedbl': 355,
  7411. 'numbersign': 556,
  7412. 'dollar': 556,
  7413. 'percent': 889,
  7414. 'ampersand': 667,
  7415. 'quoteright': 222,
  7416. 'parenleft': 333,
  7417. 'parenright': 333,
  7418. 'asterisk': 389,
  7419. 'plus': 584,
  7420. 'comma': 278,
  7421. 'hyphen': 333,
  7422. 'period': 278,
  7423. 'slash': 278,
  7424. 'zero': 556,
  7425. 'one': 556,
  7426. 'two': 556,
  7427. 'three': 556,
  7428. 'four': 556,
  7429. 'five': 556,
  7430. 'six': 556,
  7431. 'seven': 556,
  7432. 'eight': 556,
  7433. 'nine': 556,
  7434. 'colon': 278,
  7435. 'semicolon': 278,
  7436. 'less': 584,
  7437. 'equal': 584,
  7438. 'greater': 584,
  7439. 'question': 556,
  7440. 'at': 1015,
  7441. 'A': 667,
  7442. 'B': 667,
  7443. 'C': 722,
  7444. 'D': 722,
  7445. 'E': 667,
  7446. 'F': 611,
  7447. 'G': 778,
  7448. 'H': 722,
  7449. 'I': 278,
  7450. 'J': 500,
  7451. 'K': 667,
  7452. 'L': 556,
  7453. 'M': 833,
  7454. 'N': 722,
  7455. 'O': 778,
  7456. 'P': 667,
  7457. 'Q': 778,
  7458. 'R': 722,
  7459. 'S': 667,
  7460. 'T': 611,
  7461. 'U': 722,
  7462. 'V': 667,
  7463. 'W': 944,
  7464. 'X': 667,
  7465. 'Y': 667,
  7466. 'Z': 611,
  7467. 'bracketleft': 278,
  7468. 'backslash': 278,
  7469. 'bracketright': 278,
  7470. 'asciicircum': 469,
  7471. 'underscore': 556,
  7472. 'quoteleft': 222,
  7473. 'a': 556,
  7474. 'b': 556,
  7475. 'c': 500,
  7476. 'd': 556,
  7477. 'e': 556,
  7478. 'f': 278,
  7479. 'g': 556,
  7480. 'h': 556,
  7481. 'i': 222,
  7482. 'j': 222,
  7483. 'k': 500,
  7484. 'l': 222,
  7485. 'm': 833,
  7486. 'n': 556,
  7487. 'o': 556,
  7488. 'p': 556,
  7489. 'q': 556,
  7490. 'r': 333,
  7491. 's': 500,
  7492. 't': 278,
  7493. 'u': 556,
  7494. 'v': 500,
  7495. 'w': 722,
  7496. 'x': 500,
  7497. 'y': 500,
  7498. 'z': 500,
  7499. 'braceleft': 334,
  7500. 'bar': 260,
  7501. 'braceright': 334,
  7502. 'asciitilde': 584,
  7503. 'exclamdown': 333,
  7504. 'cent': 556,
  7505. 'sterling': 556,
  7506. 'fraction': 167,
  7507. 'yen': 556,
  7508. 'florin': 556,
  7509. 'section': 556,
  7510. 'currency': 556,
  7511. 'quotesingle': 191,
  7512. 'quotedblleft': 333,
  7513. 'guillemotleft': 556,
  7514. 'guilsinglleft': 333,
  7515. 'guilsinglright': 333,
  7516. 'fi': 500,
  7517. 'fl': 500,
  7518. 'endash': 556,
  7519. 'dagger': 556,
  7520. 'daggerdbl': 556,
  7521. 'periodcentered': 278,
  7522. 'paragraph': 537,
  7523. 'bullet': 350,
  7524. 'quotesinglbase': 222,
  7525. 'quotedblbase': 333,
  7526. 'quotedblright': 333,
  7527. 'guillemotright': 556,
  7528. 'ellipsis': 1000,
  7529. 'perthousand': 1000,
  7530. 'questiondown': 611,
  7531. 'grave': 333,
  7532. 'acute': 333,
  7533. 'circumflex': 333,
  7534. 'tilde': 333,
  7535. 'macron': 333,
  7536. 'breve': 333,
  7537. 'dotaccent': 333,
  7538. 'dieresis': 333,
  7539. 'ring': 333,
  7540. 'cedilla': 333,
  7541. 'hungarumlaut': 333,
  7542. 'ogonek': 333,
  7543. 'caron': 333,
  7544. 'emdash': 1000,
  7545. 'AE': 1000,
  7546. 'ordfeminine': 370,
  7547. 'Lslash': 556,
  7548. 'Oslash': 778,
  7549. 'OE': 1000,
  7550. 'ordmasculine': 365,
  7551. 'ae': 889,
  7552. 'dotlessi': 278,
  7553. 'lslash': 222,
  7554. 'oslash': 611,
  7555. 'oe': 944,
  7556. 'germandbls': 611,
  7557. 'Idieresis': 278,
  7558. 'eacute': 556,
  7559. 'abreve': 556,
  7560. 'uhungarumlaut': 556,
  7561. 'ecaron': 556,
  7562. 'Ydieresis': 667,
  7563. 'divide': 584,
  7564. 'Yacute': 667,
  7565. 'Acircumflex': 667,
  7566. 'aacute': 556,
  7567. 'Ucircumflex': 722,
  7568. 'yacute': 500,
  7569. 'scommaaccent': 500,
  7570. 'ecircumflex': 556,
  7571. 'Uring': 722,
  7572. 'Udieresis': 722,
  7573. 'aogonek': 556,
  7574. 'Uacute': 722,
  7575. 'uogonek': 556,
  7576. 'Edieresis': 667,
  7577. 'Dcroat': 722,
  7578. 'commaaccent': 250,
  7579. 'copyright': 737,
  7580. 'Emacron': 667,
  7581. 'ccaron': 500,
  7582. 'aring': 556,
  7583. 'Ncommaaccent': 722,
  7584. 'lacute': 222,
  7585. 'agrave': 556,
  7586. 'Tcommaaccent': 611,
  7587. 'Cacute': 722,
  7588. 'atilde': 556,
  7589. 'Edotaccent': 667,
  7590. 'scaron': 500,
  7591. 'scedilla': 500,
  7592. 'iacute': 278,
  7593. 'lozenge': 471,
  7594. 'Rcaron': 722,
  7595. 'Gcommaaccent': 778,
  7596. 'ucircumflex': 556,
  7597. 'acircumflex': 556,
  7598. 'Amacron': 667,
  7599. 'rcaron': 333,
  7600. 'ccedilla': 500,
  7601. 'Zdotaccent': 611,
  7602. 'Thorn': 667,
  7603. 'Omacron': 778,
  7604. 'Racute': 722,
  7605. 'Sacute': 667,
  7606. 'dcaron': 643,
  7607. 'Umacron': 722,
  7608. 'uring': 556,
  7609. 'threesuperior': 333,
  7610. 'Ograve': 778,
  7611. 'Agrave': 667,
  7612. 'Abreve': 667,
  7613. 'multiply': 584,
  7614. 'uacute': 556,
  7615. 'Tcaron': 611,
  7616. 'partialdiff': 476,
  7617. 'ydieresis': 500,
  7618. 'Nacute': 722,
  7619. 'icircumflex': 278,
  7620. 'Ecircumflex': 667,
  7621. 'adieresis': 556,
  7622. 'edieresis': 556,
  7623. 'cacute': 500,
  7624. 'nacute': 556,
  7625. 'umacron': 556,
  7626. 'Ncaron': 722,
  7627. 'Iacute': 278,
  7628. 'plusminus': 584,
  7629. 'brokenbar': 260,
  7630. 'registered': 737,
  7631. 'Gbreve': 778,
  7632. 'Idotaccent': 278,
  7633. 'summation': 600,
  7634. 'Egrave': 667,
  7635. 'racute': 333,
  7636. 'omacron': 556,
  7637. 'Zacute': 611,
  7638. 'Zcaron': 611,
  7639. 'greaterequal': 549,
  7640. 'Eth': 722,
  7641. 'Ccedilla': 722,
  7642. 'lcommaaccent': 222,
  7643. 'tcaron': 317,
  7644. 'eogonek': 556,
  7645. 'Uogonek': 722,
  7646. 'Aacute': 667,
  7647. 'Adieresis': 667,
  7648. 'egrave': 556,
  7649. 'zacute': 500,
  7650. 'iogonek': 222,
  7651. 'Oacute': 778,
  7652. 'oacute': 556,
  7653. 'amacron': 556,
  7654. 'sacute': 500,
  7655. 'idieresis': 278,
  7656. 'Ocircumflex': 778,
  7657. 'Ugrave': 722,
  7658. 'Delta': 612,
  7659. 'thorn': 556,
  7660. 'twosuperior': 333,
  7661. 'Odieresis': 778,
  7662. 'mu': 556,
  7663. 'igrave': 278,
  7664. 'ohungarumlaut': 556,
  7665. 'Eogonek': 667,
  7666. 'dcroat': 556,
  7667. 'threequarters': 834,
  7668. 'Scedilla': 667,
  7669. 'lcaron': 299,
  7670. 'Kcommaaccent': 667,
  7671. 'Lacute': 556,
  7672. 'trademark': 1000,
  7673. 'edotaccent': 556,
  7674. 'Igrave': 278,
  7675. 'Imacron': 278,
  7676. 'Lcaron': 556,
  7677. 'onehalf': 834,
  7678. 'lessequal': 549,
  7679. 'ocircumflex': 556,
  7680. 'ntilde': 556,
  7681. 'Uhungarumlaut': 722,
  7682. 'Eacute': 667,
  7683. 'emacron': 556,
  7684. 'gbreve': 556,
  7685. 'onequarter': 834,
  7686. 'Scaron': 667,
  7687. 'Scommaaccent': 667,
  7688. 'Ohungarumlaut': 778,
  7689. 'degree': 400,
  7690. 'ograve': 556,
  7691. 'Ccaron': 722,
  7692. 'ugrave': 556,
  7693. 'radical': 453,
  7694. 'Dcaron': 722,
  7695. 'rcommaaccent': 333,
  7696. 'Ntilde': 722,
  7697. 'otilde': 556,
  7698. 'Rcommaaccent': 722,
  7699. 'Lcommaaccent': 556,
  7700. 'Atilde': 667,
  7701. 'Aogonek': 667,
  7702. 'Aring': 667,
  7703. 'Otilde': 778,
  7704. 'zdotaccent': 500,
  7705. 'Ecaron': 667,
  7706. 'Iogonek': 278,
  7707. 'kcommaaccent': 500,
  7708. 'minus': 584,
  7709. 'Icircumflex': 278,
  7710. 'ncaron': 556,
  7711. 'tcommaaccent': 278,
  7712. 'logicalnot': 584,
  7713. 'odieresis': 556,
  7714. 'udieresis': 556,
  7715. 'notequal': 549,
  7716. 'gcommaaccent': 556,
  7717. 'eth': 556,
  7718. 'zcaron': 500,
  7719. 'ncommaaccent': 556,
  7720. 'onesuperior': 333,
  7721. 'imacron': 278,
  7722. 'Euro': 556
  7723. },
  7724. 'Helvetica-Bold': {
  7725. 'space': 278,
  7726. 'exclam': 333,
  7727. 'quotedbl': 474,
  7728. 'numbersign': 556,
  7729. 'dollar': 556,
  7730. 'percent': 889,
  7731. 'ampersand': 722,
  7732. 'quoteright': 278,
  7733. 'parenleft': 333,
  7734. 'parenright': 333,
  7735. 'asterisk': 389,
  7736. 'plus': 584,
  7737. 'comma': 278,
  7738. 'hyphen': 333,
  7739. 'period': 278,
  7740. 'slash': 278,
  7741. 'zero': 556,
  7742. 'one': 556,
  7743. 'two': 556,
  7744. 'three': 556,
  7745. 'four': 556,
  7746. 'five': 556,
  7747. 'six': 556,
  7748. 'seven': 556,
  7749. 'eight': 556,
  7750. 'nine': 556,
  7751. 'colon': 333,
  7752. 'semicolon': 333,
  7753. 'less': 584,
  7754. 'equal': 584,
  7755. 'greater': 584,
  7756. 'question': 611,
  7757. 'at': 975,
  7758. 'A': 722,
  7759. 'B': 722,
  7760. 'C': 722,
  7761. 'D': 722,
  7762. 'E': 667,
  7763. 'F': 611,
  7764. 'G': 778,
  7765. 'H': 722,
  7766. 'I': 278,
  7767. 'J': 556,
  7768. 'K': 722,
  7769. 'L': 611,
  7770. 'M': 833,
  7771. 'N': 722,
  7772. 'O': 778,
  7773. 'P': 667,
  7774. 'Q': 778,
  7775. 'R': 722,
  7776. 'S': 667,
  7777. 'T': 611,
  7778. 'U': 722,
  7779. 'V': 667,
  7780. 'W': 944,
  7781. 'X': 667,
  7782. 'Y': 667,
  7783. 'Z': 611,
  7784. 'bracketleft': 333,
  7785. 'backslash': 278,
  7786. 'bracketright': 333,
  7787. 'asciicircum': 584,
  7788. 'underscore': 556,
  7789. 'quoteleft': 278,
  7790. 'a': 556,
  7791. 'b': 611,
  7792. 'c': 556,
  7793. 'd': 611,
  7794. 'e': 556,
  7795. 'f': 333,
  7796. 'g': 611,
  7797. 'h': 611,
  7798. 'i': 278,
  7799. 'j': 278,
  7800. 'k': 556,
  7801. 'l': 278,
  7802. 'm': 889,
  7803. 'n': 611,
  7804. 'o': 611,
  7805. 'p': 611,
  7806. 'q': 611,
  7807. 'r': 389,
  7808. 's': 556,
  7809. 't': 333,
  7810. 'u': 611,
  7811. 'v': 556,
  7812. 'w': 778,
  7813. 'x': 556,
  7814. 'y': 556,
  7815. 'z': 500,
  7816. 'braceleft': 389,
  7817. 'bar': 280,
  7818. 'braceright': 389,
  7819. 'asciitilde': 584,
  7820. 'exclamdown': 333,
  7821. 'cent': 556,
  7822. 'sterling': 556,
  7823. 'fraction': 167,
  7824. 'yen': 556,
  7825. 'florin': 556,
  7826. 'section': 556,
  7827. 'currency': 556,
  7828. 'quotesingle': 238,
  7829. 'quotedblleft': 500,
  7830. 'guillemotleft': 556,
  7831. 'guilsinglleft': 333,
  7832. 'guilsinglright': 333,
  7833. 'fi': 611,
  7834. 'fl': 611,
  7835. 'endash': 556,
  7836. 'dagger': 556,
  7837. 'daggerdbl': 556,
  7838. 'periodcentered': 278,
  7839. 'paragraph': 556,
  7840. 'bullet': 350,
  7841. 'quotesinglbase': 278,
  7842. 'quotedblbase': 500,
  7843. 'quotedblright': 500,
  7844. 'guillemotright': 556,
  7845. 'ellipsis': 1000,
  7846. 'perthousand': 1000,
  7847. 'questiondown': 611,
  7848. 'grave': 333,
  7849. 'acute': 333,
  7850. 'circumflex': 333,
  7851. 'tilde': 333,
  7852. 'macron': 333,
  7853. 'breve': 333,
  7854. 'dotaccent': 333,
  7855. 'dieresis': 333,
  7856. 'ring': 333,
  7857. 'cedilla': 333,
  7858. 'hungarumlaut': 333,
  7859. 'ogonek': 333,
  7860. 'caron': 333,
  7861. 'emdash': 1000,
  7862. 'AE': 1000,
  7863. 'ordfeminine': 370,
  7864. 'Lslash': 611,
  7865. 'Oslash': 778,
  7866. 'OE': 1000,
  7867. 'ordmasculine': 365,
  7868. 'ae': 889,
  7869. 'dotlessi': 278,
  7870. 'lslash': 278,
  7871. 'oslash': 611,
  7872. 'oe': 944,
  7873. 'germandbls': 611,
  7874. 'Idieresis': 278,
  7875. 'eacute': 556,
  7876. 'abreve': 556,
  7877. 'uhungarumlaut': 611,
  7878. 'ecaron': 556,
  7879. 'Ydieresis': 667,
  7880. 'divide': 584,
  7881. 'Yacute': 667,
  7882. 'Acircumflex': 722,
  7883. 'aacute': 556,
  7884. 'Ucircumflex': 722,
  7885. 'yacute': 556,
  7886. 'scommaaccent': 556,
  7887. 'ecircumflex': 556,
  7888. 'Uring': 722,
  7889. 'Udieresis': 722,
  7890. 'aogonek': 556,
  7891. 'Uacute': 722,
  7892. 'uogonek': 611,
  7893. 'Edieresis': 667,
  7894. 'Dcroat': 722,
  7895. 'commaaccent': 250,
  7896. 'copyright': 737,
  7897. 'Emacron': 667,
  7898. 'ccaron': 556,
  7899. 'aring': 556,
  7900. 'Ncommaaccent': 722,
  7901. 'lacute': 278,
  7902. 'agrave': 556,
  7903. 'Tcommaaccent': 611,
  7904. 'Cacute': 722,
  7905. 'atilde': 556,
  7906. 'Edotaccent': 667,
  7907. 'scaron': 556,
  7908. 'scedilla': 556,
  7909. 'iacute': 278,
  7910. 'lozenge': 494,
  7911. 'Rcaron': 722,
  7912. 'Gcommaaccent': 778,
  7913. 'ucircumflex': 611,
  7914. 'acircumflex': 556,
  7915. 'Amacron': 722,
  7916. 'rcaron': 389,
  7917. 'ccedilla': 556,
  7918. 'Zdotaccent': 611,
  7919. 'Thorn': 667,
  7920. 'Omacron': 778,
  7921. 'Racute': 722,
  7922. 'Sacute': 667,
  7923. 'dcaron': 743,
  7924. 'Umacron': 722,
  7925. 'uring': 611,
  7926. 'threesuperior': 333,
  7927. 'Ograve': 778,
  7928. 'Agrave': 722,
  7929. 'Abreve': 722,
  7930. 'multiply': 584,
  7931. 'uacute': 611,
  7932. 'Tcaron': 611,
  7933. 'partialdiff': 494,
  7934. 'ydieresis': 556,
  7935. 'Nacute': 722,
  7936. 'icircumflex': 278,
  7937. 'Ecircumflex': 667,
  7938. 'adieresis': 556,
  7939. 'edieresis': 556,
  7940. 'cacute': 556,
  7941. 'nacute': 611,
  7942. 'umacron': 611,
  7943. 'Ncaron': 722,
  7944. 'Iacute': 278,
  7945. 'plusminus': 584,
  7946. 'brokenbar': 280,
  7947. 'registered': 737,
  7948. 'Gbreve': 778,
  7949. 'Idotaccent': 278,
  7950. 'summation': 600,
  7951. 'Egrave': 667,
  7952. 'racute': 389,
  7953. 'omacron': 611,
  7954. 'Zacute': 611,
  7955. 'Zcaron': 611,
  7956. 'greaterequal': 549,
  7957. 'Eth': 722,
  7958. 'Ccedilla': 722,
  7959. 'lcommaaccent': 278,
  7960. 'tcaron': 389,
  7961. 'eogonek': 556,
  7962. 'Uogonek': 722,
  7963. 'Aacute': 722,
  7964. 'Adieresis': 722,
  7965. 'egrave': 556,
  7966. 'zacute': 500,
  7967. 'iogonek': 278,
  7968. 'Oacute': 778,
  7969. 'oacute': 611,
  7970. 'amacron': 556,
  7971. 'sacute': 556,
  7972. 'idieresis': 278,
  7973. 'Ocircumflex': 778,
  7974. 'Ugrave': 722,
  7975. 'Delta': 612,
  7976. 'thorn': 611,
  7977. 'twosuperior': 333,
  7978. 'Odieresis': 778,
  7979. 'mu': 611,
  7980. 'igrave': 278,
  7981. 'ohungarumlaut': 611,
  7982. 'Eogonek': 667,
  7983. 'dcroat': 611,
  7984. 'threequarters': 834,
  7985. 'Scedilla': 667,
  7986. 'lcaron': 400,
  7987. 'Kcommaaccent': 722,
  7988. 'Lacute': 611,
  7989. 'trademark': 1000,
  7990. 'edotaccent': 556,
  7991. 'Igrave': 278,
  7992. 'Imacron': 278,
  7993. 'Lcaron': 611,
  7994. 'onehalf': 834,
  7995. 'lessequal': 549,
  7996. 'ocircumflex': 611,
  7997. 'ntilde': 611,
  7998. 'Uhungarumlaut': 722,
  7999. 'Eacute': 667,
  8000. 'emacron': 556,
  8001. 'gbreve': 611,
  8002. 'onequarter': 834,
  8003. 'Scaron': 667,
  8004. 'Scommaaccent': 667,
  8005. 'Ohungarumlaut': 778,
  8006. 'degree': 400,
  8007. 'ograve': 611,
  8008. 'Ccaron': 722,
  8009. 'ugrave': 611,
  8010. 'radical': 549,
  8011. 'Dcaron': 722,
  8012. 'rcommaaccent': 389,
  8013. 'Ntilde': 722,
  8014. 'otilde': 611,
  8015. 'Rcommaaccent': 722,
  8016. 'Lcommaaccent': 611,
  8017. 'Atilde': 722,
  8018. 'Aogonek': 722,
  8019. 'Aring': 722,
  8020. 'Otilde': 778,
  8021. 'zdotaccent': 500,
  8022. 'Ecaron': 667,
  8023. 'Iogonek': 278,
  8024. 'kcommaaccent': 556,
  8025. 'minus': 584,
  8026. 'Icircumflex': 278,
  8027. 'ncaron': 611,
  8028. 'tcommaaccent': 333,
  8029. 'logicalnot': 584,
  8030. 'odieresis': 611,
  8031. 'udieresis': 611,
  8032. 'notequal': 549,
  8033. 'gcommaaccent': 611,
  8034. 'eth': 611,
  8035. 'zcaron': 500,
  8036. 'ncommaaccent': 611,
  8037. 'onesuperior': 333,
  8038. 'imacron': 278,
  8039. 'Euro': 556
  8040. },
  8041. 'Helvetica-BoldOblique': {
  8042. 'space': 278,
  8043. 'exclam': 333,
  8044. 'quotedbl': 474,
  8045. 'numbersign': 556,
  8046. 'dollar': 556,
  8047. 'percent': 889,
  8048. 'ampersand': 722,
  8049. 'quoteright': 278,
  8050. 'parenleft': 333,
  8051. 'parenright': 333,
  8052. 'asterisk': 389,
  8053. 'plus': 584,
  8054. 'comma': 278,
  8055. 'hyphen': 333,
  8056. 'period': 278,
  8057. 'slash': 278,
  8058. 'zero': 556,
  8059. 'one': 556,
  8060. 'two': 556,
  8061. 'three': 556,
  8062. 'four': 556,
  8063. 'five': 556,
  8064. 'six': 556,
  8065. 'seven': 556,
  8066. 'eight': 556,
  8067. 'nine': 556,
  8068. 'colon': 333,
  8069. 'semicolon': 333,
  8070. 'less': 584,
  8071. 'equal': 584,
  8072. 'greater': 584,
  8073. 'question': 611,
  8074. 'at': 975,
  8075. 'A': 722,
  8076. 'B': 722,
  8077. 'C': 722,
  8078. 'D': 722,
  8079. 'E': 667,
  8080. 'F': 611,
  8081. 'G': 778,
  8082. 'H': 722,
  8083. 'I': 278,
  8084. 'J': 556,
  8085. 'K': 722,
  8086. 'L': 611,
  8087. 'M': 833,
  8088. 'N': 722,
  8089. 'O': 778,
  8090. 'P': 667,
  8091. 'Q': 778,
  8092. 'R': 722,
  8093. 'S': 667,
  8094. 'T': 611,
  8095. 'U': 722,
  8096. 'V': 667,
  8097. 'W': 944,
  8098. 'X': 667,
  8099. 'Y': 667,
  8100. 'Z': 611,
  8101. 'bracketleft': 333,
  8102. 'backslash': 278,
  8103. 'bracketright': 333,
  8104. 'asciicircum': 584,
  8105. 'underscore': 556,
  8106. 'quoteleft': 278,
  8107. 'a': 556,
  8108. 'b': 611,
  8109. 'c': 556,
  8110. 'd': 611,
  8111. 'e': 556,
  8112. 'f': 333,
  8113. 'g': 611,
  8114. 'h': 611,
  8115. 'i': 278,
  8116. 'j': 278,
  8117. 'k': 556,
  8118. 'l': 278,
  8119. 'm': 889,
  8120. 'n': 611,
  8121. 'o': 611,
  8122. 'p': 611,
  8123. 'q': 611,
  8124. 'r': 389,
  8125. 's': 556,
  8126. 't': 333,
  8127. 'u': 611,
  8128. 'v': 556,
  8129. 'w': 778,
  8130. 'x': 556,
  8131. 'y': 556,
  8132. 'z': 500,
  8133. 'braceleft': 389,
  8134. 'bar': 280,
  8135. 'braceright': 389,
  8136. 'asciitilde': 584,
  8137. 'exclamdown': 333,
  8138. 'cent': 556,
  8139. 'sterling': 556,
  8140. 'fraction': 167,
  8141. 'yen': 556,
  8142. 'florin': 556,
  8143. 'section': 556,
  8144. 'currency': 556,
  8145. 'quotesingle': 238,
  8146. 'quotedblleft': 500,
  8147. 'guillemotleft': 556,
  8148. 'guilsinglleft': 333,
  8149. 'guilsinglright': 333,
  8150. 'fi': 611,
  8151. 'fl': 611,
  8152. 'endash': 556,
  8153. 'dagger': 556,
  8154. 'daggerdbl': 556,
  8155. 'periodcentered': 278,
  8156. 'paragraph': 556,
  8157. 'bullet': 350,
  8158. 'quotesinglbase': 278,
  8159. 'quotedblbase': 500,
  8160. 'quotedblright': 500,
  8161. 'guillemotright': 556,
  8162. 'ellipsis': 1000,
  8163. 'perthousand': 1000,
  8164. 'questiondown': 611,
  8165. 'grave': 333,
  8166. 'acute': 333,
  8167. 'circumflex': 333,
  8168. 'tilde': 333,
  8169. 'macron': 333,
  8170. 'breve': 333,
  8171. 'dotaccent': 333,
  8172. 'dieresis': 333,
  8173. 'ring': 333,
  8174. 'cedilla': 333,
  8175. 'hungarumlaut': 333,
  8176. 'ogonek': 333,
  8177. 'caron': 333,
  8178. 'emdash': 1000,
  8179. 'AE': 1000,
  8180. 'ordfeminine': 370,
  8181. 'Lslash': 611,
  8182. 'Oslash': 778,
  8183. 'OE': 1000,
  8184. 'ordmasculine': 365,
  8185. 'ae': 889,
  8186. 'dotlessi': 278,
  8187. 'lslash': 278,
  8188. 'oslash': 611,
  8189. 'oe': 944,
  8190. 'germandbls': 611,
  8191. 'Idieresis': 278,
  8192. 'eacute': 556,
  8193. 'abreve': 556,
  8194. 'uhungarumlaut': 611,
  8195. 'ecaron': 556,
  8196. 'Ydieresis': 667,
  8197. 'divide': 584,
  8198. 'Yacute': 667,
  8199. 'Acircumflex': 722,
  8200. 'aacute': 556,
  8201. 'Ucircumflex': 722,
  8202. 'yacute': 556,
  8203. 'scommaaccent': 556,
  8204. 'ecircumflex': 556,
  8205. 'Uring': 722,
  8206. 'Udieresis': 722,
  8207. 'aogonek': 556,
  8208. 'Uacute': 722,
  8209. 'uogonek': 611,
  8210. 'Edieresis': 667,
  8211. 'Dcroat': 722,
  8212. 'commaaccent': 250,
  8213. 'copyright': 737,
  8214. 'Emacron': 667,
  8215. 'ccaron': 556,
  8216. 'aring': 556,
  8217. 'Ncommaaccent': 722,
  8218. 'lacute': 278,
  8219. 'agrave': 556,
  8220. 'Tcommaaccent': 611,
  8221. 'Cacute': 722,
  8222. 'atilde': 556,
  8223. 'Edotaccent': 667,
  8224. 'scaron': 556,
  8225. 'scedilla': 556,
  8226. 'iacute': 278,
  8227. 'lozenge': 494,
  8228. 'Rcaron': 722,
  8229. 'Gcommaaccent': 778,
  8230. 'ucircumflex': 611,
  8231. 'acircumflex': 556,
  8232. 'Amacron': 722,
  8233. 'rcaron': 389,
  8234. 'ccedilla': 556,
  8235. 'Zdotaccent': 611,
  8236. 'Thorn': 667,
  8237. 'Omacron': 778,
  8238. 'Racute': 722,
  8239. 'Sacute': 667,
  8240. 'dcaron': 743,
  8241. 'Umacron': 722,
  8242. 'uring': 611,
  8243. 'threesuperior': 333,
  8244. 'Ograve': 778,
  8245. 'Agrave': 722,
  8246. 'Abreve': 722,
  8247. 'multiply': 584,
  8248. 'uacute': 611,
  8249. 'Tcaron': 611,
  8250. 'partialdiff': 494,
  8251. 'ydieresis': 556,
  8252. 'Nacute': 722,
  8253. 'icircumflex': 278,
  8254. 'Ecircumflex': 667,
  8255. 'adieresis': 556,
  8256. 'edieresis': 556,
  8257. 'cacute': 556,
  8258. 'nacute': 611,
  8259. 'umacron': 611,
  8260. 'Ncaron': 722,
  8261. 'Iacute': 278,
  8262. 'plusminus': 584,
  8263. 'brokenbar': 280,
  8264. 'registered': 737,
  8265. 'Gbreve': 778,
  8266. 'Idotaccent': 278,
  8267. 'summation': 600,
  8268. 'Egrave': 667,
  8269. 'racute': 389,
  8270. 'omacron': 611,
  8271. 'Zacute': 611,
  8272. 'Zcaron': 611,
  8273. 'greaterequal': 549,
  8274. 'Eth': 722,
  8275. 'Ccedilla': 722,
  8276. 'lcommaaccent': 278,
  8277. 'tcaron': 389,
  8278. 'eogonek': 556,
  8279. 'Uogonek': 722,
  8280. 'Aacute': 722,
  8281. 'Adieresis': 722,
  8282. 'egrave': 556,
  8283. 'zacute': 500,
  8284. 'iogonek': 278,
  8285. 'Oacute': 778,
  8286. 'oacute': 611,
  8287. 'amacron': 556,
  8288. 'sacute': 556,
  8289. 'idieresis': 278,
  8290. 'Ocircumflex': 778,
  8291. 'Ugrave': 722,
  8292. 'Delta': 612,
  8293. 'thorn': 611,
  8294. 'twosuperior': 333,
  8295. 'Odieresis': 778,
  8296. 'mu': 611,
  8297. 'igrave': 278,
  8298. 'ohungarumlaut': 611,
  8299. 'Eogonek': 667,
  8300. 'dcroat': 611,
  8301. 'threequarters': 834,
  8302. 'Scedilla': 667,
  8303. 'lcaron': 400,
  8304. 'Kcommaaccent': 722,
  8305. 'Lacute': 611,
  8306. 'trademark': 1000,
  8307. 'edotaccent': 556,
  8308. 'Igrave': 278,
  8309. 'Imacron': 278,
  8310. 'Lcaron': 611,
  8311. 'onehalf': 834,
  8312. 'lessequal': 549,
  8313. 'ocircumflex': 611,
  8314. 'ntilde': 611,
  8315. 'Uhungarumlaut': 722,
  8316. 'Eacute': 667,
  8317. 'emacron': 556,
  8318. 'gbreve': 611,
  8319. 'onequarter': 834,
  8320. 'Scaron': 667,
  8321. 'Scommaaccent': 667,
  8322. 'Ohungarumlaut': 778,
  8323. 'degree': 400,
  8324. 'ograve': 611,
  8325. 'Ccaron': 722,
  8326. 'ugrave': 611,
  8327. 'radical': 549,
  8328. 'Dcaron': 722,
  8329. 'rcommaaccent': 389,
  8330. 'Ntilde': 722,
  8331. 'otilde': 611,
  8332. 'Rcommaaccent': 722,
  8333. 'Lcommaaccent': 611,
  8334. 'Atilde': 722,
  8335. 'Aogonek': 722,
  8336. 'Aring': 722,
  8337. 'Otilde': 778,
  8338. 'zdotaccent': 500,
  8339. 'Ecaron': 667,
  8340. 'Iogonek': 278,
  8341. 'kcommaaccent': 556,
  8342. 'minus': 584,
  8343. 'Icircumflex': 278,
  8344. 'ncaron': 611,
  8345. 'tcommaaccent': 333,
  8346. 'logicalnot': 584,
  8347. 'odieresis': 611,
  8348. 'udieresis': 611,
  8349. 'notequal': 549,
  8350. 'gcommaaccent': 611,
  8351. 'eth': 611,
  8352. 'zcaron': 500,
  8353. 'ncommaaccent': 611,
  8354. 'onesuperior': 333,
  8355. 'imacron': 278,
  8356. 'Euro': 556
  8357. },
  8358. 'Helvetica-Oblique' : {
  8359. 'space': 278,
  8360. 'exclam': 278,
  8361. 'quotedbl': 355,
  8362. 'numbersign': 556,
  8363. 'dollar': 556,
  8364. 'percent': 889,
  8365. 'ampersand': 667,
  8366. 'quoteright': 222,
  8367. 'parenleft': 333,
  8368. 'parenright': 333,
  8369. 'asterisk': 389,
  8370. 'plus': 584,
  8371. 'comma': 278,
  8372. 'hyphen': 333,
  8373. 'period': 278,
  8374. 'slash': 278,
  8375. 'zero': 556,
  8376. 'one': 556,
  8377. 'two': 556,
  8378. 'three': 556,
  8379. 'four': 556,
  8380. 'five': 556,
  8381. 'six': 556,
  8382. 'seven': 556,
  8383. 'eight': 556,
  8384. 'nine': 556,
  8385. 'colon': 278,
  8386. 'semicolon': 278,
  8387. 'less': 584,
  8388. 'equal': 584,
  8389. 'greater': 584,
  8390. 'question': 556,
  8391. 'at': 1015,
  8392. 'A': 667,
  8393. 'B': 667,
  8394. 'C': 722,
  8395. 'D': 722,
  8396. 'E': 667,
  8397. 'F': 611,
  8398. 'G': 778,
  8399. 'H': 722,
  8400. 'I': 278,
  8401. 'J': 500,
  8402. 'K': 667,
  8403. 'L': 556,
  8404. 'M': 833,
  8405. 'N': 722,
  8406. 'O': 778,
  8407. 'P': 667,
  8408. 'Q': 778,
  8409. 'R': 722,
  8410. 'S': 667,
  8411. 'T': 611,
  8412. 'U': 722,
  8413. 'V': 667,
  8414. 'W': 944,
  8415. 'X': 667,
  8416. 'Y': 667,
  8417. 'Z': 611,
  8418. 'bracketleft': 278,
  8419. 'backslash': 278,
  8420. 'bracketright': 278,
  8421. 'asciicircum': 469,
  8422. 'underscore': 556,
  8423. 'quoteleft': 222,
  8424. 'a': 556,
  8425. 'b': 556,
  8426. 'c': 500,
  8427. 'd': 556,
  8428. 'e': 556,
  8429. 'f': 278,
  8430. 'g': 556,
  8431. 'h': 556,
  8432. 'i': 222,
  8433. 'j': 222,
  8434. 'k': 500,
  8435. 'l': 222,
  8436. 'm': 833,
  8437. 'n': 556,
  8438. 'o': 556,
  8439. 'p': 556,
  8440. 'q': 556,
  8441. 'r': 333,
  8442. 's': 500,
  8443. 't': 278,
  8444. 'u': 556,
  8445. 'v': 500,
  8446. 'w': 722,
  8447. 'x': 500,
  8448. 'y': 500,
  8449. 'z': 500,
  8450. 'braceleft': 334,
  8451. 'bar': 260,
  8452. 'braceright': 334,
  8453. 'asciitilde': 584,
  8454. 'exclamdown': 333,
  8455. 'cent': 556,
  8456. 'sterling': 556,
  8457. 'fraction': 167,
  8458. 'yen': 556,
  8459. 'florin': 556,
  8460. 'section': 556,
  8461. 'currency': 556,
  8462. 'quotesingle': 191,
  8463. 'quotedblleft': 333,
  8464. 'guillemotleft': 556,
  8465. 'guilsinglleft': 333,
  8466. 'guilsinglright': 333,
  8467. 'fi': 500,
  8468. 'fl': 500,
  8469. 'endash': 556,
  8470. 'dagger': 556,
  8471. 'daggerdbl': 556,
  8472. 'periodcentered': 278,
  8473. 'paragraph': 537,
  8474. 'bullet': 350,
  8475. 'quotesinglbase': 222,
  8476. 'quotedblbase': 333,
  8477. 'quotedblright': 333,
  8478. 'guillemotright': 556,
  8479. 'ellipsis': 1000,
  8480. 'perthousand': 1000,
  8481. 'questiondown': 611,
  8482. 'grave': 333,
  8483. 'acute': 333,
  8484. 'circumflex': 333,
  8485. 'tilde': 333,
  8486. 'macron': 333,
  8487. 'breve': 333,
  8488. 'dotaccent': 333,
  8489. 'dieresis': 333,
  8490. 'ring': 333,
  8491. 'cedilla': 333,
  8492. 'hungarumlaut': 333,
  8493. 'ogonek': 333,
  8494. 'caron': 333,
  8495. 'emdash': 1000,
  8496. 'AE': 1000,
  8497. 'ordfeminine': 370,
  8498. 'Lslash': 556,
  8499. 'Oslash': 778,
  8500. 'OE': 1000,
  8501. 'ordmasculine': 365,
  8502. 'ae': 889,
  8503. 'dotlessi': 278,
  8504. 'lslash': 222,
  8505. 'oslash': 611,
  8506. 'oe': 944,
  8507. 'germandbls': 611,
  8508. 'Idieresis': 278,
  8509. 'eacute': 556,
  8510. 'abreve': 556,
  8511. 'uhungarumlaut': 556,
  8512. 'ecaron': 556,
  8513. 'Ydieresis': 667,
  8514. 'divide': 584,
  8515. 'Yacute': 667,
  8516. 'Acircumflex': 667,
  8517. 'aacute': 556,
  8518. 'Ucircumflex': 722,
  8519. 'yacute': 500,
  8520. 'scommaaccent': 500,
  8521. 'ecircumflex': 556,
  8522. 'Uring': 722,
  8523. 'Udieresis': 722,
  8524. 'aogonek': 556,
  8525. 'Uacute': 722,
  8526. 'uogonek': 556,
  8527. 'Edieresis': 667,
  8528. 'Dcroat': 722,
  8529. 'commaaccent': 250,
  8530. 'copyright': 737,
  8531. 'Emacron': 667,
  8532. 'ccaron': 500,
  8533. 'aring': 556,
  8534. 'Ncommaaccent': 722,
  8535. 'lacute': 222,
  8536. 'agrave': 556,
  8537. 'Tcommaaccent': 611,
  8538. 'Cacute': 722,
  8539. 'atilde': 556,
  8540. 'Edotaccent': 667,
  8541. 'scaron': 500,
  8542. 'scedilla': 500,
  8543. 'iacute': 278,
  8544. 'lozenge': 471,
  8545. 'Rcaron': 722,
  8546. 'Gcommaaccent': 778,
  8547. 'ucircumflex': 556,
  8548. 'acircumflex': 556,
  8549. 'Amacron': 667,
  8550. 'rcaron': 333,
  8551. 'ccedilla': 500,
  8552. 'Zdotaccent': 611,
  8553. 'Thorn': 667,
  8554. 'Omacron': 778,
  8555. 'Racute': 722,
  8556. 'Sacute': 667,
  8557. 'dcaron': 643,
  8558. 'Umacron': 722,
  8559. 'uring': 556,
  8560. 'threesuperior': 333,
  8561. 'Ograve': 778,
  8562. 'Agrave': 667,
  8563. 'Abreve': 667,
  8564. 'multiply': 584,
  8565. 'uacute': 556,
  8566. 'Tcaron': 611,
  8567. 'partialdiff': 476,
  8568. 'ydieresis': 500,
  8569. 'Nacute': 722,
  8570. 'icircumflex': 278,
  8571. 'Ecircumflex': 667,
  8572. 'adieresis': 556,
  8573. 'edieresis': 556,
  8574. 'cacute': 500,
  8575. 'nacute': 556,
  8576. 'umacron': 556,
  8577. 'Ncaron': 722,
  8578. 'Iacute': 278,
  8579. 'plusminus': 584,
  8580. 'brokenbar': 260,
  8581. 'registered': 737,
  8582. 'Gbreve': 778,
  8583. 'Idotaccent': 278,
  8584. 'summation': 600,
  8585. 'Egrave': 667,
  8586. 'racute': 333,
  8587. 'omacron': 556,
  8588. 'Zacute': 611,
  8589. 'Zcaron': 611,
  8590. 'greaterequal': 549,
  8591. 'Eth': 722,
  8592. 'Ccedilla': 722,
  8593. 'lcommaaccent': 222,
  8594. 'tcaron': 317,
  8595. 'eogonek': 556,
  8596. 'Uogonek': 722,
  8597. 'Aacute': 667,
  8598. 'Adieresis': 667,
  8599. 'egrave': 556,
  8600. 'zacute': 500,
  8601. 'iogonek': 222,
  8602. 'Oacute': 778,
  8603. 'oacute': 556,
  8604. 'amacron': 556,
  8605. 'sacute': 500,
  8606. 'idieresis': 278,
  8607. 'Ocircumflex': 778,
  8608. 'Ugrave': 722,
  8609. 'Delta': 612,
  8610. 'thorn': 556,
  8611. 'twosuperior': 333,
  8612. 'Odieresis': 778,
  8613. 'mu': 556,
  8614. 'igrave': 278,
  8615. 'ohungarumlaut': 556,
  8616. 'Eogonek': 667,
  8617. 'dcroat': 556,
  8618. 'threequarters': 834,
  8619. 'Scedilla': 667,
  8620. 'lcaron': 299,
  8621. 'Kcommaaccent': 667,
  8622. 'Lacute': 556,
  8623. 'trademark': 1000,
  8624. 'edotaccent': 556,
  8625. 'Igrave': 278,
  8626. 'Imacron': 278,
  8627. 'Lcaron': 556,
  8628. 'onehalf': 834,
  8629. 'lessequal': 549,
  8630. 'ocircumflex': 556,
  8631. 'ntilde': 556,
  8632. 'Uhungarumlaut': 722,
  8633. 'Eacute': 667,
  8634. 'emacron': 556,
  8635. 'gbreve': 556,
  8636. 'onequarter': 834,
  8637. 'Scaron': 667,
  8638. 'Scommaaccent': 667,
  8639. 'Ohungarumlaut': 778,
  8640. 'degree': 400,
  8641. 'ograve': 556,
  8642. 'Ccaron': 722,
  8643. 'ugrave': 556,
  8644. 'radical': 453,
  8645. 'Dcaron': 722,
  8646. 'rcommaaccent': 333,
  8647. 'Ntilde': 722,
  8648. 'otilde': 556,
  8649. 'Rcommaaccent': 722,
  8650. 'Lcommaaccent': 556,
  8651. 'Atilde': 667,
  8652. 'Aogonek': 667,
  8653. 'Aring': 667,
  8654. 'Otilde': 778,
  8655. 'zdotaccent': 500,
  8656. 'Ecaron': 667,
  8657. 'Iogonek': 278,
  8658. 'kcommaaccent': 500,
  8659. 'minus': 584,
  8660. 'Icircumflex': 278,
  8661. 'ncaron': 556,
  8662. 'tcommaaccent': 278,
  8663. 'logicalnot': 584,
  8664. 'odieresis': 556,
  8665. 'udieresis': 556,
  8666. 'notequal': 549,
  8667. 'gcommaaccent': 556,
  8668. 'eth': 556,
  8669. 'zcaron': 500,
  8670. 'ncommaaccent': 556,
  8671. 'onesuperior': 333,
  8672. 'imacron': 278,
  8673. 'Euro': 556
  8674. },
  8675. 'Symbol': {
  8676. 'space': 250,
  8677. 'exclam': 333,
  8678. 'universal': 713,
  8679. 'numbersign': 500,
  8680. 'existential': 549,
  8681. 'percent': 833,
  8682. 'ampersand': 778,
  8683. 'suchthat': 439,
  8684. 'parenleft': 333,
  8685. 'parenright': 333,
  8686. 'asteriskmath': 500,
  8687. 'plus': 549,
  8688. 'comma': 250,
  8689. 'minus': 549,
  8690. 'period': 250,
  8691. 'slash': 278,
  8692. 'zero': 500,
  8693. 'one': 500,
  8694. 'two': 500,
  8695. 'three': 500,
  8696. 'four': 500,
  8697. 'five': 500,
  8698. 'six': 500,
  8699. 'seven': 500,
  8700. 'eight': 500,
  8701. 'nine': 500,
  8702. 'colon': 278,
  8703. 'semicolon': 278,
  8704. 'less': 549,
  8705. 'equal': 549,
  8706. 'greater': 549,
  8707. 'question': 444,
  8708. 'congruent': 549,
  8709. 'Alpha': 722,
  8710. 'Beta': 667,
  8711. 'Chi': 722,
  8712. 'Delta': 612,
  8713. 'Epsilon': 611,
  8714. 'Phi': 763,
  8715. 'Gamma': 603,
  8716. 'Eta': 722,
  8717. 'Iota': 333,
  8718. 'theta1': 631,
  8719. 'Kappa': 722,
  8720. 'Lambda': 686,
  8721. 'Mu': 889,
  8722. 'Nu': 722,
  8723. 'Omicron': 722,
  8724. 'Pi': 768,
  8725. 'Theta': 741,
  8726. 'Rho': 556,
  8727. 'Sigma': 592,
  8728. 'Tau': 611,
  8729. 'Upsilon': 690,
  8730. 'sigma1': 439,
  8731. 'Omega': 768,
  8732. 'Xi': 645,
  8733. 'Psi': 795,
  8734. 'Zeta': 611,
  8735. 'bracketleft': 333,
  8736. 'therefore': 863,
  8737. 'bracketright': 333,
  8738. 'perpendicular': 658,
  8739. 'underscore': 500,
  8740. 'radicalex': 500,
  8741. 'alpha': 631,
  8742. 'beta': 549,
  8743. 'chi': 549,
  8744. 'delta': 494,
  8745. 'epsilon': 439,
  8746. 'phi': 521,
  8747. 'gamma': 411,
  8748. 'eta': 603,
  8749. 'iota': 329,
  8750. 'phi1': 603,
  8751. 'kappa': 549,
  8752. 'lambda': 549,
  8753. 'mu': 576,
  8754. 'nu': 521,
  8755. 'omicron': 549,
  8756. 'pi': 549,
  8757. 'theta': 521,
  8758. 'rho': 549,
  8759. 'sigma': 603,
  8760. 'tau': 439,
  8761. 'upsilon': 576,
  8762. 'omega1': 713,
  8763. 'omega': 686,
  8764. 'xi': 493,
  8765. 'psi': 686,
  8766. 'zeta': 494,
  8767. 'braceleft': 480,
  8768. 'bar': 200,
  8769. 'braceright': 480,
  8770. 'similar': 549,
  8771. 'Euro': 750,
  8772. 'Upsilon1': 620,
  8773. 'minute': 247,
  8774. 'lessequal': 549,
  8775. 'fraction': 167,
  8776. 'infinity': 713,
  8777. 'florin': 500,
  8778. 'club': 753,
  8779. 'diamond': 753,
  8780. 'heart': 753,
  8781. 'spade': 753,
  8782. 'arrowboth': 1042,
  8783. 'arrowleft': 987,
  8784. 'arrowup': 603,
  8785. 'arrowright': 987,
  8786. 'arrowdown': 603,
  8787. 'degree': 400,
  8788. 'plusminus': 549,
  8789. 'second': 411,
  8790. 'greaterequal': 549,
  8791. 'multiply': 549,
  8792. 'proportional': 713,
  8793. 'partialdiff': 494,
  8794. 'bullet': 460,
  8795. 'divide': 549,
  8796. 'notequal': 549,
  8797. 'equivalence': 549,
  8798. 'approxequal': 549,
  8799. 'ellipsis': 1000,
  8800. 'arrowvertex': 603,
  8801. 'arrowhorizex': 1000,
  8802. 'carriagereturn': 658,
  8803. 'aleph': 823,
  8804. 'Ifraktur': 686,
  8805. 'Rfraktur': 795,
  8806. 'weierstrass': 987,
  8807. 'circlemultiply': 768,
  8808. 'circleplus': 768,
  8809. 'emptyset': 823,
  8810. 'intersection': 768,
  8811. 'union': 768,
  8812. 'propersuperset': 713,
  8813. 'reflexsuperset': 713,
  8814. 'notsubset': 713,
  8815. 'propersubset': 713,
  8816. 'reflexsubset': 713,
  8817. 'element': 713,
  8818. 'notelement': 713,
  8819. 'angle': 768,
  8820. 'gradient': 713,
  8821. 'registerserif': 790,
  8822. 'copyrightserif': 790,
  8823. 'trademarkserif': 890,
  8824. 'product': 823,
  8825. 'radical': 549,
  8826. 'dotmath': 250,
  8827. 'logicalnot': 713,
  8828. 'logicaland': 603,
  8829. 'logicalor': 603,
  8830. 'arrowdblboth': 1042,
  8831. 'arrowdblleft': 987,
  8832. 'arrowdblup': 603,
  8833. 'arrowdblright': 987,
  8834. 'arrowdbldown': 603,
  8835. 'lozenge': 494,
  8836. 'angleleft': 329,
  8837. 'registersans': 790,
  8838. 'copyrightsans': 790,
  8839. 'trademarksans': 786,
  8840. 'summation': 713,
  8841. 'parenlefttp': 384,
  8842. 'parenleftex': 384,
  8843. 'parenleftbt': 384,
  8844. 'bracketlefttp': 384,
  8845. 'bracketleftex': 384,
  8846. 'bracketleftbt': 384,
  8847. 'bracelefttp': 494,
  8848. 'braceleftmid': 494,
  8849. 'braceleftbt': 494,
  8850. 'braceex': 494,
  8851. 'angleright': 329,
  8852. 'integral': 274,
  8853. 'integraltp': 686,
  8854. 'integralex': 686,
  8855. 'integralbt': 686,
  8856. 'parenrighttp': 384,
  8857. 'parenrightex': 384,
  8858. 'parenrightbt': 384,
  8859. 'bracketrighttp': 384,
  8860. 'bracketrightex': 384,
  8861. 'bracketrightbt': 384,
  8862. 'bracerighttp': 494,
  8863. 'bracerightmid': 494,
  8864. 'bracerightbt': 494,
  8865. 'apple': 790
  8866. },
  8867. 'Times-Roman': {
  8868. 'space': 250,
  8869. 'exclam': 333,
  8870. 'quotedbl': 408,
  8871. 'numbersign': 500,
  8872. 'dollar': 500,
  8873. 'percent': 833,
  8874. 'ampersand': 778,
  8875. 'quoteright': 333,
  8876. 'parenleft': 333,
  8877. 'parenright': 333,
  8878. 'asterisk': 500,
  8879. 'plus': 564,
  8880. 'comma': 250,
  8881. 'hyphen': 333,
  8882. 'period': 250,
  8883. 'slash': 278,
  8884. 'zero': 500,
  8885. 'one': 500,
  8886. 'two': 500,
  8887. 'three': 500,
  8888. 'four': 500,
  8889. 'five': 500,
  8890. 'six': 500,
  8891. 'seven': 500,
  8892. 'eight': 500,
  8893. 'nine': 500,
  8894. 'colon': 278,
  8895. 'semicolon': 278,
  8896. 'less': 564,
  8897. 'equal': 564,
  8898. 'greater': 564,
  8899. 'question': 444,
  8900. 'at': 921,
  8901. 'A': 722,
  8902. 'B': 667,
  8903. 'C': 667,
  8904. 'D': 722,
  8905. 'E': 611,
  8906. 'F': 556,
  8907. 'G': 722,
  8908. 'H': 722,
  8909. 'I': 333,
  8910. 'J': 389,
  8911. 'K': 722,
  8912. 'L': 611,
  8913. 'M': 889,
  8914. 'N': 722,
  8915. 'O': 722,
  8916. 'P': 556,
  8917. 'Q': 722,
  8918. 'R': 667,
  8919. 'S': 556,
  8920. 'T': 611,
  8921. 'U': 722,
  8922. 'V': 722,
  8923. 'W': 944,
  8924. 'X': 722,
  8925. 'Y': 722,
  8926. 'Z': 611,
  8927. 'bracketleft': 333,
  8928. 'backslash': 278,
  8929. 'bracketright': 333,
  8930. 'asciicircum': 469,
  8931. 'underscore': 500,
  8932. 'quoteleft': 333,
  8933. 'a': 444,
  8934. 'b': 500,
  8935. 'c': 444,
  8936. 'd': 500,
  8937. 'e': 444,
  8938. 'f': 333,
  8939. 'g': 500,
  8940. 'h': 500,
  8941. 'i': 278,
  8942. 'j': 278,
  8943. 'k': 500,
  8944. 'l': 278,
  8945. 'm': 778,
  8946. 'n': 500,
  8947. 'o': 500,
  8948. 'p': 500,
  8949. 'q': 500,
  8950. 'r': 333,
  8951. 's': 389,
  8952. 't': 278,
  8953. 'u': 500,
  8954. 'v': 500,
  8955. 'w': 722,
  8956. 'x': 500,
  8957. 'y': 500,
  8958. 'z': 444,
  8959. 'braceleft': 480,
  8960. 'bar': 200,
  8961. 'braceright': 480,
  8962. 'asciitilde': 541,
  8963. 'exclamdown': 333,
  8964. 'cent': 500,
  8965. 'sterling': 500,
  8966. 'fraction': 167,
  8967. 'yen': 500,
  8968. 'florin': 500,
  8969. 'section': 500,
  8970. 'currency': 500,
  8971. 'quotesingle': 180,
  8972. 'quotedblleft': 444,
  8973. 'guillemotleft': 500,
  8974. 'guilsinglleft': 333,
  8975. 'guilsinglright': 333,
  8976. 'fi': 556,
  8977. 'fl': 556,
  8978. 'endash': 500,
  8979. 'dagger': 500,
  8980. 'daggerdbl': 500,
  8981. 'periodcentered': 250,
  8982. 'paragraph': 453,
  8983. 'bullet': 350,
  8984. 'quotesinglbase': 333,
  8985. 'quotedblbase': 444,
  8986. 'quotedblright': 444,
  8987. 'guillemotright': 500,
  8988. 'ellipsis': 1000,
  8989. 'perthousand': 1000,
  8990. 'questiondown': 444,
  8991. 'grave': 333,
  8992. 'acute': 333,
  8993. 'circumflex': 333,
  8994. 'tilde': 333,
  8995. 'macron': 333,
  8996. 'breve': 333,
  8997. 'dotaccent': 333,
  8998. 'dieresis': 333,
  8999. 'ring': 333,
  9000. 'cedilla': 333,
  9001. 'hungarumlaut': 333,
  9002. 'ogonek': 333,
  9003. 'caron': 333,
  9004. 'emdash': 1000,
  9005. 'AE': 889,
  9006. 'ordfeminine': 276,
  9007. 'Lslash': 611,
  9008. 'Oslash': 722,
  9009. 'OE': 889,
  9010. 'ordmasculine': 310,
  9011. 'ae': 667,
  9012. 'dotlessi': 278,
  9013. 'lslash': 278,
  9014. 'oslash': 500,
  9015. 'oe': 722,
  9016. 'germandbls': 500,
  9017. 'Idieresis': 333,
  9018. 'eacute': 444,
  9019. 'abreve': 444,
  9020. 'uhungarumlaut': 500,
  9021. 'ecaron': 444,
  9022. 'Ydieresis': 722,
  9023. 'divide': 564,
  9024. 'Yacute': 722,
  9025. 'Acircumflex': 722,
  9026. 'aacute': 444,
  9027. 'Ucircumflex': 722,
  9028. 'yacute': 500,
  9029. 'scommaaccent': 389,
  9030. 'ecircumflex': 444,
  9031. 'Uring': 722,
  9032. 'Udieresis': 722,
  9033. 'aogonek': 444,
  9034. 'Uacute': 722,
  9035. 'uogonek': 500,
  9036. 'Edieresis': 611,
  9037. 'Dcroat': 722,
  9038. 'commaaccent': 250,
  9039. 'copyright': 760,
  9040. 'Emacron': 611,
  9041. 'ccaron': 444,
  9042. 'aring': 444,
  9043. 'Ncommaaccent': 722,
  9044. 'lacute': 278,
  9045. 'agrave': 444,
  9046. 'Tcommaaccent': 611,
  9047. 'Cacute': 667,
  9048. 'atilde': 444,
  9049. 'Edotaccent': 611,
  9050. 'scaron': 389,
  9051. 'scedilla': 389,
  9052. 'iacute': 278,
  9053. 'lozenge': 471,
  9054. 'Rcaron': 667,
  9055. 'Gcommaaccent': 722,
  9056. 'ucircumflex': 500,
  9057. 'acircumflex': 444,
  9058. 'Amacron': 722,
  9059. 'rcaron': 333,
  9060. 'ccedilla': 444,
  9061. 'Zdotaccent': 611,
  9062. 'Thorn': 556,
  9063. 'Omacron': 722,
  9064. 'Racute': 667,
  9065. 'Sacute': 556,
  9066. 'dcaron': 588,
  9067. 'Umacron': 722,
  9068. 'uring': 500,
  9069. 'threesuperior': 300,
  9070. 'Ograve': 722,
  9071. 'Agrave': 722,
  9072. 'Abreve': 722,
  9073. 'multiply': 564,
  9074. 'uacute': 500,
  9075. 'Tcaron': 611,
  9076. 'partialdiff': 476,
  9077. 'ydieresis': 500,
  9078. 'Nacute': 722,
  9079. 'icircumflex': 278,
  9080. 'Ecircumflex': 611,
  9081. 'adieresis': 444,
  9082. 'edieresis': 444,
  9083. 'cacute': 444,
  9084. 'nacute': 500,
  9085. 'umacron': 500,
  9086. 'Ncaron': 722,
  9087. 'Iacute': 333,
  9088. 'plusminus': 564,
  9089. 'brokenbar': 200,
  9090. 'registered': 760,
  9091. 'Gbreve': 722,
  9092. 'Idotaccent': 333,
  9093. 'summation': 600,
  9094. 'Egrave': 611,
  9095. 'racute': 333,
  9096. 'omacron': 500,
  9097. 'Zacute': 611,
  9098. 'Zcaron': 611,
  9099. 'greaterequal': 549,
  9100. 'Eth': 722,
  9101. 'Ccedilla': 667,
  9102. 'lcommaaccent': 278,
  9103. 'tcaron': 326,
  9104. 'eogonek': 444,
  9105. 'Uogonek': 722,
  9106. 'Aacute': 722,
  9107. 'Adieresis': 722,
  9108. 'egrave': 444,
  9109. 'zacute': 444,
  9110. 'iogonek': 278,
  9111. 'Oacute': 722,
  9112. 'oacute': 500,
  9113. 'amacron': 444,
  9114. 'sacute': 389,
  9115. 'idieresis': 278,
  9116. 'Ocircumflex': 722,
  9117. 'Ugrave': 722,
  9118. 'Delta': 612,
  9119. 'thorn': 500,
  9120. 'twosuperior': 300,
  9121. 'Odieresis': 722,
  9122. 'mu': 500,
  9123. 'igrave': 278,
  9124. 'ohungarumlaut': 500,
  9125. 'Eogonek': 611,
  9126. 'dcroat': 500,
  9127. 'threequarters': 750,
  9128. 'Scedilla': 556,
  9129. 'lcaron': 344,
  9130. 'Kcommaaccent': 722,
  9131. 'Lacute': 611,
  9132. 'trademark': 980,
  9133. 'edotaccent': 444,
  9134. 'Igrave': 333,
  9135. 'Imacron': 333,
  9136. 'Lcaron': 611,
  9137. 'onehalf': 750,
  9138. 'lessequal': 549,
  9139. 'ocircumflex': 500,
  9140. 'ntilde': 500,
  9141. 'Uhungarumlaut': 722,
  9142. 'Eacute': 611,
  9143. 'emacron': 444,
  9144. 'gbreve': 500,
  9145. 'onequarter': 750,
  9146. 'Scaron': 556,
  9147. 'Scommaaccent': 556,
  9148. 'Ohungarumlaut': 722,
  9149. 'degree': 400,
  9150. 'ograve': 500,
  9151. 'Ccaron': 667,
  9152. 'ugrave': 500,
  9153. 'radical': 453,
  9154. 'Dcaron': 722,
  9155. 'rcommaaccent': 333,
  9156. 'Ntilde': 722,
  9157. 'otilde': 500,
  9158. 'Rcommaaccent': 667,
  9159. 'Lcommaaccent': 611,
  9160. 'Atilde': 722,
  9161. 'Aogonek': 722,
  9162. 'Aring': 722,
  9163. 'Otilde': 722,
  9164. 'zdotaccent': 444,
  9165. 'Ecaron': 611,
  9166. 'Iogonek': 333,
  9167. 'kcommaaccent': 500,
  9168. 'minus': 564,
  9169. 'Icircumflex': 333,
  9170. 'ncaron': 500,
  9171. 'tcommaaccent': 278,
  9172. 'logicalnot': 564,
  9173. 'odieresis': 500,
  9174. 'udieresis': 500,
  9175. 'notequal': 549,
  9176. 'gcommaaccent': 500,
  9177. 'eth': 500,
  9178. 'zcaron': 444,
  9179. 'ncommaaccent': 500,
  9180. 'onesuperior': 300,
  9181. 'imacron': 278,
  9182. 'Euro': 500
  9183. },
  9184. 'Times-Bold': {
  9185. 'space': 250,
  9186. 'exclam': 333,
  9187. 'quotedbl': 555,
  9188. 'numbersign': 500,
  9189. 'dollar': 500,
  9190. 'percent': 1000,
  9191. 'ampersand': 833,
  9192. 'quoteright': 333,
  9193. 'parenleft': 333,
  9194. 'parenright': 333,
  9195. 'asterisk': 500,
  9196. 'plus': 570,
  9197. 'comma': 250,
  9198. 'hyphen': 333,
  9199. 'period': 250,
  9200. 'slash': 278,
  9201. 'zero': 500,
  9202. 'one': 500,
  9203. 'two': 500,
  9204. 'three': 500,
  9205. 'four': 500,
  9206. 'five': 500,
  9207. 'six': 500,
  9208. 'seven': 500,
  9209. 'eight': 500,
  9210. 'nine': 500,
  9211. 'colon': 333,
  9212. 'semicolon': 333,
  9213. 'less': 570,
  9214. 'equal': 570,
  9215. 'greater': 570,
  9216. 'question': 500,
  9217. 'at': 930,
  9218. 'A': 722,
  9219. 'B': 667,
  9220. 'C': 722,
  9221. 'D': 722,
  9222. 'E': 667,
  9223. 'F': 611,
  9224. 'G': 778,
  9225. 'H': 778,
  9226. 'I': 389,
  9227. 'J': 500,
  9228. 'K': 778,
  9229. 'L': 667,
  9230. 'M': 944,
  9231. 'N': 722,
  9232. 'O': 778,
  9233. 'P': 611,
  9234. 'Q': 778,
  9235. 'R': 722,
  9236. 'S': 556,
  9237. 'T': 667,
  9238. 'U': 722,
  9239. 'V': 722,
  9240. 'W': 1000,
  9241. 'X': 722,
  9242. 'Y': 722,
  9243. 'Z': 667,
  9244. 'bracketleft': 333,
  9245. 'backslash': 278,
  9246. 'bracketright': 333,
  9247. 'asciicircum': 581,
  9248. 'underscore': 500,
  9249. 'quoteleft': 333,
  9250. 'a': 500,
  9251. 'b': 556,
  9252. 'c': 444,
  9253. 'd': 556,
  9254. 'e': 444,
  9255. 'f': 333,
  9256. 'g': 500,
  9257. 'h': 556,
  9258. 'i': 278,
  9259. 'j': 333,
  9260. 'k': 556,
  9261. 'l': 278,
  9262. 'm': 833,
  9263. 'n': 556,
  9264. 'o': 500,
  9265. 'p': 556,
  9266. 'q': 556,
  9267. 'r': 444,
  9268. 's': 389,
  9269. 't': 333,
  9270. 'u': 556,
  9271. 'v': 500,
  9272. 'w': 722,
  9273. 'x': 500,
  9274. 'y': 500,
  9275. 'z': 444,
  9276. 'braceleft': 394,
  9277. 'bar': 220,
  9278. 'braceright': 394,
  9279. 'asciitilde': 520,
  9280. 'exclamdown': 333,
  9281. 'cent': 500,
  9282. 'sterling': 500,
  9283. 'fraction': 167,
  9284. 'yen': 500,
  9285. 'florin': 500,
  9286. 'section': 500,
  9287. 'currency': 500,
  9288. 'quotesingle': 278,
  9289. 'quotedblleft': 500,
  9290. 'guillemotleft': 500,
  9291. 'guilsinglleft': 333,
  9292. 'guilsinglright': 333,
  9293. 'fi': 556,
  9294. 'fl': 556,
  9295. 'endash': 500,
  9296. 'dagger': 500,
  9297. 'daggerdbl': 500,
  9298. 'periodcentered': 250,
  9299. 'paragraph': 540,
  9300. 'bullet': 350,
  9301. 'quotesinglbase': 333,
  9302. 'quotedblbase': 500,
  9303. 'quotedblright': 500,
  9304. 'guillemotright': 500,
  9305. 'ellipsis': 1000,
  9306. 'perthousand': 1000,
  9307. 'questiondown': 500,
  9308. 'grave': 333,
  9309. 'acute': 333,
  9310. 'circumflex': 333,
  9311. 'tilde': 333,
  9312. 'macron': 333,
  9313. 'breve': 333,
  9314. 'dotaccent': 333,
  9315. 'dieresis': 333,
  9316. 'ring': 333,
  9317. 'cedilla': 333,
  9318. 'hungarumlaut': 333,
  9319. 'ogonek': 333,
  9320. 'caron': 333,
  9321. 'emdash': 1000,
  9322. 'AE': 1000,
  9323. 'ordfeminine': 300,
  9324. 'Lslash': 667,
  9325. 'Oslash': 778,
  9326. 'OE': 1000,
  9327. 'ordmasculine': 330,
  9328. 'ae': 722,
  9329. 'dotlessi': 278,
  9330. 'lslash': 278,
  9331. 'oslash': 500,
  9332. 'oe': 722,
  9333. 'germandbls': 556,
  9334. 'Idieresis': 389,
  9335. 'eacute': 444,
  9336. 'abreve': 500,
  9337. 'uhungarumlaut': 556,
  9338. 'ecaron': 444,
  9339. 'Ydieresis': 722,
  9340. 'divide': 570,
  9341. 'Yacute': 722,
  9342. 'Acircumflex': 722,
  9343. 'aacute': 500,
  9344. 'Ucircumflex': 722,
  9345. 'yacute': 500,
  9346. 'scommaaccent': 389,
  9347. 'ecircumflex': 444,
  9348. 'Uring': 722,
  9349. 'Udieresis': 722,
  9350. 'aogonek': 500,
  9351. 'Uacute': 722,
  9352. 'uogonek': 556,
  9353. 'Edieresis': 667,
  9354. 'Dcroat': 722,
  9355. 'commaaccent': 250,
  9356. 'copyright': 747,
  9357. 'Emacron': 667,
  9358. 'ccaron': 444,
  9359. 'aring': 500,
  9360. 'Ncommaaccent': 722,
  9361. 'lacute': 278,
  9362. 'agrave': 500,
  9363. 'Tcommaaccent': 667,
  9364. 'Cacute': 722,
  9365. 'atilde': 500,
  9366. 'Edotaccent': 667,
  9367. 'scaron': 389,
  9368. 'scedilla': 389,
  9369. 'iacute': 278,
  9370. 'lozenge': 494,
  9371. 'Rcaron': 722,
  9372. 'Gcommaaccent': 778,
  9373. 'ucircumflex': 556,
  9374. 'acircumflex': 500,
  9375. 'Amacron': 722,
  9376. 'rcaron': 444,
  9377. 'ccedilla': 444,
  9378. 'Zdotaccent': 667,
  9379. 'Thorn': 611,
  9380. 'Omacron': 778,
  9381. 'Racute': 722,
  9382. 'Sacute': 556,
  9383. 'dcaron': 672,
  9384. 'Umacron': 722,
  9385. 'uring': 556,
  9386. 'threesuperior': 300,
  9387. 'Ograve': 778,
  9388. 'Agrave': 722,
  9389. 'Abreve': 722,
  9390. 'multiply': 570,
  9391. 'uacute': 556,
  9392. 'Tcaron': 667,
  9393. 'partialdiff': 494,
  9394. 'ydieresis': 500,
  9395. 'Nacute': 722,
  9396. 'icircumflex': 278,
  9397. 'Ecircumflex': 667,
  9398. 'adieresis': 500,
  9399. 'edieresis': 444,
  9400. 'cacute': 444,
  9401. 'nacute': 556,
  9402. 'umacron': 556,
  9403. 'Ncaron': 722,
  9404. 'Iacute': 389,
  9405. 'plusminus': 570,
  9406. 'brokenbar': 220,
  9407. 'registered': 747,
  9408. 'Gbreve': 778,
  9409. 'Idotaccent': 389,
  9410. 'summation': 600,
  9411. 'Egrave': 667,
  9412. 'racute': 444,
  9413. 'omacron': 500,
  9414. 'Zacute': 667,
  9415. 'Zcaron': 667,
  9416. 'greaterequal': 549,
  9417. 'Eth': 722,
  9418. 'Ccedilla': 722,
  9419. 'lcommaaccent': 278,
  9420. 'tcaron': 416,
  9421. 'eogonek': 444,
  9422. 'Uogonek': 722,
  9423. 'Aacute': 722,
  9424. 'Adieresis': 722,
  9425. 'egrave': 444,
  9426. 'zacute': 444,
  9427. 'iogonek': 278,
  9428. 'Oacute': 778,
  9429. 'oacute': 500,
  9430. 'amacron': 500,
  9431. 'sacute': 389,
  9432. 'idieresis': 278,
  9433. 'Ocircumflex': 778,
  9434. 'Ugrave': 722,
  9435. 'Delta': 612,
  9436. 'thorn': 556,
  9437. 'twosuperior': 300,
  9438. 'Odieresis': 778,
  9439. 'mu': 556,
  9440. 'igrave': 278,
  9441. 'ohungarumlaut': 500,
  9442. 'Eogonek': 667,
  9443. 'dcroat': 556,
  9444. 'threequarters': 750,
  9445. 'Scedilla': 556,
  9446. 'lcaron': 394,
  9447. 'Kcommaaccent': 778,
  9448. 'Lacute': 667,
  9449. 'trademark': 1000,
  9450. 'edotaccent': 444,
  9451. 'Igrave': 389,
  9452. 'Imacron': 389,
  9453. 'Lcaron': 667,
  9454. 'onehalf': 750,
  9455. 'lessequal': 549,
  9456. 'ocircumflex': 500,
  9457. 'ntilde': 556,
  9458. 'Uhungarumlaut': 722,
  9459. 'Eacute': 667,
  9460. 'emacron': 444,
  9461. 'gbreve': 500,
  9462. 'onequarter': 750,
  9463. 'Scaron': 556,
  9464. 'Scommaaccent': 556,
  9465. 'Ohungarumlaut': 778,
  9466. 'degree': 400,
  9467. 'ograve': 500,
  9468. 'Ccaron': 722,
  9469. 'ugrave': 556,
  9470. 'radical': 549,
  9471. 'Dcaron': 722,
  9472. 'rcommaaccent': 444,
  9473. 'Ntilde': 722,
  9474. 'otilde': 500,
  9475. 'Rcommaaccent': 722,
  9476. 'Lcommaaccent': 667,
  9477. 'Atilde': 722,
  9478. 'Aogonek': 722,
  9479. 'Aring': 722,
  9480. 'Otilde': 778,
  9481. 'zdotaccent': 444,
  9482. 'Ecaron': 667,
  9483. 'Iogonek': 389,
  9484. 'kcommaaccent': 556,
  9485. 'minus': 570,
  9486. 'Icircumflex': 389,
  9487. 'ncaron': 556,
  9488. 'tcommaaccent': 333,
  9489. 'logicalnot': 570,
  9490. 'odieresis': 500,
  9491. 'udieresis': 556,
  9492. 'notequal': 549,
  9493. 'gcommaaccent': 500,
  9494. 'eth': 500,
  9495. 'zcaron': 444,
  9496. 'ncommaaccent': 556,
  9497. 'onesuperior': 300,
  9498. 'imacron': 278,
  9499. 'Euro': 500
  9500. },
  9501. 'Times-BoldItalic': {
  9502. 'space': 250,
  9503. 'exclam': 389,
  9504. 'quotedbl': 555,
  9505. 'numbersign': 500,
  9506. 'dollar': 500,
  9507. 'percent': 833,
  9508. 'ampersand': 778,
  9509. 'quoteright': 333,
  9510. 'parenleft': 333,
  9511. 'parenright': 333,
  9512. 'asterisk': 500,
  9513. 'plus': 570,
  9514. 'comma': 250,
  9515. 'hyphen': 333,
  9516. 'period': 250,
  9517. 'slash': 278,
  9518. 'zero': 500,
  9519. 'one': 500,
  9520. 'two': 500,
  9521. 'three': 500,
  9522. 'four': 500,
  9523. 'five': 500,
  9524. 'six': 500,
  9525. 'seven': 500,
  9526. 'eight': 500,
  9527. 'nine': 500,
  9528. 'colon': 333,
  9529. 'semicolon': 333,
  9530. 'less': 570,
  9531. 'equal': 570,
  9532. 'greater': 570,
  9533. 'question': 500,
  9534. 'at': 832,
  9535. 'A': 667,
  9536. 'B': 667,
  9537. 'C': 667,
  9538. 'D': 722,
  9539. 'E': 667,
  9540. 'F': 667,
  9541. 'G': 722,
  9542. 'H': 778,
  9543. 'I': 389,
  9544. 'J': 500,
  9545. 'K': 667,
  9546. 'L': 611,
  9547. 'M': 889,
  9548. 'N': 722,
  9549. 'O': 722,
  9550. 'P': 611,
  9551. 'Q': 722,
  9552. 'R': 667,
  9553. 'S': 556,
  9554. 'T': 611,
  9555. 'U': 722,
  9556. 'V': 667,
  9557. 'W': 889,
  9558. 'X': 667,
  9559. 'Y': 611,
  9560. 'Z': 611,
  9561. 'bracketleft': 333,
  9562. 'backslash': 278,
  9563. 'bracketright': 333,
  9564. 'asciicircum': 570,
  9565. 'underscore': 500,
  9566. 'quoteleft': 333,
  9567. 'a': 500,
  9568. 'b': 500,
  9569. 'c': 444,
  9570. 'd': 500,
  9571. 'e': 444,
  9572. 'f': 333,
  9573. 'g': 500,
  9574. 'h': 556,
  9575. 'i': 278,
  9576. 'j': 278,
  9577. 'k': 500,
  9578. 'l': 278,
  9579. 'm': 778,
  9580. 'n': 556,
  9581. 'o': 500,
  9582. 'p': 500,
  9583. 'q': 500,
  9584. 'r': 389,
  9585. 's': 389,
  9586. 't': 278,
  9587. 'u': 556,
  9588. 'v': 444,
  9589. 'w': 667,
  9590. 'x': 500,
  9591. 'y': 444,
  9592. 'z': 389,
  9593. 'braceleft': 348,
  9594. 'bar': 220,
  9595. 'braceright': 348,
  9596. 'asciitilde': 570,
  9597. 'exclamdown': 389,
  9598. 'cent': 500,
  9599. 'sterling': 500,
  9600. 'fraction': 167,
  9601. 'yen': 500,
  9602. 'florin': 500,
  9603. 'section': 500,
  9604. 'currency': 500,
  9605. 'quotesingle': 278,
  9606. 'quotedblleft': 500,
  9607. 'guillemotleft': 500,
  9608. 'guilsinglleft': 333,
  9609. 'guilsinglright': 333,
  9610. 'fi': 556,
  9611. 'fl': 556,
  9612. 'endash': 500,
  9613. 'dagger': 500,
  9614. 'daggerdbl': 500,
  9615. 'periodcentered': 250,
  9616. 'paragraph': 500,
  9617. 'bullet': 350,
  9618. 'quotesinglbase': 333,
  9619. 'quotedblbase': 500,
  9620. 'quotedblright': 500,
  9621. 'guillemotright': 500,
  9622. 'ellipsis': 1000,
  9623. 'perthousand': 1000,
  9624. 'questiondown': 500,
  9625. 'grave': 333,
  9626. 'acute': 333,
  9627. 'circumflex': 333,
  9628. 'tilde': 333,
  9629. 'macron': 333,
  9630. 'breve': 333,
  9631. 'dotaccent': 333,
  9632. 'dieresis': 333,
  9633. 'ring': 333,
  9634. 'cedilla': 333,
  9635. 'hungarumlaut': 333,
  9636. 'ogonek': 333,
  9637. 'caron': 333,
  9638. 'emdash': 1000,
  9639. 'AE': 944,
  9640. 'ordfeminine': 266,
  9641. 'Lslash': 611,
  9642. 'Oslash': 722,
  9643. 'OE': 944,
  9644. 'ordmasculine': 300,
  9645. 'ae': 722,
  9646. 'dotlessi': 278,
  9647. 'lslash': 278,
  9648. 'oslash': 500,
  9649. 'oe': 722,
  9650. 'germandbls': 500,
  9651. 'Idieresis': 389,
  9652. 'eacute': 444,
  9653. 'abreve': 500,
  9654. 'uhungarumlaut': 556,
  9655. 'ecaron': 444,
  9656. 'Ydieresis': 611,
  9657. 'divide': 570,
  9658. 'Yacute': 611,
  9659. 'Acircumflex': 667,
  9660. 'aacute': 500,
  9661. 'Ucircumflex': 722,
  9662. 'yacute': 444,
  9663. 'scommaaccent': 389,
  9664. 'ecircumflex': 444,
  9665. 'Uring': 722,
  9666. 'Udieresis': 722,
  9667. 'aogonek': 500,
  9668. 'Uacute': 722,
  9669. 'uogonek': 556,
  9670. 'Edieresis': 667,
  9671. 'Dcroat': 722,
  9672. 'commaaccent': 250,
  9673. 'copyright': 747,
  9674. 'Emacron': 667,
  9675. 'ccaron': 444,
  9676. 'aring': 500,
  9677. 'Ncommaaccent': 722,
  9678. 'lacute': 278,
  9679. 'agrave': 500,
  9680. 'Tcommaaccent': 611,
  9681. 'Cacute': 667,
  9682. 'atilde': 500,
  9683. 'Edotaccent': 667,
  9684. 'scaron': 389,
  9685. 'scedilla': 389,
  9686. 'iacute': 278,
  9687. 'lozenge': 494,
  9688. 'Rcaron': 667,
  9689. 'Gcommaaccent': 722,
  9690. 'ucircumflex': 556,
  9691. 'acircumflex': 500,
  9692. 'Amacron': 667,
  9693. 'rcaron': 389,
  9694. 'ccedilla': 444,
  9695. 'Zdotaccent': 611,
  9696. 'Thorn': 611,
  9697. 'Omacron': 722,
  9698. 'Racute': 667,
  9699. 'Sacute': 556,
  9700. 'dcaron': 608,
  9701. 'Umacron': 722,
  9702. 'uring': 556,
  9703. 'threesuperior': 300,
  9704. 'Ograve': 722,
  9705. 'Agrave': 667,
  9706. 'Abreve': 667,
  9707. 'multiply': 570,
  9708. 'uacute': 556,
  9709. 'Tcaron': 611,
  9710. 'partialdiff': 494,
  9711. 'ydieresis': 444,
  9712. 'Nacute': 722,
  9713. 'icircumflex': 278,
  9714. 'Ecircumflex': 667,
  9715. 'adieresis': 500,
  9716. 'edieresis': 444,
  9717. 'cacute': 444,
  9718. 'nacute': 556,
  9719. 'umacron': 556,
  9720. 'Ncaron': 722,
  9721. 'Iacute': 389,
  9722. 'plusminus': 570,
  9723. 'brokenbar': 220,
  9724. 'registered': 747,
  9725. 'Gbreve': 722,
  9726. 'Idotaccent': 389,
  9727. 'summation': 600,
  9728. 'Egrave': 667,
  9729. 'racute': 389,
  9730. 'omacron': 500,
  9731. 'Zacute': 611,
  9732. 'Zcaron': 611,
  9733. 'greaterequal': 549,
  9734. 'Eth': 722,
  9735. 'Ccedilla': 667,
  9736. 'lcommaaccent': 278,
  9737. 'tcaron': 366,
  9738. 'eogonek': 444,
  9739. 'Uogonek': 722,
  9740. 'Aacute': 667,
  9741. 'Adieresis': 667,
  9742. 'egrave': 444,
  9743. 'zacute': 389,
  9744. 'iogonek': 278,
  9745. 'Oacute': 722,
  9746. 'oacute': 500,
  9747. 'amacron': 500,
  9748. 'sacute': 389,
  9749. 'idieresis': 278,
  9750. 'Ocircumflex': 722,
  9751. 'Ugrave': 722,
  9752. 'Delta': 612,
  9753. 'thorn': 500,
  9754. 'twosuperior': 300,
  9755. 'Odieresis': 722,
  9756. 'mu': 576,
  9757. 'igrave': 278,
  9758. 'ohungarumlaut': 500,
  9759. 'Eogonek': 667,
  9760. 'dcroat': 500,
  9761. 'threequarters': 750,
  9762. 'Scedilla': 556,
  9763. 'lcaron': 382,
  9764. 'Kcommaaccent': 667,
  9765. 'Lacute': 611,
  9766. 'trademark': 1000,
  9767. 'edotaccent': 444,
  9768. 'Igrave': 389,
  9769. 'Imacron': 389,
  9770. 'Lcaron': 611,
  9771. 'onehalf': 750,
  9772. 'lessequal': 549,
  9773. 'ocircumflex': 500,
  9774. 'ntilde': 556,
  9775. 'Uhungarumlaut': 722,
  9776. 'Eacute': 667,
  9777. 'emacron': 444,
  9778. 'gbreve': 500,
  9779. 'onequarter': 750,
  9780. 'Scaron': 556,
  9781. 'Scommaaccent': 556,
  9782. 'Ohungarumlaut': 722,
  9783. 'degree': 400,
  9784. 'ograve': 500,
  9785. 'Ccaron': 667,
  9786. 'ugrave': 556,
  9787. 'radical': 549,
  9788. 'Dcaron': 722,
  9789. 'rcommaaccent': 389,
  9790. 'Ntilde': 722,
  9791. 'otilde': 500,
  9792. 'Rcommaaccent': 667,
  9793. 'Lcommaaccent': 611,
  9794. 'Atilde': 667,
  9795. 'Aogonek': 667,
  9796. 'Aring': 667,
  9797. 'Otilde': 722,
  9798. 'zdotaccent': 389,
  9799. 'Ecaron': 667,
  9800. 'Iogonek': 389,
  9801. 'kcommaaccent': 500,
  9802. 'minus': 606,
  9803. 'Icircumflex': 389,
  9804. 'ncaron': 556,
  9805. 'tcommaaccent': 278,
  9806. 'logicalnot': 606,
  9807. 'odieresis': 500,
  9808. 'udieresis': 556,
  9809. 'notequal': 549,
  9810. 'gcommaaccent': 500,
  9811. 'eth': 500,
  9812. 'zcaron': 389,
  9813. 'ncommaaccent': 556,
  9814. 'onesuperior': 300,
  9815. 'imacron': 278,
  9816. 'Euro': 500
  9817. },
  9818. 'Times-Italic': {
  9819. 'space': 250,
  9820. 'exclam': 333,
  9821. 'quotedbl': 420,
  9822. 'numbersign': 500,
  9823. 'dollar': 500,
  9824. 'percent': 833,
  9825. 'ampersand': 778,
  9826. 'quoteright': 333,
  9827. 'parenleft': 333,
  9828. 'parenright': 333,
  9829. 'asterisk': 500,
  9830. 'plus': 675,
  9831. 'comma': 250,
  9832. 'hyphen': 333,
  9833. 'period': 250,
  9834. 'slash': 278,
  9835. 'zero': 500,
  9836. 'one': 500,
  9837. 'two': 500,
  9838. 'three': 500,
  9839. 'four': 500,
  9840. 'five': 500,
  9841. 'six': 500,
  9842. 'seven': 500,
  9843. 'eight': 500,
  9844. 'nine': 500,
  9845. 'colon': 333,
  9846. 'semicolon': 333,
  9847. 'less': 675,
  9848. 'equal': 675,
  9849. 'greater': 675,
  9850. 'question': 500,
  9851. 'at': 920,
  9852. 'A': 611,
  9853. 'B': 611,
  9854. 'C': 667,
  9855. 'D': 722,
  9856. 'E': 611,
  9857. 'F': 611,
  9858. 'G': 722,
  9859. 'H': 722,
  9860. 'I': 333,
  9861. 'J': 444,
  9862. 'K': 667,
  9863. 'L': 556,
  9864. 'M': 833,
  9865. 'N': 667,
  9866. 'O': 722,
  9867. 'P': 611,
  9868. 'Q': 722,
  9869. 'R': 611,
  9870. 'S': 500,
  9871. 'T': 556,
  9872. 'U': 722,
  9873. 'V': 611,
  9874. 'W': 833,
  9875. 'X': 611,
  9876. 'Y': 556,
  9877. 'Z': 556,
  9878. 'bracketleft': 389,
  9879. 'backslash': 278,
  9880. 'bracketright': 389,
  9881. 'asciicircum': 422,
  9882. 'underscore': 500,
  9883. 'quoteleft': 333,
  9884. 'a': 500,
  9885. 'b': 500,
  9886. 'c': 444,
  9887. 'd': 500,
  9888. 'e': 444,
  9889. 'f': 278,
  9890. 'g': 500,
  9891. 'h': 500,
  9892. 'i': 278,
  9893. 'j': 278,
  9894. 'k': 444,
  9895. 'l': 278,
  9896. 'm': 722,
  9897. 'n': 500,
  9898. 'o': 500,
  9899. 'p': 500,
  9900. 'q': 500,
  9901. 'r': 389,
  9902. 's': 389,
  9903. 't': 278,
  9904. 'u': 500,
  9905. 'v': 444,
  9906. 'w': 667,
  9907. 'x': 444,
  9908. 'y': 444,
  9909. 'z': 389,
  9910. 'braceleft': 400,
  9911. 'bar': 275,
  9912. 'braceright': 400,
  9913. 'asciitilde': 541,
  9914. 'exclamdown': 389,
  9915. 'cent': 500,
  9916. 'sterling': 500,
  9917. 'fraction': 167,
  9918. 'yen': 500,
  9919. 'florin': 500,
  9920. 'section': 500,
  9921. 'currency': 500,
  9922. 'quotesingle': 214,
  9923. 'quotedblleft': 556,
  9924. 'guillemotleft': 500,
  9925. 'guilsinglleft': 333,
  9926. 'guilsinglright': 333,
  9927. 'fi': 500,
  9928. 'fl': 500,
  9929. 'endash': 500,
  9930. 'dagger': 500,
  9931. 'daggerdbl': 500,
  9932. 'periodcentered': 250,
  9933. 'paragraph': 523,
  9934. 'bullet': 350,
  9935. 'quotesinglbase': 333,
  9936. 'quotedblbase': 556,
  9937. 'quotedblright': 556,
  9938. 'guillemotright': 500,
  9939. 'ellipsis': 889,
  9940. 'perthousand': 1000,
  9941. 'questiondown': 500,
  9942. 'grave': 333,
  9943. 'acute': 333,
  9944. 'circumflex': 333,
  9945. 'tilde': 333,
  9946. 'macron': 333,
  9947. 'breve': 333,
  9948. 'dotaccent': 333,
  9949. 'dieresis': 333,
  9950. 'ring': 333,
  9951. 'cedilla': 333,
  9952. 'hungarumlaut': 333,
  9953. 'ogonek': 333,
  9954. 'caron': 333,
  9955. 'emdash': 889,
  9956. 'AE': 889,
  9957. 'ordfeminine': 276,
  9958. 'Lslash': 556,
  9959. 'Oslash': 722,
  9960. 'OE': 944,
  9961. 'ordmasculine': 310,
  9962. 'ae': 667,
  9963. 'dotlessi': 278,
  9964. 'lslash': 278,
  9965. 'oslash': 500,
  9966. 'oe': 667,
  9967. 'germandbls': 500,
  9968. 'Idieresis': 333,
  9969. 'eacute': 444,
  9970. 'abreve': 500,
  9971. 'uhungarumlaut': 500,
  9972. 'ecaron': 444,
  9973. 'Ydieresis': 556,
  9974. 'divide': 675,
  9975. 'Yacute': 556,
  9976. 'Acircumflex': 611,
  9977. 'aacute': 500,
  9978. 'Ucircumflex': 722,
  9979. 'yacute': 444,
  9980. 'scommaaccent': 389,
  9981. 'ecircumflex': 444,
  9982. 'Uring': 722,
  9983. 'Udieresis': 722,
  9984. 'aogonek': 500,
  9985. 'Uacute': 722,
  9986. 'uogonek': 500,
  9987. 'Edieresis': 611,
  9988. 'Dcroat': 722,
  9989. 'commaaccent': 250,
  9990. 'copyright': 760,
  9991. 'Emacron': 611,
  9992. 'ccaron': 444,
  9993. 'aring': 500,
  9994. 'Ncommaaccent': 667,
  9995. 'lacute': 278,
  9996. 'agrave': 500,
  9997. 'Tcommaaccent': 556,
  9998. 'Cacute': 667,
  9999. 'atilde': 500,
  10000. 'Edotaccent': 611,
  10001. 'scaron': 389,
  10002. 'scedilla': 389,
  10003. 'iacute': 278,
  10004. 'lozenge': 471,
  10005. 'Rcaron': 611,
  10006. 'Gcommaaccent': 722,
  10007. 'ucircumflex': 500,
  10008. 'acircumflex': 500,
  10009. 'Amacron': 611,
  10010. 'rcaron': 389,
  10011. 'ccedilla': 444,
  10012. 'Zdotaccent': 556,
  10013. 'Thorn': 611,
  10014. 'Omacron': 722,
  10015. 'Racute': 611,
  10016. 'Sacute': 500,
  10017. 'dcaron': 544,
  10018. 'Umacron': 722,
  10019. 'uring': 500,
  10020. 'threesuperior': 300,
  10021. 'Ograve': 722,
  10022. 'Agrave': 611,
  10023. 'Abreve': 611,
  10024. 'multiply': 675,
  10025. 'uacute': 500,
  10026. 'Tcaron': 556,
  10027. 'partialdiff': 476,
  10028. 'ydieresis': 444,
  10029. 'Nacute': 667,
  10030. 'icircumflex': 278,
  10031. 'Ecircumflex': 611,
  10032. 'adieresis': 500,
  10033. 'edieresis': 444,
  10034. 'cacute': 444,
  10035. 'nacute': 500,
  10036. 'umacron': 500,
  10037. 'Ncaron': 667,
  10038. 'Iacute': 333,
  10039. 'plusminus': 675,
  10040. 'brokenbar': 275,
  10041. 'registered': 760,
  10042. 'Gbreve': 722,
  10043. 'Idotaccent': 333,
  10044. 'summation': 600,
  10045. 'Egrave': 611,
  10046. 'racute': 389,
  10047. 'omacron': 500,
  10048. 'Zacute': 556,
  10049. 'Zcaron': 556,
  10050. 'greaterequal': 549,
  10051. 'Eth': 722,
  10052. 'Ccedilla': 667,
  10053. 'lcommaaccent': 278,
  10054. 'tcaron': 300,
  10055. 'eogonek': 444,
  10056. 'Uogonek': 722,
  10057. 'Aacute': 611,
  10058. 'Adieresis': 611,
  10059. 'egrave': 444,
  10060. 'zacute': 389,
  10061. 'iogonek': 278,
  10062. 'Oacute': 722,
  10063. 'oacute': 500,
  10064. 'amacron': 500,
  10065. 'sacute': 389,
  10066. 'idieresis': 278,
  10067. 'Ocircumflex': 722,
  10068. 'Ugrave': 722,
  10069. 'Delta': 612,
  10070. 'thorn': 500,
  10071. 'twosuperior': 300,
  10072. 'Odieresis': 722,
  10073. 'mu': 500,
  10074. 'igrave': 278,
  10075. 'ohungarumlaut': 500,
  10076. 'Eogonek': 611,
  10077. 'dcroat': 500,
  10078. 'threequarters': 750,
  10079. 'Scedilla': 500,
  10080. 'lcaron': 300,
  10081. 'Kcommaaccent': 667,
  10082. 'Lacute': 556,
  10083. 'trademark': 980,
  10084. 'edotaccent': 444,
  10085. 'Igrave': 333,
  10086. 'Imacron': 333,
  10087. 'Lcaron': 611,
  10088. 'onehalf': 750,
  10089. 'lessequal': 549,
  10090. 'ocircumflex': 500,
  10091. 'ntilde': 500,
  10092. 'Uhungarumlaut': 722,
  10093. 'Eacute': 611,
  10094. 'emacron': 444,
  10095. 'gbreve': 500,
  10096. 'onequarter': 750,
  10097. 'Scaron': 500,
  10098. 'Scommaaccent': 500,
  10099. 'Ohungarumlaut': 722,
  10100. 'degree': 400,
  10101. 'ograve': 500,
  10102. 'Ccaron': 667,
  10103. 'ugrave': 500,
  10104. 'radical': 453,
  10105. 'Dcaron': 722,
  10106. 'rcommaaccent': 389,
  10107. 'Ntilde': 667,
  10108. 'otilde': 500,
  10109. 'Rcommaaccent': 611,
  10110. 'Lcommaaccent': 556,
  10111. 'Atilde': 611,
  10112. 'Aogonek': 611,
  10113. 'Aring': 611,
  10114. 'Otilde': 722,
  10115. 'zdotaccent': 389,
  10116. 'Ecaron': 611,
  10117. 'Iogonek': 333,
  10118. 'kcommaaccent': 444,
  10119. 'minus': 675,
  10120. 'Icircumflex': 333,
  10121. 'ncaron': 500,
  10122. 'tcommaaccent': 278,
  10123. 'logicalnot': 675,
  10124. 'odieresis': 500,
  10125. 'udieresis': 500,
  10126. 'notequal': 549,
  10127. 'gcommaaccent': 500,
  10128. 'eth': 500,
  10129. 'zcaron': 389,
  10130. 'ncommaaccent': 500,
  10131. 'onesuperior': 300,
  10132. 'imacron': 278,
  10133. 'Euro': 500
  10134. },
  10135. 'ZapfDingbats': {
  10136. 'space': 278,
  10137. 'a1': 974,
  10138. 'a2': 961,
  10139. 'a202': 974,
  10140. 'a3': 980,
  10141. 'a4': 719,
  10142. 'a5': 789,
  10143. 'a119': 790,
  10144. 'a118': 791,
  10145. 'a117': 690,
  10146. 'a11': 960,
  10147. 'a12': 939,
  10148. 'a13': 549,
  10149. 'a14': 855,
  10150. 'a15': 911,
  10151. 'a16': 933,
  10152. 'a105': 911,
  10153. 'a17': 945,
  10154. 'a18': 974,
  10155. 'a19': 755,
  10156. 'a20': 846,
  10157. 'a21': 762,
  10158. 'a22': 761,
  10159. 'a23': 571,
  10160. 'a24': 677,
  10161. 'a25': 763,
  10162. 'a26': 760,
  10163. 'a27': 759,
  10164. 'a28': 754,
  10165. 'a6': 494,
  10166. 'a7': 552,
  10167. 'a8': 537,
  10168. 'a9': 577,
  10169. 'a10': 692,
  10170. 'a29': 786,
  10171. 'a30': 788,
  10172. 'a31': 788,
  10173. 'a32': 790,
  10174. 'a33': 793,
  10175. 'a34': 794,
  10176. 'a35': 816,
  10177. 'a36': 823,
  10178. 'a37': 789,
  10179. 'a38': 841,
  10180. 'a39': 823,
  10181. 'a40': 833,
  10182. 'a41': 816,
  10183. 'a42': 831,
  10184. 'a43': 923,
  10185. 'a44': 744,
  10186. 'a45': 723,
  10187. 'a46': 749,
  10188. 'a47': 790,
  10189. 'a48': 792,
  10190. 'a49': 695,
  10191. 'a50': 776,
  10192. 'a51': 768,
  10193. 'a52': 792,
  10194. 'a53': 759,
  10195. 'a54': 707,
  10196. 'a55': 708,
  10197. 'a56': 682,
  10198. 'a57': 701,
  10199. 'a58': 826,
  10200. 'a59': 815,
  10201. 'a60': 789,
  10202. 'a61': 789,
  10203. 'a62': 707,
  10204. 'a63': 687,
  10205. 'a64': 696,
  10206. 'a65': 689,
  10207. 'a66': 786,
  10208. 'a67': 787,
  10209. 'a68': 713,
  10210. 'a69': 791,
  10211. 'a70': 785,
  10212. 'a71': 791,
  10213. 'a72': 873,
  10214. 'a73': 761,
  10215. 'a74': 762,
  10216. 'a203': 762,
  10217. 'a75': 759,
  10218. 'a204': 759,
  10219. 'a76': 892,
  10220. 'a77': 892,
  10221. 'a78': 788,
  10222. 'a79': 784,
  10223. 'a81': 438,
  10224. 'a82': 138,
  10225. 'a83': 277,
  10226. 'a84': 415,
  10227. 'a97': 392,
  10228. 'a98': 392,
  10229. 'a99': 668,
  10230. 'a100': 668,
  10231. 'a89': 390,
  10232. 'a90': 390,
  10233. 'a93': 317,
  10234. 'a94': 317,
  10235. 'a91': 276,
  10236. 'a92': 276,
  10237. 'a205': 509,
  10238. 'a85': 509,
  10239. 'a206': 410,
  10240. 'a86': 410,
  10241. 'a87': 234,
  10242. 'a88': 234,
  10243. 'a95': 334,
  10244. 'a96': 334,
  10245. 'a101': 732,
  10246. 'a102': 544,
  10247. 'a103': 544,
  10248. 'a104': 910,
  10249. 'a106': 667,
  10250. 'a107': 760,
  10251. 'a108': 760,
  10252. 'a112': 776,
  10253. 'a111': 595,
  10254. 'a110': 694,
  10255. 'a109': 626,
  10256. 'a120': 788,
  10257. 'a121': 788,
  10258. 'a122': 788,
  10259. 'a123': 788,
  10260. 'a124': 788,
  10261. 'a125': 788,
  10262. 'a126': 788,
  10263. 'a127': 788,
  10264. 'a128': 788,
  10265. 'a129': 788,
  10266. 'a130': 788,
  10267. 'a131': 788,
  10268. 'a132': 788,
  10269. 'a133': 788,
  10270. 'a134': 788,
  10271. 'a135': 788,
  10272. 'a136': 788,
  10273. 'a137': 788,
  10274. 'a138': 788,
  10275. 'a139': 788,
  10276. 'a140': 788,
  10277. 'a141': 788,
  10278. 'a142': 788,
  10279. 'a143': 788,
  10280. 'a144': 788,
  10281. 'a145': 788,
  10282. 'a146': 788,
  10283. 'a147': 788,
  10284. 'a148': 788,
  10285. 'a149': 788,
  10286. 'a150': 788,
  10287. 'a151': 788,
  10288. 'a152': 788,
  10289. 'a153': 788,
  10290. 'a154': 788,
  10291. 'a155': 788,
  10292. 'a156': 788,
  10293. 'a157': 788,
  10294. 'a158': 788,
  10295. 'a159': 788,
  10296. 'a160': 894,
  10297. 'a161': 838,
  10298. 'a163': 1016,
  10299. 'a164': 458,
  10300. 'a196': 748,
  10301. 'a165': 924,
  10302. 'a192': 748,
  10303. 'a166': 918,
  10304. 'a167': 927,
  10305. 'a168': 928,
  10306. 'a169': 928,
  10307. 'a170': 834,
  10308. 'a171': 873,
  10309. 'a172': 828,
  10310. 'a173': 924,
  10311. 'a162': 924,
  10312. 'a174': 917,
  10313. 'a175': 930,
  10314. 'a176': 931,
  10315. 'a177': 463,
  10316. 'a178': 883,
  10317. 'a179': 836,
  10318. 'a193': 836,
  10319. 'a180': 867,
  10320. 'a199': 867,
  10321. 'a181': 696,
  10322. 'a200': 696,
  10323. 'a182': 874,
  10324. 'a201': 874,
  10325. 'a183': 760,
  10326. 'a184': 946,
  10327. 'a197': 771,
  10328. 'a185': 865,
  10329. 'a194': 771,
  10330. 'a198': 888,
  10331. 'a186': 967,
  10332. 'a195': 888,
  10333. 'a187': 831,
  10334. 'a188': 873,
  10335. 'a189': 927,
  10336. 'a190': 970,
  10337. 'a191': 918
  10338. }
  10339. };
  10340. exports.Metrics = Metrics;
  10341. }));
  10342. (function (root, factory) {
  10343. {
  10344. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  10345. }
  10346. }(this, function (exports, sharedGlobal) {
  10347. var PDFJS = sharedGlobal.PDFJS;
  10348. var bidi = PDFJS.bidi = (function bidiClosure() {
  10349. // Character types for symbols from 0000 to 00FF.
  10350. var baseTypes = [
  10351. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  10352. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10353. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  10354. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  10355. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  10356. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10357. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  10358. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10359. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10360. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  10361. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10362. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10363. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  10364. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  10365. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10366. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10367. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10368. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10369. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  10370. ];
  10371. // Character types for symbols from 0600 to 06FF
  10372. var arabicTypes = [
  10373. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10374. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  10375. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', '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', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10380. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10381. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  10382. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10383. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', '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', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10392. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  10393. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10394. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  10395. ];
  10396. function isOdd(i) {
  10397. return (i & 1) !== 0;
  10398. }
  10399. function isEven(i) {
  10400. return (i & 1) === 0;
  10401. }
  10402. function findUnequal(arr, start, value) {
  10403. for (var j = start, jj = arr.length; j < jj; ++j) {
  10404. if (arr[j] !== value) {
  10405. return j;
  10406. }
  10407. }
  10408. return j;
  10409. }
  10410. function setValues(arr, start, end, value) {
  10411. for (var j = start; j < end; ++j) {
  10412. arr[j] = value;
  10413. }
  10414. }
  10415. function reverseValues(arr, start, end) {
  10416. for (var i = start, j = end - 1; i < j; ++i, --j) {
  10417. var temp = arr[i];
  10418. arr[i] = arr[j];
  10419. arr[j] = temp;
  10420. }
  10421. }
  10422. function createBidiText(str, isLTR, vertical) {
  10423. return {
  10424. str: str,
  10425. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  10426. };
  10427. }
  10428. // These are used in bidi(), which is called frequently. We re-use them on
  10429. // each call to avoid unnecessary allocations.
  10430. var chars = [];
  10431. var types = [];
  10432. function bidi(str, startLevel, vertical) {
  10433. var isLTR = true;
  10434. var strLength = str.length;
  10435. if (strLength === 0 || vertical) {
  10436. return createBidiText(str, isLTR, vertical);
  10437. }
  10438. // Get types and fill arrays
  10439. chars.length = strLength;
  10440. types.length = strLength;
  10441. var numBidi = 0;
  10442. var i, ii;
  10443. for (i = 0; i < strLength; ++i) {
  10444. chars[i] = str.charAt(i);
  10445. var charCode = str.charCodeAt(i);
  10446. var charType = 'L';
  10447. if (charCode <= 0x00ff) {
  10448. charType = baseTypes[charCode];
  10449. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  10450. charType = 'R';
  10451. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  10452. charType = arabicTypes[charCode & 0xff];
  10453. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  10454. charType = 'AL';
  10455. }
  10456. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  10457. numBidi++;
  10458. }
  10459. types[i] = charType;
  10460. }
  10461. // Detect the bidi method
  10462. // - If there are no rtl characters then no bidi needed
  10463. // - If less than 30% chars are rtl then string is primarily ltr
  10464. // - If more than 30% chars are rtl then string is primarily rtl
  10465. if (numBidi === 0) {
  10466. isLTR = true;
  10467. return createBidiText(str, isLTR);
  10468. }
  10469. if (startLevel === -1) {
  10470. if ((strLength / numBidi) < 0.3) {
  10471. isLTR = true;
  10472. startLevel = 0;
  10473. } else {
  10474. isLTR = false;
  10475. startLevel = 1;
  10476. }
  10477. }
  10478. var levels = [];
  10479. for (i = 0; i < strLength; ++i) {
  10480. levels[i] = startLevel;
  10481. }
  10482. /*
  10483. X1-X10: skip most of this, since we are NOT doing the embeddings.
  10484. */
  10485. var e = (isOdd(startLevel) ? 'R' : 'L');
  10486. var sor = e;
  10487. var eor = sor;
  10488. /*
  10489. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  10490. type of the NSM to the type of the previous character. If the NSM is at the
  10491. start of the level run, it will get the type of sor.
  10492. */
  10493. var lastType = sor;
  10494. for (i = 0; i < strLength; ++i) {
  10495. if (types[i] === 'NSM') {
  10496. types[i] = lastType;
  10497. } else {
  10498. lastType = types[i];
  10499. }
  10500. }
  10501. /*
  10502. W2. Search backwards from each instance of a European number until the
  10503. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  10504. the type of the European number to Arabic number.
  10505. */
  10506. lastType = sor;
  10507. var t;
  10508. for (i = 0; i < strLength; ++i) {
  10509. t = types[i];
  10510. if (t === 'EN') {
  10511. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  10512. } else if (t === 'R' || t === 'L' || t === 'AL') {
  10513. lastType = t;
  10514. }
  10515. }
  10516. /*
  10517. W3. Change all ALs to R.
  10518. */
  10519. for (i = 0; i < strLength; ++i) {
  10520. t = types[i];
  10521. if (t === 'AL') {
  10522. types[i] = 'R';
  10523. }
  10524. }
  10525. /*
  10526. W4. A single European separator between two European numbers changes to a
  10527. European number. A single common separator between two numbers of the same
  10528. type changes to that type:
  10529. */
  10530. for (i = 1; i < strLength - 1; ++i) {
  10531. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  10532. types[i] = 'EN';
  10533. }
  10534. if (types[i] === 'CS' &&
  10535. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  10536. types[i + 1] === types[i - 1]) {
  10537. types[i] = types[i - 1];
  10538. }
  10539. }
  10540. /*
  10541. W5. A sequence of European terminators adjacent to European numbers changes
  10542. to all European numbers:
  10543. */
  10544. for (i = 0; i < strLength; ++i) {
  10545. if (types[i] === 'EN') {
  10546. // do before
  10547. var j;
  10548. for (j = i - 1; j >= 0; --j) {
  10549. if (types[j] !== 'ET') {
  10550. break;
  10551. }
  10552. types[j] = 'EN';
  10553. }
  10554. // do after
  10555. for (j = i + 1; j < strLength; --j) {
  10556. if (types[j] !== 'ET') {
  10557. break;
  10558. }
  10559. types[j] = 'EN';
  10560. }
  10561. }
  10562. }
  10563. /*
  10564. W6. Otherwise, separators and terminators change to Other Neutral:
  10565. */
  10566. for (i = 0; i < strLength; ++i) {
  10567. t = types[i];
  10568. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  10569. types[i] = 'ON';
  10570. }
  10571. }
  10572. /*
  10573. W7. Search backwards from each instance of a European number until the
  10574. first strong type (R, L, or sor) is found. If an L is found, then change
  10575. the type of the European number to L.
  10576. */
  10577. lastType = sor;
  10578. for (i = 0; i < strLength; ++i) {
  10579. t = types[i];
  10580. if (t === 'EN') {
  10581. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  10582. } else if (t === 'R' || t === 'L') {
  10583. lastType = t;
  10584. }
  10585. }
  10586. /*
  10587. N1. A sequence of neutrals takes the direction of the surrounding strong
  10588. text if the text on both sides has the same direction. European and Arabic
  10589. numbers are treated as though they were R. Start-of-level-run (sor) and
  10590. end-of-level-run (eor) are used at level run boundaries.
  10591. */
  10592. for (i = 0; i < strLength; ++i) {
  10593. if (types[i] === 'ON') {
  10594. var end = findUnequal(types, i + 1, 'ON');
  10595. var before = sor;
  10596. if (i > 0) {
  10597. before = types[i - 1];
  10598. }
  10599. var after = eor;
  10600. if (end + 1 < strLength) {
  10601. after = types[end + 1];
  10602. }
  10603. if (before !== 'L') {
  10604. before = 'R';
  10605. }
  10606. if (after !== 'L') {
  10607. after = 'R';
  10608. }
  10609. if (before === after) {
  10610. setValues(types, i, end, before);
  10611. }
  10612. i = end - 1; // reset to end (-1 so next iteration is ok)
  10613. }
  10614. }
  10615. /*
  10616. N2. Any remaining neutrals take the embedding direction.
  10617. */
  10618. for (i = 0; i < strLength; ++i) {
  10619. if (types[i] === 'ON') {
  10620. types[i] = e;
  10621. }
  10622. }
  10623. /*
  10624. I1. For all characters with an even (left-to-right) embedding direction,
  10625. those of type R go up one level and those of type AN or EN go up two
  10626. levels.
  10627. I2. For all characters with an odd (right-to-left) embedding direction,
  10628. those of type L, EN or AN go up one level.
  10629. */
  10630. for (i = 0; i < strLength; ++i) {
  10631. t = types[i];
  10632. if (isEven(levels[i])) {
  10633. if (t === 'R') {
  10634. levels[i] += 1;
  10635. } else if (t === 'AN' || t === 'EN') {
  10636. levels[i] += 2;
  10637. }
  10638. } else { // isOdd
  10639. if (t === 'L' || t === 'AN' || t === 'EN') {
  10640. levels[i] += 1;
  10641. }
  10642. }
  10643. }
  10644. /*
  10645. L1. On each line, reset the embedding level of the following characters to
  10646. the paragraph embedding level:
  10647. segment separators,
  10648. paragraph separators,
  10649. any sequence of whitespace characters preceding a segment separator or
  10650. paragraph separator, and any sequence of white space characters at the end
  10651. of the line.
  10652. */
  10653. // don't bother as text is only single line
  10654. /*
  10655. L2. From the highest level found in the text to the lowest odd level on
  10656. each line, reverse any contiguous sequence of characters that are at that
  10657. level or higher.
  10658. */
  10659. // find highest level & lowest odd level
  10660. var highestLevel = -1;
  10661. var lowestOddLevel = 99;
  10662. var level;
  10663. for (i = 0, ii = levels.length; i < ii; ++i) {
  10664. level = levels[i];
  10665. if (highestLevel < level) {
  10666. highestLevel = level;
  10667. }
  10668. if (lowestOddLevel > level && isOdd(level)) {
  10669. lowestOddLevel = level;
  10670. }
  10671. }
  10672. // now reverse between those limits
  10673. for (level = highestLevel; level >= lowestOddLevel; --level) {
  10674. // find segments to reverse
  10675. var start = -1;
  10676. for (i = 0, ii = levels.length; i < ii; ++i) {
  10677. if (levels[i] < level) {
  10678. if (start >= 0) {
  10679. reverseValues(chars, start, i);
  10680. start = -1;
  10681. }
  10682. } else if (start < 0) {
  10683. start = i;
  10684. }
  10685. }
  10686. if (start >= 0) {
  10687. reverseValues(chars, start, levels.length);
  10688. }
  10689. }
  10690. /*
  10691. L3. Combining marks applied to a right-to-left base character will at this
  10692. point precede their base character. If the rendering engine expects them to
  10693. follow the base characters in the final display process, then the ordering
  10694. of the marks and the base character must be reversed.
  10695. */
  10696. // don't bother for now
  10697. /*
  10698. L4. A character that possesses the mirrored property as specified by
  10699. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  10700. directionality of that character is R.
  10701. */
  10702. // don't mirror as characters are already mirrored in the pdf
  10703. // Finally, return string
  10704. for (i = 0, ii = chars.length; i < ii; ++i) {
  10705. var ch = chars[i];
  10706. if (ch === '<' || ch === '>') {
  10707. chars[i] = '';
  10708. }
  10709. }
  10710. return createBidiText(chars.join(''), isLTR);
  10711. }
  10712. return bidi;
  10713. })();
  10714. exports.bidi = bidi;
  10715. }));
  10716. (function (root, factory) {
  10717. {
  10718. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  10719. }
  10720. }(this, function (exports, sharedUtil) {
  10721. var MissingDataException = sharedUtil.MissingDataException;
  10722. var assert = sharedUtil.assert;
  10723. var createPromiseCapability = sharedUtil.createPromiseCapability;
  10724. var isInt = sharedUtil.isInt;
  10725. var isEmptyObj = sharedUtil.isEmptyObj;
  10726. var ChunkedStream = (function ChunkedStreamClosure() {
  10727. function ChunkedStream(length, chunkSize, manager) {
  10728. this.bytes = new Uint8Array(length);
  10729. this.start = 0;
  10730. this.pos = 0;
  10731. this.end = length;
  10732. this.chunkSize = chunkSize;
  10733. this.loadedChunks = [];
  10734. this.numChunksLoaded = 0;
  10735. this.numChunks = Math.ceil(length / chunkSize);
  10736. this.manager = manager;
  10737. this.progressiveDataLength = 0;
  10738. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  10739. }
  10740. // required methods for a stream. if a particular stream does not
  10741. // implement these, an error should be thrown
  10742. ChunkedStream.prototype = {
  10743. getMissingChunks: function ChunkedStream_getMissingChunks() {
  10744. var chunks = [];
  10745. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  10746. if (!this.loadedChunks[chunk]) {
  10747. chunks.push(chunk);
  10748. }
  10749. }
  10750. return chunks;
  10751. },
  10752. getBaseStreams: function ChunkedStream_getBaseStreams() {
  10753. return [this];
  10754. },
  10755. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  10756. return this.numChunksLoaded === this.numChunks;
  10757. },
  10758. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  10759. var end = begin + chunk.byteLength;
  10760. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  10761. // Using this.length is inaccurate here since this.start can be moved
  10762. // See ChunkedStream.moveStart()
  10763. var length = this.bytes.length;
  10764. assert(end % this.chunkSize === 0 || end === length,
  10765. 'Bad end offset: ' + end);
  10766. this.bytes.set(new Uint8Array(chunk), begin);
  10767. var chunkSize = this.chunkSize;
  10768. var beginChunk = Math.floor(begin / chunkSize);
  10769. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10770. var curChunk;
  10771. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10772. if (!this.loadedChunks[curChunk]) {
  10773. this.loadedChunks[curChunk] = true;
  10774. ++this.numChunksLoaded;
  10775. }
  10776. }
  10777. },
  10778. onReceiveProgressiveData:
  10779. function ChunkedStream_onReceiveProgressiveData(data) {
  10780. var position = this.progressiveDataLength;
  10781. var beginChunk = Math.floor(position / this.chunkSize);
  10782. this.bytes.set(new Uint8Array(data), position);
  10783. position += data.byteLength;
  10784. this.progressiveDataLength = position;
  10785. var endChunk = position >= this.end ? this.numChunks :
  10786. Math.floor(position / this.chunkSize);
  10787. var curChunk;
  10788. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10789. if (!this.loadedChunks[curChunk]) {
  10790. this.loadedChunks[curChunk] = true;
  10791. ++this.numChunksLoaded;
  10792. }
  10793. }
  10794. },
  10795. ensureByte: function ChunkedStream_ensureByte(pos) {
  10796. var chunk = Math.floor(pos / this.chunkSize);
  10797. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  10798. return;
  10799. }
  10800. if (!this.loadedChunks[chunk]) {
  10801. throw new MissingDataException(pos, pos + 1);
  10802. }
  10803. this.lastSuccessfulEnsureByteChunk = chunk;
  10804. },
  10805. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  10806. if (begin >= end) {
  10807. return;
  10808. }
  10809. if (end <= this.progressiveDataLength) {
  10810. return;
  10811. }
  10812. var chunkSize = this.chunkSize;
  10813. var beginChunk = Math.floor(begin / chunkSize);
  10814. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10815. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10816. if (!this.loadedChunks[chunk]) {
  10817. throw new MissingDataException(begin, end);
  10818. }
  10819. }
  10820. },
  10821. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  10822. var chunk, numChunks = this.numChunks;
  10823. for (var i = 0; i < numChunks; ++i) {
  10824. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  10825. if (!this.loadedChunks[chunk]) {
  10826. return chunk;
  10827. }
  10828. }
  10829. return null;
  10830. },
  10831. hasChunk: function ChunkedStream_hasChunk(chunk) {
  10832. return !!this.loadedChunks[chunk];
  10833. },
  10834. get length() {
  10835. return this.end - this.start;
  10836. },
  10837. get isEmpty() {
  10838. return this.length === 0;
  10839. },
  10840. getByte: function ChunkedStream_getByte() {
  10841. var pos = this.pos;
  10842. if (pos >= this.end) {
  10843. return -1;
  10844. }
  10845. this.ensureByte(pos);
  10846. return this.bytes[this.pos++];
  10847. },
  10848. getUint16: function ChunkedStream_getUint16() {
  10849. var b0 = this.getByte();
  10850. var b1 = this.getByte();
  10851. if (b0 === -1 || b1 === -1) {
  10852. return -1;
  10853. }
  10854. return (b0 << 8) + b1;
  10855. },
  10856. getInt32: function ChunkedStream_getInt32() {
  10857. var b0 = this.getByte();
  10858. var b1 = this.getByte();
  10859. var b2 = this.getByte();
  10860. var b3 = this.getByte();
  10861. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  10862. },
  10863. // returns subarray of original buffer
  10864. // should only be read
  10865. getBytes: function ChunkedStream_getBytes(length) {
  10866. var bytes = this.bytes;
  10867. var pos = this.pos;
  10868. var strEnd = this.end;
  10869. if (!length) {
  10870. this.ensureRange(pos, strEnd);
  10871. return bytes.subarray(pos, strEnd);
  10872. }
  10873. var end = pos + length;
  10874. if (end > strEnd) {
  10875. end = strEnd;
  10876. }
  10877. this.ensureRange(pos, end);
  10878. this.pos = end;
  10879. return bytes.subarray(pos, end);
  10880. },
  10881. peekByte: function ChunkedStream_peekByte() {
  10882. var peekedByte = this.getByte();
  10883. this.pos--;
  10884. return peekedByte;
  10885. },
  10886. peekBytes: function ChunkedStream_peekBytes(length) {
  10887. var bytes = this.getBytes(length);
  10888. this.pos -= bytes.length;
  10889. return bytes;
  10890. },
  10891. getByteRange: function ChunkedStream_getBytes(begin, end) {
  10892. this.ensureRange(begin, end);
  10893. return this.bytes.subarray(begin, end);
  10894. },
  10895. skip: function ChunkedStream_skip(n) {
  10896. if (!n) {
  10897. n = 1;
  10898. }
  10899. this.pos += n;
  10900. },
  10901. reset: function ChunkedStream_reset() {
  10902. this.pos = this.start;
  10903. },
  10904. moveStart: function ChunkedStream_moveStart() {
  10905. this.start = this.pos;
  10906. },
  10907. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  10908. this.ensureRange(start, start + length);
  10909. function ChunkedStreamSubstream() {}
  10910. ChunkedStreamSubstream.prototype = Object.create(this);
  10911. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  10912. var chunkSize = this.chunkSize;
  10913. var beginChunk = Math.floor(this.start / chunkSize);
  10914. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  10915. var missingChunks = [];
  10916. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10917. if (!this.loadedChunks[chunk]) {
  10918. missingChunks.push(chunk);
  10919. }
  10920. }
  10921. return missingChunks;
  10922. };
  10923. var subStream = new ChunkedStreamSubstream();
  10924. subStream.pos = subStream.start = start;
  10925. subStream.end = start + length || this.end;
  10926. subStream.dict = dict;
  10927. return subStream;
  10928. },
  10929. isStream: true
  10930. };
  10931. return ChunkedStream;
  10932. })();
  10933. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  10934. function ChunkedStreamManager(length, chunkSize, url, args) {
  10935. this.stream = new ChunkedStream(length, chunkSize, this);
  10936. this.length = length;
  10937. this.chunkSize = chunkSize;
  10938. this.url = url;
  10939. this.disableAutoFetch = args.disableAutoFetch;
  10940. var msgHandler = this.msgHandler = args.msgHandler;
  10941. if (args.chunkedViewerLoading) {
  10942. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  10943. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  10944. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10945. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  10946. };
  10947. } else {
  10948. var getXhr = function getXhr() {
  10949. return new XMLHttpRequest();
  10950. };
  10951. this.networkManager = new NetworkManager(this.url, {
  10952. getXhr: getXhr,
  10953. httpHeaders: args.httpHeaders,
  10954. withCredentials: args.withCredentials
  10955. });
  10956. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10957. this.networkManager.requestRange(begin, end, {
  10958. onDone: this.onReceiveData.bind(this),
  10959. onProgress: this.onProgress.bind(this)
  10960. });
  10961. };
  10962. }
  10963. this.currRequestId = 0;
  10964. this.chunksNeededByRequest = {};
  10965. this.requestsByChunk = {};
  10966. this.promisesByRequest = {};
  10967. this.progressiveDataLength = 0;
  10968. this._loadedStreamCapability = createPromiseCapability();
  10969. if (args.initialData) {
  10970. this.onReceiveData({chunk: args.initialData});
  10971. }
  10972. }
  10973. ChunkedStreamManager.prototype = {
  10974. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  10975. return this._loadedStreamCapability.promise;
  10976. },
  10977. // Get all the chunks that are not yet loaded and groups them into
  10978. // contiguous ranges to load in as few requests as possible
  10979. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  10980. var missingChunks = this.stream.getMissingChunks();
  10981. this._requestChunks(missingChunks);
  10982. return this._loadedStreamCapability.promise;
  10983. },
  10984. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  10985. var requestId = this.currRequestId++;
  10986. var chunksNeeded;
  10987. var i, ii;
  10988. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  10989. for (i = 0, ii = chunks.length; i < ii; i++) {
  10990. if (!this.stream.hasChunk(chunks[i])) {
  10991. chunksNeeded[chunks[i]] = true;
  10992. }
  10993. }
  10994. if (isEmptyObj(chunksNeeded)) {
  10995. return Promise.resolve();
  10996. }
  10997. var capability = createPromiseCapability();
  10998. this.promisesByRequest[requestId] = capability;
  10999. var chunksToRequest = [];
  11000. for (var chunk in chunksNeeded) {
  11001. chunk = chunk | 0;
  11002. if (!(chunk in this.requestsByChunk)) {
  11003. this.requestsByChunk[chunk] = [];
  11004. chunksToRequest.push(chunk);
  11005. }
  11006. this.requestsByChunk[chunk].push(requestId);
  11007. }
  11008. if (!chunksToRequest.length) {
  11009. return capability.promise;
  11010. }
  11011. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11012. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11013. var groupedChunk = groupedChunksToRequest[i];
  11014. var begin = groupedChunk.beginChunk * this.chunkSize;
  11015. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11016. this.sendRequest(begin, end);
  11017. }
  11018. return capability.promise;
  11019. },
  11020. getStream: function ChunkedStreamManager_getStream() {
  11021. return this.stream;
  11022. },
  11023. // Loads any chunks in the requested range that are not yet loaded
  11024. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11025. end = Math.min(end, this.length);
  11026. var beginChunk = this.getBeginChunk(begin);
  11027. var endChunk = this.getEndChunk(end);
  11028. var chunks = [];
  11029. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11030. chunks.push(chunk);
  11031. }
  11032. return this._requestChunks(chunks);
  11033. },
  11034. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11035. ranges = ranges || [];
  11036. var chunksToRequest = [];
  11037. for (var i = 0; i < ranges.length; i++) {
  11038. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11039. var endChunk = this.getEndChunk(ranges[i].end);
  11040. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11041. if (chunksToRequest.indexOf(chunk) < 0) {
  11042. chunksToRequest.push(chunk);
  11043. }
  11044. }
  11045. }
  11046. chunksToRequest.sort(function(a, b) { return a - b; });
  11047. return this._requestChunks(chunksToRequest);
  11048. },
  11049. // Groups a sorted array of chunks into as few contiguous larger
  11050. // chunks as possible
  11051. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11052. var groupedChunks = [];
  11053. var beginChunk = -1;
  11054. var prevChunk = -1;
  11055. for (var i = 0; i < chunks.length; ++i) {
  11056. var chunk = chunks[i];
  11057. if (beginChunk < 0) {
  11058. beginChunk = chunk;
  11059. }
  11060. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11061. groupedChunks.push({ beginChunk: beginChunk,
  11062. endChunk: prevChunk + 1 });
  11063. beginChunk = chunk;
  11064. }
  11065. if (i + 1 === chunks.length) {
  11066. groupedChunks.push({ beginChunk: beginChunk,
  11067. endChunk: chunk + 1 });
  11068. }
  11069. prevChunk = chunk;
  11070. }
  11071. return groupedChunks;
  11072. },
  11073. onProgress: function ChunkedStreamManager_onProgress(args) {
  11074. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11075. args.loaded);
  11076. this.msgHandler.send('DocProgress', {
  11077. loaded: bytesLoaded,
  11078. total: this.length
  11079. });
  11080. },
  11081. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11082. var chunk = args.chunk;
  11083. var isProgressive = args.begin === undefined;
  11084. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11085. var end = begin + chunk.byteLength;
  11086. var beginChunk = Math.floor(begin / this.chunkSize);
  11087. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11088. Math.ceil(end / this.chunkSize);
  11089. if (isProgressive) {
  11090. this.stream.onReceiveProgressiveData(chunk);
  11091. this.progressiveDataLength = end;
  11092. } else {
  11093. this.stream.onReceiveData(begin, chunk);
  11094. }
  11095. if (this.stream.allChunksLoaded()) {
  11096. this._loadedStreamCapability.resolve(this.stream);
  11097. }
  11098. var loadedRequests = [];
  11099. var i, requestId;
  11100. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11101. // The server might return more chunks than requested
  11102. var requestIds = this.requestsByChunk[chunk] || [];
  11103. delete this.requestsByChunk[chunk];
  11104. for (i = 0; i < requestIds.length; ++i) {
  11105. requestId = requestIds[i];
  11106. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11107. if (chunk in chunksNeeded) {
  11108. delete chunksNeeded[chunk];
  11109. }
  11110. if (!isEmptyObj(chunksNeeded)) {
  11111. continue;
  11112. }
  11113. loadedRequests.push(requestId);
  11114. }
  11115. }
  11116. // If there are no pending requests, automatically fetch the next
  11117. // unfetched chunk of the PDF
  11118. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11119. var nextEmptyChunk;
  11120. if (this.stream.numChunksLoaded === 1) {
  11121. // This is a special optimization so that after fetching the first
  11122. // chunk, rather than fetching the second chunk, we fetch the last
  11123. // chunk.
  11124. var lastChunk = this.stream.numChunks - 1;
  11125. if (!this.stream.hasChunk(lastChunk)) {
  11126. nextEmptyChunk = lastChunk;
  11127. }
  11128. } else {
  11129. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11130. }
  11131. if (isInt(nextEmptyChunk)) {
  11132. this._requestChunks([nextEmptyChunk]);
  11133. }
  11134. }
  11135. for (i = 0; i < loadedRequests.length; ++i) {
  11136. requestId = loadedRequests[i];
  11137. var capability = this.promisesByRequest[requestId];
  11138. delete this.promisesByRequest[requestId];
  11139. capability.resolve();
  11140. }
  11141. this.msgHandler.send('DocProgress', {
  11142. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11143. total: this.length
  11144. });
  11145. },
  11146. onError: function ChunkedStreamManager_onError(err) {
  11147. this._loadedStreamCapability.reject(err);
  11148. },
  11149. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11150. var chunk = Math.floor(begin / this.chunkSize);
  11151. return chunk;
  11152. },
  11153. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11154. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11155. return chunk;
  11156. },
  11157. abort: function ChunkedStreamManager_abort() {
  11158. if (this.networkManager) {
  11159. this.networkManager.abortAllRequests();
  11160. }
  11161. for(var requestId in this.promisesByRequest) {
  11162. var capability = this.promisesByRequest[requestId];
  11163. capability.reject(new Error('Request was aborted'));
  11164. }
  11165. }
  11166. };
  11167. return ChunkedStreamManager;
  11168. })();
  11169. exports.ChunkedStream = ChunkedStream;
  11170. exports.ChunkedStreamManager = ChunkedStreamManager;
  11171. }));
  11172. (function (root, factory) {
  11173. {
  11174. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11175. root.pdfjsCoreArithmeticDecoder);
  11176. }
  11177. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11178. var error = sharedUtil.error;
  11179. var log2 = sharedUtil.log2;
  11180. var readInt8 = sharedUtil.readInt8;
  11181. var readUint16 = sharedUtil.readUint16;
  11182. var readUint32 = sharedUtil.readUint32;
  11183. var shadow = sharedUtil.shadow;
  11184. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11185. var Jbig2Image = (function Jbig2ImageClosure() {
  11186. // Utility data structures
  11187. function ContextCache() {}
  11188. ContextCache.prototype = {
  11189. getContexts: function(id) {
  11190. if (id in this) {
  11191. return this[id];
  11192. }
  11193. return (this[id] = new Int8Array(1 << 16));
  11194. }
  11195. };
  11196. function DecodingContext(data, start, end) {
  11197. this.data = data;
  11198. this.start = start;
  11199. this.end = end;
  11200. }
  11201. DecodingContext.prototype = {
  11202. get decoder() {
  11203. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11204. return shadow(this, 'decoder', decoder);
  11205. },
  11206. get contextCache() {
  11207. var cache = new ContextCache();
  11208. return shadow(this, 'contextCache', cache);
  11209. }
  11210. };
  11211. // Annex A. Arithmetic Integer Decoding Procedure
  11212. // A.2 Procedure for decoding values
  11213. function decodeInteger(contextCache, procedure, decoder) {
  11214. var contexts = contextCache.getContexts(procedure);
  11215. var prev = 1;
  11216. function readBits(length) {
  11217. var v = 0;
  11218. for (var i = 0; i < length; i++) {
  11219. var bit = decoder.readBit(contexts, prev);
  11220. prev = (prev < 256 ? (prev << 1) | bit :
  11221. (((prev << 1) | bit) & 511) | 256);
  11222. v = (v << 1) | bit;
  11223. }
  11224. return v >>> 0;
  11225. }
  11226. var sign = readBits(1);
  11227. var value = readBits(1) ?
  11228. (readBits(1) ?
  11229. (readBits(1) ?
  11230. (readBits(1) ?
  11231. (readBits(1) ?
  11232. (readBits(32) + 4436) :
  11233. readBits(12) + 340) :
  11234. readBits(8) + 84) :
  11235. readBits(6) + 20) :
  11236. readBits(4) + 4) :
  11237. readBits(2);
  11238. return (sign === 0 ? value : (value > 0 ? -value : null));
  11239. }
  11240. // A.3 The IAID decoding procedure
  11241. function decodeIAID(contextCache, decoder, codeLength) {
  11242. var contexts = contextCache.getContexts('IAID');
  11243. var prev = 1;
  11244. for (var i = 0; i < codeLength; i++) {
  11245. var bit = decoder.readBit(contexts, prev);
  11246. prev = (prev << 1) | bit;
  11247. }
  11248. if (codeLength < 31) {
  11249. return prev & ((1 << codeLength) - 1);
  11250. }
  11251. return prev & 0x7FFFFFFF;
  11252. }
  11253. // 7.3 Segment types
  11254. var SegmentTypes = [
  11255. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11256. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11257. null, null, null, null, null, 'patternDictionary', null, null, null,
  11258. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11259. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11260. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11261. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11262. 'IntermediateGenericRefinementRegion', null,
  11263. 'ImmediateGenericRefinementRegion',
  11264. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11265. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11266. 'Tables', null, null, null, null, null, null, null, null,
  11267. 'Extension'
  11268. ];
  11269. var CodingTemplates = [
  11270. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11271. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11272. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11273. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11274. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11275. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11276. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11277. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11278. {x: -1, y: 0}],
  11279. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11280. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11281. ];
  11282. var RefinementTemplates = [
  11283. {
  11284. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11285. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11286. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11287. },
  11288. {
  11289. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11290. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11291. {x: 0, y: 1}, {x: 1, y: 1}]
  11292. }
  11293. ];
  11294. // See 6.2.5.7 Decoding the bitmap.
  11295. var ReusedContexts = [
  11296. 0x9B25, // 10011 0110010 0101
  11297. 0x0795, // 0011 110010 101
  11298. 0x00E5, // 001 11001 01
  11299. 0x0195 // 011001 0101
  11300. ];
  11301. var RefinementReusedContexts = [
  11302. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11303. 0x0008 // '0000' + '001000'
  11304. ];
  11305. function decodeBitmapTemplate0(width, height, decodingContext) {
  11306. var decoder = decodingContext.decoder;
  11307. var contexts = decodingContext.contextCache.getContexts('GB');
  11308. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11309. // ...ooooo....
  11310. // ..ooooooo... Context template for current pixel (X)
  11311. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11312. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11313. for (i = 0; i < height; i++) {
  11314. row = bitmap[i] = new Uint8Array(width);
  11315. row1 = (i < 1) ? row : bitmap[i - 1];
  11316. row2 = (i < 2) ? row : bitmap[i - 2];
  11317. // At the beginning of each row:
  11318. // Fill contextLabel with pixels that are above/right of (X)
  11319. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11320. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11321. (row1[3] << 4);
  11322. for (j = 0; j < width; j++) {
  11323. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11324. // At each pixel: Clear contextLabel pixels that are shifted
  11325. // out of the context, then add new ones.
  11326. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11327. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11328. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11329. }
  11330. }
  11331. return bitmap;
  11332. }
  11333. // 6.2 Generic Region Decoding Procedure
  11334. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11335. decodingContext) {
  11336. if (mmr) {
  11337. error('JBIG2 error: MMR encoding is not supported');
  11338. }
  11339. // Use optimized version for the most common case
  11340. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11341. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11342. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11343. return decodeBitmapTemplate0(width, height, decodingContext);
  11344. }
  11345. var useskip = !!skip;
  11346. var template = CodingTemplates[templateIndex].concat(at);
  11347. // Sorting is non-standard, and it is not required. But sorting increases
  11348. // the number of template bits that can be reused from the previous
  11349. // contextLabel in the main loop.
  11350. template.sort(function (a, b) {
  11351. return (a.y - b.y) || (a.x - b.x);
  11352. });
  11353. var templateLength = template.length;
  11354. var templateX = new Int8Array(templateLength);
  11355. var templateY = new Int8Array(templateLength);
  11356. var changingTemplateEntries = [];
  11357. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11358. var c, k;
  11359. for (k = 0; k < templateLength; k++) {
  11360. templateX[k] = template[k].x;
  11361. templateY[k] = template[k].y;
  11362. minX = Math.min(minX, template[k].x);
  11363. maxX = Math.max(maxX, template[k].x);
  11364. minY = Math.min(minY, template[k].y);
  11365. // Check if the template pixel appears in two consecutive context labels,
  11366. // so it can be reused. Otherwise, we add it to the list of changing
  11367. // template entries.
  11368. if (k < templateLength - 1 &&
  11369. template[k].y === template[k + 1].y &&
  11370. template[k].x === template[k + 1].x - 1) {
  11371. reuseMask |= 1 << (templateLength - 1 - k);
  11372. } else {
  11373. changingTemplateEntries.push(k);
  11374. }
  11375. }
  11376. var changingEntriesLength = changingTemplateEntries.length;
  11377. var changingTemplateX = new Int8Array(changingEntriesLength);
  11378. var changingTemplateY = new Int8Array(changingEntriesLength);
  11379. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  11380. for (c = 0; c < changingEntriesLength; c++) {
  11381. k = changingTemplateEntries[c];
  11382. changingTemplateX[c] = template[k].x;
  11383. changingTemplateY[c] = template[k].y;
  11384. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  11385. }
  11386. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  11387. var sbb_left = -minX;
  11388. var sbb_top = -minY;
  11389. var sbb_right = width - maxX;
  11390. var pseudoPixelContext = ReusedContexts[templateIndex];
  11391. var row = new Uint8Array(width);
  11392. var bitmap = [];
  11393. var decoder = decodingContext.decoder;
  11394. var contexts = decodingContext.contextCache.getContexts('GB');
  11395. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  11396. for (var i = 0; i < height; i++) {
  11397. if (prediction) {
  11398. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11399. ltp ^= sltp;
  11400. if (ltp) {
  11401. bitmap.push(row); // duplicate previous row
  11402. continue;
  11403. }
  11404. }
  11405. row = new Uint8Array(row);
  11406. bitmap.push(row);
  11407. for (j = 0; j < width; j++) {
  11408. if (useskip && skip[i][j]) {
  11409. row[j] = 0;
  11410. continue;
  11411. }
  11412. // Are we in the middle of a scanline, so we can reuse contextLabel
  11413. // bits?
  11414. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  11415. // If yes, we can just shift the bits that are reusable and only
  11416. // fetch the remaining ones.
  11417. contextLabel = (contextLabel << 1) & reuseMask;
  11418. for (k = 0; k < changingEntriesLength; k++) {
  11419. i0 = i + changingTemplateY[k];
  11420. j0 = j + changingTemplateX[k];
  11421. bit = bitmap[i0][j0];
  11422. if (bit) {
  11423. bit = changingTemplateBit[k];
  11424. contextLabel |= bit;
  11425. }
  11426. }
  11427. } else {
  11428. // compute the contextLabel from scratch
  11429. contextLabel = 0;
  11430. shift = templateLength - 1;
  11431. for (k = 0; k < templateLength; k++, shift--) {
  11432. j0 = j + templateX[k];
  11433. if (j0 >= 0 && j0 < width) {
  11434. i0 = i + templateY[k];
  11435. if (i0 >= 0) {
  11436. bit = bitmap[i0][j0];
  11437. if (bit) {
  11438. contextLabel |= bit << shift;
  11439. }
  11440. }
  11441. }
  11442. }
  11443. }
  11444. var pixel = decoder.readBit(contexts, contextLabel);
  11445. row[j] = pixel;
  11446. }
  11447. }
  11448. return bitmap;
  11449. }
  11450. // 6.3.2 Generic Refinement Region Decoding Procedure
  11451. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  11452. offsetX, offsetY, prediction, at,
  11453. decodingContext) {
  11454. var codingTemplate = RefinementTemplates[templateIndex].coding;
  11455. if (templateIndex === 0) {
  11456. codingTemplate = codingTemplate.concat([at[0]]);
  11457. }
  11458. var codingTemplateLength = codingTemplate.length;
  11459. var codingTemplateX = new Int32Array(codingTemplateLength);
  11460. var codingTemplateY = new Int32Array(codingTemplateLength);
  11461. var k;
  11462. for (k = 0; k < codingTemplateLength; k++) {
  11463. codingTemplateX[k] = codingTemplate[k].x;
  11464. codingTemplateY[k] = codingTemplate[k].y;
  11465. }
  11466. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  11467. if (templateIndex === 0) {
  11468. referenceTemplate = referenceTemplate.concat([at[1]]);
  11469. }
  11470. var referenceTemplateLength = referenceTemplate.length;
  11471. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  11472. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  11473. for (k = 0; k < referenceTemplateLength; k++) {
  11474. referenceTemplateX[k] = referenceTemplate[k].x;
  11475. referenceTemplateY[k] = referenceTemplate[k].y;
  11476. }
  11477. var referenceWidth = referenceBitmap[0].length;
  11478. var referenceHeight = referenceBitmap.length;
  11479. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  11480. var bitmap = [];
  11481. var decoder = decodingContext.decoder;
  11482. var contexts = decodingContext.contextCache.getContexts('GR');
  11483. var ltp = 0;
  11484. for (var i = 0; i < height; i++) {
  11485. if (prediction) {
  11486. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11487. ltp ^= sltp;
  11488. if (ltp) {
  11489. error('JBIG2 error: prediction is not supported');
  11490. }
  11491. }
  11492. var row = new Uint8Array(width);
  11493. bitmap.push(row);
  11494. for (var j = 0; j < width; j++) {
  11495. var i0, j0;
  11496. var contextLabel = 0;
  11497. for (k = 0; k < codingTemplateLength; k++) {
  11498. i0 = i + codingTemplateY[k];
  11499. j0 = j + codingTemplateX[k];
  11500. if (i0 < 0 || j0 < 0 || j0 >= width) {
  11501. contextLabel <<= 1; // out of bound pixel
  11502. } else {
  11503. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  11504. }
  11505. }
  11506. for (k = 0; k < referenceTemplateLength; k++) {
  11507. i0 = i + referenceTemplateY[k] + offsetY;
  11508. j0 = j + referenceTemplateX[k] + offsetX;
  11509. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  11510. j0 >= referenceWidth) {
  11511. contextLabel <<= 1; // out of bound pixel
  11512. } else {
  11513. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  11514. }
  11515. }
  11516. var pixel = decoder.readBit(contexts, contextLabel);
  11517. row[j] = pixel;
  11518. }
  11519. }
  11520. return bitmap;
  11521. }
  11522. // 6.5.5 Decoding the symbol dictionary
  11523. function decodeSymbolDictionary(huffman, refinement, symbols,
  11524. numberOfNewSymbols, numberOfExportedSymbols,
  11525. huffmanTables, templateIndex, at,
  11526. refinementTemplateIndex, refinementAt,
  11527. decodingContext) {
  11528. if (huffman) {
  11529. error('JBIG2 error: huffman is not supported');
  11530. }
  11531. var newSymbols = [];
  11532. var currentHeight = 0;
  11533. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  11534. var decoder = decodingContext.decoder;
  11535. var contextCache = decodingContext.contextCache;
  11536. while (newSymbols.length < numberOfNewSymbols) {
  11537. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  11538. currentHeight += deltaHeight;
  11539. var currentWidth = 0;
  11540. var totalWidth = 0;
  11541. while (true) {
  11542. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  11543. if (deltaWidth === null) {
  11544. break; // OOB
  11545. }
  11546. currentWidth += deltaWidth;
  11547. totalWidth += currentWidth;
  11548. var bitmap;
  11549. if (refinement) {
  11550. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  11551. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  11552. if (numberOfInstances > 1) {
  11553. bitmap = decodeTextRegion(huffman, refinement,
  11554. currentWidth, currentHeight, 0,
  11555. numberOfInstances, 1, //strip size
  11556. symbols.concat(newSymbols),
  11557. symbolCodeLength,
  11558. 0, //transposed
  11559. 0, //ds offset
  11560. 1, //top left 7.4.3.1.1
  11561. 0, //OR operator
  11562. huffmanTables,
  11563. refinementTemplateIndex, refinementAt,
  11564. decodingContext);
  11565. } else {
  11566. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11567. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11568. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11569. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  11570. newSymbols[symbolId - symbols.length]);
  11571. bitmap = decodeRefinement(currentWidth, currentHeight,
  11572. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  11573. decodingContext);
  11574. }
  11575. } else {
  11576. // 6.5.8.1 Direct-coded symbol bitmap
  11577. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  11578. templateIndex, false, null, at, decodingContext);
  11579. }
  11580. newSymbols.push(bitmap);
  11581. }
  11582. }
  11583. // 6.5.10 Exported symbols
  11584. var exportedSymbols = [];
  11585. var flags = [], currentFlag = false;
  11586. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  11587. while (flags.length < totalSymbolsLength) {
  11588. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  11589. while (runLength--) {
  11590. flags.push(currentFlag);
  11591. }
  11592. currentFlag = !currentFlag;
  11593. }
  11594. for (var i = 0, ii = symbols.length; i < ii; i++) {
  11595. if (flags[i]) {
  11596. exportedSymbols.push(symbols[i]);
  11597. }
  11598. }
  11599. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  11600. if (flags[i]) {
  11601. exportedSymbols.push(newSymbols[j]);
  11602. }
  11603. }
  11604. return exportedSymbols;
  11605. }
  11606. function decodeTextRegion(huffman, refinement, width, height,
  11607. defaultPixelValue, numberOfSymbolInstances,
  11608. stripSize, inputSymbols, symbolCodeLength,
  11609. transposed, dsOffset, referenceCorner,
  11610. combinationOperator, huffmanTables,
  11611. refinementTemplateIndex, refinementAt,
  11612. decodingContext) {
  11613. if (huffman) {
  11614. error('JBIG2 error: huffman is not supported');
  11615. }
  11616. // Prepare bitmap
  11617. var bitmap = [];
  11618. var i, row;
  11619. for (i = 0; i < height; i++) {
  11620. row = new Uint8Array(width);
  11621. if (defaultPixelValue) {
  11622. for (var j = 0; j < width; j++) {
  11623. row[j] = defaultPixelValue;
  11624. }
  11625. }
  11626. bitmap.push(row);
  11627. }
  11628. var decoder = decodingContext.decoder;
  11629. var contextCache = decodingContext.contextCache;
  11630. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11631. var firstS = 0;
  11632. i = 0;
  11633. while (i < numberOfSymbolInstances) {
  11634. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11635. stripT += deltaT;
  11636. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  11637. firstS += deltaFirstS;
  11638. var currentS = firstS;
  11639. do {
  11640. var currentT = (stripSize === 1 ? 0 :
  11641. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  11642. var t = stripSize * stripT + currentT;
  11643. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11644. var applyRefinement = (refinement &&
  11645. decodeInteger(contextCache, 'IARI', decoder));
  11646. var symbolBitmap = inputSymbols[symbolId];
  11647. var symbolWidth = symbolBitmap[0].length;
  11648. var symbolHeight = symbolBitmap.length;
  11649. if (applyRefinement) {
  11650. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  11651. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  11652. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11653. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11654. symbolWidth += rdw;
  11655. symbolHeight += rdh;
  11656. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  11657. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  11658. (rdh >> 1) + rdy, false, refinementAt,
  11659. decodingContext);
  11660. }
  11661. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  11662. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  11663. var s2, t2, symbolRow;
  11664. if (transposed) {
  11665. // Place Symbol Bitmap from T1,S1
  11666. for (s2 = 0; s2 < symbolHeight; s2++) {
  11667. row = bitmap[offsetS + s2];
  11668. if (!row) {
  11669. continue;
  11670. }
  11671. symbolRow = symbolBitmap[s2];
  11672. // To ignore Parts of Symbol bitmap which goes
  11673. // outside bitmap region
  11674. var maxWidth = Math.min(width - offsetT, symbolWidth);
  11675. switch (combinationOperator) {
  11676. case 0: // OR
  11677. for (t2 = 0; t2 < maxWidth; t2++) {
  11678. row[offsetT + t2] |= symbolRow[t2];
  11679. }
  11680. break;
  11681. case 2: // XOR
  11682. for (t2 = 0; t2 < maxWidth; t2++) {
  11683. row[offsetT + t2] ^= symbolRow[t2];
  11684. }
  11685. break;
  11686. default:
  11687. error('JBIG2 error: operator ' + combinationOperator +
  11688. ' is not supported');
  11689. }
  11690. }
  11691. currentS += symbolHeight - 1;
  11692. } else {
  11693. for (t2 = 0; t2 < symbolHeight; t2++) {
  11694. row = bitmap[offsetT + t2];
  11695. if (!row) {
  11696. continue;
  11697. }
  11698. symbolRow = symbolBitmap[t2];
  11699. switch (combinationOperator) {
  11700. case 0: // OR
  11701. for (s2 = 0; s2 < symbolWidth; s2++) {
  11702. row[offsetS + s2] |= symbolRow[s2];
  11703. }
  11704. break;
  11705. case 2: // XOR
  11706. for (s2 = 0; s2 < symbolWidth; s2++) {
  11707. row[offsetS + s2] ^= symbolRow[s2];
  11708. }
  11709. break;
  11710. default:
  11711. error('JBIG2 error: operator ' + combinationOperator +
  11712. ' is not supported');
  11713. }
  11714. }
  11715. currentS += symbolWidth - 1;
  11716. }
  11717. i++;
  11718. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11719. if (deltaS === null) {
  11720. break; // OOB
  11721. }
  11722. currentS += deltaS + dsOffset;
  11723. } while (true);
  11724. }
  11725. return bitmap;
  11726. }
  11727. function readSegmentHeader(data, start) {
  11728. var segmentHeader = {};
  11729. segmentHeader.number = readUint32(data, start);
  11730. var flags = data[start + 4];
  11731. var segmentType = flags & 0x3F;
  11732. if (!SegmentTypes[segmentType]) {
  11733. error('JBIG2 error: invalid segment type: ' + segmentType);
  11734. }
  11735. segmentHeader.type = segmentType;
  11736. segmentHeader.typeName = SegmentTypes[segmentType];
  11737. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11738. var pageAssociationFieldSize = !!(flags & 0x40);
  11739. var referredFlags = data[start + 5];
  11740. var referredToCount = (referredFlags >> 5) & 7;
  11741. var retainBits = [referredFlags & 31];
  11742. var position = start + 6;
  11743. if (referredFlags === 7) {
  11744. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11745. position += 3;
  11746. var bytes = (referredToCount + 7) >> 3;
  11747. retainBits[0] = data[position++];
  11748. while (--bytes > 0) {
  11749. retainBits.push(data[position++]);
  11750. }
  11751. } else if (referredFlags === 5 || referredFlags === 6) {
  11752. error('JBIG2 error: invalid referred-to flags');
  11753. }
  11754. segmentHeader.retainBits = retainBits;
  11755. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11756. (segmentHeader.number <= 65536 ? 2 : 4));
  11757. var referredTo = [];
  11758. var i, ii;
  11759. for (i = 0; i < referredToCount; i++) {
  11760. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11761. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11762. readUint32(data, position)));
  11763. referredTo.push(number);
  11764. position += referredToSegmentNumberSize;
  11765. }
  11766. segmentHeader.referredTo = referredTo;
  11767. if (!pageAssociationFieldSize) {
  11768. segmentHeader.pageAssociation = data[position++];
  11769. } else {
  11770. segmentHeader.pageAssociation = readUint32(data, position);
  11771. position += 4;
  11772. }
  11773. segmentHeader.length = readUint32(data, position);
  11774. position += 4;
  11775. if (segmentHeader.length === 0xFFFFFFFF) {
  11776. // 7.2.7 Segment data length, unknown segment length
  11777. if (segmentType === 38) { // ImmediateGenericRegion
  11778. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11779. var genericRegionSegmentFlags = data[position +
  11780. RegionSegmentInformationFieldLength];
  11781. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11782. // searching for the segment end
  11783. var searchPatternLength = 6;
  11784. var searchPattern = new Uint8Array(searchPatternLength);
  11785. if (!genericRegionMmr) {
  11786. searchPattern[0] = 0xFF;
  11787. searchPattern[1] = 0xAC;
  11788. }
  11789. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11790. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11791. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11792. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11793. for (i = position, ii = data.length; i < ii; i++) {
  11794. var j = 0;
  11795. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11796. j++;
  11797. }
  11798. if (j === searchPatternLength) {
  11799. segmentHeader.length = i + searchPatternLength;
  11800. break;
  11801. }
  11802. }
  11803. if (segmentHeader.length === 0xFFFFFFFF) {
  11804. error('JBIG2 error: segment end was not found');
  11805. }
  11806. } else {
  11807. error('JBIG2 error: invalid unknown segment length');
  11808. }
  11809. }
  11810. segmentHeader.headerEnd = position;
  11811. return segmentHeader;
  11812. }
  11813. function readSegments(header, data, start, end) {
  11814. var segments = [];
  11815. var position = start;
  11816. while (position < end) {
  11817. var segmentHeader = readSegmentHeader(data, position);
  11818. position = segmentHeader.headerEnd;
  11819. var segment = {
  11820. header: segmentHeader,
  11821. data: data
  11822. };
  11823. if (!header.randomAccess) {
  11824. segment.start = position;
  11825. position += segmentHeader.length;
  11826. segment.end = position;
  11827. }
  11828. segments.push(segment);
  11829. if (segmentHeader.type === 51) {
  11830. break; // end of file is found
  11831. }
  11832. }
  11833. if (header.randomAccess) {
  11834. for (var i = 0, ii = segments.length; i < ii; i++) {
  11835. segments[i].start = position;
  11836. position += segments[i].header.length;
  11837. segments[i].end = position;
  11838. }
  11839. }
  11840. return segments;
  11841. }
  11842. // 7.4.1 Region segment information field
  11843. function readRegionSegmentInformation(data, start) {
  11844. return {
  11845. width: readUint32(data, start),
  11846. height: readUint32(data, start + 4),
  11847. x: readUint32(data, start + 8),
  11848. y: readUint32(data, start + 12),
  11849. combinationOperator: data[start + 16] & 7
  11850. };
  11851. }
  11852. var RegionSegmentInformationFieldLength = 17;
  11853. function processSegment(segment, visitor) {
  11854. var header = segment.header;
  11855. var data = segment.data, position = segment.start, end = segment.end;
  11856. var args, at, i, atLength;
  11857. switch (header.type) {
  11858. case 0: // SymbolDictionary
  11859. // 7.4.2 Symbol dictionary segment syntax
  11860. var dictionary = {};
  11861. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11862. dictionary.huffman = !!(dictionaryFlags & 1);
  11863. dictionary.refinement = !!(dictionaryFlags & 2);
  11864. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11865. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11866. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11867. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11868. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11869. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11870. dictionary.template = (dictionaryFlags >> 10) & 3;
  11871. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11872. position += 2;
  11873. if (!dictionary.huffman) {
  11874. atLength = dictionary.template === 0 ? 4 : 1;
  11875. at = [];
  11876. for (i = 0; i < atLength; i++) {
  11877. at.push({
  11878. x: readInt8(data, position),
  11879. y: readInt8(data, position + 1)
  11880. });
  11881. position += 2;
  11882. }
  11883. dictionary.at = at;
  11884. }
  11885. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11886. at = [];
  11887. for (i = 0; i < 2; i++) {
  11888. at.push({
  11889. x: readInt8(data, position),
  11890. y: readInt8(data, position + 1)
  11891. });
  11892. position += 2;
  11893. }
  11894. dictionary.refinementAt = at;
  11895. }
  11896. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11897. position += 4;
  11898. dictionary.numberOfNewSymbols = readUint32(data, position);
  11899. position += 4;
  11900. args = [dictionary, header.number, header.referredTo,
  11901. data, position, end];
  11902. break;
  11903. case 6: // ImmediateTextRegion
  11904. case 7: // ImmediateLosslessTextRegion
  11905. var textRegion = {};
  11906. textRegion.info = readRegionSegmentInformation(data, position);
  11907. position += RegionSegmentInformationFieldLength;
  11908. var textRegionSegmentFlags = readUint16(data, position);
  11909. position += 2;
  11910. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11911. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11912. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11913. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11914. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11915. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11916. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11917. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11918. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11919. if (textRegion.huffman) {
  11920. var textRegionHuffmanFlags = readUint16(data, position);
  11921. position += 2;
  11922. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11923. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11924. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11925. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11926. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11927. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11928. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11929. textRegion.huffmanRefinementSizeSelector =
  11930. !!(textRegionHuffmanFlags & 14);
  11931. }
  11932. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11933. at = [];
  11934. for (i = 0; i < 2; i++) {
  11935. at.push({
  11936. x: readInt8(data, position),
  11937. y: readInt8(data, position + 1)
  11938. });
  11939. position += 2;
  11940. }
  11941. textRegion.refinementAt = at;
  11942. }
  11943. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11944. position += 4;
  11945. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11946. if (textRegion.huffman) {
  11947. error('JBIG2 error: huffman is not supported');
  11948. }
  11949. args = [textRegion, header.referredTo, data, position, end];
  11950. break;
  11951. case 38: // ImmediateGenericRegion
  11952. case 39: // ImmediateLosslessGenericRegion
  11953. var genericRegion = {};
  11954. genericRegion.info = readRegionSegmentInformation(data, position);
  11955. position += RegionSegmentInformationFieldLength;
  11956. var genericRegionSegmentFlags = data[position++];
  11957. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  11958. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  11959. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  11960. if (!genericRegion.mmr) {
  11961. atLength = genericRegion.template === 0 ? 4 : 1;
  11962. at = [];
  11963. for (i = 0; i < atLength; i++) {
  11964. at.push({
  11965. x: readInt8(data, position),
  11966. y: readInt8(data, position + 1)
  11967. });
  11968. position += 2;
  11969. }
  11970. genericRegion.at = at;
  11971. }
  11972. args = [genericRegion, data, position, end];
  11973. break;
  11974. case 48: // PageInformation
  11975. var pageInfo = {
  11976. width: readUint32(data, position),
  11977. height: readUint32(data, position + 4),
  11978. resolutionX: readUint32(data, position + 8),
  11979. resolutionY: readUint32(data, position + 12)
  11980. };
  11981. if (pageInfo.height === 0xFFFFFFFF) {
  11982. delete pageInfo.height;
  11983. }
  11984. var pageSegmentFlags = data[position + 16];
  11985. var pageStripingInformation = readUint16(data, position + 17);
  11986. pageInfo.lossless = !!(pageSegmentFlags & 1);
  11987. pageInfo.refinement = !!(pageSegmentFlags & 2);
  11988. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  11989. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  11990. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  11991. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  11992. args = [pageInfo];
  11993. break;
  11994. case 49: // EndOfPage
  11995. break;
  11996. case 50: // EndOfStripe
  11997. break;
  11998. case 51: // EndOfFile
  11999. break;
  12000. case 62: // 7.4.15 defines 2 extension types which
  12001. // are comments and can be ignored.
  12002. break;
  12003. default:
  12004. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12005. header.type + ') is not implemented');
  12006. }
  12007. var callbackName = 'on' + header.typeName;
  12008. if (callbackName in visitor) {
  12009. visitor[callbackName].apply(visitor, args);
  12010. }
  12011. }
  12012. function processSegments(segments, visitor) {
  12013. for (var i = 0, ii = segments.length; i < ii; i++) {
  12014. processSegment(segments[i], visitor);
  12015. }
  12016. }
  12017. function parseJbig2(data, start, end) {
  12018. var position = start;
  12019. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12020. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12021. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12022. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12023. error('JBIG2 error: invalid header');
  12024. }
  12025. var header = {};
  12026. position += 8;
  12027. var flags = data[position++];
  12028. header.randomAccess = !(flags & 1);
  12029. if (!(flags & 2)) {
  12030. header.numberOfPages = readUint32(data, position);
  12031. position += 4;
  12032. }
  12033. var segments = readSegments(header, data, position, end);
  12034. error('Not implemented');
  12035. // processSegments(segments, new SimpleSegmentVisitor());
  12036. }
  12037. function parseJbig2Chunks(chunks) {
  12038. var visitor = new SimpleSegmentVisitor();
  12039. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12040. var chunk = chunks[i];
  12041. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12042. processSegments(segments, visitor);
  12043. }
  12044. return visitor.buffer;
  12045. }
  12046. function SimpleSegmentVisitor() {}
  12047. SimpleSegmentVisitor.prototype = {
  12048. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12049. this.currentPageInfo = info;
  12050. var rowSize = (info.width + 7) >> 3;
  12051. var buffer = new Uint8Array(rowSize * info.height);
  12052. // The contents of ArrayBuffers are initialized to 0.
  12053. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12054. if (info.defaultPixelValue) {
  12055. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12056. buffer[i] = 0xFF;
  12057. }
  12058. }
  12059. this.buffer = buffer;
  12060. },
  12061. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12062. var pageInfo = this.currentPageInfo;
  12063. var width = regionInfo.width, height = regionInfo.height;
  12064. var rowSize = (pageInfo.width + 7) >> 3;
  12065. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12066. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12067. var buffer = this.buffer;
  12068. var mask0 = 128 >> (regionInfo.x & 7);
  12069. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12070. var i, j, mask, offset;
  12071. switch (combinationOperator) {
  12072. case 0: // OR
  12073. for (i = 0; i < height; i++) {
  12074. mask = mask0;
  12075. offset = offset0;
  12076. for (j = 0; j < width; j++) {
  12077. if (bitmap[i][j]) {
  12078. buffer[offset] |= mask;
  12079. }
  12080. mask >>= 1;
  12081. if (!mask) {
  12082. mask = 128;
  12083. offset++;
  12084. }
  12085. }
  12086. offset0 += rowSize;
  12087. }
  12088. break;
  12089. case 2: // XOR
  12090. for (i = 0; i < height; i++) {
  12091. mask = mask0;
  12092. offset = offset0;
  12093. for (j = 0; j < width; j++) {
  12094. if (bitmap[i][j]) {
  12095. buffer[offset] ^= mask;
  12096. }
  12097. mask >>= 1;
  12098. if (!mask) {
  12099. mask = 128;
  12100. offset++;
  12101. }
  12102. }
  12103. offset0 += rowSize;
  12104. }
  12105. break;
  12106. default:
  12107. error('JBIG2 error: operator ' + combinationOperator +
  12108. ' is not supported');
  12109. }
  12110. },
  12111. onImmediateGenericRegion:
  12112. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12113. start, end) {
  12114. var regionInfo = region.info;
  12115. var decodingContext = new DecodingContext(data, start, end);
  12116. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12117. region.template, region.prediction, null,
  12118. region.at, decodingContext);
  12119. this.drawBitmap(regionInfo, bitmap);
  12120. },
  12121. onImmediateLosslessGenericRegion:
  12122. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12123. this.onImmediateGenericRegion.apply(this, arguments);
  12124. },
  12125. onSymbolDictionary:
  12126. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12127. currentSegment,
  12128. referredSegments,
  12129. data, start, end) {
  12130. var huffmanTables;
  12131. if (dictionary.huffman) {
  12132. error('JBIG2 error: huffman is not supported');
  12133. }
  12134. // Combines exported symbols from all referred segments
  12135. var symbols = this.symbols;
  12136. if (!symbols) {
  12137. this.symbols = symbols = {};
  12138. }
  12139. var inputSymbols = [];
  12140. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12141. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12142. }
  12143. var decodingContext = new DecodingContext(data, start, end);
  12144. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12145. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12146. dictionary.numberOfExportedSymbols, huffmanTables,
  12147. dictionary.template, dictionary.at,
  12148. dictionary.refinementTemplate, dictionary.refinementAt,
  12149. decodingContext);
  12150. },
  12151. onImmediateTextRegion:
  12152. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12153. referredSegments,
  12154. data, start, end) {
  12155. var regionInfo = region.info;
  12156. var huffmanTables;
  12157. // Combines exported symbols from all referred segments
  12158. var symbols = this.symbols;
  12159. var inputSymbols = [];
  12160. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12161. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12162. }
  12163. var symbolCodeLength = log2(inputSymbols.length);
  12164. var decodingContext = new DecodingContext(data, start, end);
  12165. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12166. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12167. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12168. symbolCodeLength, region.transposed, region.dsOffset,
  12169. region.referenceCorner, region.combinationOperator, huffmanTables,
  12170. region.refinementTemplate, region.refinementAt, decodingContext);
  12171. this.drawBitmap(regionInfo, bitmap);
  12172. },
  12173. onImmediateLosslessTextRegion:
  12174. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12175. this.onImmediateTextRegion.apply(this, arguments);
  12176. }
  12177. };
  12178. function Jbig2Image() {}
  12179. Jbig2Image.prototype = {
  12180. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12181. return parseJbig2Chunks(chunks);
  12182. }
  12183. };
  12184. return Jbig2Image;
  12185. })();
  12186. exports.Jbig2Image = Jbig2Image;
  12187. }));
  12188. (function (root, factory) {
  12189. {
  12190. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12191. root.pdfjsCoreArithmeticDecoder);
  12192. }
  12193. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12194. var info = sharedUtil.info;
  12195. var log2 = sharedUtil.log2;
  12196. var readUint16 = sharedUtil.readUint16;
  12197. var readUint32 = sharedUtil.readUint32;
  12198. var warn = sharedUtil.warn;
  12199. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12200. var JpxImage = (function JpxImageClosure() {
  12201. // Table E.1
  12202. var SubbandsGainLog2 = {
  12203. 'LL': 0,
  12204. 'LH': 1,
  12205. 'HL': 1,
  12206. 'HH': 2
  12207. };
  12208. function JpxImage() {
  12209. this.failOnCorruptedImage = false;
  12210. }
  12211. JpxImage.prototype = {
  12212. parse: function JpxImage_parse(data) {
  12213. var head = readUint16(data, 0);
  12214. // No box header, immediate start of codestream (SOC)
  12215. if (head === 0xFF4F) {
  12216. this.parseCodestream(data, 0, data.length);
  12217. return;
  12218. }
  12219. var position = 0, length = data.length;
  12220. while (position < length) {
  12221. var headerSize = 8;
  12222. var lbox = readUint32(data, position);
  12223. var tbox = readUint32(data, position + 4);
  12224. position += headerSize;
  12225. if (lbox === 1) {
  12226. // XLBox: read UInt64 according to spec.
  12227. // JavaScript's int precision of 53 bit should be sufficient here.
  12228. lbox = readUint32(data, position) * 4294967296 +
  12229. readUint32(data, position + 4);
  12230. position += 8;
  12231. headerSize += 8;
  12232. }
  12233. if (lbox === 0) {
  12234. lbox = length - position + headerSize;
  12235. }
  12236. if (lbox < headerSize) {
  12237. throw new Error('JPX Error: Invalid box field size');
  12238. }
  12239. var dataLength = lbox - headerSize;
  12240. var jumpDataLength = true;
  12241. switch (tbox) {
  12242. case 0x6A703268: // 'jp2h'
  12243. jumpDataLength = false; // parsing child boxes
  12244. break;
  12245. case 0x636F6C72: // 'colr'
  12246. // Colorspaces are not used, the CS from the PDF is used.
  12247. var method = data[position];
  12248. if (method === 1) {
  12249. // enumerated colorspace
  12250. var colorspace = readUint32(data, position + 3);
  12251. switch (colorspace) {
  12252. case 16: // this indicates a sRGB colorspace
  12253. case 17: // this indicates a grayscale colorspace
  12254. case 18: // this indicates a YUV colorspace
  12255. break;
  12256. default:
  12257. warn('Unknown colorspace ' + colorspace);
  12258. break;
  12259. }
  12260. } else if (method === 2) {
  12261. info('ICC profile not supported');
  12262. }
  12263. break;
  12264. case 0x6A703263: // 'jp2c'
  12265. this.parseCodestream(data, position, position + dataLength);
  12266. break;
  12267. case 0x6A502020: // 'jP\024\024'
  12268. if (0x0d0a870a !== readUint32(data, position)) {
  12269. warn('Invalid JP2 signature');
  12270. }
  12271. break;
  12272. // The following header types are valid but currently not used:
  12273. case 0x6A501A1A: // 'jP\032\032'
  12274. case 0x66747970: // 'ftyp'
  12275. case 0x72726571: // 'rreq'
  12276. case 0x72657320: // 'res '
  12277. case 0x69686472: // 'ihdr'
  12278. break;
  12279. default:
  12280. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12281. (tbox >> 16) & 0xFF,
  12282. (tbox >> 8) & 0xFF,
  12283. tbox & 0xFF);
  12284. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12285. break;
  12286. }
  12287. if (jumpDataLength) {
  12288. position += dataLength;
  12289. }
  12290. }
  12291. },
  12292. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12293. var newByte = stream.getByte();
  12294. while (newByte >= 0) {
  12295. var oldByte = newByte;
  12296. newByte = stream.getByte();
  12297. var code = (oldByte << 8) | newByte;
  12298. // Image and tile size (SIZ)
  12299. if (code === 0xFF51) {
  12300. stream.skip(4);
  12301. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12302. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12303. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12304. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12305. stream.skip(16);
  12306. var Csiz = stream.getUint16(); // Byte 36
  12307. this.width = Xsiz - XOsiz;
  12308. this.height = Ysiz - YOsiz;
  12309. this.componentsCount = Csiz;
  12310. // Results are always returned as Uint8Arrays
  12311. this.bitsPerComponent = 8;
  12312. return;
  12313. }
  12314. }
  12315. throw new Error('JPX Error: No size marker found in JPX stream');
  12316. },
  12317. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12318. var context = {};
  12319. try {
  12320. var doNotRecover = false;
  12321. var position = start;
  12322. while (position + 1 < end) {
  12323. var code = readUint16(data, position);
  12324. position += 2;
  12325. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12326. switch (code) {
  12327. case 0xFF4F: // Start of codestream (SOC)
  12328. context.mainHeader = true;
  12329. break;
  12330. case 0xFFD9: // End of codestream (EOC)
  12331. break;
  12332. case 0xFF51: // Image and tile size (SIZ)
  12333. length = readUint16(data, position);
  12334. var siz = {};
  12335. siz.Xsiz = readUint32(data, position + 4);
  12336. siz.Ysiz = readUint32(data, position + 8);
  12337. siz.XOsiz = readUint32(data, position + 12);
  12338. siz.YOsiz = readUint32(data, position + 16);
  12339. siz.XTsiz = readUint32(data, position + 20);
  12340. siz.YTsiz = readUint32(data, position + 24);
  12341. siz.XTOsiz = readUint32(data, position + 28);
  12342. siz.YTOsiz = readUint32(data, position + 32);
  12343. var componentsCount = readUint16(data, position + 36);
  12344. siz.Csiz = componentsCount;
  12345. var components = [];
  12346. j = position + 38;
  12347. for (var i = 0; i < componentsCount; i++) {
  12348. var component = {
  12349. precision: (data[j] & 0x7F) + 1,
  12350. isSigned: !!(data[j] & 0x80),
  12351. XRsiz: data[j + 1],
  12352. YRsiz: data[j + 1]
  12353. };
  12354. calculateComponentDimensions(component, siz);
  12355. components.push(component);
  12356. }
  12357. context.SIZ = siz;
  12358. context.components = components;
  12359. calculateTileGrids(context, components);
  12360. context.QCC = [];
  12361. context.COC = [];
  12362. break;
  12363. case 0xFF5C: // Quantization default (QCD)
  12364. length = readUint16(data, position);
  12365. var qcd = {};
  12366. j = position + 2;
  12367. sqcd = data[j++];
  12368. switch (sqcd & 0x1F) {
  12369. case 0:
  12370. spqcdSize = 8;
  12371. scalarExpounded = true;
  12372. break;
  12373. case 1:
  12374. spqcdSize = 16;
  12375. scalarExpounded = false;
  12376. break;
  12377. case 2:
  12378. spqcdSize = 16;
  12379. scalarExpounded = true;
  12380. break;
  12381. default:
  12382. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12383. }
  12384. qcd.noQuantization = (spqcdSize === 8);
  12385. qcd.scalarExpounded = scalarExpounded;
  12386. qcd.guardBits = sqcd >> 5;
  12387. spqcds = [];
  12388. while (j < length + position) {
  12389. var spqcd = {};
  12390. if (spqcdSize === 8) {
  12391. spqcd.epsilon = data[j++] >> 3;
  12392. spqcd.mu = 0;
  12393. } else {
  12394. spqcd.epsilon = data[j] >> 3;
  12395. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12396. j += 2;
  12397. }
  12398. spqcds.push(spqcd);
  12399. }
  12400. qcd.SPqcds = spqcds;
  12401. if (context.mainHeader) {
  12402. context.QCD = qcd;
  12403. } else {
  12404. context.currentTile.QCD = qcd;
  12405. context.currentTile.QCC = [];
  12406. }
  12407. break;
  12408. case 0xFF5D: // Quantization component (QCC)
  12409. length = readUint16(data, position);
  12410. var qcc = {};
  12411. j = position + 2;
  12412. var cqcc;
  12413. if (context.SIZ.Csiz < 257) {
  12414. cqcc = data[j++];
  12415. } else {
  12416. cqcc = readUint16(data, j);
  12417. j += 2;
  12418. }
  12419. sqcd = data[j++];
  12420. switch (sqcd & 0x1F) {
  12421. case 0:
  12422. spqcdSize = 8;
  12423. scalarExpounded = true;
  12424. break;
  12425. case 1:
  12426. spqcdSize = 16;
  12427. scalarExpounded = false;
  12428. break;
  12429. case 2:
  12430. spqcdSize = 16;
  12431. scalarExpounded = true;
  12432. break;
  12433. default:
  12434. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12435. }
  12436. qcc.noQuantization = (spqcdSize === 8);
  12437. qcc.scalarExpounded = scalarExpounded;
  12438. qcc.guardBits = sqcd >> 5;
  12439. spqcds = [];
  12440. while (j < (length + position)) {
  12441. spqcd = {};
  12442. if (spqcdSize === 8) {
  12443. spqcd.epsilon = data[j++] >> 3;
  12444. spqcd.mu = 0;
  12445. } else {
  12446. spqcd.epsilon = data[j] >> 3;
  12447. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12448. j += 2;
  12449. }
  12450. spqcds.push(spqcd);
  12451. }
  12452. qcc.SPqcds = spqcds;
  12453. if (context.mainHeader) {
  12454. context.QCC[cqcc] = qcc;
  12455. } else {
  12456. context.currentTile.QCC[cqcc] = qcc;
  12457. }
  12458. break;
  12459. case 0xFF52: // Coding style default (COD)
  12460. length = readUint16(data, position);
  12461. var cod = {};
  12462. j = position + 2;
  12463. var scod = data[j++];
  12464. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  12465. cod.sopMarkerUsed = !!(scod & 2);
  12466. cod.ephMarkerUsed = !!(scod & 4);
  12467. cod.progressionOrder = data[j++];
  12468. cod.layersCount = readUint16(data, j);
  12469. j += 2;
  12470. cod.multipleComponentTransform = data[j++];
  12471. cod.decompositionLevelsCount = data[j++];
  12472. cod.xcb = (data[j++] & 0xF) + 2;
  12473. cod.ycb = (data[j++] & 0xF) + 2;
  12474. var blockStyle = data[j++];
  12475. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12476. cod.resetContextProbabilities = !!(blockStyle & 2);
  12477. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12478. cod.verticalyStripe = !!(blockStyle & 8);
  12479. cod.predictableTermination = !!(blockStyle & 16);
  12480. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12481. cod.reversibleTransformation = data[j++];
  12482. if (cod.entropyCoderWithCustomPrecincts) {
  12483. var precinctsSizes = [];
  12484. while (j < length + position) {
  12485. var precinctsSize = data[j++];
  12486. precinctsSizes.push({
  12487. PPx: precinctsSize & 0xF,
  12488. PPy: precinctsSize >> 4
  12489. });
  12490. }
  12491. cod.precinctsSizes = precinctsSizes;
  12492. }
  12493. var unsupported = [];
  12494. if (cod.selectiveArithmeticCodingBypass) {
  12495. unsupported.push('selectiveArithmeticCodingBypass');
  12496. }
  12497. if (cod.resetContextProbabilities) {
  12498. unsupported.push('resetContextProbabilities');
  12499. }
  12500. if (cod.terminationOnEachCodingPass) {
  12501. unsupported.push('terminationOnEachCodingPass');
  12502. }
  12503. if (cod.verticalyStripe) {
  12504. unsupported.push('verticalyStripe');
  12505. }
  12506. if (cod.predictableTermination) {
  12507. unsupported.push('predictableTermination');
  12508. }
  12509. if (unsupported.length > 0) {
  12510. doNotRecover = true;
  12511. throw new Error('JPX Error: Unsupported COD options (' +
  12512. unsupported.join(', ') + ')');
  12513. }
  12514. if (context.mainHeader) {
  12515. context.COD = cod;
  12516. } else {
  12517. context.currentTile.COD = cod;
  12518. context.currentTile.COC = [];
  12519. }
  12520. break;
  12521. case 0xFF90: // Start of tile-part (SOT)
  12522. length = readUint16(data, position);
  12523. tile = {};
  12524. tile.index = readUint16(data, position + 2);
  12525. tile.length = readUint32(data, position + 4);
  12526. tile.dataEnd = tile.length + position - 2;
  12527. tile.partIndex = data[position + 8];
  12528. tile.partsCount = data[position + 9];
  12529. context.mainHeader = false;
  12530. if (tile.partIndex === 0) {
  12531. // reset component specific settings
  12532. tile.COD = context.COD;
  12533. tile.COC = context.COC.slice(0); // clone of the global COC
  12534. tile.QCD = context.QCD;
  12535. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12536. }
  12537. context.currentTile = tile;
  12538. break;
  12539. case 0xFF93: // Start of data (SOD)
  12540. tile = context.currentTile;
  12541. if (tile.partIndex === 0) {
  12542. initializeTile(context, tile.index);
  12543. buildPackets(context);
  12544. }
  12545. // moving to the end of the data
  12546. length = tile.dataEnd - position;
  12547. parseTilePackets(context, data, position, length);
  12548. break;
  12549. case 0xFF55: // Tile-part lengths, main header (TLM)
  12550. case 0xFF57: // Packet length, main header (PLM)
  12551. case 0xFF58: // Packet length, tile-part header (PLT)
  12552. case 0xFF64: // Comment (COM)
  12553. length = readUint16(data, position);
  12554. // skipping content
  12555. break;
  12556. case 0xFF53: // Coding style component (COC)
  12557. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  12558. 'not implemented');
  12559. default:
  12560. throw new Error('JPX Error: Unknown codestream code: ' +
  12561. code.toString(16));
  12562. }
  12563. position += length;
  12564. }
  12565. } catch (e) {
  12566. if (doNotRecover || this.failOnCorruptedImage) {
  12567. throw e;
  12568. } else {
  12569. warn('Trying to recover from ' + e.message);
  12570. }
  12571. }
  12572. this.tiles = transformComponents(context);
  12573. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12574. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12575. this.componentsCount = context.SIZ.Csiz;
  12576. }
  12577. };
  12578. function calculateComponentDimensions(component, siz) {
  12579. // Section B.2 Component mapping
  12580. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12581. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12582. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12583. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12584. component.width = component.x1 - component.x0;
  12585. component.height = component.y1 - component.y0;
  12586. }
  12587. function calculateTileGrids(context, components) {
  12588. var siz = context.SIZ;
  12589. // Section B.3 Division into tile and tile-components
  12590. var tile, tiles = [];
  12591. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12592. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12593. for (var q = 0; q < numYtiles; q++) {
  12594. for (var p = 0; p < numXtiles; p++) {
  12595. tile = {};
  12596. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12597. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12598. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12599. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12600. tile.width = tile.tx1 - tile.tx0;
  12601. tile.height = tile.ty1 - tile.ty0;
  12602. tile.components = [];
  12603. tiles.push(tile);
  12604. }
  12605. }
  12606. context.tiles = tiles;
  12607. var componentsCount = siz.Csiz;
  12608. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12609. var component = components[i];
  12610. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12611. var tileComponent = {};
  12612. tile = tiles[j];
  12613. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12614. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12615. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12616. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12617. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12618. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12619. tile.components[i] = tileComponent;
  12620. }
  12621. }
  12622. }
  12623. function getBlocksDimensions(context, component, r) {
  12624. var codOrCoc = component.codingStyleParameters;
  12625. var result = {};
  12626. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12627. result.PPx = 15;
  12628. result.PPy = 15;
  12629. } else {
  12630. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12631. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12632. }
  12633. // calculate codeblock size as described in section B.7
  12634. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12635. Math.min(codOrCoc.xcb, result.PPx));
  12636. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12637. Math.min(codOrCoc.ycb, result.PPy));
  12638. return result;
  12639. }
  12640. function buildPrecincts(context, resolution, dimensions) {
  12641. // Section B.6 Division resolution to precincts
  12642. var precinctWidth = 1 << dimensions.PPx;
  12643. var precinctHeight = 1 << dimensions.PPy;
  12644. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12645. // to precincts. Precinct partition divides a resolution according to width
  12646. // and height parameters. The subband that belongs to the resolution level
  12647. // has a different size than the level, unless it is the zero resolution.
  12648. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12649. // The precinct partitioning for a particular subband is derived from a
  12650. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12651. // resolution level)... The LL band associated with each resolution level is
  12652. // divided into precincts... Each of the resulting precinct regions is then
  12653. // mapped into its child subbands (if any) at the next lower resolution
  12654. // level. This is accomplished by using the coordinate transformation
  12655. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12656. // coordinates of a point in the LL band and child subband, respectively.
  12657. var isZeroRes = resolution.resLevel === 0;
  12658. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12659. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12660. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12661. Math.ceil(resolution.trx1 / precinctWidth) -
  12662. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12663. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12664. Math.ceil(resolution.try1 / precinctHeight) -
  12665. Math.floor(resolution.try0 / precinctHeight) : 0);
  12666. var numprecincts = numprecinctswide * numprecinctshigh;
  12667. resolution.precinctParameters = {
  12668. precinctWidth: precinctWidth,
  12669. precinctHeight: precinctHeight,
  12670. numprecinctswide: numprecinctswide,
  12671. numprecinctshigh: numprecinctshigh,
  12672. numprecincts: numprecincts,
  12673. precinctWidthInSubband: precinctWidthInSubband,
  12674. precinctHeightInSubband: precinctHeightInSubband
  12675. };
  12676. }
  12677. function buildCodeblocks(context, subband, dimensions) {
  12678. // Section B.7 Division sub-band into code-blocks
  12679. var xcb_ = dimensions.xcb_;
  12680. var ycb_ = dimensions.ycb_;
  12681. var codeblockWidth = 1 << xcb_;
  12682. var codeblockHeight = 1 << ycb_;
  12683. var cbx0 = subband.tbx0 >> xcb_;
  12684. var cby0 = subband.tby0 >> ycb_;
  12685. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12686. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12687. var precinctParameters = subband.resolution.precinctParameters;
  12688. var codeblocks = [];
  12689. var precincts = [];
  12690. var i, j, codeblock, precinctNumber;
  12691. for (j = cby0; j < cby1; j++) {
  12692. for (i = cbx0; i < cbx1; i++) {
  12693. codeblock = {
  12694. cbx: i,
  12695. cby: j,
  12696. tbx0: codeblockWidth * i,
  12697. tby0: codeblockHeight * j,
  12698. tbx1: codeblockWidth * (i + 1),
  12699. tby1: codeblockHeight * (j + 1)
  12700. };
  12701. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12702. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12703. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12704. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12705. // Calculate precinct number for this codeblock, codeblock position
  12706. // should be relative to its subband, use actual dimension and position
  12707. // See comment about codeblock group width and height
  12708. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12709. precinctParameters.precinctWidthInSubband);
  12710. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12711. precinctParameters.precinctHeightInSubband);
  12712. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12713. codeblock.precinctNumber = precinctNumber;
  12714. codeblock.subbandType = subband.type;
  12715. codeblock.Lblock = 3;
  12716. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12717. codeblock.tby1_ <= codeblock.tby0_) {
  12718. continue;
  12719. }
  12720. codeblocks.push(codeblock);
  12721. // building precinct for the sub-band
  12722. var precinct = precincts[precinctNumber];
  12723. if (precinct !== undefined) {
  12724. if (i < precinct.cbxMin) {
  12725. precinct.cbxMin = i;
  12726. } else if (i > precinct.cbxMax) {
  12727. precinct.cbxMax = i;
  12728. }
  12729. if (j < precinct.cbyMin) {
  12730. precinct.cbxMin = j;
  12731. } else if (j > precinct.cbyMax) {
  12732. precinct.cbyMax = j;
  12733. }
  12734. } else {
  12735. precincts[precinctNumber] = precinct = {
  12736. cbxMin: i,
  12737. cbyMin: j,
  12738. cbxMax: i,
  12739. cbyMax: j
  12740. };
  12741. }
  12742. codeblock.precinct = precinct;
  12743. }
  12744. }
  12745. subband.codeblockParameters = {
  12746. codeblockWidth: xcb_,
  12747. codeblockHeight: ycb_,
  12748. numcodeblockwide: cbx1 - cbx0 + 1,
  12749. numcodeblockhigh: cby1 - cby0 + 1
  12750. };
  12751. subband.codeblocks = codeblocks;
  12752. subband.precincts = precincts;
  12753. }
  12754. function createPacket(resolution, precinctNumber, layerNumber) {
  12755. var precinctCodeblocks = [];
  12756. // Section B.10.8 Order of info in packet
  12757. var subbands = resolution.subbands;
  12758. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12759. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12760. var subband = subbands[i];
  12761. var codeblocks = subband.codeblocks;
  12762. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12763. var codeblock = codeblocks[j];
  12764. if (codeblock.precinctNumber !== precinctNumber) {
  12765. continue;
  12766. }
  12767. precinctCodeblocks.push(codeblock);
  12768. }
  12769. }
  12770. return {
  12771. layerNumber: layerNumber,
  12772. codeblocks: precinctCodeblocks
  12773. };
  12774. }
  12775. function LayerResolutionComponentPositionIterator(context) {
  12776. var siz = context.SIZ;
  12777. var tileIndex = context.currentTile.index;
  12778. var tile = context.tiles[tileIndex];
  12779. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12780. var componentsCount = siz.Csiz;
  12781. var maxDecompositionLevelsCount = 0;
  12782. for (var q = 0; q < componentsCount; q++) {
  12783. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12784. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12785. }
  12786. var l = 0, r = 0, i = 0, k = 0;
  12787. this.nextPacket = function JpxImage_nextPacket() {
  12788. // Section B.12.1.1 Layer-resolution-component-position
  12789. for (; l < layersCount; l++) {
  12790. for (; r <= maxDecompositionLevelsCount; r++) {
  12791. for (; i < componentsCount; i++) {
  12792. var component = tile.components[i];
  12793. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12794. continue;
  12795. }
  12796. var resolution = component.resolutions[r];
  12797. var numprecincts = resolution.precinctParameters.numprecincts;
  12798. for (; k < numprecincts;) {
  12799. var packet = createPacket(resolution, k, l);
  12800. k++;
  12801. return packet;
  12802. }
  12803. k = 0;
  12804. }
  12805. i = 0;
  12806. }
  12807. r = 0;
  12808. }
  12809. throw new Error('JPX Error: Out of packets');
  12810. };
  12811. }
  12812. function ResolutionLayerComponentPositionIterator(context) {
  12813. var siz = context.SIZ;
  12814. var tileIndex = context.currentTile.index;
  12815. var tile = context.tiles[tileIndex];
  12816. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12817. var componentsCount = siz.Csiz;
  12818. var maxDecompositionLevelsCount = 0;
  12819. for (var q = 0; q < componentsCount; q++) {
  12820. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12821. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12822. }
  12823. var r = 0, l = 0, i = 0, k = 0;
  12824. this.nextPacket = function JpxImage_nextPacket() {
  12825. // Section B.12.1.2 Resolution-layer-component-position
  12826. for (; r <= maxDecompositionLevelsCount; r++) {
  12827. for (; l < layersCount; l++) {
  12828. for (; i < componentsCount; i++) {
  12829. var component = tile.components[i];
  12830. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12831. continue;
  12832. }
  12833. var resolution = component.resolutions[r];
  12834. var numprecincts = resolution.precinctParameters.numprecincts;
  12835. for (; k < numprecincts;) {
  12836. var packet = createPacket(resolution, k, l);
  12837. k++;
  12838. return packet;
  12839. }
  12840. k = 0;
  12841. }
  12842. i = 0;
  12843. }
  12844. l = 0;
  12845. }
  12846. throw new Error('JPX Error: Out of packets');
  12847. };
  12848. }
  12849. function ResolutionPositionComponentLayerIterator(context) {
  12850. var siz = context.SIZ;
  12851. var tileIndex = context.currentTile.index;
  12852. var tile = context.tiles[tileIndex];
  12853. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12854. var componentsCount = siz.Csiz;
  12855. var l, r, c, p;
  12856. var maxDecompositionLevelsCount = 0;
  12857. for (c = 0; c < componentsCount; c++) {
  12858. var component = tile.components[c];
  12859. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12860. component.codingStyleParameters.decompositionLevelsCount);
  12861. }
  12862. var maxNumPrecinctsInLevel = new Int32Array(
  12863. maxDecompositionLevelsCount + 1);
  12864. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12865. var maxNumPrecincts = 0;
  12866. for (c = 0; c < componentsCount; ++c) {
  12867. var resolutions = tile.components[c].resolutions;
  12868. if (r < resolutions.length) {
  12869. maxNumPrecincts = Math.max(maxNumPrecincts,
  12870. resolutions[r].precinctParameters.numprecincts);
  12871. }
  12872. }
  12873. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12874. }
  12875. l = 0;
  12876. r = 0;
  12877. c = 0;
  12878. p = 0;
  12879. this.nextPacket = function JpxImage_nextPacket() {
  12880. // Section B.12.1.3 Resolution-position-component-layer
  12881. for (; r <= maxDecompositionLevelsCount; r++) {
  12882. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12883. for (; c < componentsCount; c++) {
  12884. var component = tile.components[c];
  12885. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12886. continue;
  12887. }
  12888. var resolution = component.resolutions[r];
  12889. var numprecincts = resolution.precinctParameters.numprecincts;
  12890. if (p >= numprecincts) {
  12891. continue;
  12892. }
  12893. for (; l < layersCount;) {
  12894. var packet = createPacket(resolution, p, l);
  12895. l++;
  12896. return packet;
  12897. }
  12898. l = 0;
  12899. }
  12900. c = 0;
  12901. }
  12902. p = 0;
  12903. }
  12904. throw new Error('JPX Error: Out of packets');
  12905. };
  12906. }
  12907. function PositionComponentResolutionLayerIterator(context) {
  12908. var siz = context.SIZ;
  12909. var tileIndex = context.currentTile.index;
  12910. var tile = context.tiles[tileIndex];
  12911. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12912. var componentsCount = siz.Csiz;
  12913. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12914. var precinctsIterationSizes = precinctsSizes;
  12915. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12916. this.nextPacket = function JpxImage_nextPacket() {
  12917. // Section B.12.1.4 Position-component-resolution-layer
  12918. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12919. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12920. for (; c < componentsCount; c++) {
  12921. var component = tile.components[c];
  12922. var decompositionLevelsCount =
  12923. component.codingStyleParameters.decompositionLevelsCount;
  12924. for (; r <= decompositionLevelsCount; r++) {
  12925. var resolution = component.resolutions[r];
  12926. var sizeInImageScale =
  12927. precinctsSizes.components[c].resolutions[r];
  12928. var k = getPrecinctIndexIfExist(
  12929. px,
  12930. py,
  12931. sizeInImageScale,
  12932. precinctsIterationSizes,
  12933. resolution);
  12934. if (k === null) {
  12935. continue;
  12936. }
  12937. for (; l < layersCount;) {
  12938. var packet = createPacket(resolution, k, l);
  12939. l++;
  12940. return packet;
  12941. }
  12942. l = 0;
  12943. }
  12944. r = 0;
  12945. }
  12946. c = 0;
  12947. }
  12948. px = 0;
  12949. }
  12950. throw new Error('JPX Error: Out of packets');
  12951. };
  12952. }
  12953. function ComponentPositionResolutionLayerIterator(context) {
  12954. var siz = context.SIZ;
  12955. var tileIndex = context.currentTile.index;
  12956. var tile = context.tiles[tileIndex];
  12957. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12958. var componentsCount = siz.Csiz;
  12959. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12960. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12961. this.nextPacket = function JpxImage_nextPacket() {
  12962. // Section B.12.1.5 Component-position-resolution-layer
  12963. for (; c < componentsCount; ++c) {
  12964. var component = tile.components[c];
  12965. var precinctsIterationSizes = precinctsSizes.components[c];
  12966. var decompositionLevelsCount =
  12967. component.codingStyleParameters.decompositionLevelsCount;
  12968. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12969. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12970. for (; r <= decompositionLevelsCount; r++) {
  12971. var resolution = component.resolutions[r];
  12972. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12973. var k = getPrecinctIndexIfExist(
  12974. px,
  12975. py,
  12976. sizeInImageScale,
  12977. precinctsIterationSizes,
  12978. resolution);
  12979. if (k === null) {
  12980. continue;
  12981. }
  12982. for (; l < layersCount;) {
  12983. var packet = createPacket(resolution, k, l);
  12984. l++;
  12985. return packet;
  12986. }
  12987. l = 0;
  12988. }
  12989. r = 0;
  12990. }
  12991. px = 0;
  12992. }
  12993. py = 0;
  12994. }
  12995. throw new Error('JPX Error: Out of packets');
  12996. };
  12997. }
  12998. function getPrecinctIndexIfExist(
  12999. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13000. var posX = pxIndex * precinctIterationSizes.minWidth;
  13001. var posY = pyIndex * precinctIterationSizes.minHeight;
  13002. if (posX % sizeInImageScale.width !== 0 ||
  13003. posY % sizeInImageScale.height !== 0) {
  13004. return null;
  13005. }
  13006. var startPrecinctRowIndex =
  13007. (posY / sizeInImageScale.width) *
  13008. resolution.precinctParameters.numprecinctswide;
  13009. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13010. }
  13011. function getPrecinctSizesInImageScale(tile) {
  13012. var componentsCount = tile.components.length;
  13013. var minWidth = Number.MAX_VALUE;
  13014. var minHeight = Number.MAX_VALUE;
  13015. var maxNumWide = 0;
  13016. var maxNumHigh = 0;
  13017. var sizePerComponent = new Array(componentsCount);
  13018. for (var c = 0; c < componentsCount; c++) {
  13019. var component = tile.components[c];
  13020. var decompositionLevelsCount =
  13021. component.codingStyleParameters.decompositionLevelsCount;
  13022. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13023. var minWidthCurrentComponent = Number.MAX_VALUE;
  13024. var minHeightCurrentComponent = Number.MAX_VALUE;
  13025. var maxNumWideCurrentComponent = 0;
  13026. var maxNumHighCurrentComponent = 0;
  13027. var scale = 1;
  13028. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13029. var resolution = component.resolutions[r];
  13030. var widthCurrentResolution =
  13031. scale * resolution.precinctParameters.precinctWidth;
  13032. var heightCurrentResolution =
  13033. scale * resolution.precinctParameters.precinctHeight;
  13034. minWidthCurrentComponent = Math.min(
  13035. minWidthCurrentComponent,
  13036. widthCurrentResolution);
  13037. minHeightCurrentComponent = Math.min(
  13038. minHeightCurrentComponent,
  13039. heightCurrentResolution);
  13040. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13041. resolution.precinctParameters.numprecinctswide);
  13042. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13043. resolution.precinctParameters.numprecinctshigh);
  13044. sizePerResolution[r] = {
  13045. width: widthCurrentResolution,
  13046. height: heightCurrentResolution
  13047. };
  13048. scale <<= 1;
  13049. }
  13050. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13051. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13052. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13053. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13054. sizePerComponent[c] = {
  13055. resolutions: sizePerResolution,
  13056. minWidth: minWidthCurrentComponent,
  13057. minHeight: minHeightCurrentComponent,
  13058. maxNumWide: maxNumWideCurrentComponent,
  13059. maxNumHigh: maxNumHighCurrentComponent
  13060. };
  13061. }
  13062. return {
  13063. components: sizePerComponent,
  13064. minWidth: minWidth,
  13065. minHeight: minHeight,
  13066. maxNumWide: maxNumWide,
  13067. maxNumHigh: maxNumHigh
  13068. };
  13069. }
  13070. function buildPackets(context) {
  13071. var siz = context.SIZ;
  13072. var tileIndex = context.currentTile.index;
  13073. var tile = context.tiles[tileIndex];
  13074. var componentsCount = siz.Csiz;
  13075. // Creating resolutions and sub-bands for each component
  13076. for (var c = 0; c < componentsCount; c++) {
  13077. var component = tile.components[c];
  13078. var decompositionLevelsCount =
  13079. component.codingStyleParameters.decompositionLevelsCount;
  13080. // Section B.5 Resolution levels and sub-bands
  13081. var resolutions = [];
  13082. var subbands = [];
  13083. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13084. var blocksDimensions = getBlocksDimensions(context, component, r);
  13085. var resolution = {};
  13086. var scale = 1 << (decompositionLevelsCount - r);
  13087. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13088. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13089. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13090. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13091. resolution.resLevel = r;
  13092. buildPrecincts(context, resolution, blocksDimensions);
  13093. resolutions.push(resolution);
  13094. var subband;
  13095. if (r === 0) {
  13096. // one sub-band (LL) with last decomposition
  13097. subband = {};
  13098. subband.type = 'LL';
  13099. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13100. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13101. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13102. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13103. subband.resolution = resolution;
  13104. buildCodeblocks(context, subband, blocksDimensions);
  13105. subbands.push(subband);
  13106. resolution.subbands = [subband];
  13107. } else {
  13108. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13109. var resolutionSubbands = [];
  13110. // three sub-bands (HL, LH and HH) with rest of decompositions
  13111. subband = {};
  13112. subband.type = 'HL';
  13113. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13114. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13115. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13116. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13117. subband.resolution = resolution;
  13118. buildCodeblocks(context, subband, blocksDimensions);
  13119. subbands.push(subband);
  13120. resolutionSubbands.push(subband);
  13121. subband = {};
  13122. subband.type = 'LH';
  13123. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13124. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13125. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13126. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13127. subband.resolution = resolution;
  13128. buildCodeblocks(context, subband, blocksDimensions);
  13129. subbands.push(subband);
  13130. resolutionSubbands.push(subband);
  13131. subband = {};
  13132. subband.type = 'HH';
  13133. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13134. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13135. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13136. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13137. subband.resolution = resolution;
  13138. buildCodeblocks(context, subband, blocksDimensions);
  13139. subbands.push(subband);
  13140. resolutionSubbands.push(subband);
  13141. resolution.subbands = resolutionSubbands;
  13142. }
  13143. }
  13144. component.resolutions = resolutions;
  13145. component.subbands = subbands;
  13146. }
  13147. // Generate the packets sequence
  13148. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13149. switch (progressionOrder) {
  13150. case 0:
  13151. tile.packetsIterator =
  13152. new LayerResolutionComponentPositionIterator(context);
  13153. break;
  13154. case 1:
  13155. tile.packetsIterator =
  13156. new ResolutionLayerComponentPositionIterator(context);
  13157. break;
  13158. case 2:
  13159. tile.packetsIterator =
  13160. new ResolutionPositionComponentLayerIterator(context);
  13161. break;
  13162. case 3:
  13163. tile.packetsIterator =
  13164. new PositionComponentResolutionLayerIterator(context);
  13165. break;
  13166. case 4:
  13167. tile.packetsIterator =
  13168. new ComponentPositionResolutionLayerIterator(context);
  13169. break;
  13170. default:
  13171. throw new Error('JPX Error: Unsupported progression order ' +
  13172. progressionOrder);
  13173. }
  13174. }
  13175. function parseTilePackets(context, data, offset, dataLength) {
  13176. var position = 0;
  13177. var buffer, bufferSize = 0, skipNextBit = false;
  13178. function readBits(count) {
  13179. while (bufferSize < count) {
  13180. var b = data[offset + position];
  13181. position++;
  13182. if (skipNextBit) {
  13183. buffer = (buffer << 7) | b;
  13184. bufferSize += 7;
  13185. skipNextBit = false;
  13186. } else {
  13187. buffer = (buffer << 8) | b;
  13188. bufferSize += 8;
  13189. }
  13190. if (b === 0xFF) {
  13191. skipNextBit = true;
  13192. }
  13193. }
  13194. bufferSize -= count;
  13195. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13196. }
  13197. function skipMarkerIfEqual(value) {
  13198. if (data[offset + position - 1] === 0xFF &&
  13199. data[offset + position] === value) {
  13200. skipBytes(1);
  13201. return true;
  13202. } else if (data[offset + position] === 0xFF &&
  13203. data[offset + position + 1] === value) {
  13204. skipBytes(2);
  13205. return true;
  13206. }
  13207. return false;
  13208. }
  13209. function skipBytes(count) {
  13210. position += count;
  13211. }
  13212. function alignToByte() {
  13213. bufferSize = 0;
  13214. if (skipNextBit) {
  13215. position++;
  13216. skipNextBit = false;
  13217. }
  13218. }
  13219. function readCodingpasses() {
  13220. if (readBits(1) === 0) {
  13221. return 1;
  13222. }
  13223. if (readBits(1) === 0) {
  13224. return 2;
  13225. }
  13226. var value = readBits(2);
  13227. if (value < 3) {
  13228. return value + 3;
  13229. }
  13230. value = readBits(5);
  13231. if (value < 31) {
  13232. return value + 6;
  13233. }
  13234. value = readBits(7);
  13235. return value + 37;
  13236. }
  13237. var tileIndex = context.currentTile.index;
  13238. var tile = context.tiles[tileIndex];
  13239. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13240. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13241. var packetsIterator = tile.packetsIterator;
  13242. while (position < dataLength) {
  13243. alignToByte();
  13244. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13245. // Skip also marker segment length and packet sequence ID
  13246. skipBytes(4);
  13247. }
  13248. var packet = packetsIterator.nextPacket();
  13249. if (!readBits(1)) {
  13250. continue;
  13251. }
  13252. var layerNumber = packet.layerNumber;
  13253. var queue = [], codeblock;
  13254. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13255. codeblock = packet.codeblocks[i];
  13256. var precinct = codeblock.precinct;
  13257. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13258. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13259. var codeblockIncluded = false;
  13260. var firstTimeInclusion = false;
  13261. var valueReady;
  13262. if (codeblock['included'] !== undefined) {
  13263. codeblockIncluded = !!readBits(1);
  13264. } else {
  13265. // reading inclusion tree
  13266. precinct = codeblock.precinct;
  13267. var inclusionTree, zeroBitPlanesTree;
  13268. if (precinct['inclusionTree'] !== undefined) {
  13269. inclusionTree = precinct.inclusionTree;
  13270. } else {
  13271. // building inclusion and zero bit-planes trees
  13272. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13273. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13274. inclusionTree = new InclusionTree(width, height, layerNumber);
  13275. zeroBitPlanesTree = new TagTree(width, height);
  13276. precinct.inclusionTree = inclusionTree;
  13277. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13278. }
  13279. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13280. while (true) {
  13281. if (readBits(1)) {
  13282. valueReady = !inclusionTree.nextLevel();
  13283. if (valueReady) {
  13284. codeblock.included = true;
  13285. codeblockIncluded = firstTimeInclusion = true;
  13286. break;
  13287. }
  13288. } else {
  13289. inclusionTree.incrementValue(layerNumber);
  13290. break;
  13291. }
  13292. }
  13293. }
  13294. }
  13295. if (!codeblockIncluded) {
  13296. continue;
  13297. }
  13298. if (firstTimeInclusion) {
  13299. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13300. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13301. while (true) {
  13302. if (readBits(1)) {
  13303. valueReady = !zeroBitPlanesTree.nextLevel();
  13304. if (valueReady) {
  13305. break;
  13306. }
  13307. } else {
  13308. zeroBitPlanesTree.incrementValue();
  13309. }
  13310. }
  13311. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13312. }
  13313. var codingpasses = readCodingpasses();
  13314. while (readBits(1)) {
  13315. codeblock.Lblock++;
  13316. }
  13317. var codingpassesLog2 = log2(codingpasses);
  13318. // rounding down log2
  13319. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13320. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13321. var codedDataLength = readBits(bits);
  13322. queue.push({
  13323. codeblock: codeblock,
  13324. codingpasses: codingpasses,
  13325. dataLength: codedDataLength
  13326. });
  13327. }
  13328. alignToByte();
  13329. if (ephMarkerUsed) {
  13330. skipMarkerIfEqual(0x92);
  13331. }
  13332. while (queue.length > 0) {
  13333. var packetItem = queue.shift();
  13334. codeblock = packetItem.codeblock;
  13335. if (codeblock['data'] === undefined) {
  13336. codeblock.data = [];
  13337. }
  13338. codeblock.data.push({
  13339. data: data,
  13340. start: offset + position,
  13341. end: offset + position + packetItem.dataLength,
  13342. codingpasses: packetItem.codingpasses
  13343. });
  13344. position += packetItem.dataLength;
  13345. }
  13346. }
  13347. return position;
  13348. }
  13349. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13350. delta, mb, reversible, segmentationSymbolUsed) {
  13351. var x0 = subband.tbx0;
  13352. var y0 = subband.tby0;
  13353. var width = subband.tbx1 - subband.tbx0;
  13354. var codeblocks = subband.codeblocks;
  13355. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13356. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13357. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13358. var codeblock = codeblocks[i];
  13359. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13360. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13361. if (blockWidth === 0 || blockHeight === 0) {
  13362. continue;
  13363. }
  13364. if (codeblock['data'] === undefined) {
  13365. continue;
  13366. }
  13367. var bitModel, currentCodingpassType;
  13368. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13369. codeblock.zeroBitPlanes, mb);
  13370. currentCodingpassType = 2; // first bit plane starts from cleanup
  13371. // collect data
  13372. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  13373. var j, jj, dataItem;
  13374. for (j = 0, jj = data.length; j < jj; j++) {
  13375. dataItem = data[j];
  13376. totalLength += dataItem.end - dataItem.start;
  13377. codingpasses += dataItem.codingpasses;
  13378. }
  13379. var encodedData = new Uint8Array(totalLength);
  13380. var position = 0;
  13381. for (j = 0, jj = data.length; j < jj; j++) {
  13382. dataItem = data[j];
  13383. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  13384. encodedData.set(chunk, position);
  13385. position += chunk.length;
  13386. }
  13387. // decoding the item
  13388. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  13389. bitModel.setDecoder(decoder);
  13390. for (j = 0; j < codingpasses; j++) {
  13391. switch (currentCodingpassType) {
  13392. case 0:
  13393. bitModel.runSignificancePropogationPass();
  13394. break;
  13395. case 1:
  13396. bitModel.runMagnitudeRefinementPass();
  13397. break;
  13398. case 2:
  13399. bitModel.runCleanupPass();
  13400. if (segmentationSymbolUsed) {
  13401. bitModel.checkSegmentationSymbol();
  13402. }
  13403. break;
  13404. }
  13405. currentCodingpassType = (currentCodingpassType + 1) % 3;
  13406. }
  13407. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  13408. var sign = bitModel.coefficentsSign;
  13409. var magnitude = bitModel.coefficentsMagnitude;
  13410. var bitsDecoded = bitModel.bitsDecoded;
  13411. var magnitudeCorrection = reversible ? 0 : 0.5;
  13412. var k, n, nb;
  13413. position = 0;
  13414. // Do the interleaving of Section F.3.3 here, so we do not need
  13415. // to copy later. LL level is not interleaved, just copied.
  13416. var interleave = (subband.type !== 'LL');
  13417. for (j = 0; j < blockHeight; j++) {
  13418. var row = (offset / width) | 0; // row in the non-interleaved subband
  13419. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  13420. for (k = 0; k < blockWidth; k++) {
  13421. n = magnitude[position];
  13422. if (n !== 0) {
  13423. n = (n + magnitudeCorrection) * delta;
  13424. if (sign[position] !== 0) {
  13425. n = -n;
  13426. }
  13427. nb = bitsDecoded[position];
  13428. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  13429. if (reversible && (nb >= mb)) {
  13430. coefficients[pos] = n;
  13431. } else {
  13432. coefficients[pos] = n * (1 << (mb - nb));
  13433. }
  13434. }
  13435. offset++;
  13436. position++;
  13437. }
  13438. offset += width - blockWidth;
  13439. }
  13440. }
  13441. }
  13442. function transformTile(context, tile, c) {
  13443. var component = tile.components[c];
  13444. var codingStyleParameters = component.codingStyleParameters;
  13445. var quantizationParameters = component.quantizationParameters;
  13446. var decompositionLevelsCount =
  13447. codingStyleParameters.decompositionLevelsCount;
  13448. var spqcds = quantizationParameters.SPqcds;
  13449. var scalarExpounded = quantizationParameters.scalarExpounded;
  13450. var guardBits = quantizationParameters.guardBits;
  13451. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  13452. var precision = context.components[c].precision;
  13453. var reversible = codingStyleParameters.reversibleTransformation;
  13454. var transform = (reversible ? new ReversibleTransform() :
  13455. new IrreversibleTransform());
  13456. var subbandCoefficients = [];
  13457. var b = 0;
  13458. for (var i = 0; i <= decompositionLevelsCount; i++) {
  13459. var resolution = component.resolutions[i];
  13460. var width = resolution.trx1 - resolution.trx0;
  13461. var height = resolution.try1 - resolution.try0;
  13462. // Allocate space for the whole sublevel.
  13463. var coefficients = new Float32Array(width * height);
  13464. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  13465. var mu, epsilon;
  13466. if (!scalarExpounded) {
  13467. // formula E-5
  13468. mu = spqcds[0].mu;
  13469. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  13470. } else {
  13471. mu = spqcds[b].mu;
  13472. epsilon = spqcds[b].epsilon;
  13473. b++;
  13474. }
  13475. var subband = resolution.subbands[j];
  13476. var gainLog2 = SubbandsGainLog2[subband.type];
  13477. // calulate quantization coefficient (Section E.1.1.1)
  13478. var delta = (reversible ? 1 :
  13479. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13480. var mb = (guardBits + epsilon - 1);
  13481. // In the first resolution level, copyCoefficients will fill the
  13482. // whole array with coefficients. In the succeding passes,
  13483. // copyCoefficients will consecutively fill in the values that belong
  13484. // to the interleaved positions of the HL, LH, and HH coefficients.
  13485. // The LL coefficients will then be interleaved in Transform.iterate().
  13486. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13487. reversible, segmentationSymbolUsed);
  13488. }
  13489. subbandCoefficients.push({
  13490. width: width,
  13491. height: height,
  13492. items: coefficients
  13493. });
  13494. }
  13495. var result = transform.calculate(subbandCoefficients,
  13496. component.tcx0, component.tcy0);
  13497. return {
  13498. left: component.tcx0,
  13499. top: component.tcy0,
  13500. width: result.width,
  13501. height: result.height,
  13502. items: result.items
  13503. };
  13504. }
  13505. function transformComponents(context) {
  13506. var siz = context.SIZ;
  13507. var components = context.components;
  13508. var componentsCount = siz.Csiz;
  13509. var resultImages = [];
  13510. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13511. var tile = context.tiles[i];
  13512. var transformedTiles = [];
  13513. var c;
  13514. for (c = 0; c < componentsCount; c++) {
  13515. transformedTiles[c] = transformTile(context, tile, c);
  13516. }
  13517. var tile0 = transformedTiles[0];
  13518. var out = new Uint8Array(tile0.items.length * componentsCount);
  13519. var result = {
  13520. left: tile0.left,
  13521. top: tile0.top,
  13522. width: tile0.width,
  13523. height: tile0.height,
  13524. items: out
  13525. };
  13526. // Section G.2.2 Inverse multi component transform
  13527. var shift, offset, max, min, maxK;
  13528. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13529. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13530. var fourComponents = componentsCount === 4;
  13531. var y0items = transformedTiles[0].items;
  13532. var y1items = transformedTiles[1].items;
  13533. var y2items = transformedTiles[2].items;
  13534. var y3items = fourComponents ? transformedTiles[3].items : null;
  13535. // HACK: The multiple component transform formulas below assume that
  13536. // all components have the same precision. With this in mind, we
  13537. // compute shift and offset only once.
  13538. shift = components[0].precision - 8;
  13539. offset = (128 << shift) + 0.5;
  13540. max = 255 * (1 << shift);
  13541. maxK = max * 0.5;
  13542. min = -maxK;
  13543. var component0 = tile.components[0];
  13544. var alpha01 = componentsCount - 3;
  13545. jj = y0items.length;
  13546. if (!component0.codingStyleParameters.reversibleTransformation) {
  13547. // inverse irreversible multiple component transform
  13548. for (j = 0; j < jj; j++, pos += alpha01) {
  13549. y0 = y0items[j] + offset;
  13550. y1 = y1items[j];
  13551. y2 = y2items[j];
  13552. r = y0 + 1.402 * y2;
  13553. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13554. b = y0 + 1.772 * y1;
  13555. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13556. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13557. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13558. }
  13559. } else {
  13560. // inverse reversible multiple component transform
  13561. for (j = 0; j < jj; j++, pos += alpha01) {
  13562. y0 = y0items[j] + offset;
  13563. y1 = y1items[j];
  13564. y2 = y2items[j];
  13565. g = y0 - ((y2 + y1) >> 2);
  13566. r = g + y2;
  13567. b = g + y1;
  13568. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13569. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13570. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13571. }
  13572. }
  13573. if (fourComponents) {
  13574. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13575. k = y3items[j];
  13576. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13577. }
  13578. }
  13579. } else { // no multi-component transform
  13580. for (c = 0; c < componentsCount; c++) {
  13581. var items = transformedTiles[c].items;
  13582. shift = components[c].precision - 8;
  13583. offset = (128 << shift) + 0.5;
  13584. max = (127.5 * (1 << shift));
  13585. min = -max;
  13586. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13587. val = items[j];
  13588. out[pos] = val <= min ? 0 :
  13589. val >= max ? 255 : (val + offset) >> shift;
  13590. pos += componentsCount;
  13591. }
  13592. }
  13593. }
  13594. resultImages.push(result);
  13595. }
  13596. return resultImages;
  13597. }
  13598. function initializeTile(context, tileIndex) {
  13599. var siz = context.SIZ;
  13600. var componentsCount = siz.Csiz;
  13601. var tile = context.tiles[tileIndex];
  13602. for (var c = 0; c < componentsCount; c++) {
  13603. var component = tile.components[c];
  13604. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13605. context.currentTile.QCC[c] : context.currentTile.QCD);
  13606. component.quantizationParameters = qcdOrQcc;
  13607. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13608. context.currentTile.COC[c] : context.currentTile.COD);
  13609. component.codingStyleParameters = codOrCoc;
  13610. }
  13611. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13612. }
  13613. // Section B.10.2 Tag trees
  13614. var TagTree = (function TagTreeClosure() {
  13615. function TagTree(width, height) {
  13616. var levelsLength = log2(Math.max(width, height)) + 1;
  13617. this.levels = [];
  13618. for (var i = 0; i < levelsLength; i++) {
  13619. var level = {
  13620. width: width,
  13621. height: height,
  13622. items: []
  13623. };
  13624. this.levels.push(level);
  13625. width = Math.ceil(width / 2);
  13626. height = Math.ceil(height / 2);
  13627. }
  13628. }
  13629. TagTree.prototype = {
  13630. reset: function TagTree_reset(i, j) {
  13631. var currentLevel = 0, value = 0, level;
  13632. while (currentLevel < this.levels.length) {
  13633. level = this.levels[currentLevel];
  13634. var index = i + j * level.width;
  13635. if (level.items[index] !== undefined) {
  13636. value = level.items[index];
  13637. break;
  13638. }
  13639. level.index = index;
  13640. i >>= 1;
  13641. j >>= 1;
  13642. currentLevel++;
  13643. }
  13644. currentLevel--;
  13645. level = this.levels[currentLevel];
  13646. level.items[level.index] = value;
  13647. this.currentLevel = currentLevel;
  13648. delete this.value;
  13649. },
  13650. incrementValue: function TagTree_incrementValue() {
  13651. var level = this.levels[this.currentLevel];
  13652. level.items[level.index]++;
  13653. },
  13654. nextLevel: function TagTree_nextLevel() {
  13655. var currentLevel = this.currentLevel;
  13656. var level = this.levels[currentLevel];
  13657. var value = level.items[level.index];
  13658. currentLevel--;
  13659. if (currentLevel < 0) {
  13660. this.value = value;
  13661. return false;
  13662. }
  13663. this.currentLevel = currentLevel;
  13664. level = this.levels[currentLevel];
  13665. level.items[level.index] = value;
  13666. return true;
  13667. }
  13668. };
  13669. return TagTree;
  13670. })();
  13671. var InclusionTree = (function InclusionTreeClosure() {
  13672. function InclusionTree(width, height, defaultValue) {
  13673. var levelsLength = log2(Math.max(width, height)) + 1;
  13674. this.levels = [];
  13675. for (var i = 0; i < levelsLength; i++) {
  13676. var items = new Uint8Array(width * height);
  13677. for (var j = 0, jj = items.length; j < jj; j++) {
  13678. items[j] = defaultValue;
  13679. }
  13680. var level = {
  13681. width: width,
  13682. height: height,
  13683. items: items
  13684. };
  13685. this.levels.push(level);
  13686. width = Math.ceil(width / 2);
  13687. height = Math.ceil(height / 2);
  13688. }
  13689. }
  13690. InclusionTree.prototype = {
  13691. reset: function InclusionTree_reset(i, j, stopValue) {
  13692. var currentLevel = 0;
  13693. while (currentLevel < this.levels.length) {
  13694. var level = this.levels[currentLevel];
  13695. var index = i + j * level.width;
  13696. level.index = index;
  13697. var value = level.items[index];
  13698. if (value === 0xFF) {
  13699. break;
  13700. }
  13701. if (value > stopValue) {
  13702. this.currentLevel = currentLevel;
  13703. // already know about this one, propagating the value to top levels
  13704. this.propagateValues();
  13705. return false;
  13706. }
  13707. i >>= 1;
  13708. j >>= 1;
  13709. currentLevel++;
  13710. }
  13711. this.currentLevel = currentLevel - 1;
  13712. return true;
  13713. },
  13714. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13715. var level = this.levels[this.currentLevel];
  13716. level.items[level.index] = stopValue + 1;
  13717. this.propagateValues();
  13718. },
  13719. propagateValues: function InclusionTree_propagateValues() {
  13720. var levelIndex = this.currentLevel;
  13721. var level = this.levels[levelIndex];
  13722. var currentValue = level.items[level.index];
  13723. while (--levelIndex >= 0) {
  13724. level = this.levels[levelIndex];
  13725. level.items[level.index] = currentValue;
  13726. }
  13727. },
  13728. nextLevel: function InclusionTree_nextLevel() {
  13729. var currentLevel = this.currentLevel;
  13730. var level = this.levels[currentLevel];
  13731. var value = level.items[level.index];
  13732. level.items[level.index] = 0xFF;
  13733. currentLevel--;
  13734. if (currentLevel < 0) {
  13735. return false;
  13736. }
  13737. this.currentLevel = currentLevel;
  13738. level = this.levels[currentLevel];
  13739. level.items[level.index] = value;
  13740. return true;
  13741. }
  13742. };
  13743. return InclusionTree;
  13744. })();
  13745. // Section D. Coefficient bit modeling
  13746. var BitModel = (function BitModelClosure() {
  13747. var UNIFORM_CONTEXT = 17;
  13748. var RUNLENGTH_CONTEXT = 18;
  13749. // Table D-1
  13750. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13751. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13752. var LLAndLHContextsLabel = new Uint8Array([
  13753. 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,
  13754. 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,
  13755. 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
  13756. ]);
  13757. var HLContextLabel = new Uint8Array([
  13758. 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,
  13759. 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,
  13760. 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
  13761. ]);
  13762. var HHContextLabel = new Uint8Array([
  13763. 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,
  13764. 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,
  13765. 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
  13766. ]);
  13767. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13768. this.width = width;
  13769. this.height = height;
  13770. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13771. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13772. var coefficientCount = width * height;
  13773. // coefficients outside the encoding region treated as insignificant
  13774. // add border state cells for significanceState
  13775. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13776. this.coefficentsSign = new Uint8Array(coefficientCount);
  13777. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13778. mb > 6 ? new Uint16Array(coefficientCount) :
  13779. new Uint8Array(coefficientCount);
  13780. this.processingFlags = new Uint8Array(coefficientCount);
  13781. var bitsDecoded = new Uint8Array(coefficientCount);
  13782. if (zeroBitPlanes !== 0) {
  13783. for (var i = 0; i < coefficientCount; i++) {
  13784. bitsDecoded[i] = zeroBitPlanes;
  13785. }
  13786. }
  13787. this.bitsDecoded = bitsDecoded;
  13788. this.reset();
  13789. }
  13790. BitModel.prototype = {
  13791. setDecoder: function BitModel_setDecoder(decoder) {
  13792. this.decoder = decoder;
  13793. },
  13794. reset: function BitModel_reset() {
  13795. // We have 17 contexts that are accessed via context labels,
  13796. // plus the uniform and runlength context.
  13797. this.contexts = new Int8Array(19);
  13798. // Contexts are packed into 1 byte:
  13799. // highest 7 bits carry the index, lowest bit carries mps
  13800. this.contexts[0] = (4 << 1) | 0;
  13801. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13802. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13803. },
  13804. setNeighborsSignificance:
  13805. function BitModel_setNeighborsSignificance(row, column, index) {
  13806. var neighborsSignificance = this.neighborsSignificance;
  13807. var width = this.width, height = this.height;
  13808. var left = (column > 0);
  13809. var right = (column + 1 < width);
  13810. var i;
  13811. if (row > 0) {
  13812. i = index - width;
  13813. if (left) {
  13814. neighborsSignificance[i - 1] += 0x10;
  13815. }
  13816. if (right) {
  13817. neighborsSignificance[i + 1] += 0x10;
  13818. }
  13819. neighborsSignificance[i] += 0x04;
  13820. }
  13821. if (row + 1 < height) {
  13822. i = index + width;
  13823. if (left) {
  13824. neighborsSignificance[i - 1] += 0x10;
  13825. }
  13826. if (right) {
  13827. neighborsSignificance[i + 1] += 0x10;
  13828. }
  13829. neighborsSignificance[i] += 0x04;
  13830. }
  13831. if (left) {
  13832. neighborsSignificance[index - 1] += 0x01;
  13833. }
  13834. if (right) {
  13835. neighborsSignificance[index + 1] += 0x01;
  13836. }
  13837. neighborsSignificance[index] |= 0x80;
  13838. },
  13839. runSignificancePropogationPass:
  13840. function BitModel_runSignificancePropogationPass() {
  13841. var decoder = this.decoder;
  13842. var width = this.width, height = this.height;
  13843. var coefficentsMagnitude = this.coefficentsMagnitude;
  13844. var coefficentsSign = this.coefficentsSign;
  13845. var neighborsSignificance = this.neighborsSignificance;
  13846. var processingFlags = this.processingFlags;
  13847. var contexts = this.contexts;
  13848. var labels = this.contextLabelTable;
  13849. var bitsDecoded = this.bitsDecoded;
  13850. var processedInverseMask = ~1;
  13851. var processedMask = 1;
  13852. var firstMagnitudeBitMask = 2;
  13853. for (var i0 = 0; i0 < height; i0 += 4) {
  13854. for (var j = 0; j < width; j++) {
  13855. var index = i0 * width + j;
  13856. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13857. var i = i0 + i1;
  13858. if (i >= height) {
  13859. break;
  13860. }
  13861. // clear processed flag first
  13862. processingFlags[index] &= processedInverseMask;
  13863. if (coefficentsMagnitude[index] ||
  13864. !neighborsSignificance[index]) {
  13865. continue;
  13866. }
  13867. var contextLabel = labels[neighborsSignificance[index]];
  13868. var decision = decoder.readBit(contexts, contextLabel);
  13869. if (decision) {
  13870. var sign = this.decodeSignBit(i, j, index);
  13871. coefficentsSign[index] = sign;
  13872. coefficentsMagnitude[index] = 1;
  13873. this.setNeighborsSignificance(i, j, index);
  13874. processingFlags[index] |= firstMagnitudeBitMask;
  13875. }
  13876. bitsDecoded[index]++;
  13877. processingFlags[index] |= processedMask;
  13878. }
  13879. }
  13880. }
  13881. },
  13882. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13883. var width = this.width, height = this.height;
  13884. var coefficentsMagnitude = this.coefficentsMagnitude;
  13885. var coefficentsSign = this.coefficentsSign;
  13886. var contribution, sign0, sign1, significance1;
  13887. var contextLabel, decoded;
  13888. // calculate horizontal contribution
  13889. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13890. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13891. sign1 = coefficentsSign[index + 1];
  13892. if (significance1) {
  13893. sign0 = coefficentsSign[index - 1];
  13894. contribution = 1 - sign1 - sign0;
  13895. } else {
  13896. contribution = 1 - sign1 - sign1;
  13897. }
  13898. } else if (significance1) {
  13899. sign0 = coefficentsSign[index - 1];
  13900. contribution = 1 - sign0 - sign0;
  13901. } else {
  13902. contribution = 0;
  13903. }
  13904. var horizontalContribution = 3 * contribution;
  13905. // calculate vertical contribution and combine with the horizontal
  13906. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13907. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13908. sign1 = coefficentsSign[index + width];
  13909. if (significance1) {
  13910. sign0 = coefficentsSign[index - width];
  13911. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13912. } else {
  13913. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13914. }
  13915. } else if (significance1) {
  13916. sign0 = coefficentsSign[index - width];
  13917. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13918. } else {
  13919. contribution = horizontalContribution;
  13920. }
  13921. if (contribution >= 0) {
  13922. contextLabel = 9 + contribution;
  13923. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13924. } else {
  13925. contextLabel = 9 - contribution;
  13926. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13927. }
  13928. return decoded;
  13929. },
  13930. runMagnitudeRefinementPass:
  13931. function BitModel_runMagnitudeRefinementPass() {
  13932. var decoder = this.decoder;
  13933. var width = this.width, height = this.height;
  13934. var coefficentsMagnitude = this.coefficentsMagnitude;
  13935. var neighborsSignificance = this.neighborsSignificance;
  13936. var contexts = this.contexts;
  13937. var bitsDecoded = this.bitsDecoded;
  13938. var processingFlags = this.processingFlags;
  13939. var processedMask = 1;
  13940. var firstMagnitudeBitMask = 2;
  13941. var length = width * height;
  13942. var width4 = width * 4;
  13943. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13944. indexNext = Math.min(length, index0 + width4);
  13945. for (var j = 0; j < width; j++) {
  13946. for (var index = index0 + j; index < indexNext; index += width) {
  13947. // significant but not those that have just become
  13948. if (!coefficentsMagnitude[index] ||
  13949. (processingFlags[index] & processedMask) !== 0) {
  13950. continue;
  13951. }
  13952. var contextLabel = 16;
  13953. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13954. processingFlags[index] ^= firstMagnitudeBitMask;
  13955. // first refinement
  13956. var significance = neighborsSignificance[index] & 127;
  13957. contextLabel = significance === 0 ? 15 : 14;
  13958. }
  13959. var bit = decoder.readBit(contexts, contextLabel);
  13960. coefficentsMagnitude[index] =
  13961. (coefficentsMagnitude[index] << 1) | bit;
  13962. bitsDecoded[index]++;
  13963. processingFlags[index] |= processedMask;
  13964. }
  13965. }
  13966. }
  13967. },
  13968. runCleanupPass: function BitModel_runCleanupPass() {
  13969. var decoder = this.decoder;
  13970. var width = this.width, height = this.height;
  13971. var neighborsSignificance = this.neighborsSignificance;
  13972. var coefficentsMagnitude = this.coefficentsMagnitude;
  13973. var coefficentsSign = this.coefficentsSign;
  13974. var contexts = this.contexts;
  13975. var labels = this.contextLabelTable;
  13976. var bitsDecoded = this.bitsDecoded;
  13977. var processingFlags = this.processingFlags;
  13978. var processedMask = 1;
  13979. var firstMagnitudeBitMask = 2;
  13980. var oneRowDown = width;
  13981. var twoRowsDown = width * 2;
  13982. var threeRowsDown = width * 3;
  13983. var iNext;
  13984. for (var i0 = 0; i0 < height; i0 = iNext) {
  13985. iNext = Math.min(i0 + 4, height);
  13986. var indexBase = i0 * width;
  13987. var checkAllEmpty = i0 + 3 < height;
  13988. for (var j = 0; j < width; j++) {
  13989. var index0 = indexBase + j;
  13990. // using the property: labels[neighborsSignificance[index]] === 0
  13991. // when neighborsSignificance[index] === 0
  13992. var allEmpty = (checkAllEmpty &&
  13993. processingFlags[index0] === 0 &&
  13994. processingFlags[index0 + oneRowDown] === 0 &&
  13995. processingFlags[index0 + twoRowsDown] === 0 &&
  13996. processingFlags[index0 + threeRowsDown] === 0 &&
  13997. neighborsSignificance[index0] === 0 &&
  13998. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13999. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14000. neighborsSignificance[index0 + threeRowsDown] === 0);
  14001. var i1 = 0, index = index0;
  14002. var i = i0, sign;
  14003. if (allEmpty) {
  14004. var hasSignificantCoefficent =
  14005. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14006. if (!hasSignificantCoefficent) {
  14007. bitsDecoded[index0]++;
  14008. bitsDecoded[index0 + oneRowDown]++;
  14009. bitsDecoded[index0 + twoRowsDown]++;
  14010. bitsDecoded[index0 + threeRowsDown]++;
  14011. continue; // next column
  14012. }
  14013. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14014. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14015. if (i1 !== 0) {
  14016. i = i0 + i1;
  14017. index += i1 * width;
  14018. }
  14019. sign = this.decodeSignBit(i, j, index);
  14020. coefficentsSign[index] = sign;
  14021. coefficentsMagnitude[index] = 1;
  14022. this.setNeighborsSignificance(i, j, index);
  14023. processingFlags[index] |= firstMagnitudeBitMask;
  14024. index = index0;
  14025. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14026. bitsDecoded[index]++;
  14027. }
  14028. i1++;
  14029. }
  14030. for (i = i0 + i1; i < iNext; i++, index += width) {
  14031. if (coefficentsMagnitude[index] ||
  14032. (processingFlags[index] & processedMask) !== 0) {
  14033. continue;
  14034. }
  14035. var contextLabel = labels[neighborsSignificance[index]];
  14036. var decision = decoder.readBit(contexts, contextLabel);
  14037. if (decision === 1) {
  14038. sign = this.decodeSignBit(i, j, index);
  14039. coefficentsSign[index] = sign;
  14040. coefficentsMagnitude[index] = 1;
  14041. this.setNeighborsSignificance(i, j, index);
  14042. processingFlags[index] |= firstMagnitudeBitMask;
  14043. }
  14044. bitsDecoded[index]++;
  14045. }
  14046. }
  14047. }
  14048. },
  14049. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14050. var decoder = this.decoder;
  14051. var contexts = this.contexts;
  14052. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14053. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14054. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14055. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14056. if (symbol !== 0xA) {
  14057. throw new Error('JPX Error: Invalid segmentation symbol');
  14058. }
  14059. }
  14060. };
  14061. return BitModel;
  14062. })();
  14063. // Section F, Discrete wavelet transformation
  14064. var Transform = (function TransformClosure() {
  14065. function Transform() {}
  14066. Transform.prototype.calculate =
  14067. function transformCalculate(subbands, u0, v0) {
  14068. var ll = subbands[0];
  14069. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14070. ll = this.iterate(ll, subbands[i], u0, v0);
  14071. }
  14072. return ll;
  14073. };
  14074. Transform.prototype.extend = function extend(buffer, offset, size) {
  14075. // Section F.3.7 extending... using max extension of 4
  14076. var i1 = offset - 1, j1 = offset + 1;
  14077. var i2 = offset + size - 2, j2 = offset + size;
  14078. buffer[i1--] = buffer[j1++];
  14079. buffer[j2++] = buffer[i2--];
  14080. buffer[i1--] = buffer[j1++];
  14081. buffer[j2++] = buffer[i2--];
  14082. buffer[i1--] = buffer[j1++];
  14083. buffer[j2++] = buffer[i2--];
  14084. buffer[i1] = buffer[j1];
  14085. buffer[j2] = buffer[i2];
  14086. };
  14087. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14088. u0, v0) {
  14089. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14090. var width = hl_lh_hh.width;
  14091. var height = hl_lh_hh.height;
  14092. var items = hl_lh_hh.items;
  14093. var i, j, k, l, u, v;
  14094. // Interleave LL according to Section F.3.3
  14095. for (k = 0, i = 0; i < llHeight; i++) {
  14096. l = i * 2 * width;
  14097. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14098. items[l] = llItems[k];
  14099. }
  14100. }
  14101. // The LL band is not needed anymore.
  14102. llItems = ll.items = null;
  14103. var bufferPadding = 4;
  14104. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14105. // Section F.3.4 HOR_SR
  14106. if (width === 1) {
  14107. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14108. if ((u0 & 1) !== 0) {
  14109. for (v = 0, k = 0; v < height; v++, k += width) {
  14110. items[k] *= 0.5;
  14111. }
  14112. }
  14113. } else {
  14114. for (v = 0, k = 0; v < height; v++, k += width) {
  14115. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14116. this.extend(rowBuffer, bufferPadding, width);
  14117. this.filter(rowBuffer, bufferPadding, width);
  14118. items.set(
  14119. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14120. k);
  14121. }
  14122. }
  14123. // Accesses to the items array can take long, because it may not fit into
  14124. // CPU cache and has to be fetched from main memory. Since subsequent
  14125. // accesses to the items array are not local when reading columns, we
  14126. // have a cache miss every time. To reduce cache misses, get up to
  14127. // 'numBuffers' items at a time and store them into the individual
  14128. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14129. var numBuffers = 16;
  14130. var colBuffers = [];
  14131. for (i = 0; i < numBuffers; i++) {
  14132. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14133. }
  14134. var b, currentBuffer = 0;
  14135. ll = bufferPadding + height;
  14136. // Section F.3.5 VER_SR
  14137. if (height === 1) {
  14138. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14139. if ((v0 & 1) !== 0) {
  14140. for (u = 0; u < width; u++) {
  14141. items[u] *= 0.5;
  14142. }
  14143. }
  14144. } else {
  14145. for (u = 0; u < width; u++) {
  14146. // if we ran out of buffers, copy several image columns at once
  14147. if (currentBuffer === 0) {
  14148. numBuffers = Math.min(width - u, numBuffers);
  14149. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14150. for (b = 0; b < numBuffers; b++) {
  14151. colBuffers[b][l] = items[k + b];
  14152. }
  14153. }
  14154. currentBuffer = numBuffers;
  14155. }
  14156. currentBuffer--;
  14157. var buffer = colBuffers[currentBuffer];
  14158. this.extend(buffer, bufferPadding, height);
  14159. this.filter(buffer, bufferPadding, height);
  14160. // If this is last buffer in this group of buffers, flush all buffers.
  14161. if (currentBuffer === 0) {
  14162. k = u - numBuffers + 1;
  14163. for (l = bufferPadding; l < ll; k += width, l++) {
  14164. for (b = 0; b < numBuffers; b++) {
  14165. items[k + b] = colBuffers[b][l];
  14166. }
  14167. }
  14168. }
  14169. }
  14170. }
  14171. return {
  14172. width: width,
  14173. height: height,
  14174. items: items
  14175. };
  14176. };
  14177. return Transform;
  14178. })();
  14179. // Section 3.8.2 Irreversible 9-7 filter
  14180. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14181. function IrreversibleTransform() {
  14182. Transform.call(this);
  14183. }
  14184. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14185. IrreversibleTransform.prototype.filter =
  14186. function irreversibleTransformFilter(x, offset, length) {
  14187. var len = length >> 1;
  14188. offset = offset | 0;
  14189. var j, n, current, next;
  14190. var alpha = -1.586134342059924;
  14191. var beta = -0.052980118572961;
  14192. var gamma = 0.882911075530934;
  14193. var delta = 0.443506852043971;
  14194. var K = 1.230174104914001;
  14195. var K_ = 1 / K;
  14196. // step 1 is combined with step 3
  14197. // step 2
  14198. j = offset - 3;
  14199. for (n = len + 4; n--; j += 2) {
  14200. x[j] *= K_;
  14201. }
  14202. // step 1 & 3
  14203. j = offset - 2;
  14204. current = delta * x[j -1];
  14205. for (n = len + 3; n--; j += 2) {
  14206. next = delta * x[j + 1];
  14207. x[j] = K * x[j] - current - next;
  14208. if (n--) {
  14209. j += 2;
  14210. current = delta * x[j + 1];
  14211. x[j] = K * x[j] - current - next;
  14212. } else {
  14213. break;
  14214. }
  14215. }
  14216. // step 4
  14217. j = offset - 1;
  14218. current = gamma * x[j - 1];
  14219. for (n = len + 2; n--; j += 2) {
  14220. next = gamma * x[j + 1];
  14221. x[j] -= current + next;
  14222. if (n--) {
  14223. j += 2;
  14224. current = gamma * x[j + 1];
  14225. x[j] -= current + next;
  14226. } else {
  14227. break;
  14228. }
  14229. }
  14230. // step 5
  14231. j = offset;
  14232. current = beta * x[j - 1];
  14233. for (n = len + 1; n--; j += 2) {
  14234. next = beta * x[j + 1];
  14235. x[j] -= current + next;
  14236. if (n--) {
  14237. j += 2;
  14238. current = beta * x[j + 1];
  14239. x[j] -= current + next;
  14240. } else {
  14241. break;
  14242. }
  14243. }
  14244. // step 6
  14245. if (len !== 0) {
  14246. j = offset + 1;
  14247. current = alpha * x[j - 1];
  14248. for (n = len; n--; j += 2) {
  14249. next = alpha * x[j + 1];
  14250. x[j] -= current + next;
  14251. if (n--) {
  14252. j += 2;
  14253. current = alpha * x[j + 1];
  14254. x[j] -= current + next;
  14255. } else {
  14256. break;
  14257. }
  14258. }
  14259. }
  14260. };
  14261. return IrreversibleTransform;
  14262. })();
  14263. // Section 3.8.1 Reversible 5-3 filter
  14264. var ReversibleTransform = (function ReversibleTransformClosure() {
  14265. function ReversibleTransform() {
  14266. Transform.call(this);
  14267. }
  14268. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14269. ReversibleTransform.prototype.filter =
  14270. function reversibleTransformFilter(x, offset, length) {
  14271. var len = length >> 1;
  14272. offset = offset | 0;
  14273. var j, n;
  14274. for (j = offset, n = len + 1; n--; j += 2) {
  14275. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14276. }
  14277. for (j = offset + 1, n = len; n--; j += 2) {
  14278. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14279. }
  14280. };
  14281. return ReversibleTransform;
  14282. })();
  14283. return JpxImage;
  14284. })();
  14285. exports.JpxImage = JpxImage;
  14286. }));
  14287. (function (root, factory) {
  14288. {
  14289. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14290. }
  14291. }(this, function (exports, sharedUtil) {
  14292. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14293. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14294. // Workaround for missing math precison in JS.
  14295. var MASK_HIGH = 0xffff0000;
  14296. var MASK_LOW = 0xffff;
  14297. function MurmurHash3_64 (seed) {
  14298. var SEED = 0xc3d2e1f0;
  14299. this.h1 = seed ? seed & 0xffffffff : SEED;
  14300. this.h2 = seed ? seed & 0xffffffff : SEED;
  14301. }
  14302. var alwaysUseUint32ArrayView = false;
  14303. // old webkits have issues with non-aligned arrays
  14304. try {
  14305. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14306. } catch (e) {
  14307. alwaysUseUint32ArrayView = true;
  14308. }
  14309. MurmurHash3_64.prototype = {
  14310. update: function MurmurHash3_64_update(input) {
  14311. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14312. var i;
  14313. if (typeof input === 'string') {
  14314. var data = new Uint8Array(input.length * 2);
  14315. var length = 0;
  14316. for (i = 0; i < input.length; i++) {
  14317. var code = input.charCodeAt(i);
  14318. if (code <= 0xff) {
  14319. data[length++] = code;
  14320. }
  14321. else {
  14322. data[length++] = code >>> 8;
  14323. data[length++] = code & 0xff;
  14324. }
  14325. }
  14326. } else if (input instanceof Uint8Array) {
  14327. data = input;
  14328. length = data.length;
  14329. } else if (typeof input === 'object' && ('length' in input)) {
  14330. // processing regular arrays as well, e.g. for IE9
  14331. data = input;
  14332. length = data.length;
  14333. useUint32ArrayView = true;
  14334. } else {
  14335. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14336. 'Input must be a string or array.');
  14337. }
  14338. var blockCounts = length >> 2;
  14339. var tailLength = length - blockCounts * 4;
  14340. // we don't care about endianness here
  14341. var dataUint32 = useUint32ArrayView ?
  14342. new Uint32ArrayView(data, blockCounts) :
  14343. new Uint32Array(data.buffer, 0, blockCounts);
  14344. var k1 = 0;
  14345. var k2 = 0;
  14346. var h1 = this.h1;
  14347. var h2 = this.h2;
  14348. var C1 = 0xcc9e2d51;
  14349. var C2 = 0x1b873593;
  14350. var C1_LOW = C1 & MASK_LOW;
  14351. var C2_LOW = C2 & MASK_LOW;
  14352. for (i = 0; i < blockCounts; i++) {
  14353. if (i & 1) {
  14354. k1 = dataUint32[i];
  14355. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14356. k1 = k1 << 15 | k1 >>> 17;
  14357. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14358. h1 ^= k1;
  14359. h1 = h1 << 13 | h1 >>> 19;
  14360. h1 = h1 * 5 + 0xe6546b64;
  14361. } else {
  14362. k2 = dataUint32[i];
  14363. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14364. k2 = k2 << 15 | k2 >>> 17;
  14365. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14366. h2 ^= k2;
  14367. h2 = h2 << 13 | h2 >>> 19;
  14368. h2 = h2 * 5 + 0xe6546b64;
  14369. }
  14370. }
  14371. k1 = 0;
  14372. switch (tailLength) {
  14373. case 3:
  14374. k1 ^= data[blockCounts * 4 + 2] << 16;
  14375. /* falls through */
  14376. case 2:
  14377. k1 ^= data[blockCounts * 4 + 1] << 8;
  14378. /* falls through */
  14379. case 1:
  14380. k1 ^= data[blockCounts * 4];
  14381. /* falls through */
  14382. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14383. k1 = k1 << 15 | k1 >>> 17;
  14384. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14385. if (blockCounts & 1) {
  14386. h1 ^= k1;
  14387. } else {
  14388. h2 ^= k1;
  14389. }
  14390. }
  14391. this.h1 = h1;
  14392. this.h2 = h2;
  14393. return this;
  14394. },
  14395. hexdigest: function MurmurHash3_64_hexdigest () {
  14396. var h1 = this.h1;
  14397. var h2 = this.h2;
  14398. h1 ^= h2 >>> 1;
  14399. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  14400. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  14401. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  14402. h1 ^= h2 >>> 1;
  14403. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  14404. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  14405. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  14406. h1 ^= h2 >>> 1;
  14407. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  14408. var hex = (arr[i] >>> 0).toString(16);
  14409. while (hex.length < 8) {
  14410. hex = '0' + hex;
  14411. }
  14412. str += hex;
  14413. }
  14414. return str;
  14415. }
  14416. };
  14417. return MurmurHash3_64;
  14418. })();
  14419. exports.MurmurHash3_64 = MurmurHash3_64;
  14420. }));
  14421. (function (root, factory) {
  14422. {
  14423. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  14424. }
  14425. }(this, function (exports, sharedUtil) {
  14426. var isArray = sharedUtil.isArray;
  14427. var Name = (function NameClosure() {
  14428. function Name(name) {
  14429. this.name = name;
  14430. }
  14431. Name.prototype = {};
  14432. var nameCache = {};
  14433. Name.get = function Name_get(name) {
  14434. var nameValue = nameCache[name];
  14435. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  14436. };
  14437. return Name;
  14438. })();
  14439. var Cmd = (function CmdClosure() {
  14440. function Cmd(cmd) {
  14441. this.cmd = cmd;
  14442. }
  14443. Cmd.prototype = {};
  14444. var cmdCache = {};
  14445. Cmd.get = function Cmd_get(cmd) {
  14446. var cmdValue = cmdCache[cmd];
  14447. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  14448. };
  14449. return Cmd;
  14450. })();
  14451. var Dict = (function DictClosure() {
  14452. var nonSerializable = function nonSerializableClosure() {
  14453. return nonSerializable; // creating closure on some variable
  14454. };
  14455. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  14456. 'Background': true,
  14457. 'ExtGState': true,
  14458. 'Halftone': true,
  14459. 'Layout': true,
  14460. 'Mask': true,
  14461. 'Pagination': true,
  14462. 'Printing': true
  14463. };
  14464. function isRecursionAllowedFor(dict) {
  14465. if (!isName(dict.Type)) {
  14466. return true;
  14467. }
  14468. var dictType = dict.Type.name;
  14469. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  14470. }
  14471. // xref is optional
  14472. function Dict(xref) {
  14473. // Map should only be used internally, use functions below to access.
  14474. this.map = Object.create(null);
  14475. this.xref = xref;
  14476. this.objId = null;
  14477. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  14478. }
  14479. Dict.prototype = {
  14480. assignXref: function Dict_assignXref(newXref) {
  14481. this.xref = newXref;
  14482. },
  14483. // automatically dereferences Ref objects
  14484. get: function Dict_get(key1, key2, key3) {
  14485. var value;
  14486. var xref = this.xref;
  14487. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14488. typeof key2 === 'undefined') {
  14489. return xref ? xref.fetchIfRef(value) : value;
  14490. }
  14491. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14492. typeof key3 === 'undefined') {
  14493. return xref ? xref.fetchIfRef(value) : value;
  14494. }
  14495. value = this.map[key3] || null;
  14496. return xref ? xref.fetchIfRef(value) : value;
  14497. },
  14498. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  14499. getAsync: function Dict_getAsync(key1, key2, key3) {
  14500. var value;
  14501. var xref = this.xref;
  14502. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14503. typeof key2 === 'undefined') {
  14504. if (xref) {
  14505. return xref.fetchIfRefAsync(value);
  14506. }
  14507. return Promise.resolve(value);
  14508. }
  14509. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14510. typeof key3 === 'undefined') {
  14511. if (xref) {
  14512. return xref.fetchIfRefAsync(value);
  14513. }
  14514. return Promise.resolve(value);
  14515. }
  14516. value = this.map[key3] || null;
  14517. if (xref) {
  14518. return xref.fetchIfRefAsync(value);
  14519. }
  14520. return Promise.resolve(value);
  14521. },
  14522. // Same as get(), but dereferences all elements if the result is an Array.
  14523. getArray: function Dict_getArray(key1, key2, key3) {
  14524. var value = this.get(key1, key2, key3);
  14525. var xref = this.xref;
  14526. if (!isArray(value) || !xref) {
  14527. return value;
  14528. }
  14529. value = value.slice(); // Ensure that we don't modify the Dict data.
  14530. for (var i = 0, ii = value.length; i < ii; i++) {
  14531. if (!isRef(value[i])) {
  14532. continue;
  14533. }
  14534. value[i] = xref.fetch(value[i]);
  14535. }
  14536. return value;
  14537. },
  14538. // no dereferencing
  14539. getRaw: function Dict_getRaw(key) {
  14540. return this.map[key];
  14541. },
  14542. // creates new map and dereferences all Refs
  14543. getAll: function Dict_getAll() {
  14544. var all = Object.create(null);
  14545. var queue = null;
  14546. var key, obj;
  14547. for (key in this.map) {
  14548. obj = this.get(key);
  14549. if (obj instanceof Dict) {
  14550. if (isRecursionAllowedFor(obj)) {
  14551. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  14552. } else {
  14553. all[key] = this.getRaw(key);
  14554. }
  14555. } else {
  14556. all[key] = obj;
  14557. }
  14558. }
  14559. if (!queue) {
  14560. return all;
  14561. }
  14562. // trying to take cyclic references into the account
  14563. var processed = Object.create(null);
  14564. while (queue.length > 0) {
  14565. var item = queue.shift();
  14566. var itemObj = item.obj;
  14567. var objId = itemObj.objId;
  14568. if (objId && objId in processed) {
  14569. item.target[item.key] = processed[objId];
  14570. continue;
  14571. }
  14572. var dereferenced = Object.create(null);
  14573. for (key in itemObj.map) {
  14574. obj = itemObj.get(key);
  14575. if (obj instanceof Dict) {
  14576. if (isRecursionAllowedFor(obj)) {
  14577. queue.push({target: dereferenced, key: key, obj: obj});
  14578. } else {
  14579. dereferenced[key] = itemObj.getRaw(key);
  14580. }
  14581. } else {
  14582. dereferenced[key] = obj;
  14583. }
  14584. }
  14585. if (objId) {
  14586. processed[objId] = dereferenced;
  14587. }
  14588. item.target[item.key] = dereferenced;
  14589. }
  14590. return all;
  14591. },
  14592. getKeys: function Dict_getKeys() {
  14593. return Object.keys(this.map);
  14594. },
  14595. set: function Dict_set(key, value) {
  14596. this.map[key] = value;
  14597. },
  14598. has: function Dict_has(key) {
  14599. return key in this.map;
  14600. },
  14601. forEach: function Dict_forEach(callback) {
  14602. for (var key in this.map) {
  14603. callback(key, this.get(key));
  14604. }
  14605. }
  14606. };
  14607. Dict.empty = new Dict(null);
  14608. Dict.merge = function Dict_merge(xref, dictArray) {
  14609. var mergedDict = new Dict(xref);
  14610. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  14611. var dict = dictArray[i];
  14612. if (!isDict(dict)) {
  14613. continue;
  14614. }
  14615. for (var keyName in dict.map) {
  14616. if (mergedDict.map[keyName]) {
  14617. continue;
  14618. }
  14619. mergedDict.map[keyName] = dict.map[keyName];
  14620. }
  14621. }
  14622. return mergedDict;
  14623. };
  14624. return Dict;
  14625. })();
  14626. var Ref = (function RefClosure() {
  14627. function Ref(num, gen) {
  14628. this.num = num;
  14629. this.gen = gen;
  14630. }
  14631. Ref.prototype = {
  14632. toString: function Ref_toString() {
  14633. // This function is hot, so we make the string as compact as possible.
  14634. // |this.gen| is almost always zero, so we treat that case specially.
  14635. var str = this.num + 'R';
  14636. if (this.gen !== 0) {
  14637. str += this.gen;
  14638. }
  14639. return str;
  14640. }
  14641. };
  14642. return Ref;
  14643. })();
  14644. // The reference is identified by number and generation.
  14645. // This structure stores only one instance of the reference.
  14646. var RefSet = (function RefSetClosure() {
  14647. function RefSet() {
  14648. this.dict = {};
  14649. }
  14650. RefSet.prototype = {
  14651. has: function RefSet_has(ref) {
  14652. return ref.toString() in this.dict;
  14653. },
  14654. put: function RefSet_put(ref) {
  14655. this.dict[ref.toString()] = true;
  14656. },
  14657. remove: function RefSet_remove(ref) {
  14658. delete this.dict[ref.toString()];
  14659. }
  14660. };
  14661. return RefSet;
  14662. })();
  14663. var RefSetCache = (function RefSetCacheClosure() {
  14664. function RefSetCache() {
  14665. this.dict = Object.create(null);
  14666. }
  14667. RefSetCache.prototype = {
  14668. get: function RefSetCache_get(ref) {
  14669. return this.dict[ref.toString()];
  14670. },
  14671. has: function RefSetCache_has(ref) {
  14672. return ref.toString() in this.dict;
  14673. },
  14674. put: function RefSetCache_put(ref, obj) {
  14675. this.dict[ref.toString()] = obj;
  14676. },
  14677. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  14678. this.dict[ref.toString()] = this.get(aliasRef);
  14679. },
  14680. forEach: function RefSetCache_forEach(fn, thisArg) {
  14681. for (var i in this.dict) {
  14682. fn.call(thisArg, this.dict[i]);
  14683. }
  14684. },
  14685. clear: function RefSetCache_clear() {
  14686. this.dict = Object.create(null);
  14687. }
  14688. };
  14689. return RefSetCache;
  14690. })();
  14691. function isName(v) {
  14692. return v instanceof Name;
  14693. }
  14694. function isCmd(v, cmd) {
  14695. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  14696. }
  14697. function isDict(v, type) {
  14698. if (!(v instanceof Dict)) {
  14699. return false;
  14700. }
  14701. if (!type) {
  14702. return true;
  14703. }
  14704. var dictType = v.get('Type');
  14705. return isName(dictType) && dictType.name === type;
  14706. }
  14707. function isRef(v) {
  14708. return v instanceof Ref;
  14709. }
  14710. function isStream(v) {
  14711. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  14712. }
  14713. exports.Cmd = Cmd;
  14714. exports.Dict = Dict;
  14715. exports.Name = Name;
  14716. exports.Ref = Ref;
  14717. exports.RefSet = RefSet;
  14718. exports.RefSetCache = RefSetCache;
  14719. exports.isCmd = isCmd;
  14720. exports.isDict = isDict;
  14721. exports.isName = isName;
  14722. exports.isRef = isRef;
  14723. exports.isStream = isStream;
  14724. }));
  14725. (function (root, factory) {
  14726. {
  14727. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  14728. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  14729. root.pdfjsCoreJpx);
  14730. }
  14731. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  14732. coreJpx) {
  14733. var Util = sharedUtil.Util;
  14734. var error = sharedUtil.error;
  14735. var info = sharedUtil.info;
  14736. var isArray = sharedUtil.isArray;
  14737. var shadow = sharedUtil.shadow;
  14738. var warn = sharedUtil.warn;
  14739. var Dict = corePrimitives.Dict;
  14740. var Jbig2Image = coreJbig2.Jbig2Image;
  14741. var JpegImage = coreJpg.JpegImage;
  14742. var JpxImage = coreJpx.JpxImage;
  14743. var coreParser; // see _setCoreParser below
  14744. var EOF; // = coreParser.EOF;
  14745. var Lexer; // = coreParser.Lexer;
  14746. var coreColorSpace; // see _setCoreColorSpace below
  14747. var ColorSpace; // = coreColorSpace.ColorSpace;
  14748. var Stream = (function StreamClosure() {
  14749. function Stream(arrayBuffer, start, length, dict) {
  14750. this.bytes = (arrayBuffer instanceof Uint8Array ?
  14751. arrayBuffer : new Uint8Array(arrayBuffer));
  14752. this.start = start || 0;
  14753. this.pos = this.start;
  14754. this.end = (start + length) || this.bytes.length;
  14755. this.dict = dict;
  14756. }
  14757. // required methods for a stream. if a particular stream does not
  14758. // implement these, an error should be thrown
  14759. Stream.prototype = {
  14760. get length() {
  14761. return this.end - this.start;
  14762. },
  14763. get isEmpty() {
  14764. return this.length === 0;
  14765. },
  14766. getByte: function Stream_getByte() {
  14767. if (this.pos >= this.end) {
  14768. return -1;
  14769. }
  14770. return this.bytes[this.pos++];
  14771. },
  14772. getUint16: function Stream_getUint16() {
  14773. var b0 = this.getByte();
  14774. var b1 = this.getByte();
  14775. if (b0 === -1 || b1 === -1) {
  14776. return -1;
  14777. }
  14778. return (b0 << 8) + b1;
  14779. },
  14780. getInt32: function Stream_getInt32() {
  14781. var b0 = this.getByte();
  14782. var b1 = this.getByte();
  14783. var b2 = this.getByte();
  14784. var b3 = this.getByte();
  14785. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14786. },
  14787. // returns subarray of original buffer
  14788. // should only be read
  14789. getBytes: function Stream_getBytes(length) {
  14790. var bytes = this.bytes;
  14791. var pos = this.pos;
  14792. var strEnd = this.end;
  14793. if (!length) {
  14794. return bytes.subarray(pos, strEnd);
  14795. }
  14796. var end = pos + length;
  14797. if (end > strEnd) {
  14798. end = strEnd;
  14799. }
  14800. this.pos = end;
  14801. return bytes.subarray(pos, end);
  14802. },
  14803. peekByte: function Stream_peekByte() {
  14804. var peekedByte = this.getByte();
  14805. this.pos--;
  14806. return peekedByte;
  14807. },
  14808. peekBytes: function Stream_peekBytes(length) {
  14809. var bytes = this.getBytes(length);
  14810. this.pos -= bytes.length;
  14811. return bytes;
  14812. },
  14813. skip: function Stream_skip(n) {
  14814. if (!n) {
  14815. n = 1;
  14816. }
  14817. this.pos += n;
  14818. },
  14819. reset: function Stream_reset() {
  14820. this.pos = this.start;
  14821. },
  14822. moveStart: function Stream_moveStart() {
  14823. this.start = this.pos;
  14824. },
  14825. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  14826. return new Stream(this.bytes.buffer, start, length, dict);
  14827. },
  14828. isStream: true
  14829. };
  14830. return Stream;
  14831. })();
  14832. var StringStream = (function StringStreamClosure() {
  14833. function StringStream(str) {
  14834. var length = str.length;
  14835. var bytes = new Uint8Array(length);
  14836. for (var n = 0; n < length; ++n) {
  14837. bytes[n] = str.charCodeAt(n);
  14838. }
  14839. Stream.call(this, bytes);
  14840. }
  14841. StringStream.prototype = Stream.prototype;
  14842. return StringStream;
  14843. })();
  14844. // super class for the decoding streams
  14845. var DecodeStream = (function DecodeStreamClosure() {
  14846. // Lots of DecodeStreams are created whose buffers are never used. For these
  14847. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  14848. // having special cases that would be required if we used |null| for an empty
  14849. // buffer.
  14850. var emptyBuffer = new Uint8Array(0);
  14851. function DecodeStream(maybeMinBufferLength) {
  14852. this.pos = 0;
  14853. this.bufferLength = 0;
  14854. this.eof = false;
  14855. this.buffer = emptyBuffer;
  14856. this.minBufferLength = 512;
  14857. if (maybeMinBufferLength) {
  14858. // Compute the first power of two that is as big as maybeMinBufferLength.
  14859. while (this.minBufferLength < maybeMinBufferLength) {
  14860. this.minBufferLength *= 2;
  14861. }
  14862. }
  14863. }
  14864. DecodeStream.prototype = {
  14865. get isEmpty() {
  14866. while (!this.eof && this.bufferLength === 0) {
  14867. this.readBlock();
  14868. }
  14869. return this.bufferLength === 0;
  14870. },
  14871. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  14872. var buffer = this.buffer;
  14873. if (requested <= buffer.byteLength) {
  14874. return buffer;
  14875. }
  14876. var size = this.minBufferLength;
  14877. while (size < requested) {
  14878. size *= 2;
  14879. }
  14880. var buffer2 = new Uint8Array(size);
  14881. buffer2.set(buffer);
  14882. return (this.buffer = buffer2);
  14883. },
  14884. getByte: function DecodeStream_getByte() {
  14885. var pos = this.pos;
  14886. while (this.bufferLength <= pos) {
  14887. if (this.eof) {
  14888. return -1;
  14889. }
  14890. this.readBlock();
  14891. }
  14892. return this.buffer[this.pos++];
  14893. },
  14894. getUint16: function DecodeStream_getUint16() {
  14895. var b0 = this.getByte();
  14896. var b1 = this.getByte();
  14897. if (b0 === -1 || b1 === -1) {
  14898. return -1;
  14899. }
  14900. return (b0 << 8) + b1;
  14901. },
  14902. getInt32: function DecodeStream_getInt32() {
  14903. var b0 = this.getByte();
  14904. var b1 = this.getByte();
  14905. var b2 = this.getByte();
  14906. var b3 = this.getByte();
  14907. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14908. },
  14909. getBytes: function DecodeStream_getBytes(length) {
  14910. var end, pos = this.pos;
  14911. if (length) {
  14912. this.ensureBuffer(pos + length);
  14913. end = pos + length;
  14914. while (!this.eof && this.bufferLength < end) {
  14915. this.readBlock();
  14916. }
  14917. var bufEnd = this.bufferLength;
  14918. if (end > bufEnd) {
  14919. end = bufEnd;
  14920. }
  14921. } else {
  14922. while (!this.eof) {
  14923. this.readBlock();
  14924. }
  14925. end = this.bufferLength;
  14926. }
  14927. this.pos = end;
  14928. return this.buffer.subarray(pos, end);
  14929. },
  14930. peekByte: function DecodeStream_peekByte() {
  14931. var peekedByte = this.getByte();
  14932. this.pos--;
  14933. return peekedByte;
  14934. },
  14935. peekBytes: function DecodeStream_peekBytes(length) {
  14936. var bytes = this.getBytes(length);
  14937. this.pos -= bytes.length;
  14938. return bytes;
  14939. },
  14940. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  14941. var end = start + length;
  14942. while (this.bufferLength <= end && !this.eof) {
  14943. this.readBlock();
  14944. }
  14945. return new Stream(this.buffer, start, length, dict);
  14946. },
  14947. skip: function DecodeStream_skip(n) {
  14948. if (!n) {
  14949. n = 1;
  14950. }
  14951. this.pos += n;
  14952. },
  14953. reset: function DecodeStream_reset() {
  14954. this.pos = 0;
  14955. },
  14956. getBaseStreams: function DecodeStream_getBaseStreams() {
  14957. if (this.str && this.str.getBaseStreams) {
  14958. return this.str.getBaseStreams();
  14959. }
  14960. return [];
  14961. }
  14962. };
  14963. return DecodeStream;
  14964. })();
  14965. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  14966. function StreamsSequenceStream(streams) {
  14967. this.streams = streams;
  14968. DecodeStream.call(this, /* maybeLength = */ null);
  14969. }
  14970. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  14971. StreamsSequenceStream.prototype.readBlock =
  14972. function streamSequenceStreamReadBlock() {
  14973. var streams = this.streams;
  14974. if (streams.length === 0) {
  14975. this.eof = true;
  14976. return;
  14977. }
  14978. var stream = streams.shift();
  14979. var chunk = stream.getBytes();
  14980. var bufferLength = this.bufferLength;
  14981. var newLength = bufferLength + chunk.length;
  14982. var buffer = this.ensureBuffer(newLength);
  14983. buffer.set(chunk, bufferLength);
  14984. this.bufferLength = newLength;
  14985. };
  14986. StreamsSequenceStream.prototype.getBaseStreams =
  14987. function StreamsSequenceStream_getBaseStreams() {
  14988. var baseStreams = [];
  14989. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  14990. var stream = this.streams[i];
  14991. if (stream.getBaseStreams) {
  14992. Util.appendToArray(baseStreams, stream.getBaseStreams());
  14993. }
  14994. }
  14995. return baseStreams;
  14996. };
  14997. return StreamsSequenceStream;
  14998. })();
  14999. var FlateStream = (function FlateStreamClosure() {
  15000. var codeLenCodeMap = new Int32Array([
  15001. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  15002. ]);
  15003. var lengthDecode = new Int32Array([
  15004. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  15005. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  15006. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  15007. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  15008. ]);
  15009. var distDecode = new Int32Array([
  15010. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  15011. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  15012. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  15013. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  15014. ]);
  15015. var fixedLitCodeTab = [new Int32Array([
  15016. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  15017. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  15018. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  15019. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  15020. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  15021. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  15022. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  15023. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  15024. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  15025. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  15026. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  15027. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  15028. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  15029. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  15030. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  15031. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  15032. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  15033. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  15034. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  15035. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  15036. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  15037. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  15038. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  15039. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  15040. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  15041. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  15042. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  15043. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  15044. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  15045. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  15046. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  15047. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  15048. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  15049. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  15050. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  15051. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  15052. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  15053. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  15054. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  15055. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  15056. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  15057. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  15058. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  15059. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  15060. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  15061. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  15062. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  15063. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  15064. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  15065. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  15066. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  15067. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  15068. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  15069. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  15070. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  15071. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  15072. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  15073. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  15074. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  15075. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  15076. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  15077. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  15078. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  15079. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  15080. ]), 9];
  15081. var fixedDistCodeTab = [new Int32Array([
  15082. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  15083. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  15084. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  15085. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  15086. ]), 5];
  15087. function FlateStream(str, maybeLength) {
  15088. this.str = str;
  15089. this.dict = str.dict;
  15090. var cmf = str.getByte();
  15091. var flg = str.getByte();
  15092. if (cmf === -1 || flg === -1) {
  15093. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  15094. }
  15095. if ((cmf & 0x0f) !== 0x08) {
  15096. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  15097. }
  15098. if ((((cmf << 8) + flg) % 31) !== 0) {
  15099. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  15100. }
  15101. if (flg & 0x20) {
  15102. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  15103. }
  15104. this.codeSize = 0;
  15105. this.codeBuf = 0;
  15106. DecodeStream.call(this, maybeLength);
  15107. }
  15108. FlateStream.prototype = Object.create(DecodeStream.prototype);
  15109. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  15110. var str = this.str;
  15111. var codeSize = this.codeSize;
  15112. var codeBuf = this.codeBuf;
  15113. var b;
  15114. while (codeSize < bits) {
  15115. if ((b = str.getByte()) === -1) {
  15116. error('Bad encoding in flate stream');
  15117. }
  15118. codeBuf |= b << codeSize;
  15119. codeSize += 8;
  15120. }
  15121. b = codeBuf & ((1 << bits) - 1);
  15122. this.codeBuf = codeBuf >> bits;
  15123. this.codeSize = codeSize -= bits;
  15124. return b;
  15125. };
  15126. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  15127. var str = this.str;
  15128. var codes = table[0];
  15129. var maxLen = table[1];
  15130. var codeSize = this.codeSize;
  15131. var codeBuf = this.codeBuf;
  15132. var b;
  15133. while (codeSize < maxLen) {
  15134. if ((b = str.getByte()) === -1) {
  15135. // premature end of stream. code might however still be valid.
  15136. // codeSize < codeLen check below guards against incomplete codeVal.
  15137. break;
  15138. }
  15139. codeBuf |= (b << codeSize);
  15140. codeSize += 8;
  15141. }
  15142. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  15143. var codeLen = code >> 16;
  15144. var codeVal = code & 0xffff;
  15145. if (codeLen < 1 || codeSize < codeLen) {
  15146. error('Bad encoding in flate stream');
  15147. }
  15148. this.codeBuf = (codeBuf >> codeLen);
  15149. this.codeSize = (codeSize - codeLen);
  15150. return codeVal;
  15151. };
  15152. FlateStream.prototype.generateHuffmanTable =
  15153. function flateStreamGenerateHuffmanTable(lengths) {
  15154. var n = lengths.length;
  15155. // find max code length
  15156. var maxLen = 0;
  15157. var i;
  15158. for (i = 0; i < n; ++i) {
  15159. if (lengths[i] > maxLen) {
  15160. maxLen = lengths[i];
  15161. }
  15162. }
  15163. // build the table
  15164. var size = 1 << maxLen;
  15165. var codes = new Int32Array(size);
  15166. for (var len = 1, code = 0, skip = 2;
  15167. len <= maxLen;
  15168. ++len, code <<= 1, skip <<= 1) {
  15169. for (var val = 0; val < n; ++val) {
  15170. if (lengths[val] === len) {
  15171. // bit-reverse the code
  15172. var code2 = 0;
  15173. var t = code;
  15174. for (i = 0; i < len; ++i) {
  15175. code2 = (code2 << 1) | (t & 1);
  15176. t >>= 1;
  15177. }
  15178. // fill the table entries
  15179. for (i = code2; i < size; i += skip) {
  15180. codes[i] = (len << 16) | val;
  15181. }
  15182. ++code;
  15183. }
  15184. }
  15185. }
  15186. return [codes, maxLen];
  15187. };
  15188. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  15189. var buffer, len;
  15190. var str = this.str;
  15191. // read block header
  15192. var hdr = this.getBits(3);
  15193. if (hdr & 1) {
  15194. this.eof = true;
  15195. }
  15196. hdr >>= 1;
  15197. if (hdr === 0) { // uncompressed block
  15198. var b;
  15199. if ((b = str.getByte()) === -1) {
  15200. error('Bad block header in flate stream');
  15201. }
  15202. var blockLen = b;
  15203. if ((b = str.getByte()) === -1) {
  15204. error('Bad block header in flate stream');
  15205. }
  15206. blockLen |= (b << 8);
  15207. if ((b = str.getByte()) === -1) {
  15208. error('Bad block header in flate stream');
  15209. }
  15210. var check = b;
  15211. if ((b = str.getByte()) === -1) {
  15212. error('Bad block header in flate stream');
  15213. }
  15214. check |= (b << 8);
  15215. if (check !== (~blockLen & 0xffff) &&
  15216. (blockLen !== 0 || check !== 0)) {
  15217. // Ignoring error for bad "empty" block (see issue 1277)
  15218. error('Bad uncompressed block length in flate stream');
  15219. }
  15220. this.codeBuf = 0;
  15221. this.codeSize = 0;
  15222. var bufferLength = this.bufferLength;
  15223. buffer = this.ensureBuffer(bufferLength + blockLen);
  15224. var end = bufferLength + blockLen;
  15225. this.bufferLength = end;
  15226. if (blockLen === 0) {
  15227. if (str.peekByte() === -1) {
  15228. this.eof = true;
  15229. }
  15230. } else {
  15231. for (var n = bufferLength; n < end; ++n) {
  15232. if ((b = str.getByte()) === -1) {
  15233. this.eof = true;
  15234. break;
  15235. }
  15236. buffer[n] = b;
  15237. }
  15238. }
  15239. return;
  15240. }
  15241. var litCodeTable;
  15242. var distCodeTable;
  15243. if (hdr === 1) { // compressed block, fixed codes
  15244. litCodeTable = fixedLitCodeTab;
  15245. distCodeTable = fixedDistCodeTab;
  15246. } else if (hdr === 2) { // compressed block, dynamic codes
  15247. var numLitCodes = this.getBits(5) + 257;
  15248. var numDistCodes = this.getBits(5) + 1;
  15249. var numCodeLenCodes = this.getBits(4) + 4;
  15250. // build the code lengths code table
  15251. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  15252. var i;
  15253. for (i = 0; i < numCodeLenCodes; ++i) {
  15254. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  15255. }
  15256. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  15257. // build the literal and distance code tables
  15258. len = 0;
  15259. i = 0;
  15260. var codes = numLitCodes + numDistCodes;
  15261. var codeLengths = new Uint8Array(codes);
  15262. var bitsLength, bitsOffset, what;
  15263. while (i < codes) {
  15264. var code = this.getCode(codeLenCodeTab);
  15265. if (code === 16) {
  15266. bitsLength = 2; bitsOffset = 3; what = len;
  15267. } else if (code === 17) {
  15268. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  15269. } else if (code === 18) {
  15270. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  15271. } else {
  15272. codeLengths[i++] = len = code;
  15273. continue;
  15274. }
  15275. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  15276. while (repeatLength-- > 0) {
  15277. codeLengths[i++] = what;
  15278. }
  15279. }
  15280. litCodeTable =
  15281. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  15282. distCodeTable =
  15283. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  15284. } else {
  15285. error('Unknown block type in flate stream');
  15286. }
  15287. buffer = this.buffer;
  15288. var limit = buffer ? buffer.length : 0;
  15289. var pos = this.bufferLength;
  15290. while (true) {
  15291. var code1 = this.getCode(litCodeTable);
  15292. if (code1 < 256) {
  15293. if (pos + 1 >= limit) {
  15294. buffer = this.ensureBuffer(pos + 1);
  15295. limit = buffer.length;
  15296. }
  15297. buffer[pos++] = code1;
  15298. continue;
  15299. }
  15300. if (code1 === 256) {
  15301. this.bufferLength = pos;
  15302. return;
  15303. }
  15304. code1 -= 257;
  15305. code1 = lengthDecode[code1];
  15306. var code2 = code1 >> 16;
  15307. if (code2 > 0) {
  15308. code2 = this.getBits(code2);
  15309. }
  15310. len = (code1 & 0xffff) + code2;
  15311. code1 = this.getCode(distCodeTable);
  15312. code1 = distDecode[code1];
  15313. code2 = code1 >> 16;
  15314. if (code2 > 0) {
  15315. code2 = this.getBits(code2);
  15316. }
  15317. var dist = (code1 & 0xffff) + code2;
  15318. if (pos + len >= limit) {
  15319. buffer = this.ensureBuffer(pos + len);
  15320. limit = buffer.length;
  15321. }
  15322. for (var k = 0; k < len; ++k, ++pos) {
  15323. buffer[pos] = buffer[pos - dist];
  15324. }
  15325. }
  15326. };
  15327. return FlateStream;
  15328. })();
  15329. var PredictorStream = (function PredictorStreamClosure() {
  15330. function PredictorStream(str, maybeLength, params) {
  15331. var predictor = this.predictor = params.get('Predictor') || 1;
  15332. if (predictor <= 1) {
  15333. return str; // no prediction
  15334. }
  15335. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  15336. error('Unsupported predictor: ' + predictor);
  15337. }
  15338. if (predictor === 2) {
  15339. this.readBlock = this.readBlockTiff;
  15340. } else {
  15341. this.readBlock = this.readBlockPng;
  15342. }
  15343. this.str = str;
  15344. this.dict = str.dict;
  15345. var colors = this.colors = params.get('Colors') || 1;
  15346. var bits = this.bits = params.get('BitsPerComponent') || 8;
  15347. var columns = this.columns = params.get('Columns') || 1;
  15348. this.pixBytes = (colors * bits + 7) >> 3;
  15349. this.rowBytes = (columns * colors * bits + 7) >> 3;
  15350. DecodeStream.call(this, maybeLength);
  15351. return this;
  15352. }
  15353. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  15354. PredictorStream.prototype.readBlockTiff =
  15355. function predictorStreamReadBlockTiff() {
  15356. var rowBytes = this.rowBytes;
  15357. var bufferLength = this.bufferLength;
  15358. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15359. var bits = this.bits;
  15360. var colors = this.colors;
  15361. var rawBytes = this.str.getBytes(rowBytes);
  15362. this.eof = !rawBytes.length;
  15363. if (this.eof) {
  15364. return;
  15365. }
  15366. var inbuf = 0, outbuf = 0;
  15367. var inbits = 0, outbits = 0;
  15368. var pos = bufferLength;
  15369. var i;
  15370. if (bits === 1) {
  15371. for (i = 0; i < rowBytes; ++i) {
  15372. var c = rawBytes[i];
  15373. inbuf = (inbuf << 8) | c;
  15374. // bitwise addition is exclusive or
  15375. // first shift inbuf and then add
  15376. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  15377. // truncate inbuf (assumes colors < 16)
  15378. inbuf &= 0xFFFF;
  15379. }
  15380. } else if (bits === 8) {
  15381. for (i = 0; i < colors; ++i) {
  15382. buffer[pos++] = rawBytes[i];
  15383. }
  15384. for (; i < rowBytes; ++i) {
  15385. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  15386. pos++;
  15387. }
  15388. } else {
  15389. var compArray = new Uint8Array(colors + 1);
  15390. var bitMask = (1 << bits) - 1;
  15391. var j = 0, k = bufferLength;
  15392. var columns = this.columns;
  15393. for (i = 0; i < columns; ++i) {
  15394. for (var kk = 0; kk < colors; ++kk) {
  15395. if (inbits < bits) {
  15396. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  15397. inbits += 8;
  15398. }
  15399. compArray[kk] = (compArray[kk] +
  15400. (inbuf >> (inbits - bits))) & bitMask;
  15401. inbits -= bits;
  15402. outbuf = (outbuf << bits) | compArray[kk];
  15403. outbits += bits;
  15404. if (outbits >= 8) {
  15405. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  15406. outbits -= 8;
  15407. }
  15408. }
  15409. }
  15410. if (outbits > 0) {
  15411. buffer[k++] = (outbuf << (8 - outbits)) +
  15412. (inbuf & ((1 << (8 - outbits)) - 1));
  15413. }
  15414. }
  15415. this.bufferLength += rowBytes;
  15416. };
  15417. PredictorStream.prototype.readBlockPng =
  15418. function predictorStreamReadBlockPng() {
  15419. var rowBytes = this.rowBytes;
  15420. var pixBytes = this.pixBytes;
  15421. var predictor = this.str.getByte();
  15422. var rawBytes = this.str.getBytes(rowBytes);
  15423. this.eof = !rawBytes.length;
  15424. if (this.eof) {
  15425. return;
  15426. }
  15427. var bufferLength = this.bufferLength;
  15428. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15429. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  15430. if (prevRow.length === 0) {
  15431. prevRow = new Uint8Array(rowBytes);
  15432. }
  15433. var i, j = bufferLength, up, c;
  15434. switch (predictor) {
  15435. case 0:
  15436. for (i = 0; i < rowBytes; ++i) {
  15437. buffer[j++] = rawBytes[i];
  15438. }
  15439. break;
  15440. case 1:
  15441. for (i = 0; i < pixBytes; ++i) {
  15442. buffer[j++] = rawBytes[i];
  15443. }
  15444. for (; i < rowBytes; ++i) {
  15445. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  15446. j++;
  15447. }
  15448. break;
  15449. case 2:
  15450. for (i = 0; i < rowBytes; ++i) {
  15451. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  15452. }
  15453. break;
  15454. case 3:
  15455. for (i = 0; i < pixBytes; ++i) {
  15456. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  15457. }
  15458. for (; i < rowBytes; ++i) {
  15459. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  15460. rawBytes[i]) & 0xFF;
  15461. j++;
  15462. }
  15463. break;
  15464. case 4:
  15465. // we need to save the up left pixels values. the simplest way
  15466. // is to create a new buffer
  15467. for (i = 0; i < pixBytes; ++i) {
  15468. up = prevRow[i];
  15469. c = rawBytes[i];
  15470. buffer[j++] = up + c;
  15471. }
  15472. for (; i < rowBytes; ++i) {
  15473. up = prevRow[i];
  15474. var upLeft = prevRow[i - pixBytes];
  15475. var left = buffer[j - pixBytes];
  15476. var p = left + up - upLeft;
  15477. var pa = p - left;
  15478. if (pa < 0) {
  15479. pa = -pa;
  15480. }
  15481. var pb = p - up;
  15482. if (pb < 0) {
  15483. pb = -pb;
  15484. }
  15485. var pc = p - upLeft;
  15486. if (pc < 0) {
  15487. pc = -pc;
  15488. }
  15489. c = rawBytes[i];
  15490. if (pa <= pb && pa <= pc) {
  15491. buffer[j++] = left + c;
  15492. } else if (pb <= pc) {
  15493. buffer[j++] = up + c;
  15494. } else {
  15495. buffer[j++] = upLeft + c;
  15496. }
  15497. }
  15498. break;
  15499. default:
  15500. error('Unsupported predictor: ' + predictor);
  15501. }
  15502. this.bufferLength += rowBytes;
  15503. };
  15504. return PredictorStream;
  15505. })();
  15506. /**
  15507. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  15508. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  15509. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  15510. * a library to decode these images and the stream behaves like all the other
  15511. * DecodeStreams.
  15512. */
  15513. var JpegStream = (function JpegStreamClosure() {
  15514. function JpegStream(stream, maybeLength, dict, xref) {
  15515. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  15516. // Note: this seems to mainly affect inline images.
  15517. var ch;
  15518. while ((ch = stream.getByte()) !== -1) {
  15519. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  15520. stream.skip(-1); // Reset the stream position to the SOI.
  15521. break;
  15522. }
  15523. }
  15524. this.stream = stream;
  15525. this.maybeLength = maybeLength;
  15526. this.dict = dict;
  15527. DecodeStream.call(this, maybeLength);
  15528. }
  15529. JpegStream.prototype = Object.create(DecodeStream.prototype);
  15530. Object.defineProperty(JpegStream.prototype, 'bytes', {
  15531. get: function JpegStream_bytes() {
  15532. // If this.maybeLength is null, we'll get the entire stream.
  15533. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15534. },
  15535. configurable: true
  15536. });
  15537. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  15538. if (this.bufferLength) {
  15539. return;
  15540. }
  15541. try {
  15542. var jpegImage = new JpegImage();
  15543. // checking if values needs to be transformed before conversion
  15544. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  15545. var decodeArr = this.dict.get('Decode');
  15546. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  15547. var decodeArrLength = decodeArr.length;
  15548. var transform = new Int32Array(decodeArrLength);
  15549. var transformNeeded = false;
  15550. var maxValue = (1 << bitsPerComponent) - 1;
  15551. for (var i = 0; i < decodeArrLength; i += 2) {
  15552. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  15553. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  15554. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  15555. transformNeeded = true;
  15556. }
  15557. }
  15558. if (transformNeeded) {
  15559. jpegImage.decodeTransform = transform;
  15560. }
  15561. }
  15562. jpegImage.parse(this.bytes);
  15563. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  15564. this.forceRGB);
  15565. this.buffer = data;
  15566. this.bufferLength = data.length;
  15567. this.eof = true;
  15568. } catch (e) {
  15569. error('JPEG error: ' + e);
  15570. }
  15571. };
  15572. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  15573. this.ensureBuffer();
  15574. return this.buffer;
  15575. };
  15576. JpegStream.prototype.getIR = function JpegStream_getIR() {
  15577. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  15578. };
  15579. /**
  15580. * Checks if the image can be decoded and displayed by the browser without any
  15581. * further processing such as color space conversions.
  15582. */
  15583. JpegStream.prototype.isNativelySupported =
  15584. function JpegStream_isNativelySupported(xref, res) {
  15585. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15586. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  15587. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15588. };
  15589. /**
  15590. * Checks if the image can be decoded by the browser.
  15591. */
  15592. JpegStream.prototype.isNativelyDecodable =
  15593. function JpegStream_isNativelyDecodable(xref, res) {
  15594. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15595. return (cs.numComps === 1 || cs.numComps === 3) &&
  15596. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15597. };
  15598. return JpegStream;
  15599. })();
  15600. /**
  15601. * For JPEG 2000's we use a library to decode these images and
  15602. * the stream behaves like all the other DecodeStreams.
  15603. */
  15604. var JpxStream = (function JpxStreamClosure() {
  15605. function JpxStream(stream, maybeLength, dict) {
  15606. this.stream = stream;
  15607. this.maybeLength = maybeLength;
  15608. this.dict = dict;
  15609. DecodeStream.call(this, maybeLength);
  15610. }
  15611. JpxStream.prototype = Object.create(DecodeStream.prototype);
  15612. Object.defineProperty(JpxStream.prototype, 'bytes', {
  15613. get: function JpxStream_bytes() {
  15614. // If this.maybeLength is null, we'll get the entire stream.
  15615. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15616. },
  15617. configurable: true
  15618. });
  15619. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  15620. if (this.bufferLength) {
  15621. return;
  15622. }
  15623. var jpxImage = new JpxImage();
  15624. jpxImage.parse(this.bytes);
  15625. var width = jpxImage.width;
  15626. var height = jpxImage.height;
  15627. var componentsCount = jpxImage.componentsCount;
  15628. var tileCount = jpxImage.tiles.length;
  15629. if (tileCount === 1) {
  15630. this.buffer = jpxImage.tiles[0].items;
  15631. } else {
  15632. var data = new Uint8Array(width * height * componentsCount);
  15633. for (var k = 0; k < tileCount; k++) {
  15634. var tileComponents = jpxImage.tiles[k];
  15635. var tileWidth = tileComponents.width;
  15636. var tileHeight = tileComponents.height;
  15637. var tileLeft = tileComponents.left;
  15638. var tileTop = tileComponents.top;
  15639. var src = tileComponents.items;
  15640. var srcPosition = 0;
  15641. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  15642. var imgRowSize = width * componentsCount;
  15643. var tileRowSize = tileWidth * componentsCount;
  15644. for (var j = 0; j < tileHeight; j++) {
  15645. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  15646. data.set(rowBytes, dataPosition);
  15647. srcPosition += tileRowSize;
  15648. dataPosition += imgRowSize;
  15649. }
  15650. }
  15651. this.buffer = data;
  15652. }
  15653. this.bufferLength = this.buffer.length;
  15654. this.eof = true;
  15655. };
  15656. return JpxStream;
  15657. })();
  15658. /**
  15659. * For JBIG2's we use a library to decode these images and
  15660. * the stream behaves like all the other DecodeStreams.
  15661. */
  15662. var Jbig2Stream = (function Jbig2StreamClosure() {
  15663. function Jbig2Stream(stream, maybeLength, dict) {
  15664. this.stream = stream;
  15665. this.maybeLength = maybeLength;
  15666. this.dict = dict;
  15667. DecodeStream.call(this, maybeLength);
  15668. }
  15669. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  15670. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  15671. get: function Jbig2Stream_bytes() {
  15672. // If this.maybeLength is null, we'll get the entire stream.
  15673. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15674. },
  15675. configurable: true
  15676. });
  15677. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  15678. if (this.bufferLength) {
  15679. return;
  15680. }
  15681. var jbig2Image = new Jbig2Image();
  15682. var chunks = [], xref = this.dict.xref;
  15683. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  15684. // According to the PDF specification, DecodeParms can be either
  15685. // a dictionary, or an array whose elements are dictionaries.
  15686. if (isArray(decodeParams)) {
  15687. if (decodeParams.length > 1) {
  15688. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  15689. 'not supported.');
  15690. }
  15691. decodeParams = xref.fetchIfRef(decodeParams[0]);
  15692. }
  15693. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  15694. var globalsStream = decodeParams.get('JBIG2Globals');
  15695. var globals = globalsStream.getBytes();
  15696. chunks.push({data: globals, start: 0, end: globals.length});
  15697. }
  15698. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  15699. var data = jbig2Image.parseChunks(chunks);
  15700. var dataLength = data.length;
  15701. // JBIG2 had black as 1 and white as 0, inverting the colors
  15702. for (var i = 0; i < dataLength; i++) {
  15703. data[i] ^= 0xFF;
  15704. }
  15705. this.buffer = data;
  15706. this.bufferLength = dataLength;
  15707. this.eof = true;
  15708. };
  15709. return Jbig2Stream;
  15710. })();
  15711. var DecryptStream = (function DecryptStreamClosure() {
  15712. function DecryptStream(str, maybeLength, decrypt) {
  15713. this.str = str;
  15714. this.dict = str.dict;
  15715. this.decrypt = decrypt;
  15716. this.nextChunk = null;
  15717. this.initialized = false;
  15718. DecodeStream.call(this, maybeLength);
  15719. }
  15720. var chunkSize = 512;
  15721. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  15722. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  15723. var chunk;
  15724. if (this.initialized) {
  15725. chunk = this.nextChunk;
  15726. } else {
  15727. chunk = this.str.getBytes(chunkSize);
  15728. this.initialized = true;
  15729. }
  15730. if (!chunk || chunk.length === 0) {
  15731. this.eof = true;
  15732. return;
  15733. }
  15734. this.nextChunk = this.str.getBytes(chunkSize);
  15735. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  15736. var decrypt = this.decrypt;
  15737. chunk = decrypt(chunk, !hasMoreData);
  15738. var bufferLength = this.bufferLength;
  15739. var i, n = chunk.length;
  15740. var buffer = this.ensureBuffer(bufferLength + n);
  15741. for (i = 0; i < n; i++) {
  15742. buffer[bufferLength++] = chunk[i];
  15743. }
  15744. this.bufferLength = bufferLength;
  15745. };
  15746. return DecryptStream;
  15747. })();
  15748. var Ascii85Stream = (function Ascii85StreamClosure() {
  15749. function Ascii85Stream(str, maybeLength) {
  15750. this.str = str;
  15751. this.dict = str.dict;
  15752. this.input = new Uint8Array(5);
  15753. // Most streams increase in size when decoded, but Ascii85 streams
  15754. // typically shrink by ~20%.
  15755. if (maybeLength) {
  15756. maybeLength = 0.8 * maybeLength;
  15757. }
  15758. DecodeStream.call(this, maybeLength);
  15759. }
  15760. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  15761. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  15762. var TILDA_CHAR = 0x7E; // '~'
  15763. var Z_LOWER_CHAR = 0x7A; // 'z'
  15764. var EOF = -1;
  15765. var str = this.str;
  15766. var c = str.getByte();
  15767. while (Lexer.isSpace(c)) {
  15768. c = str.getByte();
  15769. }
  15770. if (c === EOF || c === TILDA_CHAR) {
  15771. this.eof = true;
  15772. return;
  15773. }
  15774. var bufferLength = this.bufferLength, buffer;
  15775. var i;
  15776. // special code for z
  15777. if (c === Z_LOWER_CHAR) {
  15778. buffer = this.ensureBuffer(bufferLength + 4);
  15779. for (i = 0; i < 4; ++i) {
  15780. buffer[bufferLength + i] = 0;
  15781. }
  15782. this.bufferLength += 4;
  15783. } else {
  15784. var input = this.input;
  15785. input[0] = c;
  15786. for (i = 1; i < 5; ++i) {
  15787. c = str.getByte();
  15788. while (Lexer.isSpace(c)) {
  15789. c = str.getByte();
  15790. }
  15791. input[i] = c;
  15792. if (c === EOF || c === TILDA_CHAR) {
  15793. break;
  15794. }
  15795. }
  15796. buffer = this.ensureBuffer(bufferLength + i - 1);
  15797. this.bufferLength += i - 1;
  15798. // partial ending;
  15799. if (i < 5) {
  15800. for (; i < 5; ++i) {
  15801. input[i] = 0x21 + 84;
  15802. }
  15803. this.eof = true;
  15804. }
  15805. var t = 0;
  15806. for (i = 0; i < 5; ++i) {
  15807. t = t * 85 + (input[i] - 0x21);
  15808. }
  15809. for (i = 3; i >= 0; --i) {
  15810. buffer[bufferLength + i] = t & 0xFF;
  15811. t >>= 8;
  15812. }
  15813. }
  15814. };
  15815. return Ascii85Stream;
  15816. })();
  15817. var AsciiHexStream = (function AsciiHexStreamClosure() {
  15818. function AsciiHexStream(str, maybeLength) {
  15819. this.str = str;
  15820. this.dict = str.dict;
  15821. this.firstDigit = -1;
  15822. // Most streams increase in size when decoded, but AsciiHex streams shrink
  15823. // by 50%.
  15824. if (maybeLength) {
  15825. maybeLength = 0.5 * maybeLength;
  15826. }
  15827. DecodeStream.call(this, maybeLength);
  15828. }
  15829. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  15830. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  15831. var UPSTREAM_BLOCK_SIZE = 8000;
  15832. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  15833. if (!bytes.length) {
  15834. this.eof = true;
  15835. return;
  15836. }
  15837. var maxDecodeLength = (bytes.length + 1) >> 1;
  15838. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  15839. var bufferLength = this.bufferLength;
  15840. var firstDigit = this.firstDigit;
  15841. for (var i = 0, ii = bytes.length; i < ii; i++) {
  15842. var ch = bytes[i], digit;
  15843. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  15844. digit = ch & 0x0F;
  15845. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  15846. // 'A'-'Z', 'a'-'z'
  15847. digit = (ch & 0x0F) + 9;
  15848. } else if (ch === 0x3E) { // '>'
  15849. this.eof = true;
  15850. break;
  15851. } else { // probably whitespace
  15852. continue; // ignoring
  15853. }
  15854. if (firstDigit < 0) {
  15855. firstDigit = digit;
  15856. } else {
  15857. buffer[bufferLength++] = (firstDigit << 4) | digit;
  15858. firstDigit = -1;
  15859. }
  15860. }
  15861. if (firstDigit >= 0 && this.eof) {
  15862. // incomplete byte
  15863. buffer[bufferLength++] = (firstDigit << 4);
  15864. firstDigit = -1;
  15865. }
  15866. this.firstDigit = firstDigit;
  15867. this.bufferLength = bufferLength;
  15868. };
  15869. return AsciiHexStream;
  15870. })();
  15871. var RunLengthStream = (function RunLengthStreamClosure() {
  15872. function RunLengthStream(str, maybeLength) {
  15873. this.str = str;
  15874. this.dict = str.dict;
  15875. DecodeStream.call(this, maybeLength);
  15876. }
  15877. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  15878. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  15879. // The repeatHeader has following format. The first byte defines type of run
  15880. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  15881. // (in addition to the second byte from the header), n = 129 through 255 -
  15882. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  15883. var repeatHeader = this.str.getBytes(2);
  15884. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  15885. this.eof = true;
  15886. return;
  15887. }
  15888. var buffer;
  15889. var bufferLength = this.bufferLength;
  15890. var n = repeatHeader[0];
  15891. if (n < 128) {
  15892. // copy n bytes
  15893. buffer = this.ensureBuffer(bufferLength + n + 1);
  15894. buffer[bufferLength++] = repeatHeader[1];
  15895. if (n > 0) {
  15896. var source = this.str.getBytes(n);
  15897. buffer.set(source, bufferLength);
  15898. bufferLength += n;
  15899. }
  15900. } else {
  15901. n = 257 - n;
  15902. var b = repeatHeader[1];
  15903. buffer = this.ensureBuffer(bufferLength + n + 1);
  15904. for (var i = 0; i < n; i++) {
  15905. buffer[bufferLength++] = b;
  15906. }
  15907. }
  15908. this.bufferLength = bufferLength;
  15909. };
  15910. return RunLengthStream;
  15911. })();
  15912. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  15913. var ccittEOL = -2;
  15914. var twoDimPass = 0;
  15915. var twoDimHoriz = 1;
  15916. var twoDimVert0 = 2;
  15917. var twoDimVertR1 = 3;
  15918. var twoDimVertL1 = 4;
  15919. var twoDimVertR2 = 5;
  15920. var twoDimVertL2 = 6;
  15921. var twoDimVertR3 = 7;
  15922. var twoDimVertL3 = 8;
  15923. var twoDimTable = [
  15924. [-1, -1], [-1, -1], // 000000x
  15925. [7, twoDimVertL3], // 0000010
  15926. [7, twoDimVertR3], // 0000011
  15927. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  15928. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  15929. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  15930. [4, twoDimPass], [4, twoDimPass],
  15931. [4, twoDimPass], [4, twoDimPass],
  15932. [4, twoDimPass], [4, twoDimPass],
  15933. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  15934. [3, twoDimHoriz], [3, twoDimHoriz],
  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, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  15942. [3, twoDimVertL1], [3, twoDimVertL1],
  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, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  15950. [3, twoDimVertR1], [3, twoDimVertR1],
  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. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  15958. [1, twoDimVert0], [1, twoDimVert0],
  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. ];
  15990. var whiteTable1 = [
  15991. [-1, -1], // 00000
  15992. [12, ccittEOL], // 00001
  15993. [-1, -1], [-1, -1], // 0001x
  15994. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  15995. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  15996. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  15997. [11, 1792], [11, 1792], // 1000x
  15998. [12, 1984], // 10010
  15999. [12, 2048], // 10011
  16000. [12, 2112], // 10100
  16001. [12, 2176], // 10101
  16002. [12, 2240], // 10110
  16003. [12, 2304], // 10111
  16004. [11, 1856], [11, 1856], // 1100x
  16005. [11, 1920], [11, 1920], // 1101x
  16006. [12, 2368], // 11100
  16007. [12, 2432], // 11101
  16008. [12, 2496], // 11110
  16009. [12, 2560] // 11111
  16010. ];
  16011. var whiteTable2 = [
  16012. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  16013. [8, 29], [8, 29], // 00000010x
  16014. [8, 30], [8, 30], // 00000011x
  16015. [8, 45], [8, 45], // 00000100x
  16016. [8, 46], [8, 46], // 00000101x
  16017. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  16018. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  16019. [8, 47], [8, 47], // 00001010x
  16020. [8, 48], [8, 48], // 00001011x
  16021. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  16022. [6, 13], [6, 13], [6, 13], [6, 13],
  16023. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  16024. [8, 33], [8, 33], // 00010010x
  16025. [8, 34], [8, 34], // 00010011x
  16026. [8, 35], [8, 35], // 00010100x
  16027. [8, 36], [8, 36], // 00010101x
  16028. [8, 37], [8, 37], // 00010110x
  16029. [8, 38], [8, 38], // 00010111x
  16030. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  16031. [8, 31], [8, 31], // 00011010x
  16032. [8, 32], [8, 32], // 00011011x
  16033. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  16034. [6, 1], [6, 1], [6, 1], [6, 1],
  16035. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  16036. [6, 12], [6, 12], [6, 12], [6, 12],
  16037. [8, 53], [8, 53], // 00100100x
  16038. [8, 54], [8, 54], // 00100101x
  16039. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  16040. [8, 39], [8, 39], // 00101000x
  16041. [8, 40], [8, 40], // 00101001x
  16042. [8, 41], [8, 41], // 00101010x
  16043. [8, 42], [8, 42], // 00101011x
  16044. [8, 43], [8, 43], // 00101100x
  16045. [8, 44], [8, 44], // 00101101x
  16046. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  16047. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  16048. [8, 61], [8, 61], // 00110010x
  16049. [8, 62], [8, 62], // 00110011x
  16050. [8, 63], [8, 63], // 00110100x
  16051. [8, 0], [8, 0], // 00110101x
  16052. [8, 320], [8, 320], // 00110110x
  16053. [8, 384], [8, 384], // 00110111x
  16054. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  16055. [5, 10], [5, 10], [5, 10], [5, 10],
  16056. [5, 10], [5, 10], [5, 10], [5, 10],
  16057. [5, 10], [5, 10], [5, 10], [5, 10],
  16058. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  16059. [5, 11], [5, 11], [5, 11], [5, 11],
  16060. [5, 11], [5, 11], [5, 11], [5, 11],
  16061. [5, 11], [5, 11], [5, 11], [5, 11],
  16062. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  16063. [8, 59], [8, 59], // 01001010x
  16064. [8, 60], [8, 60], // 01001011x
  16065. [9, 1472], // 010011000
  16066. [9, 1536], // 010011001
  16067. [9, 1600], // 010011010
  16068. [9, 1728], // 010011011
  16069. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  16070. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  16071. [8, 49], [8, 49], // 01010010x
  16072. [8, 50], [8, 50], // 01010011x
  16073. [8, 51], [8, 51], // 01010100x
  16074. [8, 52], [8, 52], // 01010101x
  16075. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  16076. [8, 55], [8, 55], // 01011000x
  16077. [8, 56], [8, 56], // 01011001x
  16078. [8, 57], [8, 57], // 01011010x
  16079. [8, 58], [8, 58], // 01011011x
  16080. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  16081. [6, 192], [6, 192], [6, 192], [6, 192],
  16082. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  16083. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  16084. [8, 448], [8, 448], // 01100100x
  16085. [8, 512], [8, 512], // 01100101x
  16086. [9, 704], // 011001100
  16087. [9, 768], // 011001101
  16088. [8, 640], [8, 640], // 01100111x
  16089. [8, 576], [8, 576], // 01101000x
  16090. [9, 832], // 011010010
  16091. [9, 896], // 011010011
  16092. [9, 960], // 011010100
  16093. [9, 1024], // 011010101
  16094. [9, 1088], // 011010110
  16095. [9, 1152], // 011010111
  16096. [9, 1216], // 011011000
  16097. [9, 1280], // 011011001
  16098. [9, 1344], // 011011010
  16099. [9, 1408], // 011011011
  16100. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  16101. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  16102. [4, 2], [4, 2], [4, 2], [4, 2],
  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, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  16110. [4, 3], [4, 3], [4, 3], [4, 3],
  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. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  16118. [5, 128], [5, 128], [5, 128], [5, 128],
  16119. [5, 128], [5, 128], [5, 128], [5, 128],
  16120. [5, 128], [5, 128], [5, 128], [5, 128],
  16121. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  16122. [5, 8], [5, 8], [5, 8], [5, 8],
  16123. [5, 8], [5, 8], [5, 8], [5, 8],
  16124. [5, 8], [5, 8], [5, 8], [5, 8],
  16125. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  16126. [5, 9], [5, 9], [5, 9], [5, 9],
  16127. [5, 9], [5, 9], [5, 9], [5, 9],
  16128. [5, 9], [5, 9], [5, 9], [5, 9],
  16129. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  16130. [6, 16], [6, 16], [6, 16], [6, 16],
  16131. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  16132. [6, 17], [6, 17], [6, 17], [6, 17],
  16133. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  16134. [4, 4], [4, 4], [4, 4], [4, 4],
  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, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  16142. [4, 5], [4, 5], [4, 5], [4, 5],
  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. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  16150. [6, 14], [6, 14], [6, 14], [6, 14],
  16151. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  16152. [6, 15], [6, 15], [6, 15], [6, 15],
  16153. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  16154. [5, 64], [5, 64], [5, 64], [5, 64],
  16155. [5, 64], [5, 64], [5, 64], [5, 64],
  16156. [5, 64], [5, 64], [5, 64], [5, 64],
  16157. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  16158. [4, 6], [4, 6], [4, 6], [4, 6],
  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, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  16166. [4, 7], [4, 7], [4, 7], [4, 7],
  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. ];
  16174. var blackTable1 = [
  16175. [-1, -1], [-1, -1], // 000000000000x
  16176. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  16177. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  16178. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  16179. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  16180. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  16181. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  16182. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  16183. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  16184. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  16185. [12, 1984], [12, 1984], // 000000010010x
  16186. [12, 2048], [12, 2048], // 000000010011x
  16187. [12, 2112], [12, 2112], // 000000010100x
  16188. [12, 2176], [12, 2176], // 000000010101x
  16189. [12, 2240], [12, 2240], // 000000010110x
  16190. [12, 2304], [12, 2304], // 000000010111x
  16191. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  16192. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  16193. [12, 2368], [12, 2368], // 000000011100x
  16194. [12, 2432], [12, 2432], // 000000011101x
  16195. [12, 2496], [12, 2496], // 000000011110x
  16196. [12, 2560], [12, 2560], // 000000011111x
  16197. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  16198. [10, 18], [10, 18], [10, 18], [10, 18],
  16199. [12, 52], [12, 52], // 000000100100x
  16200. [13, 640], // 0000001001010
  16201. [13, 704], // 0000001001011
  16202. [13, 768], // 0000001001100
  16203. [13, 832], // 0000001001101
  16204. [12, 55], [12, 55], // 000000100111x
  16205. [12, 56], [12, 56], // 000000101000x
  16206. [13, 1280], // 0000001010010
  16207. [13, 1344], // 0000001010011
  16208. [13, 1408], // 0000001010100
  16209. [13, 1472], // 0000001010101
  16210. [12, 59], [12, 59], // 000000101011x
  16211. [12, 60], [12, 60], // 000000101100x
  16212. [13, 1536], // 0000001011010
  16213. [13, 1600], // 0000001011011
  16214. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  16215. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  16216. [13, 1664], // 0000001100100
  16217. [13, 1728], // 0000001100101
  16218. [12, 320], [12, 320], // 000000110011x
  16219. [12, 384], [12, 384], // 000000110100x
  16220. [12, 448], [12, 448], // 000000110101x
  16221. [13, 512], // 0000001101100
  16222. [13, 576], // 0000001101101
  16223. [12, 53], [12, 53], // 000000110111x
  16224. [12, 54], [12, 54], // 000000111000x
  16225. [13, 896], // 0000001110010
  16226. [13, 960], // 0000001110011
  16227. [13, 1024], // 0000001110100
  16228. [13, 1088], // 0000001110101
  16229. [13, 1152], // 0000001110110
  16230. [13, 1216], // 0000001110111
  16231. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  16232. [10, 64], [10, 64], [10, 64], [10, 64]
  16233. ];
  16234. var blackTable2 = [
  16235. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  16236. [8, 13], [8, 13], [8, 13], [8, 13],
  16237. [8, 13], [8, 13], [8, 13], [8, 13],
  16238. [8, 13], [8, 13], [8, 13], [8, 13],
  16239. [11, 23], [11, 23], // 00000101000x
  16240. [12, 50], // 000001010010
  16241. [12, 51], // 000001010011
  16242. [12, 44], // 000001010100
  16243. [12, 45], // 000001010101
  16244. [12, 46], // 000001010110
  16245. [12, 47], // 000001010111
  16246. [12, 57], // 000001011000
  16247. [12, 58], // 000001011001
  16248. [12, 61], // 000001011010
  16249. [12, 256], // 000001011011
  16250. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  16251. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  16252. [12, 48], // 000001100100
  16253. [12, 49], // 000001100101
  16254. [12, 62], // 000001100110
  16255. [12, 63], // 000001100111
  16256. [12, 30], // 000001101000
  16257. [12, 31], // 000001101001
  16258. [12, 32], // 000001101010
  16259. [12, 33], // 000001101011
  16260. [12, 40], // 000001101100
  16261. [12, 41], // 000001101101
  16262. [11, 22], [11, 22], // 00000110111x
  16263. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  16264. [8, 14], [8, 14], [8, 14], [8, 14],
  16265. [8, 14], [8, 14], [8, 14], [8, 14],
  16266. [8, 14], [8, 14], [8, 14], [8, 14],
  16267. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  16268. [7, 10], [7, 10], [7, 10], [7, 10],
  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, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  16276. [7, 11], [7, 11], [7, 11], [7, 11],
  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. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  16284. [9, 15], [9, 15], [9, 15], [9, 15],
  16285. [12, 128], // 000011001000
  16286. [12, 192], // 000011001001
  16287. [12, 26], // 000011001010
  16288. [12, 27], // 000011001011
  16289. [12, 28], // 000011001100
  16290. [12, 29], // 000011001101
  16291. [11, 19], [11, 19], // 00001100111x
  16292. [11, 20], [11, 20], // 00001101000x
  16293. [12, 34], // 000011010010
  16294. [12, 35], // 000011010011
  16295. [12, 36], // 000011010100
  16296. [12, 37], // 000011010101
  16297. [12, 38], // 000011010110
  16298. [12, 39], // 000011010111
  16299. [11, 21], [11, 21], // 00001101100x
  16300. [12, 42], // 000011011010
  16301. [12, 43], // 000011011011
  16302. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  16303. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  16304. [7, 12], [7, 12], [7, 12], [7, 12],
  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. ];
  16312. var blackTable3 = [
  16313. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  16314. [6, 9], // 000100
  16315. [6, 8], // 000101
  16316. [5, 7], [5, 7], // 00011x
  16317. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  16318. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  16319. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  16320. [3, 1], [3, 1], [3, 1], [3, 1],
  16321. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  16322. [3, 4], [3, 4], [3, 4], [3, 4],
  16323. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  16324. [2, 3], [2, 3], [2, 3], [2, 3],
  16325. [2, 3], [2, 3], [2, 3], [2, 3],
  16326. [2, 3], [2, 3], [2, 3], [2, 3],
  16327. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  16328. [2, 2], [2, 2], [2, 2], [2, 2],
  16329. [2, 2], [2, 2], [2, 2], [2, 2],
  16330. [2, 2], [2, 2], [2, 2], [2, 2]
  16331. ];
  16332. function CCITTFaxStream(str, maybeLength, params) {
  16333. this.str = str;
  16334. this.dict = str.dict;
  16335. params = params || Dict.empty;
  16336. this.encoding = params.get('K') || 0;
  16337. this.eoline = params.get('EndOfLine') || false;
  16338. this.byteAlign = params.get('EncodedByteAlign') || false;
  16339. this.columns = params.get('Columns') || 1728;
  16340. this.rows = params.get('Rows') || 0;
  16341. var eoblock = params.get('EndOfBlock');
  16342. if (eoblock === null || eoblock === undefined) {
  16343. eoblock = true;
  16344. }
  16345. this.eoblock = eoblock;
  16346. this.black = params.get('BlackIs1') || false;
  16347. this.codingLine = new Uint32Array(this.columns + 1);
  16348. this.refLine = new Uint32Array(this.columns + 2);
  16349. this.codingLine[0] = this.columns;
  16350. this.codingPos = 0;
  16351. this.row = 0;
  16352. this.nextLine2D = this.encoding < 0;
  16353. this.inputBits = 0;
  16354. this.inputBuf = 0;
  16355. this.outputBits = 0;
  16356. var code1;
  16357. while ((code1 = this.lookBits(12)) === 0) {
  16358. this.eatBits(1);
  16359. }
  16360. if (code1 === 1) {
  16361. this.eatBits(12);
  16362. }
  16363. if (this.encoding > 0) {
  16364. this.nextLine2D = !this.lookBits(1);
  16365. this.eatBits(1);
  16366. }
  16367. DecodeStream.call(this, maybeLength);
  16368. }
  16369. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  16370. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  16371. while (!this.eof) {
  16372. var c = this.lookChar();
  16373. this.ensureBuffer(this.bufferLength + 1);
  16374. this.buffer[this.bufferLength++] = c;
  16375. }
  16376. };
  16377. CCITTFaxStream.prototype.addPixels =
  16378. function ccittFaxStreamAddPixels(a1, blackPixels) {
  16379. var codingLine = this.codingLine;
  16380. var codingPos = this.codingPos;
  16381. if (a1 > codingLine[codingPos]) {
  16382. if (a1 > this.columns) {
  16383. info('row is wrong length');
  16384. this.err = true;
  16385. a1 = this.columns;
  16386. }
  16387. if ((codingPos & 1) ^ blackPixels) {
  16388. ++codingPos;
  16389. }
  16390. codingLine[codingPos] = a1;
  16391. }
  16392. this.codingPos = codingPos;
  16393. };
  16394. CCITTFaxStream.prototype.addPixelsNeg =
  16395. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  16396. var codingLine = this.codingLine;
  16397. var codingPos = this.codingPos;
  16398. if (a1 > codingLine[codingPos]) {
  16399. if (a1 > this.columns) {
  16400. info('row is wrong length');
  16401. this.err = true;
  16402. a1 = this.columns;
  16403. }
  16404. if ((codingPos & 1) ^ blackPixels) {
  16405. ++codingPos;
  16406. }
  16407. codingLine[codingPos] = a1;
  16408. } else if (a1 < codingLine[codingPos]) {
  16409. if (a1 < 0) {
  16410. info('invalid code');
  16411. this.err = true;
  16412. a1 = 0;
  16413. }
  16414. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  16415. --codingPos;
  16416. }
  16417. codingLine[codingPos] = a1;
  16418. }
  16419. this.codingPos = codingPos;
  16420. };
  16421. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  16422. var refLine = this.refLine;
  16423. var codingLine = this.codingLine;
  16424. var columns = this.columns;
  16425. var refPos, blackPixels, bits, i;
  16426. if (this.outputBits === 0) {
  16427. if (this.eof) {
  16428. return null;
  16429. }
  16430. this.err = false;
  16431. var code1, code2, code3;
  16432. if (this.nextLine2D) {
  16433. for (i = 0; codingLine[i] < columns; ++i) {
  16434. refLine[i] = codingLine[i];
  16435. }
  16436. refLine[i++] = columns;
  16437. refLine[i] = columns;
  16438. codingLine[0] = 0;
  16439. this.codingPos = 0;
  16440. refPos = 0;
  16441. blackPixels = 0;
  16442. while (codingLine[this.codingPos] < columns) {
  16443. code1 = this.getTwoDimCode();
  16444. switch (code1) {
  16445. case twoDimPass:
  16446. this.addPixels(refLine[refPos + 1], blackPixels);
  16447. if (refLine[refPos + 1] < columns) {
  16448. refPos += 2;
  16449. }
  16450. break;
  16451. case twoDimHoriz:
  16452. code1 = code2 = 0;
  16453. if (blackPixels) {
  16454. do {
  16455. code1 += (code3 = this.getBlackCode());
  16456. } while (code3 >= 64);
  16457. do {
  16458. code2 += (code3 = this.getWhiteCode());
  16459. } while (code3 >= 64);
  16460. } else {
  16461. do {
  16462. code1 += (code3 = this.getWhiteCode());
  16463. } while (code3 >= 64);
  16464. do {
  16465. code2 += (code3 = this.getBlackCode());
  16466. } while (code3 >= 64);
  16467. }
  16468. this.addPixels(codingLine[this.codingPos] +
  16469. code1, blackPixels);
  16470. if (codingLine[this.codingPos] < columns) {
  16471. this.addPixels(codingLine[this.codingPos] + code2,
  16472. blackPixels ^ 1);
  16473. }
  16474. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16475. refLine[refPos] < columns) {
  16476. refPos += 2;
  16477. }
  16478. break;
  16479. case twoDimVertR3:
  16480. this.addPixels(refLine[refPos] + 3, blackPixels);
  16481. blackPixels ^= 1;
  16482. if (codingLine[this.codingPos] < columns) {
  16483. ++refPos;
  16484. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16485. refLine[refPos] < columns) {
  16486. refPos += 2;
  16487. }
  16488. }
  16489. break;
  16490. case twoDimVertR2:
  16491. this.addPixels(refLine[refPos] + 2, blackPixels);
  16492. blackPixels ^= 1;
  16493. if (codingLine[this.codingPos] < columns) {
  16494. ++refPos;
  16495. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16496. refLine[refPos] < columns) {
  16497. refPos += 2;
  16498. }
  16499. }
  16500. break;
  16501. case twoDimVertR1:
  16502. this.addPixels(refLine[refPos] + 1, blackPixels);
  16503. blackPixels ^= 1;
  16504. if (codingLine[this.codingPos] < columns) {
  16505. ++refPos;
  16506. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16507. refLine[refPos] < columns) {
  16508. refPos += 2;
  16509. }
  16510. }
  16511. break;
  16512. case twoDimVert0:
  16513. this.addPixels(refLine[refPos], blackPixels);
  16514. blackPixels ^= 1;
  16515. if (codingLine[this.codingPos] < columns) {
  16516. ++refPos;
  16517. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16518. refLine[refPos] < columns) {
  16519. refPos += 2;
  16520. }
  16521. }
  16522. break;
  16523. case twoDimVertL3:
  16524. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  16525. blackPixels ^= 1;
  16526. if (codingLine[this.codingPos] < columns) {
  16527. if (refPos > 0) {
  16528. --refPos;
  16529. } else {
  16530. ++refPos;
  16531. }
  16532. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16533. refLine[refPos] < columns) {
  16534. refPos += 2;
  16535. }
  16536. }
  16537. break;
  16538. case twoDimVertL2:
  16539. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  16540. blackPixels ^= 1;
  16541. if (codingLine[this.codingPos] < columns) {
  16542. if (refPos > 0) {
  16543. --refPos;
  16544. } else {
  16545. ++refPos;
  16546. }
  16547. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16548. refLine[refPos] < columns) {
  16549. refPos += 2;
  16550. }
  16551. }
  16552. break;
  16553. case twoDimVertL1:
  16554. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  16555. blackPixels ^= 1;
  16556. if (codingLine[this.codingPos] < columns) {
  16557. if (refPos > 0) {
  16558. --refPos;
  16559. } else {
  16560. ++refPos;
  16561. }
  16562. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16563. refLine[refPos] < columns) {
  16564. refPos += 2;
  16565. }
  16566. }
  16567. break;
  16568. case EOF:
  16569. this.addPixels(columns, 0);
  16570. this.eof = true;
  16571. break;
  16572. default:
  16573. info('bad 2d code');
  16574. this.addPixels(columns, 0);
  16575. this.err = true;
  16576. }
  16577. }
  16578. } else {
  16579. codingLine[0] = 0;
  16580. this.codingPos = 0;
  16581. blackPixels = 0;
  16582. while (codingLine[this.codingPos] < columns) {
  16583. code1 = 0;
  16584. if (blackPixels) {
  16585. do {
  16586. code1 += (code3 = this.getBlackCode());
  16587. } while (code3 >= 64);
  16588. } else {
  16589. do {
  16590. code1 += (code3 = this.getWhiteCode());
  16591. } while (code3 >= 64);
  16592. }
  16593. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  16594. blackPixels ^= 1;
  16595. }
  16596. }
  16597. var gotEOL = false;
  16598. if (this.byteAlign) {
  16599. this.inputBits &= ~7;
  16600. }
  16601. if (!this.eoblock && this.row === this.rows - 1) {
  16602. this.eof = true;
  16603. } else {
  16604. code1 = this.lookBits(12);
  16605. if (this.eoline) {
  16606. while (code1 !== EOF && code1 !== 1) {
  16607. this.eatBits(1);
  16608. code1 = this.lookBits(12);
  16609. }
  16610. } else {
  16611. while (code1 === 0) {
  16612. this.eatBits(1);
  16613. code1 = this.lookBits(12);
  16614. }
  16615. }
  16616. if (code1 === 1) {
  16617. this.eatBits(12);
  16618. gotEOL = true;
  16619. } else if (code1 === EOF) {
  16620. this.eof = true;
  16621. }
  16622. }
  16623. if (!this.eof && this.encoding > 0) {
  16624. this.nextLine2D = !this.lookBits(1);
  16625. this.eatBits(1);
  16626. }
  16627. if (this.eoblock && gotEOL && this.byteAlign) {
  16628. code1 = this.lookBits(12);
  16629. if (code1 === 1) {
  16630. this.eatBits(12);
  16631. if (this.encoding > 0) {
  16632. this.lookBits(1);
  16633. this.eatBits(1);
  16634. }
  16635. if (this.encoding >= 0) {
  16636. for (i = 0; i < 4; ++i) {
  16637. code1 = this.lookBits(12);
  16638. if (code1 !== 1) {
  16639. info('bad rtc code: ' + code1);
  16640. }
  16641. this.eatBits(12);
  16642. if (this.encoding > 0) {
  16643. this.lookBits(1);
  16644. this.eatBits(1);
  16645. }
  16646. }
  16647. }
  16648. this.eof = true;
  16649. }
  16650. } else if (this.err && this.eoline) {
  16651. while (true) {
  16652. code1 = this.lookBits(13);
  16653. if (code1 === EOF) {
  16654. this.eof = true;
  16655. return null;
  16656. }
  16657. if ((code1 >> 1) === 1) {
  16658. break;
  16659. }
  16660. this.eatBits(1);
  16661. }
  16662. this.eatBits(12);
  16663. if (this.encoding > 0) {
  16664. this.eatBits(1);
  16665. this.nextLine2D = !(code1 & 1);
  16666. }
  16667. }
  16668. if (codingLine[0] > 0) {
  16669. this.outputBits = codingLine[this.codingPos = 0];
  16670. } else {
  16671. this.outputBits = codingLine[this.codingPos = 1];
  16672. }
  16673. this.row++;
  16674. }
  16675. var c;
  16676. if (this.outputBits >= 8) {
  16677. c = (this.codingPos & 1) ? 0 : 0xFF;
  16678. this.outputBits -= 8;
  16679. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  16680. this.codingPos++;
  16681. this.outputBits = (codingLine[this.codingPos] -
  16682. codingLine[this.codingPos - 1]);
  16683. }
  16684. } else {
  16685. bits = 8;
  16686. c = 0;
  16687. do {
  16688. if (this.outputBits > bits) {
  16689. c <<= bits;
  16690. if (!(this.codingPos & 1)) {
  16691. c |= 0xFF >> (8 - bits);
  16692. }
  16693. this.outputBits -= bits;
  16694. bits = 0;
  16695. } else {
  16696. c <<= this.outputBits;
  16697. if (!(this.codingPos & 1)) {
  16698. c |= 0xFF >> (8 - this.outputBits);
  16699. }
  16700. bits -= this.outputBits;
  16701. this.outputBits = 0;
  16702. if (codingLine[this.codingPos] < columns) {
  16703. this.codingPos++;
  16704. this.outputBits = (codingLine[this.codingPos] -
  16705. codingLine[this.codingPos - 1]);
  16706. } else if (bits > 0) {
  16707. c <<= bits;
  16708. bits = 0;
  16709. }
  16710. }
  16711. } while (bits);
  16712. }
  16713. if (this.black) {
  16714. c ^= 0xFF;
  16715. }
  16716. return c;
  16717. };
  16718. // This functions returns the code found from the table.
  16719. // The start and end parameters set the boundaries for searching the table.
  16720. // The limit parameter is optional. Function returns an array with three
  16721. // values. The first array element indicates whether a valid code is being
  16722. // returned. The second array element is the actual code. The third array
  16723. // element indicates whether EOF was reached.
  16724. CCITTFaxStream.prototype.findTableCode =
  16725. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  16726. var limitValue = limit || 0;
  16727. for (var i = start; i <= end; ++i) {
  16728. var code = this.lookBits(i);
  16729. if (code === EOF) {
  16730. return [true, 1, false];
  16731. }
  16732. if (i < end) {
  16733. code <<= end - i;
  16734. }
  16735. if (!limitValue || code >= limitValue) {
  16736. var p = table[code - limitValue];
  16737. if (p[0] === i) {
  16738. this.eatBits(i);
  16739. return [true, p[1], true];
  16740. }
  16741. }
  16742. }
  16743. return [false, 0, false];
  16744. };
  16745. CCITTFaxStream.prototype.getTwoDimCode =
  16746. function ccittFaxStreamGetTwoDimCode() {
  16747. var code = 0;
  16748. var p;
  16749. if (this.eoblock) {
  16750. code = this.lookBits(7);
  16751. p = twoDimTable[code];
  16752. if (p && p[0] > 0) {
  16753. this.eatBits(p[0]);
  16754. return p[1];
  16755. }
  16756. } else {
  16757. var result = this.findTableCode(1, 7, twoDimTable);
  16758. if (result[0] && result[2]) {
  16759. return result[1];
  16760. }
  16761. }
  16762. info('Bad two dim code');
  16763. return EOF;
  16764. };
  16765. CCITTFaxStream.prototype.getWhiteCode =
  16766. function ccittFaxStreamGetWhiteCode() {
  16767. var code = 0;
  16768. var p;
  16769. if (this.eoblock) {
  16770. code = this.lookBits(12);
  16771. if (code === EOF) {
  16772. return 1;
  16773. }
  16774. if ((code >> 5) === 0) {
  16775. p = whiteTable1[code];
  16776. } else {
  16777. p = whiteTable2[code >> 3];
  16778. }
  16779. if (p[0] > 0) {
  16780. this.eatBits(p[0]);
  16781. return p[1];
  16782. }
  16783. } else {
  16784. var result = this.findTableCode(1, 9, whiteTable2);
  16785. if (result[0]) {
  16786. return result[1];
  16787. }
  16788. result = this.findTableCode(11, 12, whiteTable1);
  16789. if (result[0]) {
  16790. return result[1];
  16791. }
  16792. }
  16793. info('bad white code');
  16794. this.eatBits(1);
  16795. return 1;
  16796. };
  16797. CCITTFaxStream.prototype.getBlackCode =
  16798. function ccittFaxStreamGetBlackCode() {
  16799. var code, p;
  16800. if (this.eoblock) {
  16801. code = this.lookBits(13);
  16802. if (code === EOF) {
  16803. return 1;
  16804. }
  16805. if ((code >> 7) === 0) {
  16806. p = blackTable1[code];
  16807. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  16808. p = blackTable2[(code >> 1) - 64];
  16809. } else {
  16810. p = blackTable3[code >> 7];
  16811. }
  16812. if (p[0] > 0) {
  16813. this.eatBits(p[0]);
  16814. return p[1];
  16815. }
  16816. } else {
  16817. var result = this.findTableCode(2, 6, blackTable3);
  16818. if (result[0]) {
  16819. return result[1];
  16820. }
  16821. result = this.findTableCode(7, 12, blackTable2, 64);
  16822. if (result[0]) {
  16823. return result[1];
  16824. }
  16825. result = this.findTableCode(10, 13, blackTable1);
  16826. if (result[0]) {
  16827. return result[1];
  16828. }
  16829. }
  16830. info('bad black code');
  16831. this.eatBits(1);
  16832. return 1;
  16833. };
  16834. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  16835. var c;
  16836. while (this.inputBits < n) {
  16837. if ((c = this.str.getByte()) === -1) {
  16838. if (this.inputBits === 0) {
  16839. return EOF;
  16840. }
  16841. return ((this.inputBuf << (n - this.inputBits)) &
  16842. (0xFFFF >> (16 - n)));
  16843. }
  16844. this.inputBuf = (this.inputBuf << 8) + c;
  16845. this.inputBits += 8;
  16846. }
  16847. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  16848. };
  16849. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  16850. if ((this.inputBits -= n) < 0) {
  16851. this.inputBits = 0;
  16852. }
  16853. };
  16854. return CCITTFaxStream;
  16855. })();
  16856. var LZWStream = (function LZWStreamClosure() {
  16857. function LZWStream(str, maybeLength, earlyChange) {
  16858. this.str = str;
  16859. this.dict = str.dict;
  16860. this.cachedData = 0;
  16861. this.bitsCached = 0;
  16862. var maxLzwDictionarySize = 4096;
  16863. var lzwState = {
  16864. earlyChange: earlyChange,
  16865. codeLength: 9,
  16866. nextCode: 258,
  16867. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  16868. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  16869. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  16870. currentSequence: new Uint8Array(maxLzwDictionarySize),
  16871. currentSequenceLength: 0
  16872. };
  16873. for (var i = 0; i < 256; ++i) {
  16874. lzwState.dictionaryValues[i] = i;
  16875. lzwState.dictionaryLengths[i] = 1;
  16876. }
  16877. this.lzwState = lzwState;
  16878. DecodeStream.call(this, maybeLength);
  16879. }
  16880. LZWStream.prototype = Object.create(DecodeStream.prototype);
  16881. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  16882. var bitsCached = this.bitsCached;
  16883. var cachedData = this.cachedData;
  16884. while (bitsCached < n) {
  16885. var c = this.str.getByte();
  16886. if (c === -1) {
  16887. this.eof = true;
  16888. return null;
  16889. }
  16890. cachedData = (cachedData << 8) | c;
  16891. bitsCached += 8;
  16892. }
  16893. this.bitsCached = (bitsCached -= n);
  16894. this.cachedData = cachedData;
  16895. this.lastCode = null;
  16896. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  16897. };
  16898. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  16899. var blockSize = 512;
  16900. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  16901. var i, j, q;
  16902. var lzwState = this.lzwState;
  16903. if (!lzwState) {
  16904. return; // eof was found
  16905. }
  16906. var earlyChange = lzwState.earlyChange;
  16907. var nextCode = lzwState.nextCode;
  16908. var dictionaryValues = lzwState.dictionaryValues;
  16909. var dictionaryLengths = lzwState.dictionaryLengths;
  16910. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  16911. var codeLength = lzwState.codeLength;
  16912. var prevCode = lzwState.prevCode;
  16913. var currentSequence = lzwState.currentSequence;
  16914. var currentSequenceLength = lzwState.currentSequenceLength;
  16915. var decodedLength = 0;
  16916. var currentBufferLength = this.bufferLength;
  16917. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16918. for (i = 0; i < blockSize; i++) {
  16919. var code = this.readBits(codeLength);
  16920. var hasPrev = currentSequenceLength > 0;
  16921. if (code < 256) {
  16922. currentSequence[0] = code;
  16923. currentSequenceLength = 1;
  16924. } else if (code >= 258) {
  16925. if (code < nextCode) {
  16926. currentSequenceLength = dictionaryLengths[code];
  16927. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  16928. currentSequence[j] = dictionaryValues[q];
  16929. q = dictionaryPrevCodes[q];
  16930. }
  16931. } else {
  16932. currentSequence[currentSequenceLength++] = currentSequence[0];
  16933. }
  16934. } else if (code === 256) {
  16935. codeLength = 9;
  16936. nextCode = 258;
  16937. currentSequenceLength = 0;
  16938. continue;
  16939. } else {
  16940. this.eof = true;
  16941. delete this.lzwState;
  16942. break;
  16943. }
  16944. if (hasPrev) {
  16945. dictionaryPrevCodes[nextCode] = prevCode;
  16946. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  16947. dictionaryValues[nextCode] = currentSequence[0];
  16948. nextCode++;
  16949. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  16950. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  16951. 0.6931471805599453 + 1, 12) | 0;
  16952. }
  16953. prevCode = code;
  16954. decodedLength += currentSequenceLength;
  16955. if (estimatedDecodedSize < decodedLength) {
  16956. do {
  16957. estimatedDecodedSize += decodedSizeDelta;
  16958. } while (estimatedDecodedSize < decodedLength);
  16959. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16960. }
  16961. for (j = 0; j < currentSequenceLength; j++) {
  16962. buffer[currentBufferLength++] = currentSequence[j];
  16963. }
  16964. }
  16965. lzwState.nextCode = nextCode;
  16966. lzwState.codeLength = codeLength;
  16967. lzwState.prevCode = prevCode;
  16968. lzwState.currentSequenceLength = currentSequenceLength;
  16969. this.bufferLength = currentBufferLength;
  16970. };
  16971. return LZWStream;
  16972. })();
  16973. var NullStream = (function NullStreamClosure() {
  16974. function NullStream() {
  16975. Stream.call(this, new Uint8Array(0));
  16976. }
  16977. NullStream.prototype = Stream.prototype;
  16978. return NullStream;
  16979. })();
  16980. // TODO refactor to remove dependency on parser.js
  16981. function _setCoreParser(coreParser_) {
  16982. coreParser = coreParser_;
  16983. EOF = coreParser_.EOF;
  16984. Lexer = coreParser_.Lexer;
  16985. }
  16986. exports._setCoreParser = _setCoreParser;
  16987. // TODO refactor to remove dependency on colorspace.js
  16988. function _setCoreColorSpace(coreColorSpace_) {
  16989. coreColorSpace = coreColorSpace_;
  16990. ColorSpace = coreColorSpace_.ColorSpace;
  16991. }
  16992. exports._setCoreColorSpace = _setCoreColorSpace;
  16993. exports.Ascii85Stream = Ascii85Stream;
  16994. exports.AsciiHexStream = AsciiHexStream;
  16995. exports.CCITTFaxStream = CCITTFaxStream;
  16996. exports.DecryptStream = DecryptStream;
  16997. exports.DecodeStream = DecodeStream;
  16998. exports.FlateStream = FlateStream;
  16999. exports.Jbig2Stream = Jbig2Stream;
  17000. exports.JpegStream = JpegStream;
  17001. exports.JpxStream = JpxStream;
  17002. exports.NullStream = NullStream;
  17003. exports.PredictorStream = PredictorStream;
  17004. exports.RunLengthStream = RunLengthStream;
  17005. exports.Stream = Stream;
  17006. exports.StreamsSequenceStream = StreamsSequenceStream;
  17007. exports.StringStream = StringStream;
  17008. exports.LZWStream = LZWStream;
  17009. }));
  17010. (function (root, factory) {
  17011. {
  17012. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  17013. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  17014. }
  17015. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  17016. var PasswordException = sharedUtil.PasswordException;
  17017. var PasswordResponses = sharedUtil.PasswordResponses;
  17018. var bytesToString = sharedUtil.bytesToString;
  17019. var error = sharedUtil.error;
  17020. var isInt = sharedUtil.isInt;
  17021. var stringToBytes = sharedUtil.stringToBytes;
  17022. var utf8StringToString = sharedUtil.utf8StringToString;
  17023. var warn = sharedUtil.warn;
  17024. var Name = corePrimitives.Name;
  17025. var isName = corePrimitives.isName;
  17026. var DecryptStream = coreStream.DecryptStream;
  17027. var ARCFourCipher = (function ARCFourCipherClosure() {
  17028. function ARCFourCipher(key) {
  17029. this.a = 0;
  17030. this.b = 0;
  17031. var s = new Uint8Array(256);
  17032. var i, j = 0, tmp, keyLength = key.length;
  17033. for (i = 0; i < 256; ++i) {
  17034. s[i] = i;
  17035. }
  17036. for (i = 0; i < 256; ++i) {
  17037. tmp = s[i];
  17038. j = (j + tmp + key[i % keyLength]) & 0xFF;
  17039. s[i] = s[j];
  17040. s[j] = tmp;
  17041. }
  17042. this.s = s;
  17043. }
  17044. ARCFourCipher.prototype = {
  17045. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  17046. var i, n = data.length, tmp, tmp2;
  17047. var a = this.a, b = this.b, s = this.s;
  17048. var output = new Uint8Array(n);
  17049. for (i = 0; i < n; ++i) {
  17050. a = (a + 1) & 0xFF;
  17051. tmp = s[a];
  17052. b = (b + tmp) & 0xFF;
  17053. tmp2 = s[b];
  17054. s[a] = tmp2;
  17055. s[b] = tmp;
  17056. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  17057. }
  17058. this.a = a;
  17059. this.b = b;
  17060. return output;
  17061. }
  17062. };
  17063. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  17064. return ARCFourCipher;
  17065. })();
  17066. var calculateMD5 = (function calculateMD5Closure() {
  17067. var r = new Uint8Array([
  17068. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  17069. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  17070. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  17071. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  17072. var k = new Int32Array([
  17073. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  17074. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  17075. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  17076. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  17077. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  17078. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  17079. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  17080. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  17081. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  17082. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  17083. -145523070, -1120210379, 718787259, -343485551]);
  17084. function hash(data, offset, length) {
  17085. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  17086. // pre-processing
  17087. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  17088. var padded = new Uint8Array(paddedLength);
  17089. var i, j, n;
  17090. for (i = 0; i < length; ++i) {
  17091. padded[i] = data[offset++];
  17092. }
  17093. padded[i++] = 0x80;
  17094. n = paddedLength - 8;
  17095. while (i < n) {
  17096. padded[i++] = 0;
  17097. }
  17098. padded[i++] = (length << 3) & 0xFF;
  17099. padded[i++] = (length >> 5) & 0xFF;
  17100. padded[i++] = (length >> 13) & 0xFF;
  17101. padded[i++] = (length >> 21) & 0xFF;
  17102. padded[i++] = (length >>> 29) & 0xFF;
  17103. padded[i++] = 0;
  17104. padded[i++] = 0;
  17105. padded[i++] = 0;
  17106. var w = new Int32Array(16);
  17107. for (i = 0; i < paddedLength;) {
  17108. for (j = 0; j < 16; ++j, i += 4) {
  17109. w[j] = (padded[i] | (padded[i + 1] << 8) |
  17110. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  17111. }
  17112. var a = h0, b = h1, c = h2, d = h3, f, g;
  17113. for (j = 0; j < 64; ++j) {
  17114. if (j < 16) {
  17115. f = (b & c) | ((~b) & d);
  17116. g = j;
  17117. } else if (j < 32) {
  17118. f = (d & b) | ((~d) & c);
  17119. g = (5 * j + 1) & 15;
  17120. } else if (j < 48) {
  17121. f = b ^ c ^ d;
  17122. g = (3 * j + 5) & 15;
  17123. } else {
  17124. f = c ^ (b | (~d));
  17125. g = (7 * j) & 15;
  17126. }
  17127. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  17128. d = c;
  17129. c = b;
  17130. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  17131. a = tmp;
  17132. }
  17133. h0 = (h0 + a) | 0;
  17134. h1 = (h1 + b) | 0;
  17135. h2 = (h2 + c) | 0;
  17136. h3 = (h3 + d) | 0;
  17137. }
  17138. return new Uint8Array([
  17139. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  17140. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  17141. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  17142. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  17143. ]);
  17144. }
  17145. return hash;
  17146. })();
  17147. var Word64 = (function Word64Closure() {
  17148. function Word64(highInteger, lowInteger) {
  17149. this.high = highInteger | 0;
  17150. this.low = lowInteger | 0;
  17151. }
  17152. Word64.prototype = {
  17153. and: function Word64_and(word) {
  17154. this.high &= word.high;
  17155. this.low &= word.low;
  17156. },
  17157. xor: function Word64_xor(word) {
  17158. this.high ^= word.high;
  17159. this.low ^= word.low;
  17160. },
  17161. or: function Word64_or(word) {
  17162. this.high |= word.high;
  17163. this.low |= word.low;
  17164. },
  17165. shiftRight: function Word64_shiftRight(places) {
  17166. if (places >= 32) {
  17167. this.low = (this.high >>> (places - 32)) | 0;
  17168. this.high = 0;
  17169. } else {
  17170. this.low = (this.low >>> places) | (this.high << (32 - places));
  17171. this.high = (this.high >>> places) | 0;
  17172. }
  17173. },
  17174. shiftLeft: function Word64_shiftLeft(places) {
  17175. if (places >= 32) {
  17176. this.high = this.low << (places - 32);
  17177. this.low = 0;
  17178. } else {
  17179. this.high = (this.high << places) | (this.low >>> (32 - places));
  17180. this.low = this.low << places;
  17181. }
  17182. },
  17183. rotateRight: function Word64_rotateRight(places) {
  17184. var low, high;
  17185. if (places & 32) {
  17186. high = this.low;
  17187. low = this.high;
  17188. } else {
  17189. low = this.low;
  17190. high = this.high;
  17191. }
  17192. places &= 31;
  17193. this.low = (low >>> places) | (high << (32 - places));
  17194. this.high = (high >>> places) | (low << (32 - places));
  17195. },
  17196. not: function Word64_not() {
  17197. this.high = ~this.high;
  17198. this.low = ~this.low;
  17199. },
  17200. add: function Word64_add(word) {
  17201. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  17202. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  17203. if (lowAdd > 0xFFFFFFFF) {
  17204. highAdd += 1;
  17205. }
  17206. this.low = lowAdd | 0;
  17207. this.high = highAdd | 0;
  17208. },
  17209. copyTo: function Word64_copyTo(bytes, offset) {
  17210. bytes[offset] = (this.high >>> 24) & 0xFF;
  17211. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  17212. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  17213. bytes[offset + 3] = this.high & 0xFF;
  17214. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  17215. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  17216. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  17217. bytes[offset + 7] = this.low & 0xFF;
  17218. },
  17219. assign: function Word64_assign(word) {
  17220. this.high = word.high;
  17221. this.low = word.low;
  17222. }
  17223. };
  17224. return Word64;
  17225. })();
  17226. var calculateSHA256 = (function calculateSHA256Closure() {
  17227. function rotr(x, n) {
  17228. return (x >>> n) | (x << 32 - n);
  17229. }
  17230. function ch(x, y, z) {
  17231. return (x & y) ^ (~x & z);
  17232. }
  17233. function maj(x, y, z) {
  17234. return (x & y) ^ (x & z) ^ (y & z);
  17235. }
  17236. function sigma(x) {
  17237. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  17238. }
  17239. function sigmaPrime(x) {
  17240. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  17241. }
  17242. function littleSigma(x) {
  17243. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  17244. }
  17245. function littleSigmaPrime(x) {
  17246. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  17247. }
  17248. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  17249. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  17250. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  17251. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  17252. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  17253. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  17254. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  17255. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  17256. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  17257. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  17258. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  17259. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  17260. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17261. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  17262. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  17263. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  17264. function hash(data, offset, length) {
  17265. // initial hash values
  17266. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  17267. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  17268. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  17269. // pre-processing
  17270. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  17271. var padded = new Uint8Array(paddedLength);
  17272. var i, j, n;
  17273. for (i = 0; i < length; ++i) {
  17274. padded[i] = data[offset++];
  17275. }
  17276. padded[i++] = 0x80;
  17277. n = paddedLength - 8;
  17278. while (i < n) {
  17279. padded[i++] = 0;
  17280. }
  17281. padded[i++] = 0;
  17282. padded[i++] = 0;
  17283. padded[i++] = 0;
  17284. padded[i++] = (length >>> 29) & 0xFF;
  17285. padded[i++] = (length >> 21) & 0xFF;
  17286. padded[i++] = (length >> 13) & 0xFF;
  17287. padded[i++] = (length >> 5) & 0xFF;
  17288. padded[i++] = (length << 3) & 0xFF;
  17289. var w = new Uint32Array(64);
  17290. // for each 512 bit block
  17291. for (i = 0; i < paddedLength;) {
  17292. for (j = 0; j < 16; ++j) {
  17293. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  17294. (padded[i + 2] << 8) | (padded[i + 3]));
  17295. i += 4;
  17296. }
  17297. for (j = 16; j < 64; ++j) {
  17298. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  17299. littleSigma(w[j - 15]) + w[j - 16] | 0;
  17300. }
  17301. var a = h0, b = h1, c = h2, d = h3, e = h4,
  17302. f = h5, g = h6, h = h7, t1, t2;
  17303. for (j = 0; j < 64; ++j) {
  17304. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  17305. t2 = sigma(a) + maj(a, b, c);
  17306. h = g;
  17307. g = f;
  17308. f = e;
  17309. e = (d + t1) | 0;
  17310. d = c;
  17311. c = b;
  17312. b = a;
  17313. a = (t1 + t2) | 0;
  17314. }
  17315. h0 = (h0 + a) | 0;
  17316. h1 = (h1 + b) | 0;
  17317. h2 = (h2 + c) | 0;
  17318. h3 = (h3 + d) | 0;
  17319. h4 = (h4 + e) | 0;
  17320. h5 = (h5 + f) | 0;
  17321. h6 = (h6 + g) | 0;
  17322. h7 = (h7 + h) | 0;
  17323. }
  17324. return new Uint8Array([
  17325. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  17326. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  17327. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  17328. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  17329. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  17330. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  17331. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  17332. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  17333. ]);
  17334. }
  17335. return hash;
  17336. })();
  17337. var calculateSHA512 = (function calculateSHA512Closure() {
  17338. function ch(result, x, y, z, tmp) {
  17339. result.assign(x);
  17340. result.and(y);
  17341. tmp.assign(x);
  17342. tmp.not();
  17343. tmp.and(z);
  17344. result.xor(tmp);
  17345. }
  17346. function maj(result, x, y, z, tmp) {
  17347. result.assign(x);
  17348. result.and(y);
  17349. tmp.assign(x);
  17350. tmp.and(z);
  17351. result.xor(tmp);
  17352. tmp.assign(y);
  17353. tmp.and(z);
  17354. result.xor(tmp);
  17355. }
  17356. function sigma(result, x, tmp) {
  17357. result.assign(x);
  17358. result.rotateRight(28);
  17359. tmp.assign(x);
  17360. tmp.rotateRight(34);
  17361. result.xor(tmp);
  17362. tmp.assign(x);
  17363. tmp.rotateRight(39);
  17364. result.xor(tmp);
  17365. }
  17366. function sigmaPrime(result, x, tmp) {
  17367. result.assign(x);
  17368. result.rotateRight(14);
  17369. tmp.assign(x);
  17370. tmp.rotateRight(18);
  17371. result.xor(tmp);
  17372. tmp.assign(x);
  17373. tmp.rotateRight(41);
  17374. result.xor(tmp);
  17375. }
  17376. function littleSigma(result, x, tmp) {
  17377. result.assign(x);
  17378. result.rotateRight(1);
  17379. tmp.assign(x);
  17380. tmp.rotateRight(8);
  17381. result.xor(tmp);
  17382. tmp.assign(x);
  17383. tmp.shiftRight(7);
  17384. result.xor(tmp);
  17385. }
  17386. function littleSigmaPrime(result, x, tmp) {
  17387. result.assign(x);
  17388. result.rotateRight(19);
  17389. tmp.assign(x);
  17390. tmp.rotateRight(61);
  17391. result.xor(tmp);
  17392. tmp.assign(x);
  17393. tmp.shiftRight(6);
  17394. result.xor(tmp);
  17395. }
  17396. var k = [
  17397. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  17398. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  17399. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  17400. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  17401. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  17402. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  17403. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  17404. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  17405. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  17406. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  17407. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  17408. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  17409. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  17410. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  17411. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  17412. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  17413. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  17414. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  17415. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  17416. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  17417. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  17418. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  17419. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  17420. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  17421. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  17422. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  17423. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  17424. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  17425. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  17426. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  17427. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  17428. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  17429. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  17430. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  17431. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  17432. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  17433. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  17434. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  17435. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  17436. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  17437. function hash(data, offset, length, mode384) {
  17438. mode384 = !!mode384;
  17439. // initial hash values
  17440. var h0, h1, h2, h3, h4, h5, h6, h7;
  17441. if (!mode384) {
  17442. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  17443. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  17444. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  17445. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  17446. h4 = new Word64(0x510e527f, 0xade682d1);
  17447. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  17448. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  17449. h7 = new Word64(0x5be0cd19, 0x137e2179);
  17450. }
  17451. else {
  17452. // SHA384 is exactly the same
  17453. // except with different starting values and a trimmed result
  17454. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  17455. h1 = new Word64(0x629a292a, 0x367cd507);
  17456. h2 = new Word64(0x9159015a, 0x3070dd17);
  17457. h3 = new Word64(0x152fecd8, 0xf70e5939);
  17458. h4 = new Word64(0x67332667, 0xffc00b31);
  17459. h5 = new Word64(0x8eb44a87, 0x68581511);
  17460. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  17461. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  17462. }
  17463. // pre-processing
  17464. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  17465. var padded = new Uint8Array(paddedLength);
  17466. var i, j, n;
  17467. for (i = 0; i < length; ++i) {
  17468. padded[i] = data[offset++];
  17469. }
  17470. padded[i++] = 0x80;
  17471. n = paddedLength - 16;
  17472. while (i < n) {
  17473. padded[i++] = 0;
  17474. }
  17475. padded[i++] = 0;
  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++] = (length >>> 29) & 0xFF;
  17487. padded[i++] = (length >> 21) & 0xFF;
  17488. padded[i++] = (length >> 13) & 0xFF;
  17489. padded[i++] = (length >> 5) & 0xFF;
  17490. padded[i++] = (length << 3) & 0xFF;
  17491. var w = new Array(80);
  17492. for (i = 0; i < 80; i++) {
  17493. w[i] = new Word64(0, 0);
  17494. }
  17495. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  17496. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  17497. var g = new Word64(0, 0), h = new Word64(0, 0);
  17498. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  17499. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  17500. // for each 1024 bit block
  17501. for (i = 0; i < paddedLength;) {
  17502. for (j = 0; j < 16; ++j) {
  17503. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  17504. (padded[i + 2] << 8) | (padded[i + 3]);
  17505. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  17506. (padded[i + 6]) << 8 | (padded[i + 7]);
  17507. i += 8;
  17508. }
  17509. for (j = 16; j < 80; ++j) {
  17510. tmp3 = w[j];
  17511. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  17512. tmp3.add(w[j - 7]);
  17513. littleSigma(tmp1, w[j - 15], tmp2);
  17514. tmp3.add(tmp1);
  17515. tmp3.add(w[j - 16]);
  17516. }
  17517. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  17518. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  17519. for (j = 0; j < 80; ++j) {
  17520. t1.assign(h);
  17521. sigmaPrime(tmp1, e, tmp2);
  17522. t1.add(tmp1);
  17523. ch(tmp1, e, f, g, tmp2);
  17524. t1.add(tmp1);
  17525. t1.add(k[j]);
  17526. t1.add(w[j]);
  17527. sigma(t2, a, tmp2);
  17528. maj(tmp1, a, b, c, tmp2);
  17529. t2.add(tmp1);
  17530. tmp3 = h;
  17531. h = g;
  17532. g = f;
  17533. f = e;
  17534. d.add(t1);
  17535. e = d;
  17536. d = c;
  17537. c = b;
  17538. b = a;
  17539. tmp3.assign(t1);
  17540. tmp3.add(t2);
  17541. a = tmp3;
  17542. }
  17543. h0.add(a);
  17544. h1.add(b);
  17545. h2.add(c);
  17546. h3.add(d);
  17547. h4.add(e);
  17548. h5.add(f);
  17549. h6.add(g);
  17550. h7.add(h);
  17551. }
  17552. var result;
  17553. if (!mode384) {
  17554. result = new Uint8Array(64);
  17555. h0.copyTo(result,0);
  17556. h1.copyTo(result,8);
  17557. h2.copyTo(result,16);
  17558. h3.copyTo(result,24);
  17559. h4.copyTo(result,32);
  17560. h5.copyTo(result,40);
  17561. h6.copyTo(result,48);
  17562. h7.copyTo(result,56);
  17563. }
  17564. else {
  17565. result = new Uint8Array(48);
  17566. h0.copyTo(result,0);
  17567. h1.copyTo(result,8);
  17568. h2.copyTo(result,16);
  17569. h3.copyTo(result,24);
  17570. h4.copyTo(result,32);
  17571. h5.copyTo(result,40);
  17572. }
  17573. return result;
  17574. }
  17575. return hash;
  17576. })();
  17577. var calculateSHA384 = (function calculateSHA384Closure() {
  17578. function hash(data, offset, length) {
  17579. return calculateSHA512(data, offset, length, true);
  17580. }
  17581. return hash;
  17582. })();
  17583. var NullCipher = (function NullCipherClosure() {
  17584. function NullCipher() {
  17585. }
  17586. NullCipher.prototype = {
  17587. decryptBlock: function NullCipher_decryptBlock(data) {
  17588. return data;
  17589. }
  17590. };
  17591. return NullCipher;
  17592. })();
  17593. var AES128Cipher = (function AES128CipherClosure() {
  17594. var rcon = new Uint8Array([
  17595. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17596. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17597. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17598. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17599. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  17600. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  17601. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  17602. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  17603. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  17604. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  17605. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  17606. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  17607. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  17608. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  17609. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  17610. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  17611. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  17612. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17613. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17614. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17615. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17616. 0x74, 0xe8, 0xcb, 0x8d]);
  17617. var s = new Uint8Array([
  17618. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  17619. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  17620. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  17621. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  17622. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  17623. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  17624. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  17625. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  17626. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  17627. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  17628. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  17629. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  17630. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  17631. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  17632. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  17633. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  17634. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  17635. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  17636. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  17637. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  17638. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  17639. 0xb0, 0x54, 0xbb, 0x16]);
  17640. var inv_s = new Uint8Array([
  17641. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  17642. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  17643. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  17644. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  17645. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  17646. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  17647. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  17648. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  17649. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  17650. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  17651. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  17652. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  17653. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  17654. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  17655. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  17656. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  17657. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  17658. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  17659. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  17660. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  17661. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  17662. 0x55, 0x21, 0x0c, 0x7d]);
  17663. var mixCol = new Uint8Array(256);
  17664. for (var i = 0; i < 256; i++) {
  17665. if (i < 128) {
  17666. mixCol[i] = i << 1;
  17667. } else {
  17668. mixCol[i] = (i << 1) ^ 0x1b;
  17669. }
  17670. }
  17671. var mix = new Uint32Array([
  17672. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  17673. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  17674. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  17675. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  17676. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  17677. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  17678. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  17679. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  17680. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  17681. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  17682. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  17683. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  17684. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  17685. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  17686. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  17687. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  17688. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  17689. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  17690. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  17691. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  17692. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  17693. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  17694. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  17695. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  17696. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  17697. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  17698. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  17699. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  17700. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  17701. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  17702. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  17703. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  17704. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  17705. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  17706. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  17707. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  17708. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  17709. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  17710. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  17711. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  17712. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  17713. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  17714. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  17715. function expandKey128(cipherKey) {
  17716. var b = 176, result = new Uint8Array(b);
  17717. result.set(cipherKey);
  17718. for (var j = 16, i = 1; j < b; ++i) {
  17719. // RotWord
  17720. var t1 = result[j - 3], t2 = result[j - 2],
  17721. t3 = result[j - 1], t4 = result[j - 4];
  17722. // SubWord
  17723. t1 = s[t1];
  17724. t2 = s[t2];
  17725. t3 = s[t3];
  17726. t4 = s[t4];
  17727. // Rcon
  17728. t1 = t1 ^ rcon[i];
  17729. for (var n = 0; n < 4; ++n) {
  17730. result[j] = (t1 ^= result[j - 16]);
  17731. j++;
  17732. result[j] = (t2 ^= result[j - 16]);
  17733. j++;
  17734. result[j] = (t3 ^= result[j - 16]);
  17735. j++;
  17736. result[j] = (t4 ^= result[j - 16]);
  17737. j++;
  17738. }
  17739. }
  17740. return result;
  17741. }
  17742. function decrypt128(input, key) {
  17743. var state = new Uint8Array(16);
  17744. state.set(input);
  17745. var i, j, k;
  17746. var t, u, v;
  17747. // AddRoundKey
  17748. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17749. state[j] ^= key[k];
  17750. }
  17751. for (i = 9; i >= 1; --i) {
  17752. // InvShiftRows
  17753. t = state[13];
  17754. state[13] = state[9];
  17755. state[9] = state[5];
  17756. state[5] = state[1];
  17757. state[1] = t;
  17758. t = state[14];
  17759. u = state[10];
  17760. state[14] = state[6];
  17761. state[10] = state[2];
  17762. state[6] = t;
  17763. state[2] = u;
  17764. t = state[15];
  17765. u = state[11];
  17766. v = state[7];
  17767. state[15] = state[3];
  17768. state[11] = t;
  17769. state[7] = u;
  17770. state[3] = v;
  17771. // InvSubBytes
  17772. for (j = 0; j < 16; ++j) {
  17773. state[j] = inv_s[state[j]];
  17774. }
  17775. // AddRoundKey
  17776. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17777. state[j] ^= key[k];
  17778. }
  17779. // InvMixColumns
  17780. for (j = 0; j < 16; j += 4) {
  17781. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  17782. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  17783. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  17784. (s3 >>> 24) ^ (s3 << 8));
  17785. state[j] = (t >>> 24) & 0xFF;
  17786. state[j + 1] = (t >> 16) & 0xFF;
  17787. state[j + 2] = (t >> 8) & 0xFF;
  17788. state[j + 3] = t & 0xFF;
  17789. }
  17790. }
  17791. // InvShiftRows
  17792. t = state[13];
  17793. state[13] = state[9];
  17794. state[9] = state[5];
  17795. state[5] = state[1];
  17796. state[1] = t;
  17797. t = state[14];
  17798. u = state[10];
  17799. state[14] = state[6];
  17800. state[10] = state[2];
  17801. state[6] = t;
  17802. state[2] = u;
  17803. t = state[15];
  17804. u = state[11];
  17805. v = state[7];
  17806. state[15] = state[3];
  17807. state[11] = t;
  17808. state[7] = u;
  17809. state[3] = v;
  17810. for (j = 0; j < 16; ++j) {
  17811. // InvSubBytes
  17812. state[j] = inv_s[state[j]];
  17813. // AddRoundKey
  17814. state[j] ^= key[j];
  17815. }
  17816. return state;
  17817. }
  17818. function encrypt128(input, key) {
  17819. var t, u, v, k;
  17820. var state = new Uint8Array(16);
  17821. state.set(input);
  17822. for (j = 0; j < 16; ++j) {
  17823. // AddRoundKey
  17824. state[j] ^= key[j];
  17825. }
  17826. for (i = 1; i < 10; i++) {
  17827. //SubBytes
  17828. for (j = 0; j < 16; ++j) {
  17829. state[j] = s[state[j]];
  17830. }
  17831. //ShiftRows
  17832. v = state[1];
  17833. state[1] = state[5];
  17834. state[5] = state[9];
  17835. state[9] = state[13];
  17836. state[13] = v;
  17837. v = state[2];
  17838. u = state[6];
  17839. state[2] = state[10];
  17840. state[6] = state[14];
  17841. state[10] = v;
  17842. state[14] = u;
  17843. v = state[3];
  17844. u = state[7];
  17845. t = state[11];
  17846. state[3] = state[15];
  17847. state[7] = v;
  17848. state[11] = u;
  17849. state[15] = t;
  17850. //MixColumns
  17851. for (var j = 0; j < 16; j += 4) {
  17852. var s0 = state[j + 0], s1 = state[j + 1];
  17853. var s2 = state[j + 2], s3 = state[j + 3];
  17854. t = s0 ^ s1 ^ s2 ^ s3;
  17855. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  17856. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  17857. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  17858. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  17859. }
  17860. //AddRoundKey
  17861. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17862. state[j] ^= key[k];
  17863. }
  17864. }
  17865. //SubBytes
  17866. for (j = 0; j < 16; ++j) {
  17867. state[j] = s[state[j]];
  17868. }
  17869. //ShiftRows
  17870. v = state[1];
  17871. state[1] = state[5];
  17872. state[5] = state[9];
  17873. state[9] = state[13];
  17874. state[13] = v;
  17875. v = state[2];
  17876. u = state[6];
  17877. state[2] = state[10];
  17878. state[6] = state[14];
  17879. state[10] = v;
  17880. state[14] = u;
  17881. v = state[3];
  17882. u = state[7];
  17883. t = state[11];
  17884. state[3] = state[15];
  17885. state[7] = v;
  17886. state[11] = u;
  17887. state[15] = t;
  17888. //AddRoundKey
  17889. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17890. state[j] ^= key[k];
  17891. }
  17892. return state;
  17893. }
  17894. function AES128Cipher(key) {
  17895. this.key = expandKey128(key);
  17896. this.buffer = new Uint8Array(16);
  17897. this.bufferPosition = 0;
  17898. }
  17899. function decryptBlock2(data, finalize) {
  17900. var i, j, ii, sourceLength = data.length,
  17901. buffer = this.buffer, bufferLength = this.bufferPosition,
  17902. result = [], iv = this.iv;
  17903. for (i = 0; i < sourceLength; ++i) {
  17904. buffer[bufferLength] = data[i];
  17905. ++bufferLength;
  17906. if (bufferLength < 16) {
  17907. continue;
  17908. }
  17909. // buffer is full, decrypting
  17910. var plain = decrypt128(buffer, this.key);
  17911. // xor-ing the IV vector to get plain text
  17912. for (j = 0; j < 16; ++j) {
  17913. plain[j] ^= iv[j];
  17914. }
  17915. iv = buffer;
  17916. result.push(plain);
  17917. buffer = new Uint8Array(16);
  17918. bufferLength = 0;
  17919. }
  17920. // saving incomplete buffer
  17921. this.buffer = buffer;
  17922. this.bufferLength = bufferLength;
  17923. this.iv = iv;
  17924. if (result.length === 0) {
  17925. return new Uint8Array([]);
  17926. }
  17927. // combining plain text blocks into one
  17928. var outputLength = 16 * result.length;
  17929. if (finalize) {
  17930. // undo a padding that is described in RFC 2898
  17931. var lastBlock = result[result.length - 1];
  17932. var psLen = lastBlock[15];
  17933. if (psLen <= 16) {
  17934. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  17935. if (lastBlock[i] !== psLen) {
  17936. // Invalid padding, assume that the block has no padding.
  17937. psLen = 0;
  17938. break;
  17939. }
  17940. }
  17941. outputLength -= psLen;
  17942. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  17943. }
  17944. }
  17945. var output = new Uint8Array(outputLength);
  17946. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  17947. output.set(result[i], j);
  17948. }
  17949. return output;
  17950. }
  17951. AES128Cipher.prototype = {
  17952. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  17953. var i, sourceLength = data.length;
  17954. var buffer = this.buffer, bufferLength = this.bufferPosition;
  17955. // waiting for IV values -- they are at the start of the stream
  17956. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  17957. buffer[bufferLength] = data[i];
  17958. }
  17959. if (bufferLength < 16) {
  17960. // need more data
  17961. this.bufferLength = bufferLength;
  17962. return new Uint8Array([]);
  17963. }
  17964. this.iv = buffer;
  17965. this.buffer = new Uint8Array(16);
  17966. this.bufferLength = 0;
  17967. // starting decryption
  17968. this.decryptBlock = decryptBlock2;
  17969. return this.decryptBlock(data.subarray(16), finalize);
  17970. },
  17971. encrypt: function AES128Cipher_encrypt(data, iv) {
  17972. var i, j, ii, sourceLength = data.length,
  17973. buffer = this.buffer, bufferLength = this.bufferPosition,
  17974. result = [];
  17975. if (!iv) {
  17976. iv = new Uint8Array(16);
  17977. }
  17978. for (i = 0; i < sourceLength; ++i) {
  17979. buffer[bufferLength] = data[i];
  17980. ++bufferLength;
  17981. if (bufferLength < 16) {
  17982. continue;
  17983. }
  17984. for (j = 0; j < 16; ++j) {
  17985. buffer[j] ^= iv[j];
  17986. }
  17987. // buffer is full, encrypting
  17988. var cipher = encrypt128(buffer, this.key);
  17989. iv = cipher;
  17990. result.push(cipher);
  17991. buffer = new Uint8Array(16);
  17992. bufferLength = 0;
  17993. }
  17994. // saving incomplete buffer
  17995. this.buffer = buffer;
  17996. this.bufferLength = bufferLength;
  17997. this.iv = iv;
  17998. if (result.length === 0) {
  17999. return new Uint8Array([]);
  18000. }
  18001. // combining plain text blocks into one
  18002. var outputLength = 16 * result.length;
  18003. var output = new Uint8Array(outputLength);
  18004. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18005. output.set(result[i], j);
  18006. }
  18007. return output;
  18008. }
  18009. };
  18010. return AES128Cipher;
  18011. })();
  18012. var AES256Cipher = (function AES256CipherClosure() {
  18013. var rcon = new Uint8Array([
  18014. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18015. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18016. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18017. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18018. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18019. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18020. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18021. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18022. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18023. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18024. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18025. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18026. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18027. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18028. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18029. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18030. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18031. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18032. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18033. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18034. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18035. 0x74, 0xe8, 0xcb, 0x8d]);
  18036. var s = new Uint8Array([
  18037. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18038. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18039. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18040. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18041. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18042. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18043. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18044. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18045. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18046. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18047. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18048. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18049. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18050. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18051. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18052. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18053. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18054. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18055. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18056. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18057. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18058. 0xb0, 0x54, 0xbb, 0x16]);
  18059. var inv_s = new Uint8Array([
  18060. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18061. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18062. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18063. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18064. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18065. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18066. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18067. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18068. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18069. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18070. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18071. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18072. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18073. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18074. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18075. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18076. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18077. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18078. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18079. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18080. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18081. 0x55, 0x21, 0x0c, 0x7d]);
  18082. var mixCol = new Uint8Array(256);
  18083. for (var i = 0; i < 256; i++) {
  18084. if (i < 128) {
  18085. mixCol[i] = i << 1;
  18086. } else {
  18087. mixCol[i] = (i << 1) ^ 0x1b;
  18088. }
  18089. }
  18090. var mix = new Uint32Array([
  18091. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18092. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18093. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18094. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18095. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18096. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18097. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18098. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18099. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18100. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18101. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18102. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18103. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18104. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18105. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18106. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18107. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18108. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18109. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18110. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18111. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18112. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18113. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18114. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18115. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18116. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18117. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18118. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18119. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18120. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18121. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18122. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18123. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18124. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18125. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18126. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18127. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18128. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18129. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18130. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18131. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18132. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18133. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18134. function expandKey256(cipherKey) {
  18135. var b = 240, result = new Uint8Array(b);
  18136. var r = 1;
  18137. result.set(cipherKey);
  18138. for (var j = 32, i = 1; j < b; ++i) {
  18139. if (j % 32 === 16) {
  18140. t1 = s[t1];
  18141. t2 = s[t2];
  18142. t3 = s[t3];
  18143. t4 = s[t4];
  18144. } else if (j % 32 === 0) {
  18145. // RotWord
  18146. var t1 = result[j - 3], t2 = result[j - 2],
  18147. t3 = result[j - 1], t4 = result[j - 4];
  18148. // SubWord
  18149. t1 = s[t1];
  18150. t2 = s[t2];
  18151. t3 = s[t3];
  18152. t4 = s[t4];
  18153. // Rcon
  18154. t1 = t1 ^ r;
  18155. if ((r <<= 1) >= 256) {
  18156. r = (r ^ 0x1b) & 0xFF;
  18157. }
  18158. }
  18159. for (var n = 0; n < 4; ++n) {
  18160. result[j] = (t1 ^= result[j - 32]);
  18161. j++;
  18162. result[j] = (t2 ^= result[j - 32]);
  18163. j++;
  18164. result[j] = (t3 ^= result[j - 32]);
  18165. j++;
  18166. result[j] = (t4 ^= result[j - 32]);
  18167. j++;
  18168. }
  18169. }
  18170. return result;
  18171. }
  18172. function decrypt256(input, key) {
  18173. var state = new Uint8Array(16);
  18174. state.set(input);
  18175. var i, j, k;
  18176. var t, u, v;
  18177. // AddRoundKey
  18178. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18179. state[j] ^= key[k];
  18180. }
  18181. for (i = 13; i >= 1; --i) {
  18182. // InvShiftRows
  18183. t = state[13];
  18184. state[13] = state[9];
  18185. state[9] = state[5];
  18186. state[5] = state[1];
  18187. state[1] = t;
  18188. t = state[14];
  18189. u = state[10];
  18190. state[14] = state[6];
  18191. state[10] = state[2];
  18192. state[6] = t;
  18193. state[2] = u;
  18194. t = state[15];
  18195. u = state[11];
  18196. v = state[7];
  18197. state[15] = state[3];
  18198. state[11] = t;
  18199. state[7] = u;
  18200. state[3] = v;
  18201. // InvSubBytes
  18202. for (j = 0; j < 16; ++j) {
  18203. state[j] = inv_s[state[j]];
  18204. }
  18205. // AddRoundKey
  18206. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18207. state[j] ^= key[k];
  18208. }
  18209. // InvMixColumns
  18210. for (j = 0; j < 16; j += 4) {
  18211. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18212. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18213. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18214. (s3 >>> 24) ^ (s3 << 8));
  18215. state[j] = (t >>> 24) & 0xFF;
  18216. state[j + 1] = (t >> 16) & 0xFF;
  18217. state[j + 2] = (t >> 8) & 0xFF;
  18218. state[j + 3] = t & 0xFF;
  18219. }
  18220. }
  18221. // InvShiftRows
  18222. t = state[13];
  18223. state[13] = state[9];
  18224. state[9] = state[5];
  18225. state[5] = state[1];
  18226. state[1] = t;
  18227. t = state[14];
  18228. u = state[10];
  18229. state[14] = state[6];
  18230. state[10] = state[2];
  18231. state[6] = t;
  18232. state[2] = u;
  18233. t = state[15];
  18234. u = state[11];
  18235. v = state[7];
  18236. state[15] = state[3];
  18237. state[11] = t;
  18238. state[7] = u;
  18239. state[3] = v;
  18240. for (j = 0; j < 16; ++j) {
  18241. // InvSubBytes
  18242. state[j] = inv_s[state[j]];
  18243. // AddRoundKey
  18244. state[j] ^= key[j];
  18245. }
  18246. return state;
  18247. }
  18248. function encrypt256(input, key) {
  18249. var t, u, v, k;
  18250. var state = new Uint8Array(16);
  18251. state.set(input);
  18252. for (j = 0; j < 16; ++j) {
  18253. // AddRoundKey
  18254. state[j] ^= key[j];
  18255. }
  18256. for (i = 1; i < 14; i++) {
  18257. //SubBytes
  18258. for (j = 0; j < 16; ++j) {
  18259. state[j] = s[state[j]];
  18260. }
  18261. //ShiftRows
  18262. v = state[1];
  18263. state[1] = state[5];
  18264. state[5] = state[9];
  18265. state[9] = state[13];
  18266. state[13] = v;
  18267. v = state[2];
  18268. u = state[6];
  18269. state[2] = state[10];
  18270. state[6] = state[14];
  18271. state[10] = v;
  18272. state[14] = u;
  18273. v = state[3];
  18274. u = state[7];
  18275. t = state[11];
  18276. state[3] = state[15];
  18277. state[7] = v;
  18278. state[11] = u;
  18279. state[15] = t;
  18280. //MixColumns
  18281. for (var j = 0; j < 16; j += 4) {
  18282. var s0 = state[j + 0], s1 = state[j + 1];
  18283. var s2 = state[j + 2], s3 = state[j + 3];
  18284. t = s0 ^ s1 ^ s2 ^ s3;
  18285. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18286. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18287. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18288. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18289. }
  18290. //AddRoundKey
  18291. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18292. state[j] ^= key[k];
  18293. }
  18294. }
  18295. //SubBytes
  18296. for (j = 0; j < 16; ++j) {
  18297. state[j] = s[state[j]];
  18298. }
  18299. //ShiftRows
  18300. v = state[1];
  18301. state[1] = state[5];
  18302. state[5] = state[9];
  18303. state[9] = state[13];
  18304. state[13] = v;
  18305. v = state[2];
  18306. u = state[6];
  18307. state[2] = state[10];
  18308. state[6] = state[14];
  18309. state[10] = v;
  18310. state[14] = u;
  18311. v = state[3];
  18312. u = state[7];
  18313. t = state[11];
  18314. state[3] = state[15];
  18315. state[7] = v;
  18316. state[11] = u;
  18317. state[15] = t;
  18318. //AddRoundKey
  18319. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18320. state[j] ^= key[k];
  18321. }
  18322. return state;
  18323. }
  18324. function AES256Cipher(key) {
  18325. this.key = expandKey256(key);
  18326. this.buffer = new Uint8Array(16);
  18327. this.bufferPosition = 0;
  18328. }
  18329. function decryptBlock2(data, finalize) {
  18330. var i, j, ii, sourceLength = data.length,
  18331. buffer = this.buffer, bufferLength = this.bufferPosition,
  18332. result = [], iv = this.iv;
  18333. for (i = 0; i < sourceLength; ++i) {
  18334. buffer[bufferLength] = data[i];
  18335. ++bufferLength;
  18336. if (bufferLength < 16) {
  18337. continue;
  18338. }
  18339. // buffer is full, decrypting
  18340. var plain = decrypt256(buffer, this.key);
  18341. // xor-ing the IV vector to get plain text
  18342. for (j = 0; j < 16; ++j) {
  18343. plain[j] ^= iv[j];
  18344. }
  18345. iv = buffer;
  18346. result.push(plain);
  18347. buffer = new Uint8Array(16);
  18348. bufferLength = 0;
  18349. }
  18350. // saving incomplete buffer
  18351. this.buffer = buffer;
  18352. this.bufferLength = bufferLength;
  18353. this.iv = iv;
  18354. if (result.length === 0) {
  18355. return new Uint8Array([]);
  18356. }
  18357. // combining plain text blocks into one
  18358. var outputLength = 16 * result.length;
  18359. if (finalize) {
  18360. // undo a padding that is described in RFC 2898
  18361. var lastBlock = result[result.length - 1];
  18362. var psLen = lastBlock[15];
  18363. if (psLen <= 16) {
  18364. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18365. if (lastBlock[i] !== psLen) {
  18366. // Invalid padding, assume that the block has no padding.
  18367. psLen = 0;
  18368. break;
  18369. }
  18370. }
  18371. outputLength -= psLen;
  18372. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18373. }
  18374. }
  18375. var output = new Uint8Array(outputLength);
  18376. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18377. output.set(result[i], j);
  18378. }
  18379. return output;
  18380. }
  18381. AES256Cipher.prototype = {
  18382. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  18383. var i, sourceLength = data.length;
  18384. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18385. // if not supplied an IV wait for IV values
  18386. // they are at the start of the stream
  18387. if (iv) {
  18388. this.iv = iv;
  18389. } else {
  18390. for (i = 0; bufferLength < 16 &&
  18391. i < sourceLength; ++i, ++bufferLength) {
  18392. buffer[bufferLength] = data[i];
  18393. }
  18394. if (bufferLength < 16) {
  18395. //need more data
  18396. this.bufferLength = bufferLength;
  18397. return new Uint8Array([]);
  18398. }
  18399. this.iv = buffer;
  18400. data = data.subarray(16);
  18401. }
  18402. this.buffer = new Uint8Array(16);
  18403. this.bufferLength = 0;
  18404. // starting decryption
  18405. this.decryptBlock = decryptBlock2;
  18406. return this.decryptBlock(data, finalize);
  18407. },
  18408. encrypt: function AES256Cipher_encrypt(data, iv) {
  18409. var i, j, ii, sourceLength = data.length,
  18410. buffer = this.buffer, bufferLength = this.bufferPosition,
  18411. result = [];
  18412. if (!iv) {
  18413. iv = new Uint8Array(16);
  18414. }
  18415. for (i = 0; i < sourceLength; ++i) {
  18416. buffer[bufferLength] = data[i];
  18417. ++bufferLength;
  18418. if (bufferLength < 16) {
  18419. continue;
  18420. }
  18421. for (j = 0; j < 16; ++j) {
  18422. buffer[j] ^= iv[j];
  18423. }
  18424. // buffer is full, encrypting
  18425. var cipher = encrypt256(buffer, this.key);
  18426. this.iv = cipher;
  18427. result.push(cipher);
  18428. buffer = new Uint8Array(16);
  18429. bufferLength = 0;
  18430. }
  18431. // saving incomplete buffer
  18432. this.buffer = buffer;
  18433. this.bufferLength = bufferLength;
  18434. this.iv = iv;
  18435. if (result.length === 0) {
  18436. return new Uint8Array([]);
  18437. }
  18438. // combining plain text blocks into one
  18439. var outputLength = 16 * result.length;
  18440. var output = new Uint8Array(outputLength);
  18441. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18442. output.set(result[i], j);
  18443. }
  18444. return output;
  18445. }
  18446. };
  18447. return AES256Cipher;
  18448. })();
  18449. var PDF17 = (function PDF17Closure() {
  18450. function compareByteArrays(array1, array2) {
  18451. if (array1.length !== array2.length) {
  18452. return false;
  18453. }
  18454. for (var i = 0; i < array1.length; i++) {
  18455. if (array1[i] !== array2[i]) {
  18456. return false;
  18457. }
  18458. }
  18459. return true;
  18460. }
  18461. function PDF17() {
  18462. }
  18463. PDF17.prototype = {
  18464. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  18465. ownerValidationSalt,
  18466. userBytes,
  18467. ownerPassword) {
  18468. var hashData = new Uint8Array(password.length + 56);
  18469. hashData.set(password, 0);
  18470. hashData.set(ownerValidationSalt, password.length);
  18471. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18472. var result = calculateSHA256(hashData, 0, hashData.length);
  18473. return compareByteArrays(result, ownerPassword);
  18474. },
  18475. checkUserPassword: function PDF17_checkUserPassword(password,
  18476. userValidationSalt,
  18477. userPassword) {
  18478. var hashData = new Uint8Array(password.length + 8);
  18479. hashData.set(password, 0);
  18480. hashData.set(userValidationSalt, password.length);
  18481. var result = calculateSHA256(hashData, 0, hashData.length);
  18482. return compareByteArrays(result, userPassword);
  18483. },
  18484. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  18485. ownerEncryption) {
  18486. var hashData = new Uint8Array(password.length + 56);
  18487. hashData.set(password, 0);
  18488. hashData.set(ownerKeySalt, password.length);
  18489. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18490. var key = calculateSHA256(hashData, 0, hashData.length);
  18491. var cipher = new AES256Cipher(key);
  18492. return cipher.decryptBlock(ownerEncryption,
  18493. false,
  18494. new Uint8Array(16));
  18495. },
  18496. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  18497. userEncryption) {
  18498. var hashData = new Uint8Array(password.length + 8);
  18499. hashData.set(password, 0);
  18500. hashData.set(userKeySalt, password.length);
  18501. //key is the decryption key for the UE string
  18502. var key = calculateSHA256(hashData, 0, hashData.length);
  18503. var cipher = new AES256Cipher(key);
  18504. return cipher.decryptBlock(userEncryption,
  18505. false,
  18506. new Uint8Array(16));
  18507. }
  18508. };
  18509. return PDF17;
  18510. })();
  18511. var PDF20 = (function PDF20Closure() {
  18512. function concatArrays(array1, array2) {
  18513. var t = new Uint8Array(array1.length + array2.length);
  18514. t.set(array1, 0);
  18515. t.set(array2, array1.length);
  18516. return t;
  18517. }
  18518. function calculatePDF20Hash(password, input, userBytes) {
  18519. //This refers to Algorithm 2.B as defined in ISO 32000-2
  18520. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  18521. var e = [0];
  18522. var i = 0;
  18523. while (i < 64 || e[e.length - 1] > i - 32) {
  18524. var arrayLength = password.length + k.length + userBytes.length;
  18525. var k1 = new Uint8Array(arrayLength * 64);
  18526. var array = concatArrays(password, k);
  18527. array = concatArrays(array, userBytes);
  18528. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  18529. k1.set(array, pos);
  18530. }
  18531. //AES128 CBC NO PADDING with
  18532. //first 16 bytes of k as the key and the second 16 as the iv.
  18533. var cipher = new AES128Cipher(k.subarray(0, 16));
  18534. e = cipher.encrypt(k1, k.subarray(16, 32));
  18535. //Now we have to take the first 16 bytes of an unsigned
  18536. //big endian integer... and compute the remainder
  18537. //modulo 3.... That is a fairly large number and
  18538. //JavaScript isn't going to handle that well...
  18539. //So we're using a trick that allows us to perform
  18540. //modulo math byte by byte
  18541. var remainder = 0;
  18542. for (var z = 0; z < 16; z++) {
  18543. remainder *= (256 % 3);
  18544. remainder %= 3;
  18545. remainder += ((e[z] >>> 0) % 3);
  18546. remainder %= 3;
  18547. }
  18548. if (remainder === 0) {
  18549. k = calculateSHA256(e, 0, e.length);
  18550. }
  18551. else if (remainder === 1) {
  18552. k = calculateSHA384(e, 0, e.length);
  18553. }
  18554. else if (remainder === 2) {
  18555. k = calculateSHA512(e, 0, e.length);
  18556. }
  18557. i++;
  18558. }
  18559. return k.subarray(0, 32);
  18560. }
  18561. function PDF20() {
  18562. }
  18563. function compareByteArrays(array1, array2) {
  18564. if (array1.length !== array2.length) {
  18565. return false;
  18566. }
  18567. for (var i = 0; i < array1.length; i++) {
  18568. if (array1[i] !== array2[i]) {
  18569. return false;
  18570. }
  18571. }
  18572. return true;
  18573. }
  18574. PDF20.prototype = {
  18575. hash: function PDF20_hash(password, concatBytes, userBytes) {
  18576. return calculatePDF20Hash(password, concatBytes, userBytes);
  18577. },
  18578. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  18579. ownerValidationSalt,
  18580. userBytes,
  18581. ownerPassword) {
  18582. var hashData = new Uint8Array(password.length + 56);
  18583. hashData.set(password, 0);
  18584. hashData.set(ownerValidationSalt, password.length);
  18585. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18586. var result = calculatePDF20Hash(password, hashData, userBytes);
  18587. return compareByteArrays(result, ownerPassword);
  18588. },
  18589. checkUserPassword: function PDF20_checkUserPassword(password,
  18590. userValidationSalt,
  18591. userPassword) {
  18592. var hashData = new Uint8Array(password.length + 8);
  18593. hashData.set(password, 0);
  18594. hashData.set(userValidationSalt, password.length);
  18595. var result = calculatePDF20Hash(password, hashData, []);
  18596. return compareByteArrays(result, userPassword);
  18597. },
  18598. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  18599. ownerEncryption) {
  18600. var hashData = new Uint8Array(password.length + 56);
  18601. hashData.set(password, 0);
  18602. hashData.set(ownerKeySalt, password.length);
  18603. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18604. var key = calculatePDF20Hash(password, hashData, userBytes);
  18605. var cipher = new AES256Cipher(key);
  18606. return cipher.decryptBlock(ownerEncryption,
  18607. false,
  18608. new Uint8Array(16));
  18609. },
  18610. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  18611. userEncryption) {
  18612. var hashData = new Uint8Array(password.length + 8);
  18613. hashData.set(password, 0);
  18614. hashData.set(userKeySalt, password.length);
  18615. //key is the decryption key for the UE string
  18616. var key = calculatePDF20Hash(password, hashData, []);
  18617. var cipher = new AES256Cipher(key);
  18618. return cipher.decryptBlock(userEncryption,
  18619. false,
  18620. new Uint8Array(16));
  18621. }
  18622. };
  18623. return PDF20;
  18624. })();
  18625. var CipherTransform = (function CipherTransformClosure() {
  18626. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  18627. this.stringCipherConstructor = stringCipherConstructor;
  18628. this.streamCipherConstructor = streamCipherConstructor;
  18629. }
  18630. CipherTransform.prototype = {
  18631. createStream: function CipherTransform_createStream(stream, length) {
  18632. var cipher = new this.streamCipherConstructor();
  18633. return new DecryptStream(stream, length,
  18634. function cipherTransformDecryptStream(data, finalize) {
  18635. return cipher.decryptBlock(data, finalize);
  18636. }
  18637. );
  18638. },
  18639. decryptString: function CipherTransform_decryptString(s) {
  18640. var cipher = new this.stringCipherConstructor();
  18641. var data = stringToBytes(s);
  18642. data = cipher.decryptBlock(data, true);
  18643. return bytesToString(data);
  18644. }
  18645. };
  18646. return CipherTransform;
  18647. })();
  18648. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  18649. var defaultPasswordBytes = new Uint8Array([
  18650. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  18651. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  18652. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  18653. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  18654. function createEncryptionKey20(revision, password, ownerPassword,
  18655. ownerValidationSalt, ownerKeySalt, uBytes,
  18656. userPassword, userValidationSalt, userKeySalt,
  18657. ownerEncryption, userEncryption, perms) {
  18658. if (password) {
  18659. var passwordLength = Math.min(127, password.length);
  18660. password = password.subarray(0, passwordLength);
  18661. } else {
  18662. password = [];
  18663. }
  18664. var pdfAlgorithm;
  18665. if (revision === 6) {
  18666. pdfAlgorithm = new PDF20();
  18667. } else {
  18668. pdfAlgorithm = new PDF17();
  18669. }
  18670. if (pdfAlgorithm) {
  18671. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  18672. userPassword)) {
  18673. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  18674. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  18675. ownerValidationSalt,
  18676. uBytes,
  18677. ownerPassword)) {
  18678. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  18679. ownerEncryption);
  18680. }
  18681. }
  18682. return null;
  18683. }
  18684. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  18685. flags, revision, keyLength, encryptMetadata) {
  18686. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  18687. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  18688. if (password) {
  18689. n = Math.min(32, password.length);
  18690. for (; i < n; ++i) {
  18691. hashData[i] = password[i];
  18692. }
  18693. }
  18694. j = 0;
  18695. while (i < 32) {
  18696. hashData[i++] = defaultPasswordBytes[j++];
  18697. }
  18698. // as now the padded password in the hashData[0..i]
  18699. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  18700. hashData[i++] = ownerPassword[j];
  18701. }
  18702. hashData[i++] = flags & 0xFF;
  18703. hashData[i++] = (flags >> 8) & 0xFF;
  18704. hashData[i++] = (flags >> 16) & 0xFF;
  18705. hashData[i++] = (flags >>> 24) & 0xFF;
  18706. for (j = 0, n = fileId.length; j < n; ++j) {
  18707. hashData[i++] = fileId[j];
  18708. }
  18709. if (revision >= 4 && !encryptMetadata) {
  18710. hashData[i++] = 0xFF;
  18711. hashData[i++] = 0xFF;
  18712. hashData[i++] = 0xFF;
  18713. hashData[i++] = 0xFF;
  18714. }
  18715. var hash = calculateMD5(hashData, 0, i);
  18716. var keyLengthInBytes = keyLength >> 3;
  18717. if (revision >= 3) {
  18718. for (j = 0; j < 50; ++j) {
  18719. hash = calculateMD5(hash, 0, keyLengthInBytes);
  18720. }
  18721. }
  18722. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  18723. var cipher, checkData;
  18724. if (revision >= 3) {
  18725. for (i = 0; i < 32; ++i) {
  18726. hashData[i] = defaultPasswordBytes[i];
  18727. }
  18728. for (j = 0, n = fileId.length; j < n; ++j) {
  18729. hashData[i++] = fileId[j];
  18730. }
  18731. cipher = new ARCFourCipher(encryptionKey);
  18732. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  18733. n = encryptionKey.length;
  18734. var derivedKey = new Uint8Array(n), k;
  18735. for (j = 1; j <= 19; ++j) {
  18736. for (k = 0; k < n; ++k) {
  18737. derivedKey[k] = encryptionKey[k] ^ j;
  18738. }
  18739. cipher = new ARCFourCipher(derivedKey);
  18740. checkData = cipher.encryptBlock(checkData);
  18741. }
  18742. for (j = 0, n = checkData.length; j < n; ++j) {
  18743. if (userPassword[j] !== checkData[j]) {
  18744. return null;
  18745. }
  18746. }
  18747. } else {
  18748. cipher = new ARCFourCipher(encryptionKey);
  18749. checkData = cipher.encryptBlock(defaultPasswordBytes);
  18750. for (j = 0, n = checkData.length; j < n; ++j) {
  18751. if (userPassword[j] !== checkData[j]) {
  18752. return null;
  18753. }
  18754. }
  18755. }
  18756. return encryptionKey;
  18757. }
  18758. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  18759. var hashData = new Uint8Array(32), i = 0, j, n;
  18760. n = Math.min(32, password.length);
  18761. for (; i < n; ++i) {
  18762. hashData[i] = password[i];
  18763. }
  18764. j = 0;
  18765. while (i < 32) {
  18766. hashData[i++] = defaultPasswordBytes[j++];
  18767. }
  18768. var hash = calculateMD5(hashData, 0, i);
  18769. var keyLengthInBytes = keyLength >> 3;
  18770. if (revision >= 3) {
  18771. for (j = 0; j < 50; ++j) {
  18772. hash = calculateMD5(hash, 0, hash.length);
  18773. }
  18774. }
  18775. var cipher, userPassword;
  18776. if (revision >= 3) {
  18777. userPassword = ownerPassword;
  18778. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  18779. for (j = 19; j >= 0; j--) {
  18780. for (k = 0; k < keyLengthInBytes; ++k) {
  18781. derivedKey[k] = hash[k] ^ j;
  18782. }
  18783. cipher = new ARCFourCipher(derivedKey);
  18784. userPassword = cipher.encryptBlock(userPassword);
  18785. }
  18786. } else {
  18787. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  18788. userPassword = cipher.encryptBlock(ownerPassword);
  18789. }
  18790. return userPassword;
  18791. }
  18792. var identityName = Name.get('Identity');
  18793. function CipherTransformFactory(dict, fileId, password) {
  18794. var filter = dict.get('Filter');
  18795. if (!isName(filter) || filter.name !== 'Standard') {
  18796. error('unknown encryption method');
  18797. }
  18798. this.dict = dict;
  18799. var algorithm = dict.get('V');
  18800. if (!isInt(algorithm) ||
  18801. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  18802. algorithm !== 5)) {
  18803. error('unsupported encryption algorithm');
  18804. }
  18805. this.algorithm = algorithm;
  18806. var keyLength = dict.get('Length') || 40;
  18807. if (!isInt(keyLength) ||
  18808. keyLength < 40 || (keyLength % 8) !== 0) {
  18809. error('invalid key length');
  18810. }
  18811. // prepare keys
  18812. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  18813. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  18814. var flags = dict.get('P');
  18815. var revision = dict.get('R');
  18816. // meaningful when V is 4 or 5
  18817. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  18818. dict.get('EncryptMetadata') !== false);
  18819. this.encryptMetadata = encryptMetadata;
  18820. var fileIdBytes = stringToBytes(fileId);
  18821. var passwordBytes;
  18822. if (password) {
  18823. if (revision === 6) {
  18824. try {
  18825. password = utf8StringToString(password);
  18826. } catch (ex) {
  18827. warn('CipherTransformFactory: ' +
  18828. 'Unable to convert UTF8 encoded password.');
  18829. }
  18830. }
  18831. passwordBytes = stringToBytes(password);
  18832. }
  18833. var encryptionKey;
  18834. if (algorithm !== 5) {
  18835. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  18836. ownerPassword, userPassword, flags,
  18837. revision, keyLength, encryptMetadata);
  18838. }
  18839. else {
  18840. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  18841. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  18842. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  18843. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  18844. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  18845. var ownerEncryption = stringToBytes(dict.get('OE'));
  18846. var userEncryption = stringToBytes(dict.get('UE'));
  18847. var perms = stringToBytes(dict.get('Perms'));
  18848. encryptionKey =
  18849. createEncryptionKey20(revision, passwordBytes,
  18850. ownerPassword, ownerValidationSalt,
  18851. ownerKeySalt, uBytes,
  18852. userPassword, userValidationSalt,
  18853. userKeySalt, ownerEncryption,
  18854. userEncryption, perms);
  18855. }
  18856. if (!encryptionKey && !password) {
  18857. throw new PasswordException('No password given',
  18858. PasswordResponses.NEED_PASSWORD);
  18859. } else if (!encryptionKey && password) {
  18860. // Attempting use the password as an owner password
  18861. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  18862. revision, keyLength);
  18863. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  18864. ownerPassword, userPassword, flags,
  18865. revision, keyLength, encryptMetadata);
  18866. }
  18867. if (!encryptionKey) {
  18868. throw new PasswordException('Incorrect Password',
  18869. PasswordResponses.INCORRECT_PASSWORD);
  18870. }
  18871. this.encryptionKey = encryptionKey;
  18872. if (algorithm >= 4) {
  18873. this.cf = dict.get('CF');
  18874. this.stmf = dict.get('StmF') || identityName;
  18875. this.strf = dict.get('StrF') || identityName;
  18876. this.eff = dict.get('EFF') || this.stmf;
  18877. }
  18878. }
  18879. function buildObjectKey(num, gen, encryptionKey, isAes) {
  18880. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  18881. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  18882. key[i] = encryptionKey[i];
  18883. }
  18884. key[i++] = num & 0xFF;
  18885. key[i++] = (num >> 8) & 0xFF;
  18886. key[i++] = (num >> 16) & 0xFF;
  18887. key[i++] = gen & 0xFF;
  18888. key[i++] = (gen >> 8) & 0xFF;
  18889. if (isAes) {
  18890. key[i++] = 0x73;
  18891. key[i++] = 0x41;
  18892. key[i++] = 0x6C;
  18893. key[i++] = 0x54;
  18894. }
  18895. var hash = calculateMD5(key, 0, i);
  18896. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  18897. }
  18898. function buildCipherConstructor(cf, name, num, gen, key) {
  18899. var cryptFilter = cf.get(name.name);
  18900. var cfm;
  18901. if (cryptFilter !== null && cryptFilter !== undefined) {
  18902. cfm = cryptFilter.get('CFM');
  18903. }
  18904. if (!cfm || cfm.name === 'None') {
  18905. return function cipherTransformFactoryBuildCipherConstructorNone() {
  18906. return new NullCipher();
  18907. };
  18908. }
  18909. if ('V2' === cfm.name) {
  18910. return function cipherTransformFactoryBuildCipherConstructorV2() {
  18911. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  18912. };
  18913. }
  18914. if ('AESV2' === cfm.name) {
  18915. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  18916. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  18917. };
  18918. }
  18919. if ('AESV3' === cfm.name) {
  18920. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  18921. return new AES256Cipher(key);
  18922. };
  18923. }
  18924. error('Unknown crypto method');
  18925. }
  18926. CipherTransformFactory.prototype = {
  18927. createCipherTransform:
  18928. function CipherTransformFactory_createCipherTransform(num, gen) {
  18929. if (this.algorithm === 4 || this.algorithm === 5) {
  18930. return new CipherTransform(
  18931. buildCipherConstructor(this.cf, this.stmf,
  18932. num, gen, this.encryptionKey),
  18933. buildCipherConstructor(this.cf, this.strf,
  18934. num, gen, this.encryptionKey));
  18935. }
  18936. // algorithms 1 and 2
  18937. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  18938. var cipherConstructor = function buildCipherCipherConstructor() {
  18939. return new ARCFourCipher(key);
  18940. };
  18941. return new CipherTransform(cipherConstructor, cipherConstructor);
  18942. }
  18943. };
  18944. return CipherTransformFactory;
  18945. })();
  18946. exports.AES128Cipher = AES128Cipher;
  18947. exports.AES256Cipher = AES256Cipher;
  18948. exports.ARCFourCipher = ARCFourCipher;
  18949. exports.CipherTransformFactory = CipherTransformFactory;
  18950. exports.PDF17 = PDF17;
  18951. exports.PDF20 = PDF20;
  18952. exports.calculateMD5 = calculateMD5;
  18953. exports.calculateSHA256 = calculateSHA256;
  18954. exports.calculateSHA384 = calculateSHA384;
  18955. exports.calculateSHA512 = calculateSHA512;
  18956. }));
  18957. (function (root, factory) {
  18958. {
  18959. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  18960. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  18961. }
  18962. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  18963. var Util = sharedUtil.Util;
  18964. var bytesToString = sharedUtil.bytesToString;
  18965. var error = sharedUtil.error;
  18966. var Stream = coreStream.Stream;
  18967. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  18968. var coreFonts; // see _setCoreFonts below
  18969. var CFFParser; // = coreFonts.CFFParser;
  18970. var Encodings; // = coreFonts.Encodings;
  18971. var FontRendererFactory = (function FontRendererFactoryClosure() {
  18972. function getLong(data, offset) {
  18973. return (data[offset] << 24) | (data[offset + 1] << 16) |
  18974. (data[offset + 2] << 8) | data[offset + 3];
  18975. }
  18976. function getUshort(data, offset) {
  18977. return (data[offset] << 8) | data[offset + 1];
  18978. }
  18979. function parseCmap(data, start, end) {
  18980. var offset = (getUshort(data, start + 2) === 1 ?
  18981. getLong(data, start + 8) : getLong(data, start + 16));
  18982. var format = getUshort(data, start + offset);
  18983. var length, ranges, p, i;
  18984. if (format === 4) {
  18985. length = getUshort(data, start + offset + 2);
  18986. var segCount = getUshort(data, start + offset + 6) >> 1;
  18987. p = start + offset + 14;
  18988. ranges = [];
  18989. for (i = 0; i < segCount; i++, p += 2) {
  18990. ranges[i] = {end: getUshort(data, p)};
  18991. }
  18992. p += 2;
  18993. for (i = 0; i < segCount; i++, p += 2) {
  18994. ranges[i].start = getUshort(data, p);
  18995. }
  18996. for (i = 0; i < segCount; i++, p += 2) {
  18997. ranges[i].idDelta = getUshort(data, p);
  18998. }
  18999. for (i = 0; i < segCount; i++, p += 2) {
  19000. var idOffset = getUshort(data, p);
  19001. if (idOffset === 0) {
  19002. continue;
  19003. }
  19004. ranges[i].ids = [];
  19005. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19006. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19007. idOffset += 2;
  19008. }
  19009. }
  19010. return ranges;
  19011. } else if (format === 12) {
  19012. length = getLong(data, start + offset + 4);
  19013. var groups = getLong(data, start + offset + 12);
  19014. p = start + offset + 16;
  19015. ranges = [];
  19016. for (i = 0; i < groups; i++) {
  19017. ranges.push({
  19018. start: getLong(data, p),
  19019. end: getLong(data, p + 4),
  19020. idDelta: getLong(data, p + 8) - getLong(data, p)
  19021. });
  19022. p += 12;
  19023. }
  19024. return ranges;
  19025. }
  19026. error('not supported cmap: ' + format);
  19027. }
  19028. function parseCff(data, start, end) {
  19029. var properties = {};
  19030. var parser = new CFFParser(new Stream(data, start, end - start),
  19031. properties);
  19032. var cff = parser.parse();
  19033. return {
  19034. glyphs: cff.charStrings.objects,
  19035. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19036. cff.topDict.privateDict.subrsIndex.objects),
  19037. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19038. };
  19039. }
  19040. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19041. var itemSize, itemDecode;
  19042. if (isGlyphLocationsLong) {
  19043. itemSize = 4;
  19044. itemDecode = function fontItemDecodeLong(data, offset) {
  19045. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19046. (data[offset + 2] << 8) | data[offset + 3];
  19047. };
  19048. } else {
  19049. itemSize = 2;
  19050. itemDecode = function fontItemDecode(data, offset) {
  19051. return (data[offset] << 9) | (data[offset + 1] << 1);
  19052. };
  19053. }
  19054. var glyphs = [];
  19055. var startOffset = itemDecode(loca, 0);
  19056. for (var j = itemSize; j < loca.length; j += itemSize) {
  19057. var endOffset = itemDecode(loca, j);
  19058. glyphs.push(glyf.subarray(startOffset, endOffset));
  19059. startOffset = endOffset;
  19060. }
  19061. return glyphs;
  19062. }
  19063. function lookupCmap(ranges, unicode) {
  19064. var code = unicode.charCodeAt(0);
  19065. var l = 0, r = ranges.length - 1;
  19066. while (l < r) {
  19067. var c = (l + r + 1) >> 1;
  19068. if (code < ranges[c].start) {
  19069. r = c - 1;
  19070. } else {
  19071. l = c;
  19072. }
  19073. }
  19074. if (ranges[l].start <= code && code <= ranges[l].end) {
  19075. return (ranges[l].idDelta + (ranges[l].ids ?
  19076. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19077. }
  19078. return 0;
  19079. }
  19080. function compileGlyf(code, cmds, font) {
  19081. function moveTo(x, y) {
  19082. cmds.push({cmd: 'moveTo', args: [x, y]});
  19083. }
  19084. function lineTo(x, y) {
  19085. cmds.push({cmd: 'lineTo', args: [x, y]});
  19086. }
  19087. function quadraticCurveTo(xa, ya, x, y) {
  19088. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  19089. }
  19090. var i = 0;
  19091. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19092. var flags;
  19093. var x = 0, y = 0;
  19094. i += 10;
  19095. if (numberOfContours < 0) {
  19096. // composite glyph
  19097. do {
  19098. flags = (code[i] << 8) | code[i + 1];
  19099. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19100. i += 4;
  19101. var arg1, arg2;
  19102. if ((flags & 0x01)) {
  19103. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19104. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19105. i += 4;
  19106. } else {
  19107. arg1 = code[i++]; arg2 = code[i++];
  19108. }
  19109. if ((flags & 0x02)) {
  19110. x = arg1;
  19111. y = arg2;
  19112. } else {
  19113. x = 0; y = 0; // TODO "they are points" ?
  19114. }
  19115. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19116. if ((flags & 0x08)) {
  19117. scaleX =
  19118. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19119. i += 2;
  19120. } else if ((flags & 0x40)) {
  19121. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19122. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19123. i += 4;
  19124. } else if ((flags & 0x80)) {
  19125. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19126. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19127. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19128. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19129. i += 8;
  19130. }
  19131. var subglyph = font.glyphs[glyphIndex];
  19132. if (subglyph) {
  19133. cmds.push({cmd: 'save'});
  19134. cmds.push({cmd: 'transform',
  19135. args: [scaleX, scale01, scale10, scaleY, x, y]});
  19136. compileGlyf(subglyph, cmds, font);
  19137. cmds.push({cmd: 'restore'});
  19138. }
  19139. } while ((flags & 0x20));
  19140. } else {
  19141. // simple glyph
  19142. var endPtsOfContours = [];
  19143. var j, jj;
  19144. for (j = 0; j < numberOfContours; j++) {
  19145. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19146. i += 2;
  19147. }
  19148. var instructionLength = (code[i] << 8) | code[i + 1];
  19149. i += 2 + instructionLength; // skipping the instructions
  19150. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19151. var points = [];
  19152. while (points.length < numberOfPoints) {
  19153. flags = code[i++];
  19154. var repeat = 1;
  19155. if ((flags & 0x08)) {
  19156. repeat += code[i++];
  19157. }
  19158. while (repeat-- > 0) {
  19159. points.push({flags: flags});
  19160. }
  19161. }
  19162. for (j = 0; j < numberOfPoints; j++) {
  19163. switch (points[j].flags & 0x12) {
  19164. case 0x00:
  19165. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19166. i += 2;
  19167. break;
  19168. case 0x02:
  19169. x -= code[i++];
  19170. break;
  19171. case 0x12:
  19172. x += code[i++];
  19173. break;
  19174. }
  19175. points[j].x = x;
  19176. }
  19177. for (j = 0; j < numberOfPoints; j++) {
  19178. switch (points[j].flags & 0x24) {
  19179. case 0x00:
  19180. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19181. i += 2;
  19182. break;
  19183. case 0x04:
  19184. y -= code[i++];
  19185. break;
  19186. case 0x24:
  19187. y += code[i++];
  19188. break;
  19189. }
  19190. points[j].y = y;
  19191. }
  19192. var startPoint = 0;
  19193. for (i = 0; i < numberOfContours; i++) {
  19194. var endPoint = endPtsOfContours[i];
  19195. // contours might have implicit points, which is located in the middle
  19196. // between two neighboring off-curve points
  19197. var contour = points.slice(startPoint, endPoint + 1);
  19198. if ((contour[0].flags & 1)) {
  19199. contour.push(contour[0]); // using start point at the contour end
  19200. } else if ((contour[contour.length - 1].flags & 1)) {
  19201. // first is off-curve point, trying to use one from the end
  19202. contour.unshift(contour[contour.length - 1]);
  19203. } else {
  19204. // start and end are off-curve points, creating implicit one
  19205. var p = {
  19206. flags: 1,
  19207. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19208. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19209. };
  19210. contour.unshift(p);
  19211. contour.push(p);
  19212. }
  19213. moveTo(contour[0].x, contour[0].y);
  19214. for (j = 1, jj = contour.length; j < jj; j++) {
  19215. if ((contour[j].flags & 1)) {
  19216. lineTo(contour[j].x, contour[j].y);
  19217. } else if ((contour[j + 1].flags & 1)){
  19218. quadraticCurveTo(contour[j].x, contour[j].y,
  19219. contour[j + 1].x, contour[j + 1].y);
  19220. j++;
  19221. } else {
  19222. quadraticCurveTo(contour[j].x, contour[j].y,
  19223. (contour[j].x + contour[j + 1].x) / 2,
  19224. (contour[j].y + contour[j + 1].y) / 2);
  19225. }
  19226. }
  19227. startPoint = endPoint + 1;
  19228. }
  19229. }
  19230. }
  19231. function compileCharString(code, cmds, font) {
  19232. var stack = [];
  19233. var x = 0, y = 0;
  19234. var stems = 0;
  19235. function moveTo(x, y) {
  19236. cmds.push({cmd: 'moveTo', args: [x, y]});
  19237. }
  19238. function lineTo(x, y) {
  19239. cmds.push({cmd: 'lineTo', args: [x, y]});
  19240. }
  19241. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19242. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  19243. }
  19244. function parse(code) {
  19245. var i = 0;
  19246. while (i < code.length) {
  19247. var stackClean = false;
  19248. var v = code[i++];
  19249. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19250. switch (v) {
  19251. case 1: // hstem
  19252. stems += stack.length >> 1;
  19253. stackClean = true;
  19254. break;
  19255. case 3: // vstem
  19256. stems += stack.length >> 1;
  19257. stackClean = true;
  19258. break;
  19259. case 4: // vmoveto
  19260. y += stack.pop();
  19261. moveTo(x, y);
  19262. stackClean = true;
  19263. break;
  19264. case 5: // rlineto
  19265. while (stack.length > 0) {
  19266. x += stack.shift();
  19267. y += stack.shift();
  19268. lineTo(x, y);
  19269. }
  19270. break;
  19271. case 6: // hlineto
  19272. while (stack.length > 0) {
  19273. x += stack.shift();
  19274. lineTo(x, y);
  19275. if (stack.length === 0) {
  19276. break;
  19277. }
  19278. y += stack.shift();
  19279. lineTo(x, y);
  19280. }
  19281. break;
  19282. case 7: // vlineto
  19283. while (stack.length > 0) {
  19284. y += stack.shift();
  19285. lineTo(x, y);
  19286. if (stack.length === 0) {
  19287. break;
  19288. }
  19289. x += stack.shift();
  19290. lineTo(x, y);
  19291. }
  19292. break;
  19293. case 8: // rrcurveto
  19294. while (stack.length > 0) {
  19295. xa = x + stack.shift(); ya = y + stack.shift();
  19296. xb = xa + stack.shift(); yb = ya + stack.shift();
  19297. x = xb + stack.shift(); y = yb + stack.shift();
  19298. bezierCurveTo(xa, ya, xb, yb, x, y);
  19299. }
  19300. break;
  19301. case 10: // callsubr
  19302. n = stack.pop() + font.subrsBias;
  19303. subrCode = font.subrs[n];
  19304. if (subrCode) {
  19305. parse(subrCode);
  19306. }
  19307. break;
  19308. case 11: // return
  19309. return;
  19310. case 12:
  19311. v = code[i++];
  19312. switch (v) {
  19313. case 34: // flex
  19314. xa = x + stack.shift();
  19315. xb = xa + stack.shift(); y1 = y + stack.shift();
  19316. x = xb + stack.shift();
  19317. bezierCurveTo(xa, y, xb, y1, x, y1);
  19318. xa = x + stack.shift();
  19319. xb = xa + stack.shift();
  19320. x = xb + stack.shift();
  19321. bezierCurveTo(xa, y1, xb, y, x, y);
  19322. break;
  19323. case 35: // flex
  19324. xa = x + stack.shift(); ya = y + stack.shift();
  19325. xb = xa + stack.shift(); yb = ya + stack.shift();
  19326. x = xb + stack.shift(); y = yb + stack.shift();
  19327. bezierCurveTo(xa, ya, xb, yb, x, y);
  19328. xa = x + stack.shift(); ya = y + stack.shift();
  19329. xb = xa + stack.shift(); yb = ya + stack.shift();
  19330. x = xb + stack.shift(); y = yb + stack.shift();
  19331. bezierCurveTo(xa, ya, xb, yb, x, y);
  19332. stack.pop(); // fd
  19333. break;
  19334. case 36: // hflex1
  19335. xa = x + stack.shift(); y1 = y + stack.shift();
  19336. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19337. x = xb + stack.shift();
  19338. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19339. xa = x + stack.shift();
  19340. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19341. x = xb + stack.shift();
  19342. bezierCurveTo(xa, y2, xb, y3, x, y);
  19343. break;
  19344. case 37: // flex1
  19345. var x0 = x, y0 = y;
  19346. xa = x + stack.shift(); ya = y + stack.shift();
  19347. xb = xa + stack.shift(); yb = ya + stack.shift();
  19348. x = xb + stack.shift(); y = yb + stack.shift();
  19349. bezierCurveTo(xa, ya, xb, yb, x, y);
  19350. xa = x + stack.shift(); ya = y + stack.shift();
  19351. xb = xa + stack.shift(); yb = ya + stack.shift();
  19352. x = xb; y = yb;
  19353. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19354. x += stack.shift();
  19355. } else {
  19356. y += stack.shift();
  19357. }
  19358. bezierCurveTo(xa, ya, xb, yb, x, y);
  19359. break;
  19360. default:
  19361. error('unknown operator: 12 ' + v);
  19362. }
  19363. break;
  19364. case 14: // endchar
  19365. if (stack.length >= 4) {
  19366. var achar = stack.pop();
  19367. var bchar = stack.pop();
  19368. y = stack.pop();
  19369. x = stack.pop();
  19370. cmds.push({cmd: 'save'});
  19371. cmds.push({cmd: 'translate', args: [x, y]});
  19372. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19373. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19374. compileCharString(font.glyphs[gid], cmds, font);
  19375. cmds.push({cmd: 'restore'});
  19376. gid = lookupCmap(font.cmap, String.fromCharCode(
  19377. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19378. compileCharString(font.glyphs[gid], cmds, font);
  19379. }
  19380. return;
  19381. case 18: // hstemhm
  19382. stems += stack.length >> 1;
  19383. stackClean = true;
  19384. break;
  19385. case 19: // hintmask
  19386. stems += stack.length >> 1;
  19387. i += (stems + 7) >> 3;
  19388. stackClean = true;
  19389. break;
  19390. case 20: // cntrmask
  19391. stems += stack.length >> 1;
  19392. i += (stems + 7) >> 3;
  19393. stackClean = true;
  19394. break;
  19395. case 21: // rmoveto
  19396. y += stack.pop();
  19397. x += stack.pop();
  19398. moveTo(x, y);
  19399. stackClean = true;
  19400. break;
  19401. case 22: // hmoveto
  19402. x += stack.pop();
  19403. moveTo(x, y);
  19404. stackClean = true;
  19405. break;
  19406. case 23: // vstemhm
  19407. stems += stack.length >> 1;
  19408. stackClean = true;
  19409. break;
  19410. case 24: // rcurveline
  19411. while (stack.length > 2) {
  19412. xa = x + stack.shift(); ya = y + stack.shift();
  19413. xb = xa + stack.shift(); yb = ya + stack.shift();
  19414. x = xb + stack.shift(); y = yb + stack.shift();
  19415. bezierCurveTo(xa, ya, xb, yb, x, y);
  19416. }
  19417. x += stack.shift();
  19418. y += stack.shift();
  19419. lineTo(x, y);
  19420. break;
  19421. case 25: // rlinecurve
  19422. while (stack.length > 6) {
  19423. x += stack.shift();
  19424. y += stack.shift();
  19425. lineTo(x, y);
  19426. }
  19427. xa = x + stack.shift(); ya = y + stack.shift();
  19428. xb = xa + stack.shift(); yb = ya + stack.shift();
  19429. x = xb + stack.shift(); y = yb + stack.shift();
  19430. bezierCurveTo(xa, ya, xb, yb, x, y);
  19431. break;
  19432. case 26: // vvcurveto
  19433. if (stack.length % 2) {
  19434. x += stack.shift();
  19435. }
  19436. while (stack.length > 0) {
  19437. xa = x; ya = y + stack.shift();
  19438. xb = xa + stack.shift(); yb = ya + stack.shift();
  19439. x = xb; y = yb + stack.shift();
  19440. bezierCurveTo(xa, ya, xb, yb, x, y);
  19441. }
  19442. break;
  19443. case 27: // hhcurveto
  19444. if (stack.length % 2) {
  19445. y += stack.shift();
  19446. }
  19447. while (stack.length > 0) {
  19448. xa = x + stack.shift(); ya = y;
  19449. xb = xa + stack.shift(); yb = ya + stack.shift();
  19450. x = xb + stack.shift(); y = yb;
  19451. bezierCurveTo(xa, ya, xb, yb, x, y);
  19452. }
  19453. break;
  19454. case 28:
  19455. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19456. i += 2;
  19457. break;
  19458. case 29: // callgsubr
  19459. n = stack.pop() + font.gsubrsBias;
  19460. subrCode = font.gsubrs[n];
  19461. if (subrCode) {
  19462. parse(subrCode);
  19463. }
  19464. break;
  19465. case 30: // vhcurveto
  19466. while (stack.length > 0) {
  19467. xa = x; ya = y + stack.shift();
  19468. xb = xa + stack.shift(); yb = ya + stack.shift();
  19469. x = xb + stack.shift();
  19470. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19471. bezierCurveTo(xa, ya, xb, yb, x, y);
  19472. if (stack.length === 0) {
  19473. break;
  19474. }
  19475. xa = x + stack.shift(); ya = y;
  19476. xb = xa + stack.shift(); yb = ya + stack.shift();
  19477. y = yb + stack.shift();
  19478. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19479. bezierCurveTo(xa, ya, xb, yb, x, y);
  19480. }
  19481. break;
  19482. case 31: // hvcurveto
  19483. while (stack.length > 0) {
  19484. xa = x + stack.shift(); ya = y;
  19485. xb = xa + stack.shift(); yb = ya + stack.shift();
  19486. y = yb + stack.shift();
  19487. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19488. bezierCurveTo(xa, ya, xb, yb, x, y);
  19489. if (stack.length === 0) {
  19490. break;
  19491. }
  19492. xa = x; ya = y + stack.shift();
  19493. xb = xa + stack.shift(); yb = ya + stack.shift();
  19494. x = xb + stack.shift();
  19495. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19496. bezierCurveTo(xa, ya, xb, yb, x, y);
  19497. }
  19498. break;
  19499. default:
  19500. if (v < 32) {
  19501. error('unknown operator: ' + v);
  19502. }
  19503. if (v < 247) {
  19504. stack.push(v - 139);
  19505. } else if (v < 251) {
  19506. stack.push((v - 247) * 256 + code[i++] + 108);
  19507. } else if (v < 255) {
  19508. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19509. } else {
  19510. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19511. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19512. i += 4;
  19513. }
  19514. break;
  19515. }
  19516. if (stackClean) {
  19517. stack.length = 0;
  19518. }
  19519. }
  19520. }
  19521. parse(code);
  19522. }
  19523. var noop = '';
  19524. function CompiledFont(fontMatrix) {
  19525. this.compiledGlyphs = {};
  19526. this.fontMatrix = fontMatrix;
  19527. }
  19528. CompiledFont.prototype = {
  19529. getPathJs: function (unicode) {
  19530. var gid = lookupCmap(this.cmap, unicode);
  19531. var fn = this.compiledGlyphs[gid];
  19532. if (!fn) {
  19533. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19534. }
  19535. return fn;
  19536. },
  19537. compileGlyph: function (code) {
  19538. if (!code || code.length === 0 || code[0] === 14) {
  19539. return noop;
  19540. }
  19541. var cmds = [];
  19542. cmds.push({cmd: 'save'});
  19543. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  19544. cmds.push({cmd: 'scale', args: ['size', '-size']});
  19545. this.compileGlyphImpl(code, cmds);
  19546. cmds.push({cmd: 'restore'});
  19547. return cmds;
  19548. },
  19549. compileGlyphImpl: function () {
  19550. error('Children classes should implement this.');
  19551. },
  19552. hasBuiltPath: function (unicode) {
  19553. var gid = lookupCmap(this.cmap, unicode);
  19554. return gid in this.compiledGlyphs;
  19555. }
  19556. };
  19557. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19558. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19559. CompiledFont.call(this, fontMatrix);
  19560. this.glyphs = glyphs;
  19561. this.cmap = cmap;
  19562. this.compiledGlyphs = [];
  19563. }
  19564. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19565. compileGlyphImpl: function (code, cmds) {
  19566. compileGlyf(code, cmds, this);
  19567. }
  19568. });
  19569. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19570. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19571. CompiledFont.call(this, fontMatrix);
  19572. this.glyphs = cffInfo.glyphs;
  19573. this.gsubrs = cffInfo.gsubrs || [];
  19574. this.subrs = cffInfo.subrs || [];
  19575. this.cmap = cmap;
  19576. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19577. this.compiledGlyphs = [];
  19578. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19579. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19580. this.subrsBias = (this.subrs.length < 1240 ?
  19581. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19582. }
  19583. Util.inherit(Type2Compiled, CompiledFont, {
  19584. compileGlyphImpl: function (code, cmds) {
  19585. compileCharString(code, cmds, this);
  19586. }
  19587. });
  19588. return {
  19589. create: function FontRendererFactory_create(font) {
  19590. var data = new Uint8Array(font.data);
  19591. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19592. var numTables = getUshort(data, 4);
  19593. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19594. var tag = bytesToString(data.subarray(p, p + 4));
  19595. var offset = getLong(data, p + 8);
  19596. var length = getLong(data, p + 12);
  19597. switch (tag) {
  19598. case 'cmap':
  19599. cmap = parseCmap(data, offset, offset + length);
  19600. break;
  19601. case 'glyf':
  19602. glyf = data.subarray(offset, offset + length);
  19603. break;
  19604. case 'loca':
  19605. loca = data.subarray(offset, offset + length);
  19606. break;
  19607. case 'head':
  19608. unitsPerEm = getUshort(data, offset + 18);
  19609. indexToLocFormat = getUshort(data, offset + 50);
  19610. break;
  19611. case 'CFF ':
  19612. cff = parseCff(data, offset, offset + length);
  19613. break;
  19614. }
  19615. }
  19616. if (glyf) {
  19617. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19618. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19619. return new TrueTypeCompiled(
  19620. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19621. } else {
  19622. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19623. }
  19624. }
  19625. };
  19626. })();
  19627. // TODO refactor to remove cyclic dependency on fonts.js
  19628. function _setCoreFonts(coreFonts_) {
  19629. coreFonts = coreFonts_;
  19630. Encodings = coreFonts_.Encodings;
  19631. CFFParser = coreFonts_.CFFParser;
  19632. }
  19633. exports._setCoreFonts = _setCoreFonts;
  19634. exports.FontRendererFactory = FontRendererFactory;
  19635. }));
  19636. (function (root, factory) {
  19637. {
  19638. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  19639. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19640. }
  19641. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19642. var MissingDataException = sharedUtil.MissingDataException;
  19643. var StreamType = sharedUtil.StreamType;
  19644. var assert = sharedUtil.assert;
  19645. var error = sharedUtil.error;
  19646. var info = sharedUtil.info;
  19647. var isArray = sharedUtil.isArray;
  19648. var isInt = sharedUtil.isInt;
  19649. var isNum = sharedUtil.isNum;
  19650. var isString = sharedUtil.isString;
  19651. var warn = sharedUtil.warn;
  19652. var Cmd = corePrimitives.Cmd;
  19653. var Dict = corePrimitives.Dict;
  19654. var Name = corePrimitives.Name;
  19655. var Ref = corePrimitives.Ref;
  19656. var isCmd = corePrimitives.isCmd;
  19657. var isDict = corePrimitives.isDict;
  19658. var isName = corePrimitives.isName;
  19659. var Ascii85Stream = coreStream.Ascii85Stream;
  19660. var AsciiHexStream = coreStream.AsciiHexStream;
  19661. var CCITTFaxStream = coreStream.CCITTFaxStream;
  19662. var FlateStream = coreStream.FlateStream;
  19663. var Jbig2Stream = coreStream.Jbig2Stream;
  19664. var JpegStream = coreStream.JpegStream;
  19665. var JpxStream = coreStream.JpxStream;
  19666. var LZWStream = coreStream.LZWStream;
  19667. var NullStream = coreStream.NullStream;
  19668. var PredictorStream = coreStream.PredictorStream;
  19669. var RunLengthStream = coreStream.RunLengthStream;
  19670. var EOF = {};
  19671. function isEOF(v) {
  19672. return (v === EOF);
  19673. }
  19674. var MAX_LENGTH_TO_CACHE = 1000;
  19675. var Parser = (function ParserClosure() {
  19676. function Parser(lexer, allowStreams, xref) {
  19677. this.lexer = lexer;
  19678. this.allowStreams = allowStreams;
  19679. this.xref = xref;
  19680. this.imageCache = {};
  19681. this.refill();
  19682. }
  19683. Parser.prototype = {
  19684. refill: function Parser_refill() {
  19685. this.buf1 = this.lexer.getObj();
  19686. this.buf2 = this.lexer.getObj();
  19687. },
  19688. shift: function Parser_shift() {
  19689. if (isCmd(this.buf2, 'ID')) {
  19690. this.buf1 = this.buf2;
  19691. this.buf2 = null;
  19692. } else {
  19693. this.buf1 = this.buf2;
  19694. this.buf2 = this.lexer.getObj();
  19695. }
  19696. },
  19697. tryShift: function Parser_tryShift() {
  19698. try {
  19699. this.shift();
  19700. return true;
  19701. } catch (e) {
  19702. if (e instanceof MissingDataException) {
  19703. throw e;
  19704. }
  19705. // Upon failure, the caller should reset this.lexer.pos to a known good
  19706. // state and call this.shift() twice to reset the buffers.
  19707. return false;
  19708. }
  19709. },
  19710. getObj: function Parser_getObj(cipherTransform) {
  19711. var buf1 = this.buf1;
  19712. this.shift();
  19713. if (buf1 instanceof Cmd) {
  19714. switch (buf1.cmd) {
  19715. case 'BI': // inline image
  19716. return this.makeInlineImage(cipherTransform);
  19717. case '[': // array
  19718. var array = [];
  19719. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  19720. array.push(this.getObj(cipherTransform));
  19721. }
  19722. if (isEOF(this.buf1)) {
  19723. error('End of file inside array');
  19724. }
  19725. this.shift();
  19726. return array;
  19727. case '<<': // dictionary or stream
  19728. var dict = new Dict(this.xref);
  19729. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  19730. if (!isName(this.buf1)) {
  19731. info('Malformed dictionary: key must be a name object');
  19732. this.shift();
  19733. continue;
  19734. }
  19735. var key = this.buf1.name;
  19736. this.shift();
  19737. if (isEOF(this.buf1)) {
  19738. break;
  19739. }
  19740. dict.set(key, this.getObj(cipherTransform));
  19741. }
  19742. if (isEOF(this.buf1)) {
  19743. error('End of file inside dictionary');
  19744. }
  19745. // Stream objects are not allowed inside content streams or
  19746. // object streams.
  19747. if (isCmd(this.buf2, 'stream')) {
  19748. return (this.allowStreams ?
  19749. this.makeStream(dict, cipherTransform) : dict);
  19750. }
  19751. this.shift();
  19752. return dict;
  19753. default: // simple object
  19754. return buf1;
  19755. }
  19756. }
  19757. if (isInt(buf1)) { // indirect reference or integer
  19758. var num = buf1;
  19759. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  19760. var ref = new Ref(num, this.buf1);
  19761. this.shift();
  19762. this.shift();
  19763. return ref;
  19764. }
  19765. return num;
  19766. }
  19767. if (isString(buf1)) { // string
  19768. var str = buf1;
  19769. if (cipherTransform) {
  19770. str = cipherTransform.decryptString(str);
  19771. }
  19772. return str;
  19773. }
  19774. // simple object
  19775. return buf1;
  19776. },
  19777. /**
  19778. * Find the end of the stream by searching for the /EI\s/.
  19779. * @returns {number} The inline stream length.
  19780. */
  19781. findDefaultInlineStreamEnd:
  19782. function Parser_findDefaultInlineStreamEnd(stream) {
  19783. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  19784. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  19785. while ((ch = stream.getByte()) !== -1) {
  19786. if (state === 0) {
  19787. state = (ch === E) ? 1 : 0;
  19788. } else if (state === 1) {
  19789. state = (ch === I) ? 2 : 0;
  19790. } else {
  19791. assert(state === 2);
  19792. if (ch === SPACE || ch === LF || ch === CR) {
  19793. // Let's check the next five bytes are ASCII... just be sure.
  19794. n = 5;
  19795. followingBytes = stream.peekBytes(n);
  19796. for (i = 0; i < n; i++) {
  19797. ch = followingBytes[i];
  19798. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  19799. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  19800. // it's binary stuff. Resetting the state.
  19801. state = 0;
  19802. break;
  19803. }
  19804. }
  19805. if (state === 2) {
  19806. break; // Finished!
  19807. }
  19808. } else {
  19809. state = 0;
  19810. }
  19811. }
  19812. }
  19813. return ((stream.pos - 4) - startPos);
  19814. },
  19815. /**
  19816. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  19817. * @returns {number} The inline stream length.
  19818. */
  19819. findDCTDecodeInlineStreamEnd:
  19820. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  19821. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  19822. while ((b = stream.getByte()) !== -1) {
  19823. if (b !== 0xFF) { // Not a valid marker.
  19824. continue;
  19825. }
  19826. switch (stream.getByte()) {
  19827. case 0x00: // Byte stuffing.
  19828. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  19829. break;
  19830. case 0xFF: // Fill byte.
  19831. // Avoid skipping a valid marker, resetting the stream position.
  19832. stream.skip(-1);
  19833. break;
  19834. case 0xD9: // EOI
  19835. foundEOI = true;
  19836. break;
  19837. case 0xC0: // SOF0
  19838. case 0xC1: // SOF1
  19839. case 0xC2: // SOF2
  19840. case 0xC3: // SOF3
  19841. case 0xC5: // SOF5
  19842. case 0xC6: // SOF6
  19843. case 0xC7: // SOF7
  19844. case 0xC9: // SOF9
  19845. case 0xCA: // SOF10
  19846. case 0xCB: // SOF11
  19847. case 0xCD: // SOF13
  19848. case 0xCE: // SOF14
  19849. case 0xCF: // SOF15
  19850. case 0xC4: // DHT
  19851. case 0xCC: // DAC
  19852. case 0xDA: // SOS
  19853. case 0xDB: // DQT
  19854. case 0xDC: // DNL
  19855. case 0xDD: // DRI
  19856. case 0xDE: // DHP
  19857. case 0xDF: // EXP
  19858. case 0xE0: // APP0
  19859. case 0xE1: // APP1
  19860. case 0xE2: // APP2
  19861. case 0xE3: // APP3
  19862. case 0xE4: // APP4
  19863. case 0xE5: // APP5
  19864. case 0xE6: // APP6
  19865. case 0xE7: // APP7
  19866. case 0xE8: // APP8
  19867. case 0xE9: // APP9
  19868. case 0xEA: // APP10
  19869. case 0xEB: // APP11
  19870. case 0xEC: // APP12
  19871. case 0xED: // APP13
  19872. case 0xEE: // APP14
  19873. case 0xEF: // APP15
  19874. case 0xFE: // COM
  19875. // The marker should be followed by the length of the segment.
  19876. markerLength = stream.getUint16();
  19877. if (markerLength > 2) {
  19878. // |markerLength| contains the byte length of the marker segment,
  19879. // including its own length (2 bytes) and excluding the marker.
  19880. stream.skip(markerLength - 2); // Jump to the next marker.
  19881. } else {
  19882. // The marker length is invalid, resetting the stream position.
  19883. stream.skip(-2);
  19884. }
  19885. break;
  19886. }
  19887. if (foundEOI) {
  19888. break;
  19889. }
  19890. }
  19891. length = stream.pos - startPos;
  19892. if (b === -1) {
  19893. warn('Inline DCTDecode image stream: ' +
  19894. 'EOI marker not found, searching for /EI/ instead.');
  19895. stream.skip(-length); // Reset the stream position.
  19896. return this.findDefaultInlineStreamEnd(stream);
  19897. }
  19898. this.inlineStreamSkipEI(stream);
  19899. return length;
  19900. },
  19901. /**
  19902. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  19903. * @returns {number} The inline stream length.
  19904. */
  19905. findASCII85DecodeInlineStreamEnd:
  19906. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  19907. var TILDE = 0x7E, GT = 0x3E;
  19908. var startPos = stream.pos, ch, length;
  19909. while ((ch = stream.getByte()) !== -1) {
  19910. if (ch === TILDE && stream.peekByte() === GT) {
  19911. stream.skip();
  19912. break;
  19913. }
  19914. }
  19915. length = stream.pos - startPos;
  19916. if (ch === -1) {
  19917. warn('Inline ASCII85Decode image stream: ' +
  19918. 'EOD marker not found, searching for /EI/ instead.');
  19919. stream.skip(-length); // Reset the stream position.
  19920. return this.findDefaultInlineStreamEnd(stream);
  19921. }
  19922. this.inlineStreamSkipEI(stream);
  19923. return length;
  19924. },
  19925. /**
  19926. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  19927. * @returns {number} The inline stream length.
  19928. */
  19929. findASCIIHexDecodeInlineStreamEnd:
  19930. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  19931. var GT = 0x3E;
  19932. var startPos = stream.pos, ch, length;
  19933. while ((ch = stream.getByte()) !== -1) {
  19934. if (ch === GT) {
  19935. break;
  19936. }
  19937. }
  19938. length = stream.pos - startPos;
  19939. if (ch === -1) {
  19940. warn('Inline ASCIIHexDecode image stream: ' +
  19941. 'EOD marker not found, searching for /EI/ instead.');
  19942. stream.skip(-length); // Reset the stream position.
  19943. return this.findDefaultInlineStreamEnd(stream);
  19944. }
  19945. this.inlineStreamSkipEI(stream);
  19946. return length;
  19947. },
  19948. /**
  19949. * Skip over the /EI/ for streams where we search for an EOD marker.
  19950. */
  19951. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  19952. var E = 0x45, I = 0x49;
  19953. var state = 0, ch;
  19954. while ((ch = stream.getByte()) !== -1) {
  19955. if (state === 0) {
  19956. state = (ch === E) ? 1 : 0;
  19957. } else if (state === 1) {
  19958. state = (ch === I) ? 2 : 0;
  19959. } else if (state === 2) {
  19960. break;
  19961. }
  19962. }
  19963. },
  19964. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  19965. var lexer = this.lexer;
  19966. var stream = lexer.stream;
  19967. // Parse dictionary.
  19968. var dict = new Dict(this.xref);
  19969. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  19970. if (!isName(this.buf1)) {
  19971. error('Dictionary key must be a name object');
  19972. }
  19973. var key = this.buf1.name;
  19974. this.shift();
  19975. if (isEOF(this.buf1)) {
  19976. break;
  19977. }
  19978. dict.set(key, this.getObj(cipherTransform));
  19979. }
  19980. // Extract the name of the first (i.e. the current) image filter.
  19981. var filter = dict.get('Filter', 'F'), filterName;
  19982. if (isName(filter)) {
  19983. filterName = filter.name;
  19984. } else if (isArray(filter) && isName(filter[0])) {
  19985. filterName = filter[0].name;
  19986. }
  19987. // Parse image stream.
  19988. var startPos = stream.pos, length, i, ii;
  19989. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  19990. length = this.findDCTDecodeInlineStreamEnd(stream);
  19991. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  19992. length = this.findASCII85DecodeInlineStreamEnd(stream);
  19993. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  19994. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  19995. } else {
  19996. length = this.findDefaultInlineStreamEnd(stream);
  19997. }
  19998. var imageStream = stream.makeSubStream(startPos, length, dict);
  19999. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  20000. // adler32 checksum.
  20001. var adler32;
  20002. if (length < MAX_LENGTH_TO_CACHE) {
  20003. var imageBytes = imageStream.getBytes();
  20004. imageStream.reset();
  20005. var a = 1;
  20006. var b = 0;
  20007. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  20008. // No modulo required in the loop if imageBytes.length < 5552.
  20009. a += imageBytes[i] & 0xff;
  20010. b += a;
  20011. }
  20012. adler32 = ((b % 65521) << 16) | (a % 65521);
  20013. if (this.imageCache.adler32 === adler32) {
  20014. this.buf2 = Cmd.get('EI');
  20015. this.shift();
  20016. this.imageCache[adler32].reset();
  20017. return this.imageCache[adler32];
  20018. }
  20019. }
  20020. if (cipherTransform) {
  20021. imageStream = cipherTransform.createStream(imageStream, length);
  20022. }
  20023. imageStream = this.filter(imageStream, dict, length);
  20024. imageStream.dict = dict;
  20025. if (adler32 !== undefined) {
  20026. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  20027. this.imageCache[adler32] = imageStream;
  20028. }
  20029. this.buf2 = Cmd.get('EI');
  20030. this.shift();
  20031. return imageStream;
  20032. },
  20033. makeStream: function Parser_makeStream(dict, cipherTransform) {
  20034. var lexer = this.lexer;
  20035. var stream = lexer.stream;
  20036. // get stream start position
  20037. lexer.skipToNextLine();
  20038. var pos = stream.pos - 1;
  20039. // get length
  20040. var length = dict.get('Length');
  20041. if (!isInt(length)) {
  20042. info('Bad ' + length + ' attribute in stream');
  20043. length = 0;
  20044. }
  20045. // skip over the stream data
  20046. stream.pos = pos + length;
  20047. lexer.nextChar();
  20048. // Shift '>>' and check whether the new object marks the end of the stream
  20049. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  20050. this.shift(); // 'stream'
  20051. } else {
  20052. // bad stream length, scanning for endstream
  20053. stream.pos = pos;
  20054. var SCAN_BLOCK_SIZE = 2048;
  20055. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  20056. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  20057. 0x61, 0x6D];
  20058. var skipped = 0, found = false, i, j;
  20059. while (stream.pos < stream.end) {
  20060. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  20061. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  20062. if (scanLength <= 0) {
  20063. break;
  20064. }
  20065. found = false;
  20066. for (i = 0, j = 0; i < scanLength; i++) {
  20067. var b = scanBytes[i];
  20068. if (b !== ENDSTREAM_SIGNATURE[j]) {
  20069. i -= j;
  20070. j = 0;
  20071. } else {
  20072. j++;
  20073. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  20074. i++;
  20075. found = true;
  20076. break;
  20077. }
  20078. }
  20079. }
  20080. if (found) {
  20081. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  20082. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  20083. break;
  20084. }
  20085. skipped += scanLength;
  20086. stream.pos += scanLength;
  20087. }
  20088. if (!found) {
  20089. error('Missing endstream');
  20090. }
  20091. length = skipped;
  20092. lexer.nextChar();
  20093. this.shift();
  20094. this.shift();
  20095. }
  20096. this.shift(); // 'endstream'
  20097. stream = stream.makeSubStream(pos, length, dict);
  20098. if (cipherTransform) {
  20099. stream = cipherTransform.createStream(stream, length);
  20100. }
  20101. stream = this.filter(stream, dict, length);
  20102. stream.dict = dict;
  20103. return stream;
  20104. },
  20105. filter: function Parser_filter(stream, dict, length) {
  20106. var filter = dict.get('Filter', 'F');
  20107. var params = dict.get('DecodeParms', 'DP');
  20108. if (isName(filter)) {
  20109. return this.makeFilter(stream, filter.name, length, params);
  20110. }
  20111. var maybeLength = length;
  20112. if (isArray(filter)) {
  20113. var filterArray = filter;
  20114. var paramsArray = params;
  20115. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  20116. filter = filterArray[i];
  20117. if (!isName(filter)) {
  20118. error('Bad filter name: ' + filter);
  20119. }
  20120. params = null;
  20121. if (isArray(paramsArray) && (i in paramsArray)) {
  20122. params = paramsArray[i];
  20123. }
  20124. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  20125. // after the first stream the length variable is invalid
  20126. maybeLength = null;
  20127. }
  20128. }
  20129. return stream;
  20130. },
  20131. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  20132. if (stream.dict.get('Length') === 0 && !maybeLength) {
  20133. warn('Empty "' + name + '" stream.');
  20134. return new NullStream(stream);
  20135. }
  20136. try {
  20137. if (params && this.xref) {
  20138. params = this.xref.fetchIfRef(params);
  20139. }
  20140. var xrefStreamStats = this.xref.stats.streamTypes;
  20141. if (name === 'FlateDecode' || name === 'Fl') {
  20142. xrefStreamStats[StreamType.FLATE] = true;
  20143. if (params) {
  20144. return new PredictorStream(new FlateStream(stream, maybeLength),
  20145. maybeLength, params);
  20146. }
  20147. return new FlateStream(stream, maybeLength);
  20148. }
  20149. if (name === 'LZWDecode' || name === 'LZW') {
  20150. xrefStreamStats[StreamType.LZW] = true;
  20151. var earlyChange = 1;
  20152. if (params) {
  20153. if (params.has('EarlyChange')) {
  20154. earlyChange = params.get('EarlyChange');
  20155. }
  20156. return new PredictorStream(
  20157. new LZWStream(stream, maybeLength, earlyChange),
  20158. maybeLength, params);
  20159. }
  20160. return new LZWStream(stream, maybeLength, earlyChange);
  20161. }
  20162. if (name === 'DCTDecode' || name === 'DCT') {
  20163. xrefStreamStats[StreamType.DCT] = true;
  20164. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  20165. }
  20166. if (name === 'JPXDecode' || name === 'JPX') {
  20167. xrefStreamStats[StreamType.JPX] = true;
  20168. return new JpxStream(stream, maybeLength, stream.dict);
  20169. }
  20170. if (name === 'ASCII85Decode' || name === 'A85') {
  20171. xrefStreamStats[StreamType.A85] = true;
  20172. return new Ascii85Stream(stream, maybeLength);
  20173. }
  20174. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  20175. xrefStreamStats[StreamType.AHX] = true;
  20176. return new AsciiHexStream(stream, maybeLength);
  20177. }
  20178. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  20179. xrefStreamStats[StreamType.CCF] = true;
  20180. return new CCITTFaxStream(stream, maybeLength, params);
  20181. }
  20182. if (name === 'RunLengthDecode' || name === 'RL') {
  20183. xrefStreamStats[StreamType.RL] = true;
  20184. return new RunLengthStream(stream, maybeLength);
  20185. }
  20186. if (name === 'JBIG2Decode') {
  20187. xrefStreamStats[StreamType.JBIG] = true;
  20188. return new Jbig2Stream(stream, maybeLength, stream.dict);
  20189. }
  20190. warn('filter "' + name + '" not supported yet');
  20191. return stream;
  20192. } catch (ex) {
  20193. if (ex instanceof MissingDataException) {
  20194. throw ex;
  20195. }
  20196. warn('Invalid stream: \"' + ex + '\"');
  20197. return new NullStream(stream);
  20198. }
  20199. }
  20200. };
  20201. return Parser;
  20202. })();
  20203. var Lexer = (function LexerClosure() {
  20204. function Lexer(stream, knownCommands) {
  20205. this.stream = stream;
  20206. this.nextChar();
  20207. // While lexing, we build up many strings one char at a time. Using += for
  20208. // this can result in lots of garbage strings. It's better to build an
  20209. // array of single-char strings and then join() them together at the end.
  20210. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  20211. // purpose uses less memory than using a new array for each string.
  20212. this.strBuf = [];
  20213. // The PDFs might have "glued" commands with other commands, operands or
  20214. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  20215. // commands and their prefixes. The prefixes are built the following way:
  20216. // if there a command that is a prefix of the other valid command or
  20217. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  20218. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  20219. // other commands or literals as a prefix. The knowCommands is optional.
  20220. this.knownCommands = knownCommands;
  20221. }
  20222. Lexer.isSpace = function Lexer_isSpace(ch) {
  20223. // Space is one of the following characters: SPACE, TAB, CR or LF.
  20224. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  20225. };
  20226. // A '1' in this array means the character is white space. A '1' or
  20227. // '2' means the character ends a name or command.
  20228. var specialChars = [
  20229. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  20230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  20231. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  20232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  20233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  20234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  20235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  20236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  20237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  20238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  20239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  20240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  20241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  20242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  20243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  20244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  20245. ];
  20246. function toHexDigit(ch) {
  20247. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20248. return ch & 0x0F;
  20249. }
  20250. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20251. // 'A'-'F', 'a'-'f'
  20252. return (ch & 0x0F) + 9;
  20253. }
  20254. return -1;
  20255. }
  20256. Lexer.prototype = {
  20257. nextChar: function Lexer_nextChar() {
  20258. return (this.currentChar = this.stream.getByte());
  20259. },
  20260. peekChar: function Lexer_peekChar() {
  20261. return this.stream.peekByte();
  20262. },
  20263. getNumber: function Lexer_getNumber() {
  20264. var ch = this.currentChar;
  20265. var eNotation = false;
  20266. var divideBy = 0; // different from 0 if it's a floating point value
  20267. var sign = 1;
  20268. if (ch === 0x2D) { // '-'
  20269. sign = -1;
  20270. ch = this.nextChar();
  20271. if (ch === 0x2D) { // '-'
  20272. // Ignore double negative (this is consistent with Adobe Reader).
  20273. ch = this.nextChar();
  20274. }
  20275. } else if (ch === 0x2B) { // '+'
  20276. ch = this.nextChar();
  20277. }
  20278. if (ch === 0x2E) { // '.'
  20279. divideBy = 10;
  20280. ch = this.nextChar();
  20281. }
  20282. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20283. error('Invalid number: ' + String.fromCharCode(ch));
  20284. return 0;
  20285. }
  20286. var baseValue = ch - 0x30; // '0'
  20287. var powerValue = 0;
  20288. var powerValueSign = 1;
  20289. while ((ch = this.nextChar()) >= 0) {
  20290. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  20291. var currentDigit = ch - 0x30; // '0'
  20292. if (eNotation) { // We are after an 'e' or 'E'
  20293. powerValue = powerValue * 10 + currentDigit;
  20294. } else {
  20295. if (divideBy !== 0) { // We are after a point
  20296. divideBy *= 10;
  20297. }
  20298. baseValue = baseValue * 10 + currentDigit;
  20299. }
  20300. } else if (ch === 0x2E) { // '.'
  20301. if (divideBy === 0) {
  20302. divideBy = 1;
  20303. } else {
  20304. // A number can have only one '.'
  20305. break;
  20306. }
  20307. } else if (ch === 0x2D) { // '-'
  20308. // ignore minus signs in the middle of numbers to match
  20309. // Adobe's behavior
  20310. warn('Badly formated number');
  20311. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  20312. // 'E' can be either a scientific notation or the beginning of a new
  20313. // operator
  20314. ch = this.peekChar();
  20315. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  20316. powerValueSign = (ch === 0x2D) ? -1 : 1;
  20317. this.nextChar(); // Consume the sign character
  20318. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20319. // The 'E' must be the beginning of a new operator
  20320. break;
  20321. }
  20322. eNotation = true;
  20323. } else {
  20324. // the last character doesn't belong to us
  20325. break;
  20326. }
  20327. }
  20328. if (divideBy !== 0) {
  20329. baseValue /= divideBy;
  20330. }
  20331. if (eNotation) {
  20332. baseValue *= Math.pow(10, powerValueSign * powerValue);
  20333. }
  20334. return sign * baseValue;
  20335. },
  20336. getString: function Lexer_getString() {
  20337. var numParen = 1;
  20338. var done = false;
  20339. var strBuf = this.strBuf;
  20340. strBuf.length = 0;
  20341. var ch = this.nextChar();
  20342. while (true) {
  20343. var charBuffered = false;
  20344. switch (ch | 0) {
  20345. case -1:
  20346. warn('Unterminated string');
  20347. done = true;
  20348. break;
  20349. case 0x28: // '('
  20350. ++numParen;
  20351. strBuf.push('(');
  20352. break;
  20353. case 0x29: // ')'
  20354. if (--numParen === 0) {
  20355. this.nextChar(); // consume strings ')'
  20356. done = true;
  20357. } else {
  20358. strBuf.push(')');
  20359. }
  20360. break;
  20361. case 0x5C: // '\\'
  20362. ch = this.nextChar();
  20363. switch (ch) {
  20364. case -1:
  20365. warn('Unterminated string');
  20366. done = true;
  20367. break;
  20368. case 0x6E: // 'n'
  20369. strBuf.push('\n');
  20370. break;
  20371. case 0x72: // 'r'
  20372. strBuf.push('\r');
  20373. break;
  20374. case 0x74: // 't'
  20375. strBuf.push('\t');
  20376. break;
  20377. case 0x62: // 'b'
  20378. strBuf.push('\b');
  20379. break;
  20380. case 0x66: // 'f'
  20381. strBuf.push('\f');
  20382. break;
  20383. case 0x5C: // '\'
  20384. case 0x28: // '('
  20385. case 0x29: // ')'
  20386. strBuf.push(String.fromCharCode(ch));
  20387. break;
  20388. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  20389. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  20390. var x = ch & 0x0F;
  20391. ch = this.nextChar();
  20392. charBuffered = true;
  20393. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20394. x = (x << 3) + (ch & 0x0F);
  20395. ch = this.nextChar();
  20396. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20397. charBuffered = false;
  20398. x = (x << 3) + (ch & 0x0F);
  20399. }
  20400. }
  20401. strBuf.push(String.fromCharCode(x));
  20402. break;
  20403. case 0x0D: // CR
  20404. if (this.peekChar() === 0x0A) { // LF
  20405. this.nextChar();
  20406. }
  20407. break;
  20408. case 0x0A: // LF
  20409. break;
  20410. default:
  20411. strBuf.push(String.fromCharCode(ch));
  20412. break;
  20413. }
  20414. break;
  20415. default:
  20416. strBuf.push(String.fromCharCode(ch));
  20417. break;
  20418. }
  20419. if (done) {
  20420. break;
  20421. }
  20422. if (!charBuffered) {
  20423. ch = this.nextChar();
  20424. }
  20425. }
  20426. return strBuf.join('');
  20427. },
  20428. getName: function Lexer_getName() {
  20429. var ch, previousCh;
  20430. var strBuf = this.strBuf;
  20431. strBuf.length = 0;
  20432. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20433. if (ch === 0x23) { // '#'
  20434. ch = this.nextChar();
  20435. if (specialChars[ch]) {
  20436. warn('Lexer_getName: ' +
  20437. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  20438. strBuf.push('#');
  20439. break;
  20440. }
  20441. var x = toHexDigit(ch);
  20442. if (x !== -1) {
  20443. previousCh = ch;
  20444. ch = this.nextChar();
  20445. var x2 = toHexDigit(ch);
  20446. if (x2 === -1) {
  20447. warn('Lexer_getName: Illegal digit (' +
  20448. String.fromCharCode(ch) +') in hexadecimal number.');
  20449. strBuf.push('#', String.fromCharCode(previousCh));
  20450. if (specialChars[ch]) {
  20451. break;
  20452. }
  20453. strBuf.push(String.fromCharCode(ch));
  20454. continue;
  20455. }
  20456. strBuf.push(String.fromCharCode((x << 4) | x2));
  20457. } else {
  20458. strBuf.push('#', String.fromCharCode(ch));
  20459. }
  20460. } else {
  20461. strBuf.push(String.fromCharCode(ch));
  20462. }
  20463. }
  20464. if (strBuf.length > 127) {
  20465. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  20466. }
  20467. return Name.get(strBuf.join(''));
  20468. },
  20469. getHexString: function Lexer_getHexString() {
  20470. var strBuf = this.strBuf;
  20471. strBuf.length = 0;
  20472. var ch = this.currentChar;
  20473. var isFirstHex = true;
  20474. var firstDigit;
  20475. var secondDigit;
  20476. while (true) {
  20477. if (ch < 0) {
  20478. warn('Unterminated hex string');
  20479. break;
  20480. } else if (ch === 0x3E) { // '>'
  20481. this.nextChar();
  20482. break;
  20483. } else if (specialChars[ch] === 1) {
  20484. ch = this.nextChar();
  20485. continue;
  20486. } else {
  20487. if (isFirstHex) {
  20488. firstDigit = toHexDigit(ch);
  20489. if (firstDigit === -1) {
  20490. warn('Ignoring invalid character "' + ch + '" in hex string');
  20491. ch = this.nextChar();
  20492. continue;
  20493. }
  20494. } else {
  20495. secondDigit = toHexDigit(ch);
  20496. if (secondDigit === -1) {
  20497. warn('Ignoring invalid character "' + ch + '" in hex string');
  20498. ch = this.nextChar();
  20499. continue;
  20500. }
  20501. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  20502. }
  20503. isFirstHex = !isFirstHex;
  20504. ch = this.nextChar();
  20505. }
  20506. }
  20507. return strBuf.join('');
  20508. },
  20509. getObj: function Lexer_getObj() {
  20510. // skip whitespace and comments
  20511. var comment = false;
  20512. var ch = this.currentChar;
  20513. while (true) {
  20514. if (ch < 0) {
  20515. return EOF;
  20516. }
  20517. if (comment) {
  20518. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  20519. comment = false;
  20520. }
  20521. } else if (ch === 0x25) { // '%'
  20522. comment = true;
  20523. } else if (specialChars[ch] !== 1) {
  20524. break;
  20525. }
  20526. ch = this.nextChar();
  20527. }
  20528. // start reading token
  20529. switch (ch | 0) {
  20530. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  20531. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  20532. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  20533. return this.getNumber();
  20534. case 0x28: // '('
  20535. return this.getString();
  20536. case 0x2F: // '/'
  20537. return this.getName();
  20538. // array punctuation
  20539. case 0x5B: // '['
  20540. this.nextChar();
  20541. return Cmd.get('[');
  20542. case 0x5D: // ']'
  20543. this.nextChar();
  20544. return Cmd.get(']');
  20545. // hex string or dict punctuation
  20546. case 0x3C: // '<'
  20547. ch = this.nextChar();
  20548. if (ch === 0x3C) {
  20549. // dict punctuation
  20550. this.nextChar();
  20551. return Cmd.get('<<');
  20552. }
  20553. return this.getHexString();
  20554. // dict punctuation
  20555. case 0x3E: // '>'
  20556. ch = this.nextChar();
  20557. if (ch === 0x3E) {
  20558. this.nextChar();
  20559. return Cmd.get('>>');
  20560. }
  20561. return Cmd.get('>');
  20562. case 0x7B: // '{'
  20563. this.nextChar();
  20564. return Cmd.get('{');
  20565. case 0x7D: // '}'
  20566. this.nextChar();
  20567. return Cmd.get('}');
  20568. case 0x29: // ')'
  20569. error('Illegal character: ' + ch);
  20570. break;
  20571. }
  20572. // command
  20573. var str = String.fromCharCode(ch);
  20574. var knownCommands = this.knownCommands;
  20575. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20576. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20577. // stop if known command is found and next character does not make
  20578. // the str a command
  20579. var possibleCommand = str + String.fromCharCode(ch);
  20580. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  20581. break;
  20582. }
  20583. if (str.length === 128) {
  20584. error('Command token too long: ' + str.length);
  20585. }
  20586. str = possibleCommand;
  20587. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20588. }
  20589. if (str === 'true') {
  20590. return true;
  20591. }
  20592. if (str === 'false') {
  20593. return false;
  20594. }
  20595. if (str === 'null') {
  20596. return null;
  20597. }
  20598. return Cmd.get(str);
  20599. },
  20600. skipToNextLine: function Lexer_skipToNextLine() {
  20601. var ch = this.currentChar;
  20602. while (ch >= 0) {
  20603. if (ch === 0x0D) { // CR
  20604. ch = this.nextChar();
  20605. if (ch === 0x0A) { // LF
  20606. this.nextChar();
  20607. }
  20608. break;
  20609. } else if (ch === 0x0A) { // LF
  20610. this.nextChar();
  20611. break;
  20612. }
  20613. ch = this.nextChar();
  20614. }
  20615. }
  20616. };
  20617. return Lexer;
  20618. })();
  20619. var Linearization = {
  20620. create: function LinearizationCreate(stream) {
  20621. function getInt(name, allowZeroValue) {
  20622. var obj = linDict.get(name);
  20623. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  20624. return obj;
  20625. }
  20626. throw new Error('The "' + name + '" parameter in the linearization ' +
  20627. 'dictionary is invalid.');
  20628. }
  20629. function getHints() {
  20630. var hints = linDict.get('H'), hintsLength, item;
  20631. if (isArray(hints) &&
  20632. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  20633. for (var index = 0; index < hintsLength; index++) {
  20634. if (!(isInt(item = hints[index]) && item > 0)) {
  20635. throw new Error('Hint (' + index +
  20636. ') in the linearization dictionary is invalid.');
  20637. }
  20638. }
  20639. return hints;
  20640. }
  20641. throw new Error('Hint array in the linearization dictionary is invalid.');
  20642. }
  20643. var parser = new Parser(new Lexer(stream), false, null);
  20644. var obj1 = parser.getObj();
  20645. var obj2 = parser.getObj();
  20646. var obj3 = parser.getObj();
  20647. var linDict = parser.getObj();
  20648. var obj, length;
  20649. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  20650. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  20651. return null; // No valid linearization dictionary found.
  20652. } else if ((length = getInt('L')) !== stream.length) {
  20653. throw new Error('The "L" parameter in the linearization dictionary ' +
  20654. 'does not equal the stream length.');
  20655. }
  20656. return {
  20657. length: length,
  20658. hints: getHints(),
  20659. objectNumberFirst: getInt('O'),
  20660. endFirst: getInt('E'),
  20661. numPages: getInt('N'),
  20662. mainXRefEntriesOffset: getInt('T'),
  20663. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  20664. };
  20665. }
  20666. };
  20667. exports.EOF = EOF;
  20668. exports.Lexer = Lexer;
  20669. exports.Linearization = Linearization;
  20670. exports.Parser = Parser;
  20671. exports.isEOF = isEOF;
  20672. // TODO refactor to remove dependency on stream.js
  20673. coreStream._setCoreParser(exports);
  20674. }));
  20675. (function (root, factory) {
  20676. {
  20677. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  20678. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  20679. }
  20680. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  20681. var Util = sharedUtil.Util;
  20682. var assert = sharedUtil.assert;
  20683. var error = sharedUtil.error;
  20684. var isInt = sharedUtil.isInt;
  20685. var isString = sharedUtil.isString;
  20686. var warn = sharedUtil.warn;
  20687. var isName = corePrimitives.isName;
  20688. var isCmd = corePrimitives.isCmd;
  20689. var isStream = corePrimitives.isStream;
  20690. var StringStream = coreStream.StringStream;
  20691. var Lexer = coreParser.Lexer;
  20692. var isEOF = coreParser.isEOF;
  20693. var BUILT_IN_CMAPS = [
  20694. // << Start unicode maps.
  20695. 'Adobe-GB1-UCS2',
  20696. 'Adobe-CNS1-UCS2',
  20697. 'Adobe-Japan1-UCS2',
  20698. 'Adobe-Korea1-UCS2',
  20699. // >> End unicode maps.
  20700. '78-EUC-H',
  20701. '78-EUC-V',
  20702. '78-H',
  20703. '78-RKSJ-H',
  20704. '78-RKSJ-V',
  20705. '78-V',
  20706. '78ms-RKSJ-H',
  20707. '78ms-RKSJ-V',
  20708. '83pv-RKSJ-H',
  20709. '90ms-RKSJ-H',
  20710. '90ms-RKSJ-V',
  20711. '90msp-RKSJ-H',
  20712. '90msp-RKSJ-V',
  20713. '90pv-RKSJ-H',
  20714. '90pv-RKSJ-V',
  20715. 'Add-H',
  20716. 'Add-RKSJ-H',
  20717. 'Add-RKSJ-V',
  20718. 'Add-V',
  20719. 'Adobe-CNS1-0',
  20720. 'Adobe-CNS1-1',
  20721. 'Adobe-CNS1-2',
  20722. 'Adobe-CNS1-3',
  20723. 'Adobe-CNS1-4',
  20724. 'Adobe-CNS1-5',
  20725. 'Adobe-CNS1-6',
  20726. 'Adobe-GB1-0',
  20727. 'Adobe-GB1-1',
  20728. 'Adobe-GB1-2',
  20729. 'Adobe-GB1-3',
  20730. 'Adobe-GB1-4',
  20731. 'Adobe-GB1-5',
  20732. 'Adobe-Japan1-0',
  20733. 'Adobe-Japan1-1',
  20734. 'Adobe-Japan1-2',
  20735. 'Adobe-Japan1-3',
  20736. 'Adobe-Japan1-4',
  20737. 'Adobe-Japan1-5',
  20738. 'Adobe-Japan1-6',
  20739. 'Adobe-Korea1-0',
  20740. 'Adobe-Korea1-1',
  20741. 'Adobe-Korea1-2',
  20742. 'B5-H',
  20743. 'B5-V',
  20744. 'B5pc-H',
  20745. 'B5pc-V',
  20746. 'CNS-EUC-H',
  20747. 'CNS-EUC-V',
  20748. 'CNS1-H',
  20749. 'CNS1-V',
  20750. 'CNS2-H',
  20751. 'CNS2-V',
  20752. 'ETHK-B5-H',
  20753. 'ETHK-B5-V',
  20754. 'ETen-B5-H',
  20755. 'ETen-B5-V',
  20756. 'ETenms-B5-H',
  20757. 'ETenms-B5-V',
  20758. 'EUC-H',
  20759. 'EUC-V',
  20760. 'Ext-H',
  20761. 'Ext-RKSJ-H',
  20762. 'Ext-RKSJ-V',
  20763. 'Ext-V',
  20764. 'GB-EUC-H',
  20765. 'GB-EUC-V',
  20766. 'GB-H',
  20767. 'GB-V',
  20768. 'GBK-EUC-H',
  20769. 'GBK-EUC-V',
  20770. 'GBK2K-H',
  20771. 'GBK2K-V',
  20772. 'GBKp-EUC-H',
  20773. 'GBKp-EUC-V',
  20774. 'GBT-EUC-H',
  20775. 'GBT-EUC-V',
  20776. 'GBT-H',
  20777. 'GBT-V',
  20778. 'GBTpc-EUC-H',
  20779. 'GBTpc-EUC-V',
  20780. 'GBpc-EUC-H',
  20781. 'GBpc-EUC-V',
  20782. 'H',
  20783. 'HKdla-B5-H',
  20784. 'HKdla-B5-V',
  20785. 'HKdlb-B5-H',
  20786. 'HKdlb-B5-V',
  20787. 'HKgccs-B5-H',
  20788. 'HKgccs-B5-V',
  20789. 'HKm314-B5-H',
  20790. 'HKm314-B5-V',
  20791. 'HKm471-B5-H',
  20792. 'HKm471-B5-V',
  20793. 'HKscs-B5-H',
  20794. 'HKscs-B5-V',
  20795. 'Hankaku',
  20796. 'Hiragana',
  20797. 'KSC-EUC-H',
  20798. 'KSC-EUC-V',
  20799. 'KSC-H',
  20800. 'KSC-Johab-H',
  20801. 'KSC-Johab-V',
  20802. 'KSC-V',
  20803. 'KSCms-UHC-H',
  20804. 'KSCms-UHC-HW-H',
  20805. 'KSCms-UHC-HW-V',
  20806. 'KSCms-UHC-V',
  20807. 'KSCpc-EUC-H',
  20808. 'KSCpc-EUC-V',
  20809. 'Katakana',
  20810. 'NWP-H',
  20811. 'NWP-V',
  20812. 'RKSJ-H',
  20813. 'RKSJ-V',
  20814. 'Roman',
  20815. 'UniCNS-UCS2-H',
  20816. 'UniCNS-UCS2-V',
  20817. 'UniCNS-UTF16-H',
  20818. 'UniCNS-UTF16-V',
  20819. 'UniCNS-UTF32-H',
  20820. 'UniCNS-UTF32-V',
  20821. 'UniCNS-UTF8-H',
  20822. 'UniCNS-UTF8-V',
  20823. 'UniGB-UCS2-H',
  20824. 'UniGB-UCS2-V',
  20825. 'UniGB-UTF16-H',
  20826. 'UniGB-UTF16-V',
  20827. 'UniGB-UTF32-H',
  20828. 'UniGB-UTF32-V',
  20829. 'UniGB-UTF8-H',
  20830. 'UniGB-UTF8-V',
  20831. 'UniJIS-UCS2-H',
  20832. 'UniJIS-UCS2-HW-H',
  20833. 'UniJIS-UCS2-HW-V',
  20834. 'UniJIS-UCS2-V',
  20835. 'UniJIS-UTF16-H',
  20836. 'UniJIS-UTF16-V',
  20837. 'UniJIS-UTF32-H',
  20838. 'UniJIS-UTF32-V',
  20839. 'UniJIS-UTF8-H',
  20840. 'UniJIS-UTF8-V',
  20841. 'UniJIS2004-UTF16-H',
  20842. 'UniJIS2004-UTF16-V',
  20843. 'UniJIS2004-UTF32-H',
  20844. 'UniJIS2004-UTF32-V',
  20845. 'UniJIS2004-UTF8-H',
  20846. 'UniJIS2004-UTF8-V',
  20847. 'UniJISPro-UCS2-HW-V',
  20848. 'UniJISPro-UCS2-V',
  20849. 'UniJISPro-UTF8-V',
  20850. 'UniJISX0213-UTF32-H',
  20851. 'UniJISX0213-UTF32-V',
  20852. 'UniJISX02132004-UTF32-H',
  20853. 'UniJISX02132004-UTF32-V',
  20854. 'UniKS-UCS2-H',
  20855. 'UniKS-UCS2-V',
  20856. 'UniKS-UTF16-H',
  20857. 'UniKS-UTF16-V',
  20858. 'UniKS-UTF32-H',
  20859. 'UniKS-UTF32-V',
  20860. 'UniKS-UTF8-H',
  20861. 'UniKS-UTF8-V',
  20862. 'V',
  20863. 'WP-Symbol'];
  20864. // CMap, not to be confused with TrueType's cmap.
  20865. var CMap = (function CMapClosure() {
  20866. function CMap(builtInCMap) {
  20867. // Codespace ranges are stored as follows:
  20868. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  20869. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  20870. this.codespaceRanges = [[], [], [], []];
  20871. this.numCodespaceRanges = 0;
  20872. // Map entries have one of two forms.
  20873. // - cid chars are 16-bit unsigned integers, stored as integers.
  20874. // - bf chars are variable-length byte sequences, stored as strings, with
  20875. // one byte per character.
  20876. this._map = [];
  20877. this.name = '';
  20878. this.vertical = false;
  20879. this.useCMap = null;
  20880. this.builtInCMap = builtInCMap;
  20881. }
  20882. CMap.prototype = {
  20883. addCodespaceRange: function(n, low, high) {
  20884. this.codespaceRanges[n - 1].push(low, high);
  20885. this.numCodespaceRanges++;
  20886. },
  20887. mapCidRange: function(low, high, dstLow) {
  20888. while (low <= high) {
  20889. this._map[low++] = dstLow++;
  20890. }
  20891. },
  20892. mapBfRange: function(low, high, dstLow) {
  20893. var lastByte = dstLow.length - 1;
  20894. while (low <= high) {
  20895. this._map[low++] = dstLow;
  20896. // Only the last byte has to be incremented.
  20897. dstLow = dstLow.substr(0, lastByte) +
  20898. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  20899. }
  20900. },
  20901. mapBfRangeToArray: function(low, high, array) {
  20902. var i = 0, ii = array.length;
  20903. while (low <= high && i < ii) {
  20904. this._map[low] = array[i++];
  20905. ++low;
  20906. }
  20907. },
  20908. // This is used for both bf and cid chars.
  20909. mapOne: function(src, dst) {
  20910. this._map[src] = dst;
  20911. },
  20912. lookup: function(code) {
  20913. return this._map[code];
  20914. },
  20915. contains: function(code) {
  20916. return this._map[code] !== undefined;
  20917. },
  20918. forEach: function(callback) {
  20919. // Most maps have fewer than 65536 entries, and for those we use normal
  20920. // array iteration. But really sparse tables are possible -- e.g. with
  20921. // indices in the *billions*. For such tables we use for..in, which isn't
  20922. // ideal because it stringifies the indices for all present elements, but
  20923. // it does avoid iterating over every undefined entry.
  20924. var map = this._map;
  20925. var length = map.length;
  20926. var i;
  20927. if (length <= 0x10000) {
  20928. for (i = 0; i < length; i++) {
  20929. if (map[i] !== undefined) {
  20930. callback(i, map[i]);
  20931. }
  20932. }
  20933. } else {
  20934. for (i in this._map) {
  20935. callback(i, map[i]);
  20936. }
  20937. }
  20938. },
  20939. charCodeOf: function(value) {
  20940. return this._map.indexOf(value);
  20941. },
  20942. getMap: function() {
  20943. return this._map;
  20944. },
  20945. readCharCode: function(str, offset, out) {
  20946. var c = 0;
  20947. var codespaceRanges = this.codespaceRanges;
  20948. var codespaceRangesLen = this.codespaceRanges.length;
  20949. // 9.7.6.2 CMap Mapping
  20950. // The code length is at most 4.
  20951. for (var n = 0; n < codespaceRangesLen; n++) {
  20952. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  20953. // Check each codespace range to see if it falls within.
  20954. var codespaceRange = codespaceRanges[n];
  20955. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  20956. var low = codespaceRange[k++];
  20957. var high = codespaceRange[k++];
  20958. if (c >= low && c <= high) {
  20959. out.charcode = c;
  20960. out.length = n + 1;
  20961. return;
  20962. }
  20963. }
  20964. }
  20965. out.charcode = 0;
  20966. out.length = 1;
  20967. },
  20968. get length() {
  20969. return this._map.length;
  20970. },
  20971. get isIdentityCMap() {
  20972. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  20973. return false;
  20974. }
  20975. if (this._map.length !== 0x10000) {
  20976. return false;
  20977. }
  20978. for (var i = 0; i < 0x10000; i++) {
  20979. if (this._map[i] !== i) {
  20980. return false;
  20981. }
  20982. }
  20983. return true;
  20984. }
  20985. };
  20986. return CMap;
  20987. })();
  20988. // A special case of CMap, where the _map array implicitly has a length of
  20989. // 65536 and each element is equal to its index.
  20990. var IdentityCMap = (function IdentityCMapClosure() {
  20991. function IdentityCMap(vertical, n) {
  20992. CMap.call(this);
  20993. this.vertical = vertical;
  20994. this.addCodespaceRange(n, 0, 0xffff);
  20995. }
  20996. Util.inherit(IdentityCMap, CMap, {});
  20997. IdentityCMap.prototype = {
  20998. addCodespaceRange: CMap.prototype.addCodespaceRange,
  20999. mapCidRange: function(low, high, dstLow) {
  21000. error('should not call mapCidRange');
  21001. },
  21002. mapBfRange: function(low, high, dstLow) {
  21003. error('should not call mapBfRange');
  21004. },
  21005. mapBfRangeToArray: function(low, high, array) {
  21006. error('should not call mapBfRangeToArray');
  21007. },
  21008. mapOne: function(src, dst) {
  21009. error('should not call mapCidOne');
  21010. },
  21011. lookup: function(code) {
  21012. return (isInt(code) && code <= 0xffff) ? code : undefined;
  21013. },
  21014. contains: function(code) {
  21015. return isInt(code) && code <= 0xffff;
  21016. },
  21017. forEach: function(callback) {
  21018. for (var i = 0; i <= 0xffff; i++) {
  21019. callback(i, i);
  21020. }
  21021. },
  21022. charCodeOf: function(value) {
  21023. return (isInt(value) && value <= 0xffff) ? value : -1;
  21024. },
  21025. getMap: function() {
  21026. // Sometimes identity maps must be instantiated, but it's rare.
  21027. var map = new Array(0x10000);
  21028. for (var i = 0; i <= 0xffff; i++) {
  21029. map[i] = i;
  21030. }
  21031. return map;
  21032. },
  21033. readCharCode: CMap.prototype.readCharCode,
  21034. get length() {
  21035. return 0x10000;
  21036. },
  21037. get isIdentityCMap() {
  21038. error('should not access .isIdentityCMap');
  21039. }
  21040. };
  21041. return IdentityCMap;
  21042. })();
  21043. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  21044. function fetchBinaryData(url) {
  21045. var nonBinaryRequest = PDFJS.disableWorker;
  21046. var request = new XMLHttpRequest();
  21047. request.open('GET', url, false);
  21048. if (!nonBinaryRequest) {
  21049. try {
  21050. request.responseType = 'arraybuffer';
  21051. nonBinaryRequest = request.responseType !== 'arraybuffer';
  21052. } catch (e) {
  21053. nonBinaryRequest = true;
  21054. }
  21055. }
  21056. if (nonBinaryRequest && request.overrideMimeType) {
  21057. request.overrideMimeType('text/plain; charset=x-user-defined');
  21058. }
  21059. request.send(null);
  21060. if (nonBinaryRequest ? !request.responseText : !request.response) {
  21061. error('Unable to get binary cMap at: ' + url);
  21062. }
  21063. if (nonBinaryRequest) {
  21064. var data = Array.prototype.map.call(request.responseText, function (ch) {
  21065. return ch.charCodeAt(0) & 255;
  21066. });
  21067. return new Uint8Array(data);
  21068. }
  21069. return new Uint8Array(request.response);
  21070. }
  21071. function hexToInt(a, size) {
  21072. var n = 0;
  21073. for (var i = 0; i <= size; i++) {
  21074. n = (n << 8) | a[i];
  21075. }
  21076. return n >>> 0;
  21077. }
  21078. function hexToStr(a, size) {
  21079. // This code is hot. Special-case some common values to avoid creating an
  21080. // object with subarray().
  21081. if (size === 1) {
  21082. return String.fromCharCode(a[0], a[1]);
  21083. }
  21084. if (size === 3) {
  21085. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  21086. }
  21087. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  21088. }
  21089. function addHex(a, b, size) {
  21090. var c = 0;
  21091. for (var i = size; i >= 0; i--) {
  21092. c += a[i] + b[i];
  21093. a[i] = c & 255;
  21094. c >>= 8;
  21095. }
  21096. }
  21097. function incHex(a, size) {
  21098. var c = 1;
  21099. for (var i = size; i >= 0 && c > 0; i--) {
  21100. c += a[i];
  21101. a[i] = c & 255;
  21102. c >>= 8;
  21103. }
  21104. }
  21105. var MAX_NUM_SIZE = 16;
  21106. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  21107. function BinaryCMapStream(data) {
  21108. this.buffer = data;
  21109. this.pos = 0;
  21110. this.end = data.length;
  21111. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  21112. }
  21113. BinaryCMapStream.prototype = {
  21114. readByte: function () {
  21115. if (this.pos >= this.end) {
  21116. return -1;
  21117. }
  21118. return this.buffer[this.pos++];
  21119. },
  21120. readNumber: function () {
  21121. var n = 0;
  21122. var last;
  21123. do {
  21124. var b = this.readByte();
  21125. if (b < 0) {
  21126. error('unexpected EOF in bcmap');
  21127. }
  21128. last = !(b & 0x80);
  21129. n = (n << 7) | (b & 0x7F);
  21130. } while (!last);
  21131. return n;
  21132. },
  21133. readSigned: function () {
  21134. var n = this.readNumber();
  21135. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  21136. },
  21137. readHex: function (num, size) {
  21138. num.set(this.buffer.subarray(this.pos,
  21139. this.pos + size + 1));
  21140. this.pos += size + 1;
  21141. },
  21142. readHexNumber: function (num, size) {
  21143. var last;
  21144. var stack = this.tmpBuf, sp = 0;
  21145. do {
  21146. var b = this.readByte();
  21147. if (b < 0) {
  21148. error('unexpected EOF in bcmap');
  21149. }
  21150. last = !(b & 0x80);
  21151. stack[sp++] = b & 0x7F;
  21152. } while (!last);
  21153. var i = size, buffer = 0, bufferSize = 0;
  21154. while (i >= 0) {
  21155. while (bufferSize < 8 && stack.length > 0) {
  21156. buffer = (stack[--sp] << bufferSize) | buffer;
  21157. bufferSize += 7;
  21158. }
  21159. num[i] = buffer & 255;
  21160. i--;
  21161. buffer >>= 8;
  21162. bufferSize -= 8;
  21163. }
  21164. },
  21165. readHexSigned: function (num, size) {
  21166. this.readHexNumber(num, size);
  21167. var sign = num[size] & 1 ? 255 : 0;
  21168. var c = 0;
  21169. for (var i = 0; i <= size; i++) {
  21170. c = ((c & 1) << 8) | num[i];
  21171. num[i] = (c >> 1) ^ sign;
  21172. }
  21173. },
  21174. readString: function () {
  21175. var len = this.readNumber();
  21176. var s = '';
  21177. for (var i = 0; i < len; i++) {
  21178. s += String.fromCharCode(this.readNumber());
  21179. }
  21180. return s;
  21181. }
  21182. };
  21183. function processBinaryCMap(url, cMap, extend) {
  21184. var data = fetchBinaryData(url);
  21185. var stream = new BinaryCMapStream(data);
  21186. var header = stream.readByte();
  21187. cMap.vertical = !!(header & 1);
  21188. var useCMap = null;
  21189. var start = new Uint8Array(MAX_NUM_SIZE);
  21190. var end = new Uint8Array(MAX_NUM_SIZE);
  21191. var char = new Uint8Array(MAX_NUM_SIZE);
  21192. var charCode = new Uint8Array(MAX_NUM_SIZE);
  21193. var tmp = new Uint8Array(MAX_NUM_SIZE);
  21194. var code;
  21195. var b;
  21196. while ((b = stream.readByte()) >= 0) {
  21197. var type = b >> 5;
  21198. if (type === 7) { // metadata, e.g. comment or usecmap
  21199. switch (b & 0x1F) {
  21200. case 0:
  21201. stream.readString(); // skipping comment
  21202. break;
  21203. case 1:
  21204. useCMap = stream.readString();
  21205. break;
  21206. }
  21207. continue;
  21208. }
  21209. var sequence = !!(b & 0x10);
  21210. var dataSize = b & 15;
  21211. assert(dataSize + 1 <= MAX_NUM_SIZE);
  21212. var ucs2DataSize = 1;
  21213. var subitemsCount = stream.readNumber();
  21214. var i;
  21215. switch (type) {
  21216. case 0: // codespacerange
  21217. stream.readHex(start, dataSize);
  21218. stream.readHexNumber(end, dataSize);
  21219. addHex(end, start, dataSize);
  21220. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21221. hexToInt(end, dataSize));
  21222. for (i = 1; i < subitemsCount; i++) {
  21223. incHex(end, dataSize);
  21224. stream.readHexNumber(start, dataSize);
  21225. addHex(start, end, dataSize);
  21226. stream.readHexNumber(end, dataSize);
  21227. addHex(end, start, dataSize);
  21228. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21229. hexToInt(end, dataSize));
  21230. }
  21231. break;
  21232. case 1: // notdefrange
  21233. stream.readHex(start, dataSize);
  21234. stream.readHexNumber(end, dataSize);
  21235. addHex(end, start, dataSize);
  21236. code = stream.readNumber();
  21237. // undefined range, skipping
  21238. for (i = 1; i < subitemsCount; i++) {
  21239. incHex(end, dataSize);
  21240. stream.readHexNumber(start, dataSize);
  21241. addHex(start, end, dataSize);
  21242. stream.readHexNumber(end, dataSize);
  21243. addHex(end, start, dataSize);
  21244. code = stream.readNumber();
  21245. // nop
  21246. }
  21247. break;
  21248. case 2: // cidchar
  21249. stream.readHex(char, dataSize);
  21250. code = stream.readNumber();
  21251. cMap.mapOne(hexToInt(char, dataSize), code);
  21252. for (i = 1; i < subitemsCount; i++) {
  21253. incHex(char, dataSize);
  21254. if (!sequence) {
  21255. stream.readHexNumber(tmp, dataSize);
  21256. addHex(char, tmp, dataSize);
  21257. }
  21258. code = stream.readSigned() + (code + 1);
  21259. cMap.mapOne(hexToInt(char, dataSize), code);
  21260. }
  21261. break;
  21262. case 3: // cidrange
  21263. stream.readHex(start, dataSize);
  21264. stream.readHexNumber(end, dataSize);
  21265. addHex(end, start, dataSize);
  21266. code = stream.readNumber();
  21267. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21268. code);
  21269. for (i = 1; i < subitemsCount; i++) {
  21270. incHex(end, dataSize);
  21271. if (!sequence) {
  21272. stream.readHexNumber(start, dataSize);
  21273. addHex(start, end, dataSize);
  21274. } else {
  21275. start.set(end);
  21276. }
  21277. stream.readHexNumber(end, dataSize);
  21278. addHex(end, start, dataSize);
  21279. code = stream.readNumber();
  21280. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21281. code);
  21282. }
  21283. break;
  21284. case 4: // bfchar
  21285. stream.readHex(char, ucs2DataSize);
  21286. stream.readHex(charCode, dataSize);
  21287. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21288. hexToStr(charCode, dataSize));
  21289. for (i = 1; i < subitemsCount; i++) {
  21290. incHex(char, ucs2DataSize);
  21291. if (!sequence) {
  21292. stream.readHexNumber(tmp, ucs2DataSize);
  21293. addHex(char, tmp, ucs2DataSize);
  21294. }
  21295. incHex(charCode, dataSize);
  21296. stream.readHexSigned(tmp, dataSize);
  21297. addHex(charCode, tmp, dataSize);
  21298. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21299. hexToStr(charCode, dataSize));
  21300. }
  21301. break;
  21302. case 5: // bfrange
  21303. stream.readHex(start, ucs2DataSize);
  21304. stream.readHexNumber(end, ucs2DataSize);
  21305. addHex(end, start, ucs2DataSize);
  21306. stream.readHex(charCode, dataSize);
  21307. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21308. hexToInt(end, ucs2DataSize),
  21309. hexToStr(charCode, dataSize));
  21310. for (i = 1; i < subitemsCount; i++) {
  21311. incHex(end, ucs2DataSize);
  21312. if (!sequence) {
  21313. stream.readHexNumber(start, ucs2DataSize);
  21314. addHex(start, end, ucs2DataSize);
  21315. } else {
  21316. start.set(end);
  21317. }
  21318. stream.readHexNumber(end, ucs2DataSize);
  21319. addHex(end, start, ucs2DataSize);
  21320. stream.readHex(charCode, dataSize);
  21321. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21322. hexToInt(end, ucs2DataSize),
  21323. hexToStr(charCode, dataSize));
  21324. }
  21325. break;
  21326. default:
  21327. error('Unknown type: ' + type);
  21328. break;
  21329. }
  21330. }
  21331. if (useCMap) {
  21332. extend(useCMap);
  21333. }
  21334. return cMap;
  21335. }
  21336. function BinaryCMapReader() {}
  21337. BinaryCMapReader.prototype = {
  21338. read: processBinaryCMap
  21339. };
  21340. return BinaryCMapReader;
  21341. })();
  21342. var CMapFactory = (function CMapFactoryClosure() {
  21343. function strToInt(str) {
  21344. var a = 0;
  21345. for (var i = 0; i < str.length; i++) {
  21346. a = (a << 8) | str.charCodeAt(i);
  21347. }
  21348. return a >>> 0;
  21349. }
  21350. function expectString(obj) {
  21351. if (!isString(obj)) {
  21352. error('Malformed CMap: expected string.');
  21353. }
  21354. }
  21355. function expectInt(obj) {
  21356. if (!isInt(obj)) {
  21357. error('Malformed CMap: expected int.');
  21358. }
  21359. }
  21360. function parseBfChar(cMap, lexer) {
  21361. while (true) {
  21362. var obj = lexer.getObj();
  21363. if (isEOF(obj)) {
  21364. break;
  21365. }
  21366. if (isCmd(obj, 'endbfchar')) {
  21367. return;
  21368. }
  21369. expectString(obj);
  21370. var src = strToInt(obj);
  21371. obj = lexer.getObj();
  21372. // TODO are /dstName used?
  21373. expectString(obj);
  21374. var dst = obj;
  21375. cMap.mapOne(src, dst);
  21376. }
  21377. }
  21378. function parseBfRange(cMap, lexer) {
  21379. while (true) {
  21380. var obj = lexer.getObj();
  21381. if (isEOF(obj)) {
  21382. break;
  21383. }
  21384. if (isCmd(obj, 'endbfrange')) {
  21385. return;
  21386. }
  21387. expectString(obj);
  21388. var low = strToInt(obj);
  21389. obj = lexer.getObj();
  21390. expectString(obj);
  21391. var high = strToInt(obj);
  21392. obj = lexer.getObj();
  21393. if (isInt(obj) || isString(obj)) {
  21394. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  21395. cMap.mapBfRange(low, high, dstLow);
  21396. } else if (isCmd(obj, '[')) {
  21397. obj = lexer.getObj();
  21398. var array = [];
  21399. while (!isCmd(obj, ']') && !isEOF(obj)) {
  21400. array.push(obj);
  21401. obj = lexer.getObj();
  21402. }
  21403. cMap.mapBfRangeToArray(low, high, array);
  21404. } else {
  21405. break;
  21406. }
  21407. }
  21408. error('Invalid bf range.');
  21409. }
  21410. function parseCidChar(cMap, lexer) {
  21411. while (true) {
  21412. var obj = lexer.getObj();
  21413. if (isEOF(obj)) {
  21414. break;
  21415. }
  21416. if (isCmd(obj, 'endcidchar')) {
  21417. return;
  21418. }
  21419. expectString(obj);
  21420. var src = strToInt(obj);
  21421. obj = lexer.getObj();
  21422. expectInt(obj);
  21423. var dst = obj;
  21424. cMap.mapOne(src, dst);
  21425. }
  21426. }
  21427. function parseCidRange(cMap, lexer) {
  21428. while (true) {
  21429. var obj = lexer.getObj();
  21430. if (isEOF(obj)) {
  21431. break;
  21432. }
  21433. if (isCmd(obj, 'endcidrange')) {
  21434. return;
  21435. }
  21436. expectString(obj);
  21437. var low = strToInt(obj);
  21438. obj = lexer.getObj();
  21439. expectString(obj);
  21440. var high = strToInt(obj);
  21441. obj = lexer.getObj();
  21442. expectInt(obj);
  21443. var dstLow = obj;
  21444. cMap.mapCidRange(low, high, dstLow);
  21445. }
  21446. }
  21447. function parseCodespaceRange(cMap, lexer) {
  21448. while (true) {
  21449. var obj = lexer.getObj();
  21450. if (isEOF(obj)) {
  21451. break;
  21452. }
  21453. if (isCmd(obj, 'endcodespacerange')) {
  21454. return;
  21455. }
  21456. if (!isString(obj)) {
  21457. break;
  21458. }
  21459. var low = strToInt(obj);
  21460. obj = lexer.getObj();
  21461. if (!isString(obj)) {
  21462. break;
  21463. }
  21464. var high = strToInt(obj);
  21465. cMap.addCodespaceRange(obj.length, low, high);
  21466. }
  21467. error('Invalid codespace range.');
  21468. }
  21469. function parseWMode(cMap, lexer) {
  21470. var obj = lexer.getObj();
  21471. if (isInt(obj)) {
  21472. cMap.vertical = !!obj;
  21473. }
  21474. }
  21475. function parseCMapName(cMap, lexer) {
  21476. var obj = lexer.getObj();
  21477. if (isName(obj) && isString(obj.name)) {
  21478. cMap.name = obj.name;
  21479. }
  21480. }
  21481. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  21482. var previous;
  21483. var embededUseCMap;
  21484. objLoop: while (true) {
  21485. var obj = lexer.getObj();
  21486. if (isEOF(obj)) {
  21487. break;
  21488. } else if (isName(obj)) {
  21489. if (obj.name === 'WMode') {
  21490. parseWMode(cMap, lexer);
  21491. } else if (obj.name === 'CMapName') {
  21492. parseCMapName(cMap, lexer);
  21493. }
  21494. previous = obj;
  21495. } else if (isCmd(obj)) {
  21496. switch (obj.cmd) {
  21497. case 'endcmap':
  21498. break objLoop;
  21499. case 'usecmap':
  21500. if (isName(previous)) {
  21501. embededUseCMap = previous.name;
  21502. }
  21503. break;
  21504. case 'begincodespacerange':
  21505. parseCodespaceRange(cMap, lexer);
  21506. break;
  21507. case 'beginbfchar':
  21508. parseBfChar(cMap, lexer);
  21509. break;
  21510. case 'begincidchar':
  21511. parseCidChar(cMap, lexer);
  21512. break;
  21513. case 'beginbfrange':
  21514. parseBfRange(cMap, lexer);
  21515. break;
  21516. case 'begincidrange':
  21517. parseCidRange(cMap, lexer);
  21518. break;
  21519. }
  21520. }
  21521. }
  21522. if (!useCMap && embededUseCMap) {
  21523. // Load the usecmap definition from the file only if there wasn't one
  21524. // specified.
  21525. useCMap = embededUseCMap;
  21526. }
  21527. if (useCMap) {
  21528. extendCMap(cMap, builtInCMapParams, useCMap);
  21529. }
  21530. }
  21531. function extendCMap(cMap, builtInCMapParams, useCMap) {
  21532. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  21533. // If there aren't any code space ranges defined clone all the parent ones
  21534. // into this cMap.
  21535. if (cMap.numCodespaceRanges === 0) {
  21536. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  21537. for (var i = 0; i < useCodespaceRanges.length; i++) {
  21538. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  21539. }
  21540. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  21541. }
  21542. // Merge the map into the current one, making sure not to override
  21543. // any previously defined entries.
  21544. cMap.useCMap.forEach(function(key, value) {
  21545. if (!cMap.contains(key)) {
  21546. cMap.mapOne(key, cMap.useCMap.lookup(key));
  21547. }
  21548. });
  21549. }
  21550. function parseBinaryCMap(name, builtInCMapParams) {
  21551. var url = builtInCMapParams.url + name + '.bcmap';
  21552. var cMap = new CMap(true);
  21553. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  21554. extendCMap(cMap, builtInCMapParams, useCMap);
  21555. });
  21556. return cMap;
  21557. }
  21558. function createBuiltInCMap(name, builtInCMapParams) {
  21559. if (name === 'Identity-H') {
  21560. return new IdentityCMap(false, 2);
  21561. } else if (name === 'Identity-V') {
  21562. return new IdentityCMap(true, 2);
  21563. }
  21564. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  21565. error('Unknown cMap name: ' + name);
  21566. }
  21567. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  21568. if (builtInCMapParams.packed) {
  21569. return parseBinaryCMap(name, builtInCMapParams);
  21570. }
  21571. var request = new XMLHttpRequest();
  21572. var url = builtInCMapParams.url + name;
  21573. request.open('GET', url, false);
  21574. request.send(null);
  21575. if (!request.responseText) {
  21576. error('Unable to get cMap at: ' + url);
  21577. }
  21578. var cMap = new CMap(true);
  21579. var lexer = new Lexer(new StringStream(request.responseText));
  21580. parseCMap(cMap, lexer, builtInCMapParams, null);
  21581. return cMap;
  21582. }
  21583. return {
  21584. create: function (encoding, builtInCMapParams, useCMap) {
  21585. if (isName(encoding)) {
  21586. return createBuiltInCMap(encoding.name, builtInCMapParams);
  21587. } else if (isStream(encoding)) {
  21588. var cMap = new CMap();
  21589. var lexer = new Lexer(encoding);
  21590. try {
  21591. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  21592. } catch (e) {
  21593. warn('Invalid CMap data. ' + e);
  21594. }
  21595. if (cMap.isIdentityCMap) {
  21596. return createBuiltInCMap(cMap.name, builtInCMapParams);
  21597. }
  21598. return cMap;
  21599. }
  21600. error('Encoding required.');
  21601. }
  21602. };
  21603. })();
  21604. exports.CMap = CMap;
  21605. exports.CMapFactory = CMapFactory;
  21606. exports.IdentityCMap = IdentityCMap;
  21607. }));
  21608. (function (root, factory) {
  21609. {
  21610. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  21611. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  21612. root.pdfjsCoreChunkedStream);
  21613. }
  21614. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  21615. coreChunkedStream) {
  21616. var InvalidPDFException = sharedUtil.InvalidPDFException;
  21617. var MissingDataException = sharedUtil.MissingDataException;
  21618. var XRefParseException = sharedUtil.XRefParseException;
  21619. var assert = sharedUtil.assert;
  21620. var bytesToString = sharedUtil.bytesToString;
  21621. var createPromiseCapability = sharedUtil.createPromiseCapability;
  21622. var error = sharedUtil.error;
  21623. var info = sharedUtil.info;
  21624. var isArray = sharedUtil.isArray;
  21625. var isInt = sharedUtil.isInt;
  21626. var isString = sharedUtil.isString;
  21627. var shadow = sharedUtil.shadow;
  21628. var stringToPDFString = sharedUtil.stringToPDFString;
  21629. var stringToUTF8String = sharedUtil.stringToUTF8String;
  21630. var warn = sharedUtil.warn;
  21631. var Ref = corePrimitives.Ref;
  21632. var RefSet = corePrimitives.RefSet;
  21633. var RefSetCache = corePrimitives.RefSetCache;
  21634. var isName = corePrimitives.isName;
  21635. var isCmd = corePrimitives.isCmd;
  21636. var isDict = corePrimitives.isDict;
  21637. var isRef = corePrimitives.isRef;
  21638. var isStream = corePrimitives.isStream;
  21639. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  21640. var Lexer = coreParser.Lexer;
  21641. var Parser = coreParser.Parser;
  21642. var ChunkedStream = coreChunkedStream.ChunkedStream;
  21643. var Catalog = (function CatalogClosure() {
  21644. function Catalog(pdfManager, xref, pageFactory) {
  21645. this.pdfManager = pdfManager;
  21646. this.xref = xref;
  21647. this.catDict = xref.getCatalogObj();
  21648. this.fontCache = new RefSetCache();
  21649. assert(isDict(this.catDict),
  21650. 'catalog object is not a dictionary');
  21651. // TODO refactor to move getPage() to the PDFDocument.
  21652. this.pageFactory = pageFactory;
  21653. this.pagePromises = [];
  21654. }
  21655. Catalog.prototype = {
  21656. get metadata() {
  21657. var streamRef = this.catDict.getRaw('Metadata');
  21658. if (!isRef(streamRef)) {
  21659. return shadow(this, 'metadata', null);
  21660. }
  21661. var encryptMetadata = (!this.xref.encrypt ? false :
  21662. this.xref.encrypt.encryptMetadata);
  21663. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  21664. var metadata;
  21665. if (stream && isDict(stream.dict)) {
  21666. var type = stream.dict.get('Type');
  21667. var subtype = stream.dict.get('Subtype');
  21668. if (isName(type) && isName(subtype) &&
  21669. type.name === 'Metadata' && subtype.name === 'XML') {
  21670. // XXX: This should examine the charset the XML document defines,
  21671. // however since there are currently no real means to decode
  21672. // arbitrary charsets, let's just hope that the author of the PDF
  21673. // was reasonable enough to stick with the XML default charset,
  21674. // which is UTF-8.
  21675. try {
  21676. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  21677. } catch (e) {
  21678. info('Skipping invalid metadata.');
  21679. }
  21680. }
  21681. }
  21682. return shadow(this, 'metadata', metadata);
  21683. },
  21684. get toplevelPagesDict() {
  21685. var pagesObj = this.catDict.get('Pages');
  21686. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  21687. // shadow the prototype getter
  21688. return shadow(this, 'toplevelPagesDict', pagesObj);
  21689. },
  21690. get documentOutline() {
  21691. var obj = null;
  21692. try {
  21693. obj = this.readDocumentOutline();
  21694. } catch (ex) {
  21695. if (ex instanceof MissingDataException) {
  21696. throw ex;
  21697. }
  21698. warn('Unable to read document outline');
  21699. }
  21700. return shadow(this, 'documentOutline', obj);
  21701. },
  21702. readDocumentOutline: function Catalog_readDocumentOutline() {
  21703. var xref = this.xref;
  21704. var obj = this.catDict.get('Outlines');
  21705. var root = { items: [] };
  21706. if (isDict(obj)) {
  21707. obj = obj.getRaw('First');
  21708. var processed = new RefSet();
  21709. if (isRef(obj)) {
  21710. var queue = [{obj: obj, parent: root}];
  21711. // to avoid recursion keeping track of the items
  21712. // in the processed dictionary
  21713. processed.put(obj);
  21714. while (queue.length > 0) {
  21715. var i = queue.shift();
  21716. var outlineDict = xref.fetchIfRef(i.obj);
  21717. if (outlineDict === null) {
  21718. continue;
  21719. }
  21720. if (!outlineDict.has('Title')) {
  21721. error('Invalid outline item');
  21722. }
  21723. var dest = outlineDict.get('A');
  21724. if (dest) {
  21725. dest = dest.get('D');
  21726. } else if (outlineDict.has('Dest')) {
  21727. dest = outlineDict.getRaw('Dest');
  21728. if (isName(dest)) {
  21729. dest = dest.name;
  21730. }
  21731. }
  21732. var title = outlineDict.get('Title');
  21733. var outlineItem = {
  21734. dest: dest,
  21735. title: stringToPDFString(title),
  21736. color: outlineDict.get('C') || [0, 0, 0],
  21737. count: outlineDict.get('Count'),
  21738. bold: !!(outlineDict.get('F') & 2),
  21739. italic: !!(outlineDict.get('F') & 1),
  21740. items: []
  21741. };
  21742. i.parent.items.push(outlineItem);
  21743. obj = outlineDict.getRaw('First');
  21744. if (isRef(obj) && !processed.has(obj)) {
  21745. queue.push({obj: obj, parent: outlineItem});
  21746. processed.put(obj);
  21747. }
  21748. obj = outlineDict.getRaw('Next');
  21749. if (isRef(obj) && !processed.has(obj)) {
  21750. queue.push({obj: obj, parent: i.parent});
  21751. processed.put(obj);
  21752. }
  21753. }
  21754. }
  21755. }
  21756. return (root.items.length > 0 ? root.items : null);
  21757. },
  21758. get numPages() {
  21759. var obj = this.toplevelPagesDict.get('Count');
  21760. assert(
  21761. isInt(obj),
  21762. 'page count in top level pages object is not an integer'
  21763. );
  21764. // shadow the prototype getter
  21765. return shadow(this, 'num', obj);
  21766. },
  21767. get destinations() {
  21768. function fetchDestination(dest) {
  21769. return isDict(dest) ? dest.get('D') : dest;
  21770. }
  21771. var xref = this.xref;
  21772. var dests = {}, nameTreeRef, nameDictionaryRef;
  21773. var obj = this.catDict.get('Names');
  21774. if (obj && obj.has('Dests')) {
  21775. nameTreeRef = obj.getRaw('Dests');
  21776. } else if (this.catDict.has('Dests')) {
  21777. nameDictionaryRef = this.catDict.get('Dests');
  21778. }
  21779. if (nameDictionaryRef) {
  21780. // reading simple destination dictionary
  21781. obj = nameDictionaryRef;
  21782. obj.forEach(function catalogForEach(key, value) {
  21783. if (!value) {
  21784. return;
  21785. }
  21786. dests[key] = fetchDestination(value);
  21787. });
  21788. }
  21789. if (nameTreeRef) {
  21790. var nameTree = new NameTree(nameTreeRef, xref);
  21791. var names = nameTree.getAll();
  21792. for (var name in names) {
  21793. if (!names.hasOwnProperty(name)) {
  21794. continue;
  21795. }
  21796. dests[name] = fetchDestination(names[name]);
  21797. }
  21798. }
  21799. return shadow(this, 'destinations', dests);
  21800. },
  21801. getDestination: function Catalog_getDestination(destinationId) {
  21802. function fetchDestination(dest) {
  21803. return isDict(dest) ? dest.get('D') : dest;
  21804. }
  21805. var xref = this.xref;
  21806. var dest = null, nameTreeRef, nameDictionaryRef;
  21807. var obj = this.catDict.get('Names');
  21808. if (obj && obj.has('Dests')) {
  21809. nameTreeRef = obj.getRaw('Dests');
  21810. } else if (this.catDict.has('Dests')) {
  21811. nameDictionaryRef = this.catDict.get('Dests');
  21812. }
  21813. if (nameDictionaryRef) { // Simple destination dictionary.
  21814. var value = nameDictionaryRef.get(destinationId);
  21815. if (value) {
  21816. dest = fetchDestination(value);
  21817. }
  21818. }
  21819. if (nameTreeRef) {
  21820. var nameTree = new NameTree(nameTreeRef, xref);
  21821. dest = fetchDestination(nameTree.get(destinationId));
  21822. }
  21823. return dest;
  21824. },
  21825. get attachments() {
  21826. var xref = this.xref;
  21827. var attachments = null, nameTreeRef;
  21828. var obj = this.catDict.get('Names');
  21829. if (obj) {
  21830. nameTreeRef = obj.getRaw('EmbeddedFiles');
  21831. }
  21832. if (nameTreeRef) {
  21833. var nameTree = new NameTree(nameTreeRef, xref);
  21834. var names = nameTree.getAll();
  21835. for (var name in names) {
  21836. if (!names.hasOwnProperty(name)) {
  21837. continue;
  21838. }
  21839. var fs = new FileSpec(names[name], xref);
  21840. if (!attachments) {
  21841. attachments = {};
  21842. }
  21843. attachments[stringToPDFString(name)] = fs.serializable;
  21844. }
  21845. }
  21846. return shadow(this, 'attachments', attachments);
  21847. },
  21848. get javaScript() {
  21849. var xref = this.xref;
  21850. var obj = this.catDict.get('Names');
  21851. var javaScript = [];
  21852. function appendIfJavaScriptDict(jsDict) {
  21853. var type = jsDict.get('S');
  21854. if (!isName(type) || type.name !== 'JavaScript') {
  21855. return;
  21856. }
  21857. var js = jsDict.get('JS');
  21858. if (isStream(js)) {
  21859. js = bytesToString(js.getBytes());
  21860. } else if (!isString(js)) {
  21861. return;
  21862. }
  21863. javaScript.push(stringToPDFString(js));
  21864. }
  21865. if (obj && obj.has('JavaScript')) {
  21866. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  21867. var names = nameTree.getAll();
  21868. for (var name in names) {
  21869. if (!names.hasOwnProperty(name)) {
  21870. continue;
  21871. }
  21872. // We don't really use the JavaScript right now. This code is
  21873. // defensive so we don't cause errors on document load.
  21874. var jsDict = names[name];
  21875. if (isDict(jsDict)) {
  21876. appendIfJavaScriptDict(jsDict);
  21877. }
  21878. }
  21879. }
  21880. // Append OpenAction actions to javaScript array
  21881. var openactionDict = this.catDict.get('OpenAction');
  21882. if (isDict(openactionDict, 'Action')) {
  21883. var actionType = openactionDict.get('S');
  21884. if (isName(actionType) && actionType.name === 'Named') {
  21885. // The named Print action is not a part of the PDF 1.7 specification,
  21886. // but is supported by many PDF readers/writers (including Adobe's).
  21887. var action = openactionDict.get('N');
  21888. if (isName(action) && action.name === 'Print') {
  21889. javaScript.push('print({});');
  21890. }
  21891. } else {
  21892. appendIfJavaScriptDict(openactionDict);
  21893. }
  21894. }
  21895. return shadow(this, 'javaScript', javaScript);
  21896. },
  21897. cleanup: function Catalog_cleanup() {
  21898. var promises = [];
  21899. this.fontCache.forEach(function (promise) {
  21900. promises.push(promise);
  21901. });
  21902. return Promise.all(promises).then(function (translatedFonts) {
  21903. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  21904. var font = translatedFonts[i].dict;
  21905. delete font.translated;
  21906. }
  21907. this.fontCache.clear();
  21908. }.bind(this));
  21909. },
  21910. getPage: function Catalog_getPage(pageIndex) {
  21911. if (!(pageIndex in this.pagePromises)) {
  21912. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  21913. function (a) {
  21914. var dict = a[0];
  21915. var ref = a[1];
  21916. return this.pageFactory.createPage(pageIndex, dict, ref,
  21917. this.fontCache);
  21918. }.bind(this)
  21919. );
  21920. }
  21921. return this.pagePromises[pageIndex];
  21922. },
  21923. getPageDict: function Catalog_getPageDict(pageIndex) {
  21924. var capability = createPromiseCapability();
  21925. var nodesToVisit = [this.catDict.getRaw('Pages')];
  21926. var currentPageIndex = 0;
  21927. var xref = this.xref;
  21928. var checkAllKids = false;
  21929. function next() {
  21930. while (nodesToVisit.length) {
  21931. var currentNode = nodesToVisit.pop();
  21932. if (isRef(currentNode)) {
  21933. xref.fetchAsync(currentNode).then(function (obj) {
  21934. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  21935. if (pageIndex === currentPageIndex) {
  21936. capability.resolve([obj, currentNode]);
  21937. } else {
  21938. currentPageIndex++;
  21939. next();
  21940. }
  21941. return;
  21942. }
  21943. nodesToVisit.push(obj);
  21944. next();
  21945. }, capability.reject);
  21946. return;
  21947. }
  21948. // Must be a child page dictionary.
  21949. assert(
  21950. isDict(currentNode),
  21951. 'page dictionary kid reference points to wrong type of object'
  21952. );
  21953. var count = currentNode.get('Count');
  21954. // If the current node doesn't have any children, avoid getting stuck
  21955. // in an empty node further down in the tree (see issue5644.pdf).
  21956. if (count === 0) {
  21957. checkAllKids = true;
  21958. }
  21959. // Skip nodes where the page can't be.
  21960. if (currentPageIndex + count <= pageIndex) {
  21961. currentPageIndex += count;
  21962. continue;
  21963. }
  21964. var kids = currentNode.get('Kids');
  21965. assert(isArray(kids), 'page dictionary kids object is not an array');
  21966. if (!checkAllKids && count === kids.length) {
  21967. // Nodes that don't have the page have been skipped and this is the
  21968. // bottom of the tree which means the page requested must be a
  21969. // descendant of this pages node. Ideally we would just resolve the
  21970. // promise with the page ref here, but there is the case where more
  21971. // pages nodes could link to single a page (see issue 3666 pdf). To
  21972. // handle this push it back on the queue so if it is a pages node it
  21973. // will be descended into.
  21974. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  21975. currentPageIndex = pageIndex;
  21976. continue;
  21977. } else {
  21978. for (var last = kids.length - 1; last >= 0; last--) {
  21979. nodesToVisit.push(kids[last]);
  21980. }
  21981. }
  21982. }
  21983. capability.reject('Page index ' + pageIndex + ' not found.');
  21984. }
  21985. next();
  21986. return capability.promise;
  21987. },
  21988. getPageIndex: function Catalog_getPageIndex(ref) {
  21989. // The page tree nodes have the count of all the leaves below them. To get
  21990. // how many pages are before we just have to walk up the tree and keep
  21991. // adding the count of siblings to the left of the node.
  21992. var xref = this.xref;
  21993. function pagesBeforeRef(kidRef) {
  21994. var total = 0;
  21995. var parentRef;
  21996. return xref.fetchAsync(kidRef).then(function (node) {
  21997. if (!node) {
  21998. return null;
  21999. }
  22000. parentRef = node.getRaw('Parent');
  22001. return node.getAsync('Parent');
  22002. }).then(function (parent) {
  22003. if (!parent) {
  22004. return null;
  22005. }
  22006. return parent.getAsync('Kids');
  22007. }).then(function (kids) {
  22008. if (!kids) {
  22009. return null;
  22010. }
  22011. var kidPromises = [];
  22012. var found = false;
  22013. for (var i = 0; i < kids.length; i++) {
  22014. var kid = kids[i];
  22015. assert(isRef(kid), 'kids must be a ref');
  22016. if (kid.num === kidRef.num) {
  22017. found = true;
  22018. break;
  22019. }
  22020. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  22021. if (kid.has('Count')) {
  22022. var count = kid.get('Count');
  22023. total += count;
  22024. } else { // page leaf node
  22025. total++;
  22026. }
  22027. }));
  22028. }
  22029. if (!found) {
  22030. error('kid ref not found in parents kids');
  22031. }
  22032. return Promise.all(kidPromises).then(function () {
  22033. return [total, parentRef];
  22034. });
  22035. });
  22036. }
  22037. var total = 0;
  22038. function next(ref) {
  22039. return pagesBeforeRef(ref).then(function (args) {
  22040. if (!args) {
  22041. return total;
  22042. }
  22043. var count = args[0];
  22044. var parentRef = args[1];
  22045. total += count;
  22046. return next(parentRef);
  22047. });
  22048. }
  22049. return next(ref);
  22050. }
  22051. };
  22052. return Catalog;
  22053. })();
  22054. var XRef = (function XRefClosure() {
  22055. function XRef(stream, password) {
  22056. this.stream = stream;
  22057. this.entries = [];
  22058. this.xrefstms = {};
  22059. // prepare the XRef cache
  22060. this.cache = [];
  22061. this.password = password;
  22062. this.stats = {
  22063. streamTypes: [],
  22064. fontTypes: []
  22065. };
  22066. }
  22067. XRef.prototype = {
  22068. setStartXRef: function XRef_setStartXRef(startXRef) {
  22069. // Store the starting positions of xref tables as we process them
  22070. // so we can recover from missing data errors
  22071. this.startXRefQueue = [startXRef];
  22072. },
  22073. parse: function XRef_parse(recoveryMode) {
  22074. var trailerDict;
  22075. if (!recoveryMode) {
  22076. trailerDict = this.readXRef();
  22077. } else {
  22078. warn('Indexing all PDF objects');
  22079. trailerDict = this.indexObjects();
  22080. }
  22081. trailerDict.assignXref(this);
  22082. this.trailer = trailerDict;
  22083. var encrypt = trailerDict.get('Encrypt');
  22084. if (encrypt) {
  22085. var ids = trailerDict.get('ID');
  22086. var fileId = (ids && ids.length) ? ids[0] : '';
  22087. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  22088. this.password);
  22089. }
  22090. // get the root dictionary (catalog) object
  22091. if (!(this.root = trailerDict.get('Root'))) {
  22092. error('Invalid root reference');
  22093. }
  22094. },
  22095. processXRefTable: function XRef_processXRefTable(parser) {
  22096. if (!('tableState' in this)) {
  22097. // Stores state of the table as we process it so we can resume
  22098. // from middle of table in case of missing data error
  22099. this.tableState = {
  22100. entryNum: 0,
  22101. streamPos: parser.lexer.stream.pos,
  22102. parserBuf1: parser.buf1,
  22103. parserBuf2: parser.buf2
  22104. };
  22105. }
  22106. var obj = this.readXRefTable(parser);
  22107. // Sanity check
  22108. if (!isCmd(obj, 'trailer')) {
  22109. error('Invalid XRef table: could not find trailer dictionary');
  22110. }
  22111. // Read trailer dictionary, e.g.
  22112. // trailer
  22113. // << /Size 22
  22114. // /Root 20R
  22115. // /Info 10R
  22116. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  22117. // >>
  22118. // The parser goes through the entire stream << ... >> and provides
  22119. // a getter interface for the key-value table
  22120. var dict = parser.getObj();
  22121. // The pdflib PDF generator can generate a nested trailer dictionary
  22122. if (!isDict(dict) && dict.dict) {
  22123. dict = dict.dict;
  22124. }
  22125. if (!isDict(dict)) {
  22126. error('Invalid XRef table: could not parse trailer dictionary');
  22127. }
  22128. delete this.tableState;
  22129. return dict;
  22130. },
  22131. readXRefTable: function XRef_readXRefTable(parser) {
  22132. // Example of cross-reference table:
  22133. // xref
  22134. // 0 1 <-- subsection header (first obj #, obj count)
  22135. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  22136. // 23 2 <-- subsection header ... and so on ...
  22137. // 0000025518 00002 n
  22138. // 0000025635 00000 n
  22139. // trailer
  22140. // ...
  22141. var stream = parser.lexer.stream;
  22142. var tableState = this.tableState;
  22143. stream.pos = tableState.streamPos;
  22144. parser.buf1 = tableState.parserBuf1;
  22145. parser.buf2 = tableState.parserBuf2;
  22146. // Outer loop is over subsection headers
  22147. var obj;
  22148. while (true) {
  22149. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  22150. if (isCmd(obj = parser.getObj(), 'trailer')) {
  22151. break;
  22152. }
  22153. tableState.firstEntryNum = obj;
  22154. tableState.entryCount = parser.getObj();
  22155. }
  22156. var first = tableState.firstEntryNum;
  22157. var count = tableState.entryCount;
  22158. if (!isInt(first) || !isInt(count)) {
  22159. error('Invalid XRef table: wrong types in subsection header');
  22160. }
  22161. // Inner loop is over objects themselves
  22162. for (var i = tableState.entryNum; i < count; i++) {
  22163. tableState.streamPos = stream.pos;
  22164. tableState.entryNum = i;
  22165. tableState.parserBuf1 = parser.buf1;
  22166. tableState.parserBuf2 = parser.buf2;
  22167. var entry = {};
  22168. entry.offset = parser.getObj();
  22169. entry.gen = parser.getObj();
  22170. var type = parser.getObj();
  22171. if (isCmd(type, 'f')) {
  22172. entry.free = true;
  22173. } else if (isCmd(type, 'n')) {
  22174. entry.uncompressed = true;
  22175. }
  22176. // Validate entry obj
  22177. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  22178. !(entry.free || entry.uncompressed)) {
  22179. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  22180. }
  22181. if (!this.entries[i + first]) {
  22182. this.entries[i + first] = entry;
  22183. }
  22184. }
  22185. tableState.entryNum = 0;
  22186. tableState.streamPos = stream.pos;
  22187. tableState.parserBuf1 = parser.buf1;
  22188. tableState.parserBuf2 = parser.buf2;
  22189. delete tableState.firstEntryNum;
  22190. delete tableState.entryCount;
  22191. }
  22192. // Per issue 3248: hp scanners generate bad XRef
  22193. if (first === 1 && this.entries[1] && this.entries[1].free) {
  22194. // shifting the entries
  22195. this.entries.shift();
  22196. }
  22197. // Sanity check: as per spec, first object must be free
  22198. if (this.entries[0] && !this.entries[0].free) {
  22199. error('Invalid XRef table: unexpected first object');
  22200. }
  22201. return obj;
  22202. },
  22203. processXRefStream: function XRef_processXRefStream(stream) {
  22204. if (!('streamState' in this)) {
  22205. // Stores state of the stream as we process it so we can resume
  22206. // from middle of stream in case of missing data error
  22207. var streamParameters = stream.dict;
  22208. var byteWidths = streamParameters.get('W');
  22209. var range = streamParameters.get('Index');
  22210. if (!range) {
  22211. range = [0, streamParameters.get('Size')];
  22212. }
  22213. this.streamState = {
  22214. entryRanges: range,
  22215. byteWidths: byteWidths,
  22216. entryNum: 0,
  22217. streamPos: stream.pos
  22218. };
  22219. }
  22220. this.readXRefStream(stream);
  22221. delete this.streamState;
  22222. return stream.dict;
  22223. },
  22224. readXRefStream: function XRef_readXRefStream(stream) {
  22225. var i, j;
  22226. var streamState = this.streamState;
  22227. stream.pos = streamState.streamPos;
  22228. var byteWidths = streamState.byteWidths;
  22229. var typeFieldWidth = byteWidths[0];
  22230. var offsetFieldWidth = byteWidths[1];
  22231. var generationFieldWidth = byteWidths[2];
  22232. var entryRanges = streamState.entryRanges;
  22233. while (entryRanges.length > 0) {
  22234. var first = entryRanges[0];
  22235. var n = entryRanges[1];
  22236. if (!isInt(first) || !isInt(n)) {
  22237. error('Invalid XRef range fields: ' + first + ', ' + n);
  22238. }
  22239. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  22240. !isInt(generationFieldWidth)) {
  22241. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  22242. }
  22243. for (i = streamState.entryNum; i < n; ++i) {
  22244. streamState.entryNum = i;
  22245. streamState.streamPos = stream.pos;
  22246. var type = 0, offset = 0, generation = 0;
  22247. for (j = 0; j < typeFieldWidth; ++j) {
  22248. type = (type << 8) | stream.getByte();
  22249. }
  22250. // if type field is absent, its default value is 1
  22251. if (typeFieldWidth === 0) {
  22252. type = 1;
  22253. }
  22254. for (j = 0; j < offsetFieldWidth; ++j) {
  22255. offset = (offset << 8) | stream.getByte();
  22256. }
  22257. for (j = 0; j < generationFieldWidth; ++j) {
  22258. generation = (generation << 8) | stream.getByte();
  22259. }
  22260. var entry = {};
  22261. entry.offset = offset;
  22262. entry.gen = generation;
  22263. switch (type) {
  22264. case 0:
  22265. entry.free = true;
  22266. break;
  22267. case 1:
  22268. entry.uncompressed = true;
  22269. break;
  22270. case 2:
  22271. break;
  22272. default:
  22273. error('Invalid XRef entry type: ' + type);
  22274. }
  22275. if (!this.entries[first + i]) {
  22276. this.entries[first + i] = entry;
  22277. }
  22278. }
  22279. streamState.entryNum = 0;
  22280. streamState.streamPos = stream.pos;
  22281. entryRanges.splice(0, 2);
  22282. }
  22283. },
  22284. indexObjects: function XRef_indexObjects() {
  22285. // Simple scan through the PDF content to find objects,
  22286. // trailers and XRef streams.
  22287. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  22288. var PERCENT = 0x25, LT = 0x3C;
  22289. function readToken(data, offset) {
  22290. var token = '', ch = data[offset];
  22291. while (ch !== LF && ch !== CR && ch !== LT) {
  22292. if (++offset >= data.length) {
  22293. break;
  22294. }
  22295. token += String.fromCharCode(ch);
  22296. ch = data[offset];
  22297. }
  22298. return token;
  22299. }
  22300. function skipUntil(data, offset, what) {
  22301. var length = what.length, dataLength = data.length;
  22302. var skipped = 0;
  22303. // finding byte sequence
  22304. while (offset < dataLength) {
  22305. var i = 0;
  22306. while (i < length && data[offset + i] === what[i]) {
  22307. ++i;
  22308. }
  22309. if (i >= length) {
  22310. break; // sequence found
  22311. }
  22312. offset++;
  22313. skipped++;
  22314. }
  22315. return skipped;
  22316. }
  22317. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  22318. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  22319. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  22320. 101, 102]);
  22321. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  22322. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  22323. // Clear out any existing entries, since they may be bogus.
  22324. this.entries.length = 0;
  22325. var stream = this.stream;
  22326. stream.pos = 0;
  22327. var buffer = stream.getBytes();
  22328. var position = stream.start, length = buffer.length;
  22329. var trailers = [], xrefStms = [];
  22330. while (position < length) {
  22331. var ch = buffer[position];
  22332. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  22333. ++position;
  22334. continue;
  22335. }
  22336. if (ch === PERCENT) { // %-comment
  22337. do {
  22338. ++position;
  22339. if (position >= length) {
  22340. break;
  22341. }
  22342. ch = buffer[position];
  22343. } while (ch !== LF && ch !== CR);
  22344. continue;
  22345. }
  22346. var token = readToken(buffer, position);
  22347. var m;
  22348. if (token.indexOf('xref') === 0 &&
  22349. (token.length === 4 || /\s/.test(token[4]))) {
  22350. position += skipUntil(buffer, position, trailerBytes);
  22351. trailers.push(position);
  22352. position += skipUntil(buffer, position, startxrefBytes);
  22353. } else if ((m = objRegExp.exec(token))) {
  22354. if (typeof this.entries[m[1]] === 'undefined') {
  22355. this.entries[m[1]] = {
  22356. offset: position - stream.start,
  22357. gen: m[2] | 0,
  22358. uncompressed: true
  22359. };
  22360. }
  22361. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  22362. var content = buffer.subarray(position, position + contentLength);
  22363. // checking XRef stream suspect
  22364. // (it shall have '/XRef' and next char is not a letter)
  22365. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  22366. if (xrefTagOffset < contentLength &&
  22367. content[xrefTagOffset + 5] < 64) {
  22368. xrefStms.push(position - stream.start);
  22369. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  22370. }
  22371. position += contentLength;
  22372. } else if (token.indexOf('trailer') === 0 &&
  22373. (token.length === 7 || /\s/.test(token[7]))) {
  22374. trailers.push(position);
  22375. position += skipUntil(buffer, position, startxrefBytes);
  22376. } else {
  22377. position += token.length + 1;
  22378. }
  22379. }
  22380. // reading XRef streams
  22381. var i, ii;
  22382. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  22383. this.startXRefQueue.push(xrefStms[i]);
  22384. this.readXRef(/* recoveryMode */ true);
  22385. }
  22386. // finding main trailer
  22387. var dict;
  22388. for (i = 0, ii = trailers.length; i < ii; ++i) {
  22389. stream.pos = trailers[i];
  22390. var parser = new Parser(new Lexer(stream), true, this);
  22391. var obj = parser.getObj();
  22392. if (!isCmd(obj, 'trailer')) {
  22393. continue;
  22394. }
  22395. // read the trailer dictionary
  22396. if (!isDict(dict = parser.getObj())) {
  22397. continue;
  22398. }
  22399. // taking the first one with 'ID'
  22400. if (dict.has('ID')) {
  22401. return dict;
  22402. }
  22403. }
  22404. // no tailer with 'ID', taking last one (if exists)
  22405. if (dict) {
  22406. return dict;
  22407. }
  22408. // nothing helps
  22409. // calling error() would reject worker with an UnknownErrorException.
  22410. throw new InvalidPDFException('Invalid PDF structure');
  22411. },
  22412. readXRef: function XRef_readXRef(recoveryMode) {
  22413. var stream = this.stream;
  22414. try {
  22415. while (this.startXRefQueue.length) {
  22416. var startXRef = this.startXRefQueue[0];
  22417. stream.pos = startXRef + stream.start;
  22418. var parser = new Parser(new Lexer(stream), true, this);
  22419. var obj = parser.getObj();
  22420. var dict;
  22421. // Get dictionary
  22422. if (isCmd(obj, 'xref')) {
  22423. // Parse end-of-file XRef
  22424. dict = this.processXRefTable(parser);
  22425. if (!this.topDict) {
  22426. this.topDict = dict;
  22427. }
  22428. // Recursively get other XRefs 'XRefStm', if any
  22429. obj = dict.get('XRefStm');
  22430. if (isInt(obj)) {
  22431. var pos = obj;
  22432. // ignore previously loaded xref streams
  22433. // (possible infinite recursion)
  22434. if (!(pos in this.xrefstms)) {
  22435. this.xrefstms[pos] = 1;
  22436. this.startXRefQueue.push(pos);
  22437. }
  22438. }
  22439. } else if (isInt(obj)) {
  22440. // Parse in-stream XRef
  22441. if (!isInt(parser.getObj()) ||
  22442. !isCmd(parser.getObj(), 'obj') ||
  22443. !isStream(obj = parser.getObj())) {
  22444. error('Invalid XRef stream');
  22445. }
  22446. dict = this.processXRefStream(obj);
  22447. if (!this.topDict) {
  22448. this.topDict = dict;
  22449. }
  22450. if (!dict) {
  22451. error('Failed to read XRef stream');
  22452. }
  22453. } else {
  22454. error('Invalid XRef stream header');
  22455. }
  22456. // Recursively get previous dictionary, if any
  22457. obj = dict.get('Prev');
  22458. if (isInt(obj)) {
  22459. this.startXRefQueue.push(obj);
  22460. } else if (isRef(obj)) {
  22461. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  22462. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  22463. this.startXRefQueue.push(obj.num);
  22464. }
  22465. this.startXRefQueue.shift();
  22466. }
  22467. return this.topDict;
  22468. } catch (e) {
  22469. if (e instanceof MissingDataException) {
  22470. throw e;
  22471. }
  22472. info('(while reading XRef): ' + e);
  22473. }
  22474. if (recoveryMode) {
  22475. return;
  22476. }
  22477. throw new XRefParseException();
  22478. },
  22479. getEntry: function XRef_getEntry(i) {
  22480. var xrefEntry = this.entries[i];
  22481. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  22482. return xrefEntry;
  22483. }
  22484. return null;
  22485. },
  22486. fetchIfRef: function XRef_fetchIfRef(obj) {
  22487. if (!isRef(obj)) {
  22488. return obj;
  22489. }
  22490. return this.fetch(obj);
  22491. },
  22492. fetch: function XRef_fetch(ref, suppressEncryption) {
  22493. assert(isRef(ref), 'ref object is not a reference');
  22494. var num = ref.num;
  22495. if (num in this.cache) {
  22496. var cacheEntry = this.cache[num];
  22497. return cacheEntry;
  22498. }
  22499. var xrefEntry = this.getEntry(num);
  22500. // the referenced entry can be free
  22501. if (xrefEntry === null) {
  22502. return (this.cache[num] = null);
  22503. }
  22504. if (xrefEntry.uncompressed) {
  22505. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  22506. } else {
  22507. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  22508. }
  22509. if (isDict(xrefEntry)){
  22510. xrefEntry.objId = ref.toString();
  22511. } else if (isStream(xrefEntry)) {
  22512. xrefEntry.dict.objId = ref.toString();
  22513. }
  22514. return xrefEntry;
  22515. },
  22516. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  22517. suppressEncryption) {
  22518. var gen = ref.gen;
  22519. var num = ref.num;
  22520. if (xrefEntry.gen !== gen) {
  22521. error('inconsistent generation in XRef');
  22522. }
  22523. var stream = this.stream.makeSubStream(xrefEntry.offset +
  22524. this.stream.start);
  22525. var parser = new Parser(new Lexer(stream), true, this);
  22526. var obj1 = parser.getObj();
  22527. var obj2 = parser.getObj();
  22528. var obj3 = parser.getObj();
  22529. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  22530. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  22531. !isCmd(obj3)) {
  22532. error('bad XRef entry');
  22533. }
  22534. if (!isCmd(obj3, 'obj')) {
  22535. // some bad PDFs use "obj1234" and really mean 1234
  22536. if (obj3.cmd.indexOf('obj') === 0) {
  22537. num = parseInt(obj3.cmd.substring(3), 10);
  22538. if (!isNaN(num)) {
  22539. return num;
  22540. }
  22541. }
  22542. error('bad XRef entry');
  22543. }
  22544. if (this.encrypt && !suppressEncryption) {
  22545. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  22546. } else {
  22547. xrefEntry = parser.getObj();
  22548. }
  22549. if (!isStream(xrefEntry)) {
  22550. this.cache[num] = xrefEntry;
  22551. }
  22552. return xrefEntry;
  22553. },
  22554. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  22555. suppressEncryption) {
  22556. var tableOffset = xrefEntry.offset;
  22557. var stream = this.fetch(new Ref(tableOffset, 0));
  22558. if (!isStream(stream)) {
  22559. error('bad ObjStm stream');
  22560. }
  22561. var first = stream.dict.get('First');
  22562. var n = stream.dict.get('N');
  22563. if (!isInt(first) || !isInt(n)) {
  22564. error('invalid first and n parameters for ObjStm stream');
  22565. }
  22566. var parser = new Parser(new Lexer(stream), false, this);
  22567. parser.allowStreams = true;
  22568. var i, entries = [], num, nums = [];
  22569. // read the object numbers to populate cache
  22570. for (i = 0; i < n; ++i) {
  22571. num = parser.getObj();
  22572. if (!isInt(num)) {
  22573. error('invalid object number in the ObjStm stream: ' + num);
  22574. }
  22575. nums.push(num);
  22576. var offset = parser.getObj();
  22577. if (!isInt(offset)) {
  22578. error('invalid object offset in the ObjStm stream: ' + offset);
  22579. }
  22580. }
  22581. // read stream objects for cache
  22582. for (i = 0; i < n; ++i) {
  22583. entries.push(parser.getObj());
  22584. num = nums[i];
  22585. var entry = this.entries[num];
  22586. if (entry && entry.offset === tableOffset && entry.gen === i) {
  22587. this.cache[num] = entries[i];
  22588. }
  22589. }
  22590. xrefEntry = entries[xrefEntry.gen];
  22591. if (xrefEntry === undefined) {
  22592. error('bad XRef entry for compressed object');
  22593. }
  22594. return xrefEntry;
  22595. },
  22596. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  22597. if (!isRef(obj)) {
  22598. return Promise.resolve(obj);
  22599. }
  22600. return this.fetchAsync(obj);
  22601. },
  22602. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  22603. var streamManager = this.stream.manager;
  22604. var xref = this;
  22605. return new Promise(function tryFetch(resolve, reject) {
  22606. try {
  22607. resolve(xref.fetch(ref, suppressEncryption));
  22608. } catch (e) {
  22609. if (e instanceof MissingDataException) {
  22610. streamManager.requestRange(e.begin, e.end).then(function () {
  22611. tryFetch(resolve, reject);
  22612. }, reject);
  22613. return;
  22614. }
  22615. reject(e);
  22616. }
  22617. });
  22618. },
  22619. getCatalogObj: function XRef_getCatalogObj() {
  22620. return this.root;
  22621. }
  22622. };
  22623. return XRef;
  22624. })();
  22625. /**
  22626. * A NameTree is like a Dict but has some advantageous properties, see the
  22627. * spec (7.9.6) for more details.
  22628. * TODO: implement all the Dict functions and make this more efficent.
  22629. */
  22630. var NameTree = (function NameTreeClosure() {
  22631. function NameTree(root, xref) {
  22632. this.root = root;
  22633. this.xref = xref;
  22634. }
  22635. NameTree.prototype = {
  22636. getAll: function NameTree_getAll() {
  22637. var dict = {};
  22638. if (!this.root) {
  22639. return dict;
  22640. }
  22641. var xref = this.xref;
  22642. // reading name tree
  22643. var processed = new RefSet();
  22644. processed.put(this.root);
  22645. var queue = [this.root];
  22646. while (queue.length > 0) {
  22647. var i, n;
  22648. var obj = xref.fetchIfRef(queue.shift());
  22649. if (!isDict(obj)) {
  22650. continue;
  22651. }
  22652. if (obj.has('Kids')) {
  22653. var kids = obj.get('Kids');
  22654. for (i = 0, n = kids.length; i < n; i++) {
  22655. var kid = kids[i];
  22656. if (processed.has(kid)) {
  22657. error('invalid destinations');
  22658. }
  22659. queue.push(kid);
  22660. processed.put(kid);
  22661. }
  22662. continue;
  22663. }
  22664. var names = obj.get('Names');
  22665. if (names) {
  22666. for (i = 0, n = names.length; i < n; i += 2) {
  22667. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  22668. }
  22669. }
  22670. }
  22671. return dict;
  22672. },
  22673. get: function NameTree_get(destinationId) {
  22674. if (!this.root) {
  22675. return null;
  22676. }
  22677. var xref = this.xref;
  22678. var kidsOrNames = xref.fetchIfRef(this.root);
  22679. var loopCount = 0;
  22680. var MAX_NAMES_LEVELS = 10;
  22681. var l, r, m;
  22682. // Perform a binary search to quickly find the entry that
  22683. // contains the named destination we are looking for.
  22684. while (kidsOrNames.has('Kids')) {
  22685. loopCount++;
  22686. if (loopCount > MAX_NAMES_LEVELS) {
  22687. warn('Search depth limit for named destionations has been reached.');
  22688. return null;
  22689. }
  22690. var kids = kidsOrNames.get('Kids');
  22691. if (!isArray(kids)) {
  22692. return null;
  22693. }
  22694. l = 0;
  22695. r = kids.length - 1;
  22696. while (l <= r) {
  22697. m = (l + r) >> 1;
  22698. var kid = xref.fetchIfRef(kids[m]);
  22699. var limits = kid.get('Limits');
  22700. if (destinationId < xref.fetchIfRef(limits[0])) {
  22701. r = m - 1;
  22702. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  22703. l = m + 1;
  22704. } else {
  22705. kidsOrNames = xref.fetchIfRef(kids[m]);
  22706. break;
  22707. }
  22708. }
  22709. if (l > r) {
  22710. return null;
  22711. }
  22712. }
  22713. // If we get here, then we have found the right entry. Now
  22714. // go through the named destinations in the Named dictionary
  22715. // until we find the exact destination we're looking for.
  22716. var names = kidsOrNames.get('Names');
  22717. if (isArray(names)) {
  22718. // Perform a binary search to reduce the lookup time.
  22719. l = 0;
  22720. r = names.length - 2;
  22721. while (l <= r) {
  22722. // Check only even indices (0, 2, 4, ...) because the
  22723. // odd indices contain the actual D array.
  22724. m = (l + r) & ~1;
  22725. if (destinationId < xref.fetchIfRef(names[m])) {
  22726. r = m - 2;
  22727. } else if (destinationId > xref.fetchIfRef(names[m])) {
  22728. l = m + 2;
  22729. } else {
  22730. return xref.fetchIfRef(names[m + 1]);
  22731. }
  22732. }
  22733. }
  22734. return null;
  22735. }
  22736. };
  22737. return NameTree;
  22738. })();
  22739. /**
  22740. * "A PDF file can refer to the contents of another file by using a File
  22741. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  22742. * NOTE: Only embedded files are supported (as part of the attachments support)
  22743. * TODO: support the 'URL' file system (with caching if !/V), portable
  22744. * collections attributes and related files (/RF)
  22745. */
  22746. var FileSpec = (function FileSpecClosure() {
  22747. function FileSpec(root, xref) {
  22748. if (!root || !isDict(root)) {
  22749. return;
  22750. }
  22751. this.xref = xref;
  22752. this.root = root;
  22753. if (root.has('FS')) {
  22754. this.fs = root.get('FS');
  22755. }
  22756. this.description = root.has('Desc') ?
  22757. stringToPDFString(root.get('Desc')) :
  22758. '';
  22759. if (root.has('RF')) {
  22760. warn('Related file specifications are not supported');
  22761. }
  22762. this.contentAvailable = true;
  22763. if (!root.has('EF')) {
  22764. this.contentAvailable = false;
  22765. warn('Non-embedded file specifications are not supported');
  22766. }
  22767. }
  22768. function pickPlatformItem(dict) {
  22769. // Look for the filename in this order:
  22770. // UF, F, Unix, Mac, DOS
  22771. if (dict.has('UF')) {
  22772. return dict.get('UF');
  22773. } else if (dict.has('F')) {
  22774. return dict.get('F');
  22775. } else if (dict.has('Unix')) {
  22776. return dict.get('Unix');
  22777. } else if (dict.has('Mac')) {
  22778. return dict.get('Mac');
  22779. } else if (dict.has('DOS')) {
  22780. return dict.get('DOS');
  22781. } else {
  22782. return null;
  22783. }
  22784. }
  22785. FileSpec.prototype = {
  22786. get filename() {
  22787. if (!this._filename && this.root) {
  22788. var filename = pickPlatformItem(this.root) || 'unnamed';
  22789. this._filename = stringToPDFString(filename).
  22790. replace(/\\\\/g, '\\').
  22791. replace(/\\\//g, '/').
  22792. replace(/\\/g, '/');
  22793. }
  22794. return this._filename;
  22795. },
  22796. get content() {
  22797. if (!this.contentAvailable) {
  22798. return null;
  22799. }
  22800. if (!this.contentRef && this.root) {
  22801. this.contentRef = pickPlatformItem(this.root.get('EF'));
  22802. }
  22803. var content = null;
  22804. if (this.contentRef) {
  22805. var xref = this.xref;
  22806. var fileObj = xref.fetchIfRef(this.contentRef);
  22807. if (fileObj && isStream(fileObj)) {
  22808. content = fileObj.getBytes();
  22809. } else {
  22810. warn('Embedded file specification points to non-existing/invalid ' +
  22811. 'content');
  22812. }
  22813. } else {
  22814. warn('Embedded file specification does not have a content');
  22815. }
  22816. return content;
  22817. },
  22818. get serializable() {
  22819. return {
  22820. filename: this.filename,
  22821. content: this.content
  22822. };
  22823. }
  22824. };
  22825. return FileSpec;
  22826. })();
  22827. /**
  22828. * A helper for loading missing data in object graphs. It traverses the graph
  22829. * depth first and queues up any objects that have missing data. Once it has
  22830. * has traversed as many objects that are available it attempts to bundle the
  22831. * missing data requests and then resume from the nodes that weren't ready.
  22832. *
  22833. * NOTE: It provides protection from circular references by keeping track of
  22834. * of loaded references. However, you must be careful not to load any graphs
  22835. * that have references to the catalog or other pages since that will cause the
  22836. * entire PDF document object graph to be traversed.
  22837. */
  22838. var ObjectLoader = (function() {
  22839. function mayHaveChildren(value) {
  22840. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  22841. }
  22842. function addChildren(node, nodesToVisit) {
  22843. var value;
  22844. if (isDict(node) || isStream(node)) {
  22845. var map;
  22846. if (isDict(node)) {
  22847. map = node.map;
  22848. } else {
  22849. map = node.dict.map;
  22850. }
  22851. for (var key in map) {
  22852. value = map[key];
  22853. if (mayHaveChildren(value)) {
  22854. nodesToVisit.push(value);
  22855. }
  22856. }
  22857. } else if (isArray(node)) {
  22858. for (var i = 0, ii = node.length; i < ii; i++) {
  22859. value = node[i];
  22860. if (mayHaveChildren(value)) {
  22861. nodesToVisit.push(value);
  22862. }
  22863. }
  22864. }
  22865. }
  22866. function ObjectLoader(obj, keys, xref) {
  22867. this.obj = obj;
  22868. this.keys = keys;
  22869. this.xref = xref;
  22870. this.refSet = null;
  22871. this.capability = null;
  22872. }
  22873. ObjectLoader.prototype = {
  22874. load: function ObjectLoader_load() {
  22875. var keys = this.keys;
  22876. this.capability = createPromiseCapability();
  22877. // Don't walk the graph if all the data is already loaded.
  22878. if (!(this.xref.stream instanceof ChunkedStream) ||
  22879. this.xref.stream.getMissingChunks().length === 0) {
  22880. this.capability.resolve();
  22881. return this.capability.promise;
  22882. }
  22883. this.refSet = new RefSet();
  22884. // Setup the initial nodes to visit.
  22885. var nodesToVisit = [];
  22886. for (var i = 0; i < keys.length; i++) {
  22887. nodesToVisit.push(this.obj[keys[i]]);
  22888. }
  22889. this._walk(nodesToVisit);
  22890. return this.capability.promise;
  22891. },
  22892. _walk: function ObjectLoader_walk(nodesToVisit) {
  22893. var nodesToRevisit = [];
  22894. var pendingRequests = [];
  22895. // DFS walk of the object graph.
  22896. while (nodesToVisit.length) {
  22897. var currentNode = nodesToVisit.pop();
  22898. // Only references or chunked streams can cause missing data exceptions.
  22899. if (isRef(currentNode)) {
  22900. // Skip nodes that have already been visited.
  22901. if (this.refSet.has(currentNode)) {
  22902. continue;
  22903. }
  22904. try {
  22905. var ref = currentNode;
  22906. this.refSet.put(ref);
  22907. currentNode = this.xref.fetch(currentNode);
  22908. } catch (e) {
  22909. if (!(e instanceof MissingDataException)) {
  22910. throw e;
  22911. }
  22912. nodesToRevisit.push(currentNode);
  22913. pendingRequests.push({ begin: e.begin, end: e.end });
  22914. }
  22915. }
  22916. if (currentNode && currentNode.getBaseStreams) {
  22917. var baseStreams = currentNode.getBaseStreams();
  22918. var foundMissingData = false;
  22919. for (var i = 0; i < baseStreams.length; i++) {
  22920. var stream = baseStreams[i];
  22921. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  22922. foundMissingData = true;
  22923. pendingRequests.push({
  22924. begin: stream.start,
  22925. end: stream.end
  22926. });
  22927. }
  22928. }
  22929. if (foundMissingData) {
  22930. nodesToRevisit.push(currentNode);
  22931. }
  22932. }
  22933. addChildren(currentNode, nodesToVisit);
  22934. }
  22935. if (pendingRequests.length) {
  22936. this.xref.stream.manager.requestRanges(pendingRequests).then(
  22937. function pendingRequestCallback() {
  22938. nodesToVisit = nodesToRevisit;
  22939. for (var i = 0; i < nodesToRevisit.length; i++) {
  22940. var node = nodesToRevisit[i];
  22941. // Remove any reference nodes from the currrent refset so they
  22942. // aren't skipped when we revist them.
  22943. if (isRef(node)) {
  22944. this.refSet.remove(node);
  22945. }
  22946. }
  22947. this._walk(nodesToVisit);
  22948. }.bind(this), this.capability.reject);
  22949. return;
  22950. }
  22951. // Everything is loaded.
  22952. this.refSet = null;
  22953. this.capability.resolve();
  22954. }
  22955. };
  22956. return ObjectLoader;
  22957. })();
  22958. exports.Catalog = Catalog;
  22959. exports.ObjectLoader = ObjectLoader;
  22960. exports.XRef = XRef;
  22961. }));
  22962. (function (root, factory) {
  22963. {
  22964. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  22965. root.pdfjsCoreParser);
  22966. }
  22967. }(this, function (exports, sharedUtil, coreParser) {
  22968. var error = sharedUtil.error;
  22969. var EOF = coreParser.EOF;
  22970. var Lexer = coreParser.Lexer;
  22971. var PostScriptParser = (function PostScriptParserClosure() {
  22972. function PostScriptParser(lexer) {
  22973. this.lexer = lexer;
  22974. this.operators = [];
  22975. this.token = null;
  22976. this.prev = null;
  22977. }
  22978. PostScriptParser.prototype = {
  22979. nextToken: function PostScriptParser_nextToken() {
  22980. this.prev = this.token;
  22981. this.token = this.lexer.getToken();
  22982. },
  22983. accept: function PostScriptParser_accept(type) {
  22984. if (this.token.type === type) {
  22985. this.nextToken();
  22986. return true;
  22987. }
  22988. return false;
  22989. },
  22990. expect: function PostScriptParser_expect(type) {
  22991. if (this.accept(type)) {
  22992. return true;
  22993. }
  22994. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  22995. type + '.');
  22996. },
  22997. parse: function PostScriptParser_parse() {
  22998. this.nextToken();
  22999. this.expect(PostScriptTokenTypes.LBRACE);
  23000. this.parseBlock();
  23001. this.expect(PostScriptTokenTypes.RBRACE);
  23002. return this.operators;
  23003. },
  23004. parseBlock: function PostScriptParser_parseBlock() {
  23005. while (true) {
  23006. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  23007. this.operators.push(this.prev.value);
  23008. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  23009. this.operators.push(this.prev.value);
  23010. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23011. this.parseCondition();
  23012. } else {
  23013. return;
  23014. }
  23015. }
  23016. },
  23017. parseCondition: function PostScriptParser_parseCondition() {
  23018. // Add two place holders that will be updated later
  23019. var conditionLocation = this.operators.length;
  23020. this.operators.push(null, null);
  23021. this.parseBlock();
  23022. this.expect(PostScriptTokenTypes.RBRACE);
  23023. if (this.accept(PostScriptTokenTypes.IF)) {
  23024. // The true block is right after the 'if' so it just falls through on
  23025. // true else it jumps and skips the true block.
  23026. this.operators[conditionLocation] = this.operators.length;
  23027. this.operators[conditionLocation + 1] = 'jz';
  23028. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23029. var jumpLocation = this.operators.length;
  23030. this.operators.push(null, null);
  23031. var endOfTrue = this.operators.length;
  23032. this.parseBlock();
  23033. this.expect(PostScriptTokenTypes.RBRACE);
  23034. this.expect(PostScriptTokenTypes.IFELSE);
  23035. // The jump is added at the end of the true block to skip the false
  23036. // block.
  23037. this.operators[jumpLocation] = this.operators.length;
  23038. this.operators[jumpLocation + 1] = 'j';
  23039. this.operators[conditionLocation] = endOfTrue;
  23040. this.operators[conditionLocation + 1] = 'jz';
  23041. } else {
  23042. error('PS Function: error parsing conditional.');
  23043. }
  23044. }
  23045. };
  23046. return PostScriptParser;
  23047. })();
  23048. var PostScriptTokenTypes = {
  23049. LBRACE: 0,
  23050. RBRACE: 1,
  23051. NUMBER: 2,
  23052. OPERATOR: 3,
  23053. IF: 4,
  23054. IFELSE: 5
  23055. };
  23056. var PostScriptToken = (function PostScriptTokenClosure() {
  23057. function PostScriptToken(type, value) {
  23058. this.type = type;
  23059. this.value = value;
  23060. }
  23061. var opCache = {};
  23062. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  23063. var opValue = opCache[op];
  23064. if (opValue) {
  23065. return opValue;
  23066. }
  23067. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  23068. };
  23069. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  23070. '{');
  23071. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  23072. '}');
  23073. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  23074. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  23075. 'IFELSE');
  23076. return PostScriptToken;
  23077. })();
  23078. var PostScriptLexer = (function PostScriptLexerClosure() {
  23079. function PostScriptLexer(stream) {
  23080. this.stream = stream;
  23081. this.nextChar();
  23082. this.strBuf = [];
  23083. }
  23084. PostScriptLexer.prototype = {
  23085. nextChar: function PostScriptLexer_nextChar() {
  23086. return (this.currentChar = this.stream.getByte());
  23087. },
  23088. getToken: function PostScriptLexer_getToken() {
  23089. var comment = false;
  23090. var ch = this.currentChar;
  23091. // skip comments
  23092. while (true) {
  23093. if (ch < 0) {
  23094. return EOF;
  23095. }
  23096. if (comment) {
  23097. if (ch === 0x0A || ch === 0x0D) {
  23098. comment = false;
  23099. }
  23100. } else if (ch === 0x25) { // '%'
  23101. comment = true;
  23102. } else if (!Lexer.isSpace(ch)) {
  23103. break;
  23104. }
  23105. ch = this.nextChar();
  23106. }
  23107. switch (ch | 0) {
  23108. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23109. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23110. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23111. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  23112. this.getNumber());
  23113. case 0x7B: // '{'
  23114. this.nextChar();
  23115. return PostScriptToken.LBRACE;
  23116. case 0x7D: // '}'
  23117. this.nextChar();
  23118. return PostScriptToken.RBRACE;
  23119. }
  23120. // operator
  23121. var strBuf = this.strBuf;
  23122. strBuf.length = 0;
  23123. strBuf[0] = String.fromCharCode(ch);
  23124. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  23125. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  23126. strBuf.push(String.fromCharCode(ch));
  23127. }
  23128. var str = strBuf.join('');
  23129. switch (str.toLowerCase()) {
  23130. case 'if':
  23131. return PostScriptToken.IF;
  23132. case 'ifelse':
  23133. return PostScriptToken.IFELSE;
  23134. default:
  23135. return PostScriptToken.getOperator(str);
  23136. }
  23137. },
  23138. getNumber: function PostScriptLexer_getNumber() {
  23139. var ch = this.currentChar;
  23140. var strBuf = this.strBuf;
  23141. strBuf.length = 0;
  23142. strBuf[0] = String.fromCharCode(ch);
  23143. while ((ch = this.nextChar()) >= 0) {
  23144. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  23145. ch === 0x2D || ch === 0x2E) { // '-', '.'
  23146. strBuf.push(String.fromCharCode(ch));
  23147. } else {
  23148. break;
  23149. }
  23150. }
  23151. var value = parseFloat(strBuf.join(''));
  23152. if (isNaN(value)) {
  23153. error('Invalid floating point number: ' + value);
  23154. }
  23155. return value;
  23156. }
  23157. };
  23158. return PostScriptLexer;
  23159. })();
  23160. exports.PostScriptLexer = PostScriptLexer;
  23161. exports.PostScriptParser = PostScriptParser;
  23162. }));
  23163. (function (root, factory) {
  23164. {
  23165. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  23166. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  23167. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  23168. root.pdfjsCoreFontRenderer);
  23169. }
  23170. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  23171. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  23172. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23173. var FontType = sharedUtil.FontType;
  23174. var Util = sharedUtil.Util;
  23175. var assert = sharedUtil.assert;
  23176. var bytesToString = sharedUtil.bytesToString;
  23177. var error = sharedUtil.error;
  23178. var info = sharedUtil.info;
  23179. var isArray = sharedUtil.isArray;
  23180. var isInt = sharedUtil.isInt;
  23181. var isNum = sharedUtil.isNum;
  23182. var readUint32 = sharedUtil.readUint32;
  23183. var shadow = sharedUtil.shadow;
  23184. var stringToBytes = sharedUtil.stringToBytes;
  23185. var string32 = sharedUtil.string32;
  23186. var warn = sharedUtil.warn;
  23187. var Name = corePrimitives.Name;
  23188. var Stream = coreStream.Stream;
  23189. var Lexer = coreParser.Lexer;
  23190. var CMapFactory = coreCMap.CMapFactory;
  23191. var IdentityCMap = coreCMap.IdentityCMap;
  23192. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  23193. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  23194. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  23195. var ExpertCharset = coreCharsets.ExpertCharset;
  23196. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  23197. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  23198. // Unicode Private Use Area
  23199. var PRIVATE_USE_OFFSET_START = 0xE000;
  23200. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  23201. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  23202. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  23203. // except for Type 3 fonts
  23204. var PDF_GLYPH_SPACE_UNITS = 1000;
  23205. // Hinting is currently disabled due to unknown problems on windows
  23206. // in tracemonkey and various other pdfs with type1 fonts.
  23207. var HINTING_ENABLED = false;
  23208. // Accented charactars are not displayed properly on windows, using this flag
  23209. // to control analysis of seac charstrings.
  23210. var SEAC_ANALYSIS_ENABLED = false;
  23211. var FontFlags = {
  23212. FixedPitch: 1,
  23213. Serif: 2,
  23214. Symbolic: 4,
  23215. Script: 8,
  23216. Nonsymbolic: 32,
  23217. Italic: 64,
  23218. AllCap: 65536,
  23219. SmallCap: 131072,
  23220. ForceBold: 262144
  23221. };
  23222. var Encodings = {
  23223. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23224. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23225. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  23226. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  23227. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  23228. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  23229. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  23230. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  23231. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  23232. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  23233. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  23234. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  23235. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  23236. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  23237. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  23238. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  23239. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  23240. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  23241. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  23242. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23243. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23244. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  23245. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  23246. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  23247. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  23248. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  23249. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  23250. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  23251. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  23252. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  23253. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  23254. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  23255. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  23256. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  23257. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  23258. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  23259. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  23260. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  23261. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  23262. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  23263. 'Ydieresissmall'],
  23264. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23265. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23266. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  23267. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  23268. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23269. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  23270. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  23271. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  23272. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  23273. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  23274. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  23275. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  23276. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  23277. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  23278. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23279. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23280. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23281. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23282. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  23283. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  23284. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  23285. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  23286. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  23287. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  23288. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  23289. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  23290. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  23291. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  23292. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  23293. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  23294. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  23295. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  23296. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  23297. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  23298. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23299. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  23300. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  23301. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  23302. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  23303. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  23304. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23305. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23306. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23307. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23308. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23309. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23310. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23311. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23312. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23313. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23314. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23315. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  23316. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  23317. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  23318. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23319. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  23320. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  23321. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  23322. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  23323. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  23324. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  23325. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  23326. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  23327. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  23328. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  23329. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  23330. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  23331. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  23332. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  23333. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  23334. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  23335. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  23336. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  23337. 'ogonek', 'caron'],
  23338. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23339. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23340. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23341. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23342. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23343. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23344. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23345. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23346. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23347. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  23348. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  23349. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23350. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23351. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  23352. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23353. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23354. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  23355. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  23356. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  23357. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  23358. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  23359. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  23360. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  23361. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  23362. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  23363. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23364. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23365. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23366. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23367. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23368. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23369. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23370. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23371. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23372. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23373. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23374. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23375. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  23376. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  23377. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  23378. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  23379. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  23380. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  23381. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  23382. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  23383. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  23384. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  23385. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  23386. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  23387. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  23388. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  23389. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  23390. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  23391. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  23392. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  23393. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  23394. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  23395. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  23396. 'ydieresis'],
  23397. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23398. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23399. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  23400. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  23401. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23402. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23403. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  23404. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  23405. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  23406. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  23407. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  23408. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  23409. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  23410. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  23411. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  23412. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23413. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  23414. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  23415. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  23416. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  23417. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  23418. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  23419. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  23420. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  23421. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  23422. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  23423. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  23424. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  23425. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  23426. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  23427. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  23428. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  23429. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  23430. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  23431. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  23432. 'bracerightbt'],
  23433. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23434. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23435. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  23436. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  23437. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  23438. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  23439. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  23440. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  23441. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  23442. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  23443. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  23444. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  23445. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  23446. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  23447. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  23448. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  23449. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  23450. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  23451. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  23452. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  23453. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  23454. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  23455. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  23456. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  23457. };
  23458. /**
  23459. * Hold a map of decoded fonts and of the standard fourteen Type1
  23460. * fonts and their acronyms.
  23461. */
  23462. var stdFontMap = {
  23463. 'ArialNarrow': 'Helvetica',
  23464. 'ArialNarrow-Bold': 'Helvetica-Bold',
  23465. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  23466. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  23467. 'ArialBlack': 'Helvetica',
  23468. 'ArialBlack-Bold': 'Helvetica-Bold',
  23469. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  23470. 'ArialBlack-Italic': 'Helvetica-Oblique',
  23471. 'Arial': 'Helvetica',
  23472. 'Arial-Bold': 'Helvetica-Bold',
  23473. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  23474. 'Arial-Italic': 'Helvetica-Oblique',
  23475. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  23476. 'Arial-BoldMT': 'Helvetica-Bold',
  23477. 'Arial-ItalicMT': 'Helvetica-Oblique',
  23478. 'ArialMT': 'Helvetica',
  23479. 'Courier-Bold': 'Courier-Bold',
  23480. 'Courier-BoldItalic': 'Courier-BoldOblique',
  23481. 'Courier-Italic': 'Courier-Oblique',
  23482. 'CourierNew': 'Courier',
  23483. 'CourierNew-Bold': 'Courier-Bold',
  23484. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  23485. 'CourierNew-Italic': 'Courier-Oblique',
  23486. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  23487. 'CourierNewPS-BoldMT': 'Courier-Bold',
  23488. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  23489. 'CourierNewPSMT': 'Courier',
  23490. 'Helvetica': 'Helvetica',
  23491. 'Helvetica-Bold': 'Helvetica-Bold',
  23492. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  23493. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  23494. 'Helvetica-Italic': 'Helvetica-Oblique',
  23495. 'Helvetica-Oblique':'Helvetica-Oblique',
  23496. 'Symbol-Bold': 'Symbol',
  23497. 'Symbol-BoldItalic': 'Symbol',
  23498. 'Symbol-Italic': 'Symbol',
  23499. 'TimesNewRoman': 'Times-Roman',
  23500. 'TimesNewRoman-Bold': 'Times-Bold',
  23501. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  23502. 'TimesNewRoman-Italic': 'Times-Italic',
  23503. 'TimesNewRomanPS': 'Times-Roman',
  23504. 'TimesNewRomanPS-Bold': 'Times-Bold',
  23505. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  23506. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  23507. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  23508. 'TimesNewRomanPS-Italic': 'Times-Italic',
  23509. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  23510. 'TimesNewRomanPSMT': 'Times-Roman',
  23511. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  23512. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  23513. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  23514. };
  23515. /**
  23516. * Holds the map of the non-standard fonts that might be included as a standard
  23517. * fonts without glyph data.
  23518. */
  23519. var nonStdFontMap = {
  23520. 'CenturyGothic': 'Helvetica',
  23521. 'CenturyGothic-Bold': 'Helvetica-Bold',
  23522. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  23523. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  23524. 'ComicSansMS': 'Comic Sans MS',
  23525. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  23526. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  23527. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  23528. 'LucidaConsole': 'Courier',
  23529. 'LucidaConsole-Bold': 'Courier-Bold',
  23530. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  23531. 'LucidaConsole-Italic': 'Courier-Oblique',
  23532. 'MS-Gothic': 'MS Gothic',
  23533. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  23534. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  23535. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  23536. 'MS-Mincho': 'MS Mincho',
  23537. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  23538. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  23539. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  23540. 'MS-PGothic': 'MS PGothic',
  23541. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  23542. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  23543. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  23544. 'MS-PMincho': 'MS PMincho',
  23545. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  23546. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  23547. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  23548. 'Wingdings': 'ZapfDingbats'
  23549. };
  23550. var serifFonts = {
  23551. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  23552. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  23553. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  23554. 'Arno': true, 'Aster': true, 'Aurora': true,
  23555. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  23556. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  23557. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  23558. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  23559. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  23560. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  23561. 'Cartier': true, 'Caslon': true, 'Catull': true,
  23562. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  23563. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  23564. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  23565. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  23566. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  23567. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  23568. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  23569. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  23570. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  23571. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  23572. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  23573. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  23574. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  23575. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  23576. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  23577. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  23578. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  23579. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  23580. 'Miller': true, 'Minion': true, 'Modern': true,
  23581. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  23582. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  23583. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  23584. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  23585. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  23586. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  23587. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  23588. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  23589. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  23590. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  23591. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  23592. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  23593. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  23594. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  23595. };
  23596. var symbolsFonts = {
  23597. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  23598. };
  23599. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  23600. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  23601. // glyphs, but common for some set of the standard fonts.
  23602. var GlyphMapForStandardFonts = {
  23603. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  23604. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  23605. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  23606. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  23607. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  23608. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  23609. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  23610. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  23611. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  23612. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  23613. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  23614. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  23615. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  23616. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  23617. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  23618. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  23619. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  23620. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  23621. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  23622. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  23623. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  23624. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  23625. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  23626. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  23627. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  23628. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  23629. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  23630. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  23631. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  23632. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  23633. '298': 380, '305': 963,
  23634. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  23635. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  23636. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  23637. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  23638. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  23639. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  23640. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  23641. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  23642. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  23643. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  23644. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  23645. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  23646. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  23647. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  23648. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  23649. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  23650. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  23651. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  23652. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  23653. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  23654. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  23655. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  23656. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  23657. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  23658. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  23659. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  23660. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  23661. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  23662. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  23663. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  23664. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  23665. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  23666. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  23667. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  23668. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  23669. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  23670. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  23671. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  23672. };
  23673. // The glyph map for ArialBlack differs slightly from the glyph map used for
  23674. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  23675. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  23676. var SupplementalGlyphMapForArialBlack = {
  23677. '227': 322, '264': 261, '291': 346,
  23678. };
  23679. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  23680. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  23681. // to the similar equivalents in the normal characters range.
  23682. var SpecialPUASymbols = {
  23683. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  23684. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  23685. '63720': 0x00AE, // registersans (0xF8E8) => registered
  23686. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  23687. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  23688. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  23689. '63729': 0x23A7, // bracelefttp (0xF8F1)
  23690. '63730': 0x23A8, // braceleftmid (0xF8F2)
  23691. '63731': 0x23A9, // braceleftbt (0xF8F3)
  23692. '63740': 0x23AB, // bracerighttp (0xF8FC)
  23693. '63741': 0x23AC, // bracerightmid (0xF8FD)
  23694. '63742': 0x23AD, // bracerightbt (0xF8FE)
  23695. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  23696. '63727': 0x23A2, // bracketleftex (0xF8EF)
  23697. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  23698. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  23699. '63738': 0x23A5, // bracketrightex (0xF8FA)
  23700. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  23701. '63723': 0x239B, // parenlefttp (0xF8EB)
  23702. '63724': 0x239C, // parenleftex (0xF8EC)
  23703. '63725': 0x239D, // parenleftbt (0xF8ED)
  23704. '63734': 0x239E, // parenrighttp (0xF8F6)
  23705. '63735': 0x239F, // parenrightex (0xF8F7)
  23706. '63736': 0x23A0, // parenrightbt (0xF8F8)
  23707. };
  23708. function mapSpecialUnicodeValues(code) {
  23709. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  23710. return 0;
  23711. } else if (code >= 0xF600 && code <= 0xF8FF) {
  23712. return (SpecialPUASymbols[code] || code);
  23713. }
  23714. return code;
  23715. }
  23716. var UnicodeRanges = [
  23717. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  23718. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  23719. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  23720. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  23721. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  23722. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  23723. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  23724. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  23725. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  23726. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  23727. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  23728. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  23729. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  23730. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  23731. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  23732. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  23733. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  23734. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  23735. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  23736. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  23737. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  23738. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  23739. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  23740. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  23741. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  23742. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  23743. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  23744. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  23745. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  23746. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  23747. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  23748. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  23749. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  23750. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  23751. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  23752. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  23753. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  23754. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  23755. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  23756. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  23757. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  23758. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  23759. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  23760. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  23761. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  23762. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  23763. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  23764. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  23765. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  23766. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  23767. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  23768. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  23769. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  23770. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  23771. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  23772. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  23773. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  23774. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  23775. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  23776. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  23777. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  23778. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  23779. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  23780. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  23781. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  23782. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  23783. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  23784. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  23785. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  23786. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  23787. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  23788. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  23789. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  23790. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  23791. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  23792. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  23793. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  23794. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  23795. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  23796. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  23797. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  23798. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  23799. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  23800. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  23801. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  23802. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  23803. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  23804. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  23805. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  23806. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  23807. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  23808. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  23809. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  23810. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  23811. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  23812. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  23813. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  23814. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  23815. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  23816. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  23817. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  23818. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  23819. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  23820. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  23821. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  23822. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  23823. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  23824. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  23825. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  23826. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  23827. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  23828. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  23829. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  23830. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  23831. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  23832. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  23833. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  23834. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  23835. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  23836. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  23837. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  23838. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  23839. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  23840. ];
  23841. var MacStandardGlyphOrdering = [
  23842. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  23843. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  23844. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  23845. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  23846. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  23847. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  23848. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  23849. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  23850. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  23851. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  23852. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  23853. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  23854. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23855. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  23856. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  23857. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  23858. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  23859. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  23860. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  23861. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  23862. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  23863. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  23864. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  23865. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  23866. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  23867. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  23868. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  23869. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  23870. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  23871. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  23872. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  23873. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  23874. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  23875. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  23876. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  23877. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  23878. function getUnicodeRangeFor(value) {
  23879. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  23880. var range = UnicodeRanges[i];
  23881. if (value >= range.begin && value < range.end) {
  23882. return i;
  23883. }
  23884. }
  23885. return -1;
  23886. }
  23887. function isRTLRangeFor(value) {
  23888. var range = UnicodeRanges[13];
  23889. if (value >= range.begin && value < range.end) {
  23890. return true;
  23891. }
  23892. range = UnicodeRanges[11];
  23893. if (value >= range.begin && value < range.end) {
  23894. return true;
  23895. }
  23896. return false;
  23897. }
  23898. // The normalization table is obtained by filtering the Unicode characters
  23899. // database with <compat> entries.
  23900. var NormalizedUnicodes = {
  23901. '\u00A8': '\u0020\u0308',
  23902. '\u00AF': '\u0020\u0304',
  23903. '\u00B4': '\u0020\u0301',
  23904. '\u00B5': '\u03BC',
  23905. '\u00B8': '\u0020\u0327',
  23906. '\u0132': '\u0049\u004A',
  23907. '\u0133': '\u0069\u006A',
  23908. '\u013F': '\u004C\u00B7',
  23909. '\u0140': '\u006C\u00B7',
  23910. '\u0149': '\u02BC\u006E',
  23911. '\u017F': '\u0073',
  23912. '\u01C4': '\u0044\u017D',
  23913. '\u01C5': '\u0044\u017E',
  23914. '\u01C6': '\u0064\u017E',
  23915. '\u01C7': '\u004C\u004A',
  23916. '\u01C8': '\u004C\u006A',
  23917. '\u01C9': '\u006C\u006A',
  23918. '\u01CA': '\u004E\u004A',
  23919. '\u01CB': '\u004E\u006A',
  23920. '\u01CC': '\u006E\u006A',
  23921. '\u01F1': '\u0044\u005A',
  23922. '\u01F2': '\u0044\u007A',
  23923. '\u01F3': '\u0064\u007A',
  23924. '\u02D8': '\u0020\u0306',
  23925. '\u02D9': '\u0020\u0307',
  23926. '\u02DA': '\u0020\u030A',
  23927. '\u02DB': '\u0020\u0328',
  23928. '\u02DC': '\u0020\u0303',
  23929. '\u02DD': '\u0020\u030B',
  23930. '\u037A': '\u0020\u0345',
  23931. '\u0384': '\u0020\u0301',
  23932. '\u03D0': '\u03B2',
  23933. '\u03D1': '\u03B8',
  23934. '\u03D2': '\u03A5',
  23935. '\u03D5': '\u03C6',
  23936. '\u03D6': '\u03C0',
  23937. '\u03F0': '\u03BA',
  23938. '\u03F1': '\u03C1',
  23939. '\u03F2': '\u03C2',
  23940. '\u03F4': '\u0398',
  23941. '\u03F5': '\u03B5',
  23942. '\u03F9': '\u03A3',
  23943. '\u0587': '\u0565\u0582',
  23944. '\u0675': '\u0627\u0674',
  23945. '\u0676': '\u0648\u0674',
  23946. '\u0677': '\u06C7\u0674',
  23947. '\u0678': '\u064A\u0674',
  23948. '\u0E33': '\u0E4D\u0E32',
  23949. '\u0EB3': '\u0ECD\u0EB2',
  23950. '\u0EDC': '\u0EAB\u0E99',
  23951. '\u0EDD': '\u0EAB\u0EA1',
  23952. '\u0F77': '\u0FB2\u0F81',
  23953. '\u0F79': '\u0FB3\u0F81',
  23954. '\u1E9A': '\u0061\u02BE',
  23955. '\u1FBD': '\u0020\u0313',
  23956. '\u1FBF': '\u0020\u0313',
  23957. '\u1FC0': '\u0020\u0342',
  23958. '\u1FFE': '\u0020\u0314',
  23959. '\u2002': '\u0020',
  23960. '\u2003': '\u0020',
  23961. '\u2004': '\u0020',
  23962. '\u2005': '\u0020',
  23963. '\u2006': '\u0020',
  23964. '\u2008': '\u0020',
  23965. '\u2009': '\u0020',
  23966. '\u200A': '\u0020',
  23967. '\u2017': '\u0020\u0333',
  23968. '\u2024': '\u002E',
  23969. '\u2025': '\u002E\u002E',
  23970. '\u2026': '\u002E\u002E\u002E',
  23971. '\u2033': '\u2032\u2032',
  23972. '\u2034': '\u2032\u2032\u2032',
  23973. '\u2036': '\u2035\u2035',
  23974. '\u2037': '\u2035\u2035\u2035',
  23975. '\u203C': '\u0021\u0021',
  23976. '\u203E': '\u0020\u0305',
  23977. '\u2047': '\u003F\u003F',
  23978. '\u2048': '\u003F\u0021',
  23979. '\u2049': '\u0021\u003F',
  23980. '\u2057': '\u2032\u2032\u2032\u2032',
  23981. '\u205F': '\u0020',
  23982. '\u20A8': '\u0052\u0073',
  23983. '\u2100': '\u0061\u002F\u0063',
  23984. '\u2101': '\u0061\u002F\u0073',
  23985. '\u2103': '\u00B0\u0043',
  23986. '\u2105': '\u0063\u002F\u006F',
  23987. '\u2106': '\u0063\u002F\u0075',
  23988. '\u2107': '\u0190',
  23989. '\u2109': '\u00B0\u0046',
  23990. '\u2116': '\u004E\u006F',
  23991. '\u2121': '\u0054\u0045\u004C',
  23992. '\u2135': '\u05D0',
  23993. '\u2136': '\u05D1',
  23994. '\u2137': '\u05D2',
  23995. '\u2138': '\u05D3',
  23996. '\u213B': '\u0046\u0041\u0058',
  23997. '\u2160': '\u0049',
  23998. '\u2161': '\u0049\u0049',
  23999. '\u2162': '\u0049\u0049\u0049',
  24000. '\u2163': '\u0049\u0056',
  24001. '\u2164': '\u0056',
  24002. '\u2165': '\u0056\u0049',
  24003. '\u2166': '\u0056\u0049\u0049',
  24004. '\u2167': '\u0056\u0049\u0049\u0049',
  24005. '\u2168': '\u0049\u0058',
  24006. '\u2169': '\u0058',
  24007. '\u216A': '\u0058\u0049',
  24008. '\u216B': '\u0058\u0049\u0049',
  24009. '\u216C': '\u004C',
  24010. '\u216D': '\u0043',
  24011. '\u216E': '\u0044',
  24012. '\u216F': '\u004D',
  24013. '\u2170': '\u0069',
  24014. '\u2171': '\u0069\u0069',
  24015. '\u2172': '\u0069\u0069\u0069',
  24016. '\u2173': '\u0069\u0076',
  24017. '\u2174': '\u0076',
  24018. '\u2175': '\u0076\u0069',
  24019. '\u2176': '\u0076\u0069\u0069',
  24020. '\u2177': '\u0076\u0069\u0069\u0069',
  24021. '\u2178': '\u0069\u0078',
  24022. '\u2179': '\u0078',
  24023. '\u217A': '\u0078\u0069',
  24024. '\u217B': '\u0078\u0069\u0069',
  24025. '\u217C': '\u006C',
  24026. '\u217D': '\u0063',
  24027. '\u217E': '\u0064',
  24028. '\u217F': '\u006D',
  24029. '\u222C': '\u222B\u222B',
  24030. '\u222D': '\u222B\u222B\u222B',
  24031. '\u222F': '\u222E\u222E',
  24032. '\u2230': '\u222E\u222E\u222E',
  24033. '\u2474': '\u0028\u0031\u0029',
  24034. '\u2475': '\u0028\u0032\u0029',
  24035. '\u2476': '\u0028\u0033\u0029',
  24036. '\u2477': '\u0028\u0034\u0029',
  24037. '\u2478': '\u0028\u0035\u0029',
  24038. '\u2479': '\u0028\u0036\u0029',
  24039. '\u247A': '\u0028\u0037\u0029',
  24040. '\u247B': '\u0028\u0038\u0029',
  24041. '\u247C': '\u0028\u0039\u0029',
  24042. '\u247D': '\u0028\u0031\u0030\u0029',
  24043. '\u247E': '\u0028\u0031\u0031\u0029',
  24044. '\u247F': '\u0028\u0031\u0032\u0029',
  24045. '\u2480': '\u0028\u0031\u0033\u0029',
  24046. '\u2481': '\u0028\u0031\u0034\u0029',
  24047. '\u2482': '\u0028\u0031\u0035\u0029',
  24048. '\u2483': '\u0028\u0031\u0036\u0029',
  24049. '\u2484': '\u0028\u0031\u0037\u0029',
  24050. '\u2485': '\u0028\u0031\u0038\u0029',
  24051. '\u2486': '\u0028\u0031\u0039\u0029',
  24052. '\u2487': '\u0028\u0032\u0030\u0029',
  24053. '\u2488': '\u0031\u002E',
  24054. '\u2489': '\u0032\u002E',
  24055. '\u248A': '\u0033\u002E',
  24056. '\u248B': '\u0034\u002E',
  24057. '\u248C': '\u0035\u002E',
  24058. '\u248D': '\u0036\u002E',
  24059. '\u248E': '\u0037\u002E',
  24060. '\u248F': '\u0038\u002E',
  24061. '\u2490': '\u0039\u002E',
  24062. '\u2491': '\u0031\u0030\u002E',
  24063. '\u2492': '\u0031\u0031\u002E',
  24064. '\u2493': '\u0031\u0032\u002E',
  24065. '\u2494': '\u0031\u0033\u002E',
  24066. '\u2495': '\u0031\u0034\u002E',
  24067. '\u2496': '\u0031\u0035\u002E',
  24068. '\u2497': '\u0031\u0036\u002E',
  24069. '\u2498': '\u0031\u0037\u002E',
  24070. '\u2499': '\u0031\u0038\u002E',
  24071. '\u249A': '\u0031\u0039\u002E',
  24072. '\u249B': '\u0032\u0030\u002E',
  24073. '\u249C': '\u0028\u0061\u0029',
  24074. '\u249D': '\u0028\u0062\u0029',
  24075. '\u249E': '\u0028\u0063\u0029',
  24076. '\u249F': '\u0028\u0064\u0029',
  24077. '\u24A0': '\u0028\u0065\u0029',
  24078. '\u24A1': '\u0028\u0066\u0029',
  24079. '\u24A2': '\u0028\u0067\u0029',
  24080. '\u24A3': '\u0028\u0068\u0029',
  24081. '\u24A4': '\u0028\u0069\u0029',
  24082. '\u24A5': '\u0028\u006A\u0029',
  24083. '\u24A6': '\u0028\u006B\u0029',
  24084. '\u24A7': '\u0028\u006C\u0029',
  24085. '\u24A8': '\u0028\u006D\u0029',
  24086. '\u24A9': '\u0028\u006E\u0029',
  24087. '\u24AA': '\u0028\u006F\u0029',
  24088. '\u24AB': '\u0028\u0070\u0029',
  24089. '\u24AC': '\u0028\u0071\u0029',
  24090. '\u24AD': '\u0028\u0072\u0029',
  24091. '\u24AE': '\u0028\u0073\u0029',
  24092. '\u24AF': '\u0028\u0074\u0029',
  24093. '\u24B0': '\u0028\u0075\u0029',
  24094. '\u24B1': '\u0028\u0076\u0029',
  24095. '\u24B2': '\u0028\u0077\u0029',
  24096. '\u24B3': '\u0028\u0078\u0029',
  24097. '\u24B4': '\u0028\u0079\u0029',
  24098. '\u24B5': '\u0028\u007A\u0029',
  24099. '\u2A0C': '\u222B\u222B\u222B\u222B',
  24100. '\u2A74': '\u003A\u003A\u003D',
  24101. '\u2A75': '\u003D\u003D',
  24102. '\u2A76': '\u003D\u003D\u003D',
  24103. '\u2E9F': '\u6BCD',
  24104. '\u2EF3': '\u9F9F',
  24105. '\u2F00': '\u4E00',
  24106. '\u2F01': '\u4E28',
  24107. '\u2F02': '\u4E36',
  24108. '\u2F03': '\u4E3F',
  24109. '\u2F04': '\u4E59',
  24110. '\u2F05': '\u4E85',
  24111. '\u2F06': '\u4E8C',
  24112. '\u2F07': '\u4EA0',
  24113. '\u2F08': '\u4EBA',
  24114. '\u2F09': '\u513F',
  24115. '\u2F0A': '\u5165',
  24116. '\u2F0B': '\u516B',
  24117. '\u2F0C': '\u5182',
  24118. '\u2F0D': '\u5196',
  24119. '\u2F0E': '\u51AB',
  24120. '\u2F0F': '\u51E0',
  24121. '\u2F10': '\u51F5',
  24122. '\u2F11': '\u5200',
  24123. '\u2F12': '\u529B',
  24124. '\u2F13': '\u52F9',
  24125. '\u2F14': '\u5315',
  24126. '\u2F15': '\u531A',
  24127. '\u2F16': '\u5338',
  24128. '\u2F17': '\u5341',
  24129. '\u2F18': '\u535C',
  24130. '\u2F19': '\u5369',
  24131. '\u2F1A': '\u5382',
  24132. '\u2F1B': '\u53B6',
  24133. '\u2F1C': '\u53C8',
  24134. '\u2F1D': '\u53E3',
  24135. '\u2F1E': '\u56D7',
  24136. '\u2F1F': '\u571F',
  24137. '\u2F20': '\u58EB',
  24138. '\u2F21': '\u5902',
  24139. '\u2F22': '\u590A',
  24140. '\u2F23': '\u5915',
  24141. '\u2F24': '\u5927',
  24142. '\u2F25': '\u5973',
  24143. '\u2F26': '\u5B50',
  24144. '\u2F27': '\u5B80',
  24145. '\u2F28': '\u5BF8',
  24146. '\u2F29': '\u5C0F',
  24147. '\u2F2A': '\u5C22',
  24148. '\u2F2B': '\u5C38',
  24149. '\u2F2C': '\u5C6E',
  24150. '\u2F2D': '\u5C71',
  24151. '\u2F2E': '\u5DDB',
  24152. '\u2F2F': '\u5DE5',
  24153. '\u2F30': '\u5DF1',
  24154. '\u2F31': '\u5DFE',
  24155. '\u2F32': '\u5E72',
  24156. '\u2F33': '\u5E7A',
  24157. '\u2F34': '\u5E7F',
  24158. '\u2F35': '\u5EF4',
  24159. '\u2F36': '\u5EFE',
  24160. '\u2F37': '\u5F0B',
  24161. '\u2F38': '\u5F13',
  24162. '\u2F39': '\u5F50',
  24163. '\u2F3A': '\u5F61',
  24164. '\u2F3B': '\u5F73',
  24165. '\u2F3C': '\u5FC3',
  24166. '\u2F3D': '\u6208',
  24167. '\u2F3E': '\u6236',
  24168. '\u2F3F': '\u624B',
  24169. '\u2F40': '\u652F',
  24170. '\u2F41': '\u6534',
  24171. '\u2F42': '\u6587',
  24172. '\u2F43': '\u6597',
  24173. '\u2F44': '\u65A4',
  24174. '\u2F45': '\u65B9',
  24175. '\u2F46': '\u65E0',
  24176. '\u2F47': '\u65E5',
  24177. '\u2F48': '\u66F0',
  24178. '\u2F49': '\u6708',
  24179. '\u2F4A': '\u6728',
  24180. '\u2F4B': '\u6B20',
  24181. '\u2F4C': '\u6B62',
  24182. '\u2F4D': '\u6B79',
  24183. '\u2F4E': '\u6BB3',
  24184. '\u2F4F': '\u6BCB',
  24185. '\u2F50': '\u6BD4',
  24186. '\u2F51': '\u6BDB',
  24187. '\u2F52': '\u6C0F',
  24188. '\u2F53': '\u6C14',
  24189. '\u2F54': '\u6C34',
  24190. '\u2F55': '\u706B',
  24191. '\u2F56': '\u722A',
  24192. '\u2F57': '\u7236',
  24193. '\u2F58': '\u723B',
  24194. '\u2F59': '\u723F',
  24195. '\u2F5A': '\u7247',
  24196. '\u2F5B': '\u7259',
  24197. '\u2F5C': '\u725B',
  24198. '\u2F5D': '\u72AC',
  24199. '\u2F5E': '\u7384',
  24200. '\u2F5F': '\u7389',
  24201. '\u2F60': '\u74DC',
  24202. '\u2F61': '\u74E6',
  24203. '\u2F62': '\u7518',
  24204. '\u2F63': '\u751F',
  24205. '\u2F64': '\u7528',
  24206. '\u2F65': '\u7530',
  24207. '\u2F66': '\u758B',
  24208. '\u2F67': '\u7592',
  24209. '\u2F68': '\u7676',
  24210. '\u2F69': '\u767D',
  24211. '\u2F6A': '\u76AE',
  24212. '\u2F6B': '\u76BF',
  24213. '\u2F6C': '\u76EE',
  24214. '\u2F6D': '\u77DB',
  24215. '\u2F6E': '\u77E2',
  24216. '\u2F6F': '\u77F3',
  24217. '\u2F70': '\u793A',
  24218. '\u2F71': '\u79B8',
  24219. '\u2F72': '\u79BE',
  24220. '\u2F73': '\u7A74',
  24221. '\u2F74': '\u7ACB',
  24222. '\u2F75': '\u7AF9',
  24223. '\u2F76': '\u7C73',
  24224. '\u2F77': '\u7CF8',
  24225. '\u2F78': '\u7F36',
  24226. '\u2F79': '\u7F51',
  24227. '\u2F7A': '\u7F8A',
  24228. '\u2F7B': '\u7FBD',
  24229. '\u2F7C': '\u8001',
  24230. '\u2F7D': '\u800C',
  24231. '\u2F7E': '\u8012',
  24232. '\u2F7F': '\u8033',
  24233. '\u2F80': '\u807F',
  24234. '\u2F81': '\u8089',
  24235. '\u2F82': '\u81E3',
  24236. '\u2F83': '\u81EA',
  24237. '\u2F84': '\u81F3',
  24238. '\u2F85': '\u81FC',
  24239. '\u2F86': '\u820C',
  24240. '\u2F87': '\u821B',
  24241. '\u2F88': '\u821F',
  24242. '\u2F89': '\u826E',
  24243. '\u2F8A': '\u8272',
  24244. '\u2F8B': '\u8278',
  24245. '\u2F8C': '\u864D',
  24246. '\u2F8D': '\u866B',
  24247. '\u2F8E': '\u8840',
  24248. '\u2F8F': '\u884C',
  24249. '\u2F90': '\u8863',
  24250. '\u2F91': '\u897E',
  24251. '\u2F92': '\u898B',
  24252. '\u2F93': '\u89D2',
  24253. '\u2F94': '\u8A00',
  24254. '\u2F95': '\u8C37',
  24255. '\u2F96': '\u8C46',
  24256. '\u2F97': '\u8C55',
  24257. '\u2F98': '\u8C78',
  24258. '\u2F99': '\u8C9D',
  24259. '\u2F9A': '\u8D64',
  24260. '\u2F9B': '\u8D70',
  24261. '\u2F9C': '\u8DB3',
  24262. '\u2F9D': '\u8EAB',
  24263. '\u2F9E': '\u8ECA',
  24264. '\u2F9F': '\u8F9B',
  24265. '\u2FA0': '\u8FB0',
  24266. '\u2FA1': '\u8FB5',
  24267. '\u2FA2': '\u9091',
  24268. '\u2FA3': '\u9149',
  24269. '\u2FA4': '\u91C6',
  24270. '\u2FA5': '\u91CC',
  24271. '\u2FA6': '\u91D1',
  24272. '\u2FA7': '\u9577',
  24273. '\u2FA8': '\u9580',
  24274. '\u2FA9': '\u961C',
  24275. '\u2FAA': '\u96B6',
  24276. '\u2FAB': '\u96B9',
  24277. '\u2FAC': '\u96E8',
  24278. '\u2FAD': '\u9751',
  24279. '\u2FAE': '\u975E',
  24280. '\u2FAF': '\u9762',
  24281. '\u2FB0': '\u9769',
  24282. '\u2FB1': '\u97CB',
  24283. '\u2FB2': '\u97ED',
  24284. '\u2FB3': '\u97F3',
  24285. '\u2FB4': '\u9801',
  24286. '\u2FB5': '\u98A8',
  24287. '\u2FB6': '\u98DB',
  24288. '\u2FB7': '\u98DF',
  24289. '\u2FB8': '\u9996',
  24290. '\u2FB9': '\u9999',
  24291. '\u2FBA': '\u99AC',
  24292. '\u2FBB': '\u9AA8',
  24293. '\u2FBC': '\u9AD8',
  24294. '\u2FBD': '\u9ADF',
  24295. '\u2FBE': '\u9B25',
  24296. '\u2FBF': '\u9B2F',
  24297. '\u2FC0': '\u9B32',
  24298. '\u2FC1': '\u9B3C',
  24299. '\u2FC2': '\u9B5A',
  24300. '\u2FC3': '\u9CE5',
  24301. '\u2FC4': '\u9E75',
  24302. '\u2FC5': '\u9E7F',
  24303. '\u2FC6': '\u9EA5',
  24304. '\u2FC7': '\u9EBB',
  24305. '\u2FC8': '\u9EC3',
  24306. '\u2FC9': '\u9ECD',
  24307. '\u2FCA': '\u9ED1',
  24308. '\u2FCB': '\u9EF9',
  24309. '\u2FCC': '\u9EFD',
  24310. '\u2FCD': '\u9F0E',
  24311. '\u2FCE': '\u9F13',
  24312. '\u2FCF': '\u9F20',
  24313. '\u2FD0': '\u9F3B',
  24314. '\u2FD1': '\u9F4A',
  24315. '\u2FD2': '\u9F52',
  24316. '\u2FD3': '\u9F8D',
  24317. '\u2FD4': '\u9F9C',
  24318. '\u2FD5': '\u9FA0',
  24319. '\u3036': '\u3012',
  24320. '\u3038': '\u5341',
  24321. '\u3039': '\u5344',
  24322. '\u303A': '\u5345',
  24323. '\u309B': '\u0020\u3099',
  24324. '\u309C': '\u0020\u309A',
  24325. '\u3131': '\u1100',
  24326. '\u3132': '\u1101',
  24327. '\u3133': '\u11AA',
  24328. '\u3134': '\u1102',
  24329. '\u3135': '\u11AC',
  24330. '\u3136': '\u11AD',
  24331. '\u3137': '\u1103',
  24332. '\u3138': '\u1104',
  24333. '\u3139': '\u1105',
  24334. '\u313A': '\u11B0',
  24335. '\u313B': '\u11B1',
  24336. '\u313C': '\u11B2',
  24337. '\u313D': '\u11B3',
  24338. '\u313E': '\u11B4',
  24339. '\u313F': '\u11B5',
  24340. '\u3140': '\u111A',
  24341. '\u3141': '\u1106',
  24342. '\u3142': '\u1107',
  24343. '\u3143': '\u1108',
  24344. '\u3144': '\u1121',
  24345. '\u3145': '\u1109',
  24346. '\u3146': '\u110A',
  24347. '\u3147': '\u110B',
  24348. '\u3148': '\u110C',
  24349. '\u3149': '\u110D',
  24350. '\u314A': '\u110E',
  24351. '\u314B': '\u110F',
  24352. '\u314C': '\u1110',
  24353. '\u314D': '\u1111',
  24354. '\u314E': '\u1112',
  24355. '\u314F': '\u1161',
  24356. '\u3150': '\u1162',
  24357. '\u3151': '\u1163',
  24358. '\u3152': '\u1164',
  24359. '\u3153': '\u1165',
  24360. '\u3154': '\u1166',
  24361. '\u3155': '\u1167',
  24362. '\u3156': '\u1168',
  24363. '\u3157': '\u1169',
  24364. '\u3158': '\u116A',
  24365. '\u3159': '\u116B',
  24366. '\u315A': '\u116C',
  24367. '\u315B': '\u116D',
  24368. '\u315C': '\u116E',
  24369. '\u315D': '\u116F',
  24370. '\u315E': '\u1170',
  24371. '\u315F': '\u1171',
  24372. '\u3160': '\u1172',
  24373. '\u3161': '\u1173',
  24374. '\u3162': '\u1174',
  24375. '\u3163': '\u1175',
  24376. '\u3164': '\u1160',
  24377. '\u3165': '\u1114',
  24378. '\u3166': '\u1115',
  24379. '\u3167': '\u11C7',
  24380. '\u3168': '\u11C8',
  24381. '\u3169': '\u11CC',
  24382. '\u316A': '\u11CE',
  24383. '\u316B': '\u11D3',
  24384. '\u316C': '\u11D7',
  24385. '\u316D': '\u11D9',
  24386. '\u316E': '\u111C',
  24387. '\u316F': '\u11DD',
  24388. '\u3170': '\u11DF',
  24389. '\u3171': '\u111D',
  24390. '\u3172': '\u111E',
  24391. '\u3173': '\u1120',
  24392. '\u3174': '\u1122',
  24393. '\u3175': '\u1123',
  24394. '\u3176': '\u1127',
  24395. '\u3177': '\u1129',
  24396. '\u3178': '\u112B',
  24397. '\u3179': '\u112C',
  24398. '\u317A': '\u112D',
  24399. '\u317B': '\u112E',
  24400. '\u317C': '\u112F',
  24401. '\u317D': '\u1132',
  24402. '\u317E': '\u1136',
  24403. '\u317F': '\u1140',
  24404. '\u3180': '\u1147',
  24405. '\u3181': '\u114C',
  24406. '\u3182': '\u11F1',
  24407. '\u3183': '\u11F2',
  24408. '\u3184': '\u1157',
  24409. '\u3185': '\u1158',
  24410. '\u3186': '\u1159',
  24411. '\u3187': '\u1184',
  24412. '\u3188': '\u1185',
  24413. '\u3189': '\u1188',
  24414. '\u318A': '\u1191',
  24415. '\u318B': '\u1192',
  24416. '\u318C': '\u1194',
  24417. '\u318D': '\u119E',
  24418. '\u318E': '\u11A1',
  24419. '\u3200': '\u0028\u1100\u0029',
  24420. '\u3201': '\u0028\u1102\u0029',
  24421. '\u3202': '\u0028\u1103\u0029',
  24422. '\u3203': '\u0028\u1105\u0029',
  24423. '\u3204': '\u0028\u1106\u0029',
  24424. '\u3205': '\u0028\u1107\u0029',
  24425. '\u3206': '\u0028\u1109\u0029',
  24426. '\u3207': '\u0028\u110B\u0029',
  24427. '\u3208': '\u0028\u110C\u0029',
  24428. '\u3209': '\u0028\u110E\u0029',
  24429. '\u320A': '\u0028\u110F\u0029',
  24430. '\u320B': '\u0028\u1110\u0029',
  24431. '\u320C': '\u0028\u1111\u0029',
  24432. '\u320D': '\u0028\u1112\u0029',
  24433. '\u320E': '\u0028\u1100\u1161\u0029',
  24434. '\u320F': '\u0028\u1102\u1161\u0029',
  24435. '\u3210': '\u0028\u1103\u1161\u0029',
  24436. '\u3211': '\u0028\u1105\u1161\u0029',
  24437. '\u3212': '\u0028\u1106\u1161\u0029',
  24438. '\u3213': '\u0028\u1107\u1161\u0029',
  24439. '\u3214': '\u0028\u1109\u1161\u0029',
  24440. '\u3215': '\u0028\u110B\u1161\u0029',
  24441. '\u3216': '\u0028\u110C\u1161\u0029',
  24442. '\u3217': '\u0028\u110E\u1161\u0029',
  24443. '\u3218': '\u0028\u110F\u1161\u0029',
  24444. '\u3219': '\u0028\u1110\u1161\u0029',
  24445. '\u321A': '\u0028\u1111\u1161\u0029',
  24446. '\u321B': '\u0028\u1112\u1161\u0029',
  24447. '\u321C': '\u0028\u110C\u116E\u0029',
  24448. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  24449. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  24450. '\u3220': '\u0028\u4E00\u0029',
  24451. '\u3221': '\u0028\u4E8C\u0029',
  24452. '\u3222': '\u0028\u4E09\u0029',
  24453. '\u3223': '\u0028\u56DB\u0029',
  24454. '\u3224': '\u0028\u4E94\u0029',
  24455. '\u3225': '\u0028\u516D\u0029',
  24456. '\u3226': '\u0028\u4E03\u0029',
  24457. '\u3227': '\u0028\u516B\u0029',
  24458. '\u3228': '\u0028\u4E5D\u0029',
  24459. '\u3229': '\u0028\u5341\u0029',
  24460. '\u322A': '\u0028\u6708\u0029',
  24461. '\u322B': '\u0028\u706B\u0029',
  24462. '\u322C': '\u0028\u6C34\u0029',
  24463. '\u322D': '\u0028\u6728\u0029',
  24464. '\u322E': '\u0028\u91D1\u0029',
  24465. '\u322F': '\u0028\u571F\u0029',
  24466. '\u3230': '\u0028\u65E5\u0029',
  24467. '\u3231': '\u0028\u682A\u0029',
  24468. '\u3232': '\u0028\u6709\u0029',
  24469. '\u3233': '\u0028\u793E\u0029',
  24470. '\u3234': '\u0028\u540D\u0029',
  24471. '\u3235': '\u0028\u7279\u0029',
  24472. '\u3236': '\u0028\u8CA1\u0029',
  24473. '\u3237': '\u0028\u795D\u0029',
  24474. '\u3238': '\u0028\u52B4\u0029',
  24475. '\u3239': '\u0028\u4EE3\u0029',
  24476. '\u323A': '\u0028\u547C\u0029',
  24477. '\u323B': '\u0028\u5B66\u0029',
  24478. '\u323C': '\u0028\u76E3\u0029',
  24479. '\u323D': '\u0028\u4F01\u0029',
  24480. '\u323E': '\u0028\u8CC7\u0029',
  24481. '\u323F': '\u0028\u5354\u0029',
  24482. '\u3240': '\u0028\u796D\u0029',
  24483. '\u3241': '\u0028\u4F11\u0029',
  24484. '\u3242': '\u0028\u81EA\u0029',
  24485. '\u3243': '\u0028\u81F3\u0029',
  24486. '\u32C0': '\u0031\u6708',
  24487. '\u32C1': '\u0032\u6708',
  24488. '\u32C2': '\u0033\u6708',
  24489. '\u32C3': '\u0034\u6708',
  24490. '\u32C4': '\u0035\u6708',
  24491. '\u32C5': '\u0036\u6708',
  24492. '\u32C6': '\u0037\u6708',
  24493. '\u32C7': '\u0038\u6708',
  24494. '\u32C8': '\u0039\u6708',
  24495. '\u32C9': '\u0031\u0030\u6708',
  24496. '\u32CA': '\u0031\u0031\u6708',
  24497. '\u32CB': '\u0031\u0032\u6708',
  24498. '\u3358': '\u0030\u70B9',
  24499. '\u3359': '\u0031\u70B9',
  24500. '\u335A': '\u0032\u70B9',
  24501. '\u335B': '\u0033\u70B9',
  24502. '\u335C': '\u0034\u70B9',
  24503. '\u335D': '\u0035\u70B9',
  24504. '\u335E': '\u0036\u70B9',
  24505. '\u335F': '\u0037\u70B9',
  24506. '\u3360': '\u0038\u70B9',
  24507. '\u3361': '\u0039\u70B9',
  24508. '\u3362': '\u0031\u0030\u70B9',
  24509. '\u3363': '\u0031\u0031\u70B9',
  24510. '\u3364': '\u0031\u0032\u70B9',
  24511. '\u3365': '\u0031\u0033\u70B9',
  24512. '\u3366': '\u0031\u0034\u70B9',
  24513. '\u3367': '\u0031\u0035\u70B9',
  24514. '\u3368': '\u0031\u0036\u70B9',
  24515. '\u3369': '\u0031\u0037\u70B9',
  24516. '\u336A': '\u0031\u0038\u70B9',
  24517. '\u336B': '\u0031\u0039\u70B9',
  24518. '\u336C': '\u0032\u0030\u70B9',
  24519. '\u336D': '\u0032\u0031\u70B9',
  24520. '\u336E': '\u0032\u0032\u70B9',
  24521. '\u336F': '\u0032\u0033\u70B9',
  24522. '\u3370': '\u0032\u0034\u70B9',
  24523. '\u33E0': '\u0031\u65E5',
  24524. '\u33E1': '\u0032\u65E5',
  24525. '\u33E2': '\u0033\u65E5',
  24526. '\u33E3': '\u0034\u65E5',
  24527. '\u33E4': '\u0035\u65E5',
  24528. '\u33E5': '\u0036\u65E5',
  24529. '\u33E6': '\u0037\u65E5',
  24530. '\u33E7': '\u0038\u65E5',
  24531. '\u33E8': '\u0039\u65E5',
  24532. '\u33E9': '\u0031\u0030\u65E5',
  24533. '\u33EA': '\u0031\u0031\u65E5',
  24534. '\u33EB': '\u0031\u0032\u65E5',
  24535. '\u33EC': '\u0031\u0033\u65E5',
  24536. '\u33ED': '\u0031\u0034\u65E5',
  24537. '\u33EE': '\u0031\u0035\u65E5',
  24538. '\u33EF': '\u0031\u0036\u65E5',
  24539. '\u33F0': '\u0031\u0037\u65E5',
  24540. '\u33F1': '\u0031\u0038\u65E5',
  24541. '\u33F2': '\u0031\u0039\u65E5',
  24542. '\u33F3': '\u0032\u0030\u65E5',
  24543. '\u33F4': '\u0032\u0031\u65E5',
  24544. '\u33F5': '\u0032\u0032\u65E5',
  24545. '\u33F6': '\u0032\u0033\u65E5',
  24546. '\u33F7': '\u0032\u0034\u65E5',
  24547. '\u33F8': '\u0032\u0035\u65E5',
  24548. '\u33F9': '\u0032\u0036\u65E5',
  24549. '\u33FA': '\u0032\u0037\u65E5',
  24550. '\u33FB': '\u0032\u0038\u65E5',
  24551. '\u33FC': '\u0032\u0039\u65E5',
  24552. '\u33FD': '\u0033\u0030\u65E5',
  24553. '\u33FE': '\u0033\u0031\u65E5',
  24554. '\uFB00': '\u0066\u0066',
  24555. '\uFB01': '\u0066\u0069',
  24556. '\uFB02': '\u0066\u006C',
  24557. '\uFB03': '\u0066\u0066\u0069',
  24558. '\uFB04': '\u0066\u0066\u006C',
  24559. '\uFB05': '\u017F\u0074',
  24560. '\uFB06': '\u0073\u0074',
  24561. '\uFB13': '\u0574\u0576',
  24562. '\uFB14': '\u0574\u0565',
  24563. '\uFB15': '\u0574\u056B',
  24564. '\uFB16': '\u057E\u0576',
  24565. '\uFB17': '\u0574\u056D',
  24566. '\uFB4F': '\u05D0\u05DC',
  24567. '\uFB50': '\u0671',
  24568. '\uFB51': '\u0671',
  24569. '\uFB52': '\u067B',
  24570. '\uFB53': '\u067B',
  24571. '\uFB54': '\u067B',
  24572. '\uFB55': '\u067B',
  24573. '\uFB56': '\u067E',
  24574. '\uFB57': '\u067E',
  24575. '\uFB58': '\u067E',
  24576. '\uFB59': '\u067E',
  24577. '\uFB5A': '\u0680',
  24578. '\uFB5B': '\u0680',
  24579. '\uFB5C': '\u0680',
  24580. '\uFB5D': '\u0680',
  24581. '\uFB5E': '\u067A',
  24582. '\uFB5F': '\u067A',
  24583. '\uFB60': '\u067A',
  24584. '\uFB61': '\u067A',
  24585. '\uFB62': '\u067F',
  24586. '\uFB63': '\u067F',
  24587. '\uFB64': '\u067F',
  24588. '\uFB65': '\u067F',
  24589. '\uFB66': '\u0679',
  24590. '\uFB67': '\u0679',
  24591. '\uFB68': '\u0679',
  24592. '\uFB69': '\u0679',
  24593. '\uFB6A': '\u06A4',
  24594. '\uFB6B': '\u06A4',
  24595. '\uFB6C': '\u06A4',
  24596. '\uFB6D': '\u06A4',
  24597. '\uFB6E': '\u06A6',
  24598. '\uFB6F': '\u06A6',
  24599. '\uFB70': '\u06A6',
  24600. '\uFB71': '\u06A6',
  24601. '\uFB72': '\u0684',
  24602. '\uFB73': '\u0684',
  24603. '\uFB74': '\u0684',
  24604. '\uFB75': '\u0684',
  24605. '\uFB76': '\u0683',
  24606. '\uFB77': '\u0683',
  24607. '\uFB78': '\u0683',
  24608. '\uFB79': '\u0683',
  24609. '\uFB7A': '\u0686',
  24610. '\uFB7B': '\u0686',
  24611. '\uFB7C': '\u0686',
  24612. '\uFB7D': '\u0686',
  24613. '\uFB7E': '\u0687',
  24614. '\uFB7F': '\u0687',
  24615. '\uFB80': '\u0687',
  24616. '\uFB81': '\u0687',
  24617. '\uFB82': '\u068D',
  24618. '\uFB83': '\u068D',
  24619. '\uFB84': '\u068C',
  24620. '\uFB85': '\u068C',
  24621. '\uFB86': '\u068E',
  24622. '\uFB87': '\u068E',
  24623. '\uFB88': '\u0688',
  24624. '\uFB89': '\u0688',
  24625. '\uFB8A': '\u0698',
  24626. '\uFB8B': '\u0698',
  24627. '\uFB8C': '\u0691',
  24628. '\uFB8D': '\u0691',
  24629. '\uFB8E': '\u06A9',
  24630. '\uFB8F': '\u06A9',
  24631. '\uFB90': '\u06A9',
  24632. '\uFB91': '\u06A9',
  24633. '\uFB92': '\u06AF',
  24634. '\uFB93': '\u06AF',
  24635. '\uFB94': '\u06AF',
  24636. '\uFB95': '\u06AF',
  24637. '\uFB96': '\u06B3',
  24638. '\uFB97': '\u06B3',
  24639. '\uFB98': '\u06B3',
  24640. '\uFB99': '\u06B3',
  24641. '\uFB9A': '\u06B1',
  24642. '\uFB9B': '\u06B1',
  24643. '\uFB9C': '\u06B1',
  24644. '\uFB9D': '\u06B1',
  24645. '\uFB9E': '\u06BA',
  24646. '\uFB9F': '\u06BA',
  24647. '\uFBA0': '\u06BB',
  24648. '\uFBA1': '\u06BB',
  24649. '\uFBA2': '\u06BB',
  24650. '\uFBA3': '\u06BB',
  24651. '\uFBA4': '\u06C0',
  24652. '\uFBA5': '\u06C0',
  24653. '\uFBA6': '\u06C1',
  24654. '\uFBA7': '\u06C1',
  24655. '\uFBA8': '\u06C1',
  24656. '\uFBA9': '\u06C1',
  24657. '\uFBAA': '\u06BE',
  24658. '\uFBAB': '\u06BE',
  24659. '\uFBAC': '\u06BE',
  24660. '\uFBAD': '\u06BE',
  24661. '\uFBAE': '\u06D2',
  24662. '\uFBAF': '\u06D2',
  24663. '\uFBB0': '\u06D3',
  24664. '\uFBB1': '\u06D3',
  24665. '\uFBD3': '\u06AD',
  24666. '\uFBD4': '\u06AD',
  24667. '\uFBD5': '\u06AD',
  24668. '\uFBD6': '\u06AD',
  24669. '\uFBD7': '\u06C7',
  24670. '\uFBD8': '\u06C7',
  24671. '\uFBD9': '\u06C6',
  24672. '\uFBDA': '\u06C6',
  24673. '\uFBDB': '\u06C8',
  24674. '\uFBDC': '\u06C8',
  24675. '\uFBDD': '\u0677',
  24676. '\uFBDE': '\u06CB',
  24677. '\uFBDF': '\u06CB',
  24678. '\uFBE0': '\u06C5',
  24679. '\uFBE1': '\u06C5',
  24680. '\uFBE2': '\u06C9',
  24681. '\uFBE3': '\u06C9',
  24682. '\uFBE4': '\u06D0',
  24683. '\uFBE5': '\u06D0',
  24684. '\uFBE6': '\u06D0',
  24685. '\uFBE7': '\u06D0',
  24686. '\uFBE8': '\u0649',
  24687. '\uFBE9': '\u0649',
  24688. '\uFBEA': '\u0626\u0627',
  24689. '\uFBEB': '\u0626\u0627',
  24690. '\uFBEC': '\u0626\u06D5',
  24691. '\uFBED': '\u0626\u06D5',
  24692. '\uFBEE': '\u0626\u0648',
  24693. '\uFBEF': '\u0626\u0648',
  24694. '\uFBF0': '\u0626\u06C7',
  24695. '\uFBF1': '\u0626\u06C7',
  24696. '\uFBF2': '\u0626\u06C6',
  24697. '\uFBF3': '\u0626\u06C6',
  24698. '\uFBF4': '\u0626\u06C8',
  24699. '\uFBF5': '\u0626\u06C8',
  24700. '\uFBF6': '\u0626\u06D0',
  24701. '\uFBF7': '\u0626\u06D0',
  24702. '\uFBF8': '\u0626\u06D0',
  24703. '\uFBF9': '\u0626\u0649',
  24704. '\uFBFA': '\u0626\u0649',
  24705. '\uFBFB': '\u0626\u0649',
  24706. '\uFBFC': '\u06CC',
  24707. '\uFBFD': '\u06CC',
  24708. '\uFBFE': '\u06CC',
  24709. '\uFBFF': '\u06CC',
  24710. '\uFC00': '\u0626\u062C',
  24711. '\uFC01': '\u0626\u062D',
  24712. '\uFC02': '\u0626\u0645',
  24713. '\uFC03': '\u0626\u0649',
  24714. '\uFC04': '\u0626\u064A',
  24715. '\uFC05': '\u0628\u062C',
  24716. '\uFC06': '\u0628\u062D',
  24717. '\uFC07': '\u0628\u062E',
  24718. '\uFC08': '\u0628\u0645',
  24719. '\uFC09': '\u0628\u0649',
  24720. '\uFC0A': '\u0628\u064A',
  24721. '\uFC0B': '\u062A\u062C',
  24722. '\uFC0C': '\u062A\u062D',
  24723. '\uFC0D': '\u062A\u062E',
  24724. '\uFC0E': '\u062A\u0645',
  24725. '\uFC0F': '\u062A\u0649',
  24726. '\uFC10': '\u062A\u064A',
  24727. '\uFC11': '\u062B\u062C',
  24728. '\uFC12': '\u062B\u0645',
  24729. '\uFC13': '\u062B\u0649',
  24730. '\uFC14': '\u062B\u064A',
  24731. '\uFC15': '\u062C\u062D',
  24732. '\uFC16': '\u062C\u0645',
  24733. '\uFC17': '\u062D\u062C',
  24734. '\uFC18': '\u062D\u0645',
  24735. '\uFC19': '\u062E\u062C',
  24736. '\uFC1A': '\u062E\u062D',
  24737. '\uFC1B': '\u062E\u0645',
  24738. '\uFC1C': '\u0633\u062C',
  24739. '\uFC1D': '\u0633\u062D',
  24740. '\uFC1E': '\u0633\u062E',
  24741. '\uFC1F': '\u0633\u0645',
  24742. '\uFC20': '\u0635\u062D',
  24743. '\uFC21': '\u0635\u0645',
  24744. '\uFC22': '\u0636\u062C',
  24745. '\uFC23': '\u0636\u062D',
  24746. '\uFC24': '\u0636\u062E',
  24747. '\uFC25': '\u0636\u0645',
  24748. '\uFC26': '\u0637\u062D',
  24749. '\uFC27': '\u0637\u0645',
  24750. '\uFC28': '\u0638\u0645',
  24751. '\uFC29': '\u0639\u062C',
  24752. '\uFC2A': '\u0639\u0645',
  24753. '\uFC2B': '\u063A\u062C',
  24754. '\uFC2C': '\u063A\u0645',
  24755. '\uFC2D': '\u0641\u062C',
  24756. '\uFC2E': '\u0641\u062D',
  24757. '\uFC2F': '\u0641\u062E',
  24758. '\uFC30': '\u0641\u0645',
  24759. '\uFC31': '\u0641\u0649',
  24760. '\uFC32': '\u0641\u064A',
  24761. '\uFC33': '\u0642\u062D',
  24762. '\uFC34': '\u0642\u0645',
  24763. '\uFC35': '\u0642\u0649',
  24764. '\uFC36': '\u0642\u064A',
  24765. '\uFC37': '\u0643\u0627',
  24766. '\uFC38': '\u0643\u062C',
  24767. '\uFC39': '\u0643\u062D',
  24768. '\uFC3A': '\u0643\u062E',
  24769. '\uFC3B': '\u0643\u0644',
  24770. '\uFC3C': '\u0643\u0645',
  24771. '\uFC3D': '\u0643\u0649',
  24772. '\uFC3E': '\u0643\u064A',
  24773. '\uFC3F': '\u0644\u062C',
  24774. '\uFC40': '\u0644\u062D',
  24775. '\uFC41': '\u0644\u062E',
  24776. '\uFC42': '\u0644\u0645',
  24777. '\uFC43': '\u0644\u0649',
  24778. '\uFC44': '\u0644\u064A',
  24779. '\uFC45': '\u0645\u062C',
  24780. '\uFC46': '\u0645\u062D',
  24781. '\uFC47': '\u0645\u062E',
  24782. '\uFC48': '\u0645\u0645',
  24783. '\uFC49': '\u0645\u0649',
  24784. '\uFC4A': '\u0645\u064A',
  24785. '\uFC4B': '\u0646\u062C',
  24786. '\uFC4C': '\u0646\u062D',
  24787. '\uFC4D': '\u0646\u062E',
  24788. '\uFC4E': '\u0646\u0645',
  24789. '\uFC4F': '\u0646\u0649',
  24790. '\uFC50': '\u0646\u064A',
  24791. '\uFC51': '\u0647\u062C',
  24792. '\uFC52': '\u0647\u0645',
  24793. '\uFC53': '\u0647\u0649',
  24794. '\uFC54': '\u0647\u064A',
  24795. '\uFC55': '\u064A\u062C',
  24796. '\uFC56': '\u064A\u062D',
  24797. '\uFC57': '\u064A\u062E',
  24798. '\uFC58': '\u064A\u0645',
  24799. '\uFC59': '\u064A\u0649',
  24800. '\uFC5A': '\u064A\u064A',
  24801. '\uFC5B': '\u0630\u0670',
  24802. '\uFC5C': '\u0631\u0670',
  24803. '\uFC5D': '\u0649\u0670',
  24804. '\uFC5E': '\u0020\u064C\u0651',
  24805. '\uFC5F': '\u0020\u064D\u0651',
  24806. '\uFC60': '\u0020\u064E\u0651',
  24807. '\uFC61': '\u0020\u064F\u0651',
  24808. '\uFC62': '\u0020\u0650\u0651',
  24809. '\uFC63': '\u0020\u0651\u0670',
  24810. '\uFC64': '\u0626\u0631',
  24811. '\uFC65': '\u0626\u0632',
  24812. '\uFC66': '\u0626\u0645',
  24813. '\uFC67': '\u0626\u0646',
  24814. '\uFC68': '\u0626\u0649',
  24815. '\uFC69': '\u0626\u064A',
  24816. '\uFC6A': '\u0628\u0631',
  24817. '\uFC6B': '\u0628\u0632',
  24818. '\uFC6C': '\u0628\u0645',
  24819. '\uFC6D': '\u0628\u0646',
  24820. '\uFC6E': '\u0628\u0649',
  24821. '\uFC6F': '\u0628\u064A',
  24822. '\uFC70': '\u062A\u0631',
  24823. '\uFC71': '\u062A\u0632',
  24824. '\uFC72': '\u062A\u0645',
  24825. '\uFC73': '\u062A\u0646',
  24826. '\uFC74': '\u062A\u0649',
  24827. '\uFC75': '\u062A\u064A',
  24828. '\uFC76': '\u062B\u0631',
  24829. '\uFC77': '\u062B\u0632',
  24830. '\uFC78': '\u062B\u0645',
  24831. '\uFC79': '\u062B\u0646',
  24832. '\uFC7A': '\u062B\u0649',
  24833. '\uFC7B': '\u062B\u064A',
  24834. '\uFC7C': '\u0641\u0649',
  24835. '\uFC7D': '\u0641\u064A',
  24836. '\uFC7E': '\u0642\u0649',
  24837. '\uFC7F': '\u0642\u064A',
  24838. '\uFC80': '\u0643\u0627',
  24839. '\uFC81': '\u0643\u0644',
  24840. '\uFC82': '\u0643\u0645',
  24841. '\uFC83': '\u0643\u0649',
  24842. '\uFC84': '\u0643\u064A',
  24843. '\uFC85': '\u0644\u0645',
  24844. '\uFC86': '\u0644\u0649',
  24845. '\uFC87': '\u0644\u064A',
  24846. '\uFC88': '\u0645\u0627',
  24847. '\uFC89': '\u0645\u0645',
  24848. '\uFC8A': '\u0646\u0631',
  24849. '\uFC8B': '\u0646\u0632',
  24850. '\uFC8C': '\u0646\u0645',
  24851. '\uFC8D': '\u0646\u0646',
  24852. '\uFC8E': '\u0646\u0649',
  24853. '\uFC8F': '\u0646\u064A',
  24854. '\uFC90': '\u0649\u0670',
  24855. '\uFC91': '\u064A\u0631',
  24856. '\uFC92': '\u064A\u0632',
  24857. '\uFC93': '\u064A\u0645',
  24858. '\uFC94': '\u064A\u0646',
  24859. '\uFC95': '\u064A\u0649',
  24860. '\uFC96': '\u064A\u064A',
  24861. '\uFC97': '\u0626\u062C',
  24862. '\uFC98': '\u0626\u062D',
  24863. '\uFC99': '\u0626\u062E',
  24864. '\uFC9A': '\u0626\u0645',
  24865. '\uFC9B': '\u0626\u0647',
  24866. '\uFC9C': '\u0628\u062C',
  24867. '\uFC9D': '\u0628\u062D',
  24868. '\uFC9E': '\u0628\u062E',
  24869. '\uFC9F': '\u0628\u0645',
  24870. '\uFCA0': '\u0628\u0647',
  24871. '\uFCA1': '\u062A\u062C',
  24872. '\uFCA2': '\u062A\u062D',
  24873. '\uFCA3': '\u062A\u062E',
  24874. '\uFCA4': '\u062A\u0645',
  24875. '\uFCA5': '\u062A\u0647',
  24876. '\uFCA6': '\u062B\u0645',
  24877. '\uFCA7': '\u062C\u062D',
  24878. '\uFCA8': '\u062C\u0645',
  24879. '\uFCA9': '\u062D\u062C',
  24880. '\uFCAA': '\u062D\u0645',
  24881. '\uFCAB': '\u062E\u062C',
  24882. '\uFCAC': '\u062E\u0645',
  24883. '\uFCAD': '\u0633\u062C',
  24884. '\uFCAE': '\u0633\u062D',
  24885. '\uFCAF': '\u0633\u062E',
  24886. '\uFCB0': '\u0633\u0645',
  24887. '\uFCB1': '\u0635\u062D',
  24888. '\uFCB2': '\u0635\u062E',
  24889. '\uFCB3': '\u0635\u0645',
  24890. '\uFCB4': '\u0636\u062C',
  24891. '\uFCB5': '\u0636\u062D',
  24892. '\uFCB6': '\u0636\u062E',
  24893. '\uFCB7': '\u0636\u0645',
  24894. '\uFCB8': '\u0637\u062D',
  24895. '\uFCB9': '\u0638\u0645',
  24896. '\uFCBA': '\u0639\u062C',
  24897. '\uFCBB': '\u0639\u0645',
  24898. '\uFCBC': '\u063A\u062C',
  24899. '\uFCBD': '\u063A\u0645',
  24900. '\uFCBE': '\u0641\u062C',
  24901. '\uFCBF': '\u0641\u062D',
  24902. '\uFCC0': '\u0641\u062E',
  24903. '\uFCC1': '\u0641\u0645',
  24904. '\uFCC2': '\u0642\u062D',
  24905. '\uFCC3': '\u0642\u0645',
  24906. '\uFCC4': '\u0643\u062C',
  24907. '\uFCC5': '\u0643\u062D',
  24908. '\uFCC6': '\u0643\u062E',
  24909. '\uFCC7': '\u0643\u0644',
  24910. '\uFCC8': '\u0643\u0645',
  24911. '\uFCC9': '\u0644\u062C',
  24912. '\uFCCA': '\u0644\u062D',
  24913. '\uFCCB': '\u0644\u062E',
  24914. '\uFCCC': '\u0644\u0645',
  24915. '\uFCCD': '\u0644\u0647',
  24916. '\uFCCE': '\u0645\u062C',
  24917. '\uFCCF': '\u0645\u062D',
  24918. '\uFCD0': '\u0645\u062E',
  24919. '\uFCD1': '\u0645\u0645',
  24920. '\uFCD2': '\u0646\u062C',
  24921. '\uFCD3': '\u0646\u062D',
  24922. '\uFCD4': '\u0646\u062E',
  24923. '\uFCD5': '\u0646\u0645',
  24924. '\uFCD6': '\u0646\u0647',
  24925. '\uFCD7': '\u0647\u062C',
  24926. '\uFCD8': '\u0647\u0645',
  24927. '\uFCD9': '\u0647\u0670',
  24928. '\uFCDA': '\u064A\u062C',
  24929. '\uFCDB': '\u064A\u062D',
  24930. '\uFCDC': '\u064A\u062E',
  24931. '\uFCDD': '\u064A\u0645',
  24932. '\uFCDE': '\u064A\u0647',
  24933. '\uFCDF': '\u0626\u0645',
  24934. '\uFCE0': '\u0626\u0647',
  24935. '\uFCE1': '\u0628\u0645',
  24936. '\uFCE2': '\u0628\u0647',
  24937. '\uFCE3': '\u062A\u0645',
  24938. '\uFCE4': '\u062A\u0647',
  24939. '\uFCE5': '\u062B\u0645',
  24940. '\uFCE6': '\u062B\u0647',
  24941. '\uFCE7': '\u0633\u0645',
  24942. '\uFCE8': '\u0633\u0647',
  24943. '\uFCE9': '\u0634\u0645',
  24944. '\uFCEA': '\u0634\u0647',
  24945. '\uFCEB': '\u0643\u0644',
  24946. '\uFCEC': '\u0643\u0645',
  24947. '\uFCED': '\u0644\u0645',
  24948. '\uFCEE': '\u0646\u0645',
  24949. '\uFCEF': '\u0646\u0647',
  24950. '\uFCF0': '\u064A\u0645',
  24951. '\uFCF1': '\u064A\u0647',
  24952. '\uFCF2': '\u0640\u064E\u0651',
  24953. '\uFCF3': '\u0640\u064F\u0651',
  24954. '\uFCF4': '\u0640\u0650\u0651',
  24955. '\uFCF5': '\u0637\u0649',
  24956. '\uFCF6': '\u0637\u064A',
  24957. '\uFCF7': '\u0639\u0649',
  24958. '\uFCF8': '\u0639\u064A',
  24959. '\uFCF9': '\u063A\u0649',
  24960. '\uFCFA': '\u063A\u064A',
  24961. '\uFCFB': '\u0633\u0649',
  24962. '\uFCFC': '\u0633\u064A',
  24963. '\uFCFD': '\u0634\u0649',
  24964. '\uFCFE': '\u0634\u064A',
  24965. '\uFCFF': '\u062D\u0649',
  24966. '\uFD00': '\u062D\u064A',
  24967. '\uFD01': '\u062C\u0649',
  24968. '\uFD02': '\u062C\u064A',
  24969. '\uFD03': '\u062E\u0649',
  24970. '\uFD04': '\u062E\u064A',
  24971. '\uFD05': '\u0635\u0649',
  24972. '\uFD06': '\u0635\u064A',
  24973. '\uFD07': '\u0636\u0649',
  24974. '\uFD08': '\u0636\u064A',
  24975. '\uFD09': '\u0634\u062C',
  24976. '\uFD0A': '\u0634\u062D',
  24977. '\uFD0B': '\u0634\u062E',
  24978. '\uFD0C': '\u0634\u0645',
  24979. '\uFD0D': '\u0634\u0631',
  24980. '\uFD0E': '\u0633\u0631',
  24981. '\uFD0F': '\u0635\u0631',
  24982. '\uFD10': '\u0636\u0631',
  24983. '\uFD11': '\u0637\u0649',
  24984. '\uFD12': '\u0637\u064A',
  24985. '\uFD13': '\u0639\u0649',
  24986. '\uFD14': '\u0639\u064A',
  24987. '\uFD15': '\u063A\u0649',
  24988. '\uFD16': '\u063A\u064A',
  24989. '\uFD17': '\u0633\u0649',
  24990. '\uFD18': '\u0633\u064A',
  24991. '\uFD19': '\u0634\u0649',
  24992. '\uFD1A': '\u0634\u064A',
  24993. '\uFD1B': '\u062D\u0649',
  24994. '\uFD1C': '\u062D\u064A',
  24995. '\uFD1D': '\u062C\u0649',
  24996. '\uFD1E': '\u062C\u064A',
  24997. '\uFD1F': '\u062E\u0649',
  24998. '\uFD20': '\u062E\u064A',
  24999. '\uFD21': '\u0635\u0649',
  25000. '\uFD22': '\u0635\u064A',
  25001. '\uFD23': '\u0636\u0649',
  25002. '\uFD24': '\u0636\u064A',
  25003. '\uFD25': '\u0634\u062C',
  25004. '\uFD26': '\u0634\u062D',
  25005. '\uFD27': '\u0634\u062E',
  25006. '\uFD28': '\u0634\u0645',
  25007. '\uFD29': '\u0634\u0631',
  25008. '\uFD2A': '\u0633\u0631',
  25009. '\uFD2B': '\u0635\u0631',
  25010. '\uFD2C': '\u0636\u0631',
  25011. '\uFD2D': '\u0634\u062C',
  25012. '\uFD2E': '\u0634\u062D',
  25013. '\uFD2F': '\u0634\u062E',
  25014. '\uFD30': '\u0634\u0645',
  25015. '\uFD31': '\u0633\u0647',
  25016. '\uFD32': '\u0634\u0647',
  25017. '\uFD33': '\u0637\u0645',
  25018. '\uFD34': '\u0633\u062C',
  25019. '\uFD35': '\u0633\u062D',
  25020. '\uFD36': '\u0633\u062E',
  25021. '\uFD37': '\u0634\u062C',
  25022. '\uFD38': '\u0634\u062D',
  25023. '\uFD39': '\u0634\u062E',
  25024. '\uFD3A': '\u0637\u0645',
  25025. '\uFD3B': '\u0638\u0645',
  25026. '\uFD3C': '\u0627\u064B',
  25027. '\uFD3D': '\u0627\u064B',
  25028. '\uFD50': '\u062A\u062C\u0645',
  25029. '\uFD51': '\u062A\u062D\u062C',
  25030. '\uFD52': '\u062A\u062D\u062C',
  25031. '\uFD53': '\u062A\u062D\u0645',
  25032. '\uFD54': '\u062A\u062E\u0645',
  25033. '\uFD55': '\u062A\u0645\u062C',
  25034. '\uFD56': '\u062A\u0645\u062D',
  25035. '\uFD57': '\u062A\u0645\u062E',
  25036. '\uFD58': '\u062C\u0645\u062D',
  25037. '\uFD59': '\u062C\u0645\u062D',
  25038. '\uFD5A': '\u062D\u0645\u064A',
  25039. '\uFD5B': '\u062D\u0645\u0649',
  25040. '\uFD5C': '\u0633\u062D\u062C',
  25041. '\uFD5D': '\u0633\u062C\u062D',
  25042. '\uFD5E': '\u0633\u062C\u0649',
  25043. '\uFD5F': '\u0633\u0645\u062D',
  25044. '\uFD60': '\u0633\u0645\u062D',
  25045. '\uFD61': '\u0633\u0645\u062C',
  25046. '\uFD62': '\u0633\u0645\u0645',
  25047. '\uFD63': '\u0633\u0645\u0645',
  25048. '\uFD64': '\u0635\u062D\u062D',
  25049. '\uFD65': '\u0635\u062D\u062D',
  25050. '\uFD66': '\u0635\u0645\u0645',
  25051. '\uFD67': '\u0634\u062D\u0645',
  25052. '\uFD68': '\u0634\u062D\u0645',
  25053. '\uFD69': '\u0634\u062C\u064A',
  25054. '\uFD6A': '\u0634\u0645\u062E',
  25055. '\uFD6B': '\u0634\u0645\u062E',
  25056. '\uFD6C': '\u0634\u0645\u0645',
  25057. '\uFD6D': '\u0634\u0645\u0645',
  25058. '\uFD6E': '\u0636\u062D\u0649',
  25059. '\uFD6F': '\u0636\u062E\u0645',
  25060. '\uFD70': '\u0636\u062E\u0645',
  25061. '\uFD71': '\u0637\u0645\u062D',
  25062. '\uFD72': '\u0637\u0645\u062D',
  25063. '\uFD73': '\u0637\u0645\u0645',
  25064. '\uFD74': '\u0637\u0645\u064A',
  25065. '\uFD75': '\u0639\u062C\u0645',
  25066. '\uFD76': '\u0639\u0645\u0645',
  25067. '\uFD77': '\u0639\u0645\u0645',
  25068. '\uFD78': '\u0639\u0645\u0649',
  25069. '\uFD79': '\u063A\u0645\u0645',
  25070. '\uFD7A': '\u063A\u0645\u064A',
  25071. '\uFD7B': '\u063A\u0645\u0649',
  25072. '\uFD7C': '\u0641\u062E\u0645',
  25073. '\uFD7D': '\u0641\u062E\u0645',
  25074. '\uFD7E': '\u0642\u0645\u062D',
  25075. '\uFD7F': '\u0642\u0645\u0645',
  25076. '\uFD80': '\u0644\u062D\u0645',
  25077. '\uFD81': '\u0644\u062D\u064A',
  25078. '\uFD82': '\u0644\u062D\u0649',
  25079. '\uFD83': '\u0644\u062C\u062C',
  25080. '\uFD84': '\u0644\u062C\u062C',
  25081. '\uFD85': '\u0644\u062E\u0645',
  25082. '\uFD86': '\u0644\u062E\u0645',
  25083. '\uFD87': '\u0644\u0645\u062D',
  25084. '\uFD88': '\u0644\u0645\u062D',
  25085. '\uFD89': '\u0645\u062D\u062C',
  25086. '\uFD8A': '\u0645\u062D\u0645',
  25087. '\uFD8B': '\u0645\u062D\u064A',
  25088. '\uFD8C': '\u0645\u062C\u062D',
  25089. '\uFD8D': '\u0645\u062C\u0645',
  25090. '\uFD8E': '\u0645\u062E\u062C',
  25091. '\uFD8F': '\u0645\u062E\u0645',
  25092. '\uFD92': '\u0645\u062C\u062E',
  25093. '\uFD93': '\u0647\u0645\u062C',
  25094. '\uFD94': '\u0647\u0645\u0645',
  25095. '\uFD95': '\u0646\u062D\u0645',
  25096. '\uFD96': '\u0646\u062D\u0649',
  25097. '\uFD97': '\u0646\u062C\u0645',
  25098. '\uFD98': '\u0646\u062C\u0645',
  25099. '\uFD99': '\u0646\u062C\u0649',
  25100. '\uFD9A': '\u0646\u0645\u064A',
  25101. '\uFD9B': '\u0646\u0645\u0649',
  25102. '\uFD9C': '\u064A\u0645\u0645',
  25103. '\uFD9D': '\u064A\u0645\u0645',
  25104. '\uFD9E': '\u0628\u062E\u064A',
  25105. '\uFD9F': '\u062A\u062C\u064A',
  25106. '\uFDA0': '\u062A\u062C\u0649',
  25107. '\uFDA1': '\u062A\u062E\u064A',
  25108. '\uFDA2': '\u062A\u062E\u0649',
  25109. '\uFDA3': '\u062A\u0645\u064A',
  25110. '\uFDA4': '\u062A\u0645\u0649',
  25111. '\uFDA5': '\u062C\u0645\u064A',
  25112. '\uFDA6': '\u062C\u062D\u0649',
  25113. '\uFDA7': '\u062C\u0645\u0649',
  25114. '\uFDA8': '\u0633\u062E\u0649',
  25115. '\uFDA9': '\u0635\u062D\u064A',
  25116. '\uFDAA': '\u0634\u062D\u064A',
  25117. '\uFDAB': '\u0636\u062D\u064A',
  25118. '\uFDAC': '\u0644\u062C\u064A',
  25119. '\uFDAD': '\u0644\u0645\u064A',
  25120. '\uFDAE': '\u064A\u062D\u064A',
  25121. '\uFDAF': '\u064A\u062C\u064A',
  25122. '\uFDB0': '\u064A\u0645\u064A',
  25123. '\uFDB1': '\u0645\u0645\u064A',
  25124. '\uFDB2': '\u0642\u0645\u064A',
  25125. '\uFDB3': '\u0646\u062D\u064A',
  25126. '\uFDB4': '\u0642\u0645\u062D',
  25127. '\uFDB5': '\u0644\u062D\u0645',
  25128. '\uFDB6': '\u0639\u0645\u064A',
  25129. '\uFDB7': '\u0643\u0645\u064A',
  25130. '\uFDB8': '\u0646\u062C\u062D',
  25131. '\uFDB9': '\u0645\u062E\u064A',
  25132. '\uFDBA': '\u0644\u062C\u0645',
  25133. '\uFDBB': '\u0643\u0645\u0645',
  25134. '\uFDBC': '\u0644\u062C\u0645',
  25135. '\uFDBD': '\u0646\u062C\u062D',
  25136. '\uFDBE': '\u062C\u062D\u064A',
  25137. '\uFDBF': '\u062D\u062C\u064A',
  25138. '\uFDC0': '\u0645\u062C\u064A',
  25139. '\uFDC1': '\u0641\u0645\u064A',
  25140. '\uFDC2': '\u0628\u062D\u064A',
  25141. '\uFDC3': '\u0643\u0645\u0645',
  25142. '\uFDC4': '\u0639\u062C\u0645',
  25143. '\uFDC5': '\u0635\u0645\u0645',
  25144. '\uFDC6': '\u0633\u062E\u064A',
  25145. '\uFDC7': '\u0646\u062C\u064A',
  25146. '\uFE49': '\u203E',
  25147. '\uFE4A': '\u203E',
  25148. '\uFE4B': '\u203E',
  25149. '\uFE4C': '\u203E',
  25150. '\uFE4D': '\u005F',
  25151. '\uFE4E': '\u005F',
  25152. '\uFE4F': '\u005F',
  25153. '\uFE80': '\u0621',
  25154. '\uFE81': '\u0622',
  25155. '\uFE82': '\u0622',
  25156. '\uFE83': '\u0623',
  25157. '\uFE84': '\u0623',
  25158. '\uFE85': '\u0624',
  25159. '\uFE86': '\u0624',
  25160. '\uFE87': '\u0625',
  25161. '\uFE88': '\u0625',
  25162. '\uFE89': '\u0626',
  25163. '\uFE8A': '\u0626',
  25164. '\uFE8B': '\u0626',
  25165. '\uFE8C': '\u0626',
  25166. '\uFE8D': '\u0627',
  25167. '\uFE8E': '\u0627',
  25168. '\uFE8F': '\u0628',
  25169. '\uFE90': '\u0628',
  25170. '\uFE91': '\u0628',
  25171. '\uFE92': '\u0628',
  25172. '\uFE93': '\u0629',
  25173. '\uFE94': '\u0629',
  25174. '\uFE95': '\u062A',
  25175. '\uFE96': '\u062A',
  25176. '\uFE97': '\u062A',
  25177. '\uFE98': '\u062A',
  25178. '\uFE99': '\u062B',
  25179. '\uFE9A': '\u062B',
  25180. '\uFE9B': '\u062B',
  25181. '\uFE9C': '\u062B',
  25182. '\uFE9D': '\u062C',
  25183. '\uFE9E': '\u062C',
  25184. '\uFE9F': '\u062C',
  25185. '\uFEA0': '\u062C',
  25186. '\uFEA1': '\u062D',
  25187. '\uFEA2': '\u062D',
  25188. '\uFEA3': '\u062D',
  25189. '\uFEA4': '\u062D',
  25190. '\uFEA5': '\u062E',
  25191. '\uFEA6': '\u062E',
  25192. '\uFEA7': '\u062E',
  25193. '\uFEA8': '\u062E',
  25194. '\uFEA9': '\u062F',
  25195. '\uFEAA': '\u062F',
  25196. '\uFEAB': '\u0630',
  25197. '\uFEAC': '\u0630',
  25198. '\uFEAD': '\u0631',
  25199. '\uFEAE': '\u0631',
  25200. '\uFEAF': '\u0632',
  25201. '\uFEB0': '\u0632',
  25202. '\uFEB1': '\u0633',
  25203. '\uFEB2': '\u0633',
  25204. '\uFEB3': '\u0633',
  25205. '\uFEB4': '\u0633',
  25206. '\uFEB5': '\u0634',
  25207. '\uFEB6': '\u0634',
  25208. '\uFEB7': '\u0634',
  25209. '\uFEB8': '\u0634',
  25210. '\uFEB9': '\u0635',
  25211. '\uFEBA': '\u0635',
  25212. '\uFEBB': '\u0635',
  25213. '\uFEBC': '\u0635',
  25214. '\uFEBD': '\u0636',
  25215. '\uFEBE': '\u0636',
  25216. '\uFEBF': '\u0636',
  25217. '\uFEC0': '\u0636',
  25218. '\uFEC1': '\u0637',
  25219. '\uFEC2': '\u0637',
  25220. '\uFEC3': '\u0637',
  25221. '\uFEC4': '\u0637',
  25222. '\uFEC5': '\u0638',
  25223. '\uFEC6': '\u0638',
  25224. '\uFEC7': '\u0638',
  25225. '\uFEC8': '\u0638',
  25226. '\uFEC9': '\u0639',
  25227. '\uFECA': '\u0639',
  25228. '\uFECB': '\u0639',
  25229. '\uFECC': '\u0639',
  25230. '\uFECD': '\u063A',
  25231. '\uFECE': '\u063A',
  25232. '\uFECF': '\u063A',
  25233. '\uFED0': '\u063A',
  25234. '\uFED1': '\u0641',
  25235. '\uFED2': '\u0641',
  25236. '\uFED3': '\u0641',
  25237. '\uFED4': '\u0641',
  25238. '\uFED5': '\u0642',
  25239. '\uFED6': '\u0642',
  25240. '\uFED7': '\u0642',
  25241. '\uFED8': '\u0642',
  25242. '\uFED9': '\u0643',
  25243. '\uFEDA': '\u0643',
  25244. '\uFEDB': '\u0643',
  25245. '\uFEDC': '\u0643',
  25246. '\uFEDD': '\u0644',
  25247. '\uFEDE': '\u0644',
  25248. '\uFEDF': '\u0644',
  25249. '\uFEE0': '\u0644',
  25250. '\uFEE1': '\u0645',
  25251. '\uFEE2': '\u0645',
  25252. '\uFEE3': '\u0645',
  25253. '\uFEE4': '\u0645',
  25254. '\uFEE5': '\u0646',
  25255. '\uFEE6': '\u0646',
  25256. '\uFEE7': '\u0646',
  25257. '\uFEE8': '\u0646',
  25258. '\uFEE9': '\u0647',
  25259. '\uFEEA': '\u0647',
  25260. '\uFEEB': '\u0647',
  25261. '\uFEEC': '\u0647',
  25262. '\uFEED': '\u0648',
  25263. '\uFEEE': '\u0648',
  25264. '\uFEEF': '\u0649',
  25265. '\uFEF0': '\u0649',
  25266. '\uFEF1': '\u064A',
  25267. '\uFEF2': '\u064A',
  25268. '\uFEF3': '\u064A',
  25269. '\uFEF4': '\u064A',
  25270. '\uFEF5': '\u0644\u0622',
  25271. '\uFEF6': '\u0644\u0622',
  25272. '\uFEF7': '\u0644\u0623',
  25273. '\uFEF8': '\u0644\u0623',
  25274. '\uFEF9': '\u0644\u0625',
  25275. '\uFEFA': '\u0644\u0625',
  25276. '\uFEFB': '\u0644\u0627',
  25277. '\uFEFC': '\u0644\u0627'
  25278. };
  25279. function reverseIfRtl(chars) {
  25280. var charsLength = chars.length;
  25281. //reverse an arabic ligature
  25282. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  25283. return chars;
  25284. }
  25285. var s = '';
  25286. for (var ii = charsLength - 1; ii >= 0; ii--) {
  25287. s += chars[ii];
  25288. }
  25289. return s;
  25290. }
  25291. function adjustWidths(properties) {
  25292. if (!properties.fontMatrix) {
  25293. return;
  25294. }
  25295. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  25296. return;
  25297. }
  25298. // adjusting width to fontMatrix scale
  25299. var scale = 0.001 / properties.fontMatrix[0];
  25300. var glyphsWidths = properties.widths;
  25301. for (var glyph in glyphsWidths) {
  25302. glyphsWidths[glyph] *= scale;
  25303. }
  25304. properties.defaultWidth *= scale;
  25305. }
  25306. function getFontType(type, subtype) {
  25307. switch (type) {
  25308. case 'Type1':
  25309. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  25310. case 'CIDFontType0':
  25311. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  25312. FontType.CIDFONTTYPE0;
  25313. case 'OpenType':
  25314. return FontType.OPENTYPE;
  25315. case 'TrueType':
  25316. return FontType.TRUETYPE;
  25317. case 'CIDFontType2':
  25318. return FontType.CIDFONTTYPE2;
  25319. case 'MMType1':
  25320. return FontType.MMTYPE1;
  25321. case 'Type0':
  25322. return FontType.TYPE0;
  25323. default:
  25324. return FontType.UNKNOWN;
  25325. }
  25326. }
  25327. var Glyph = (function GlyphClosure() {
  25328. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  25329. isSpace) {
  25330. this.fontChar = fontChar;
  25331. this.unicode = unicode;
  25332. this.accent = accent;
  25333. this.width = width;
  25334. this.vmetric = vmetric;
  25335. this.operatorListId = operatorListId;
  25336. this.isSpace = isSpace;
  25337. }
  25338. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  25339. vmetric, operatorListId, isSpace) {
  25340. return this.fontChar === fontChar &&
  25341. this.unicode === unicode &&
  25342. this.accent === accent &&
  25343. this.width === width &&
  25344. this.vmetric === vmetric &&
  25345. this.operatorListId === operatorListId &&
  25346. this.isSpace === isSpace;
  25347. };
  25348. return Glyph;
  25349. })();
  25350. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  25351. function ToUnicodeMap(cmap) {
  25352. // The elements of this._map can be integers or strings, depending on how
  25353. // |cmap| was created.
  25354. this._map = cmap;
  25355. }
  25356. ToUnicodeMap.prototype = {
  25357. get length() {
  25358. return this._map.length;
  25359. },
  25360. forEach: function(callback) {
  25361. for (var charCode in this._map) {
  25362. callback(charCode, this._map[charCode].charCodeAt(0));
  25363. }
  25364. },
  25365. has: function(i) {
  25366. return this._map[i] !== undefined;
  25367. },
  25368. get: function(i) {
  25369. return this._map[i];
  25370. },
  25371. charCodeOf: function(v) {
  25372. return this._map.indexOf(v);
  25373. }
  25374. };
  25375. return ToUnicodeMap;
  25376. })();
  25377. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  25378. function IdentityToUnicodeMap(firstChar, lastChar) {
  25379. this.firstChar = firstChar;
  25380. this.lastChar = lastChar;
  25381. }
  25382. IdentityToUnicodeMap.prototype = {
  25383. get length() {
  25384. return (this.lastChar + 1) - this.firstChar;
  25385. },
  25386. forEach: function (callback) {
  25387. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  25388. callback(i, i);
  25389. }
  25390. },
  25391. has: function (i) {
  25392. return this.firstChar <= i && i <= this.lastChar;
  25393. },
  25394. get: function (i) {
  25395. if (this.firstChar <= i && i <= this.lastChar) {
  25396. return String.fromCharCode(i);
  25397. }
  25398. return undefined;
  25399. },
  25400. charCodeOf: function (v) {
  25401. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  25402. }
  25403. };
  25404. return IdentityToUnicodeMap;
  25405. })();
  25406. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  25407. function writeInt16(dest, offset, num) {
  25408. dest[offset] = (num >> 8) & 0xFF;
  25409. dest[offset + 1] = num & 0xFF;
  25410. }
  25411. function writeInt32(dest, offset, num) {
  25412. dest[offset] = (num >> 24) & 0xFF;
  25413. dest[offset + 1] = (num >> 16) & 0xFF;
  25414. dest[offset + 2] = (num >> 8) & 0xFF;
  25415. dest[offset + 3] = num & 0xFF;
  25416. }
  25417. function writeData(dest, offset, data) {
  25418. var i, ii;
  25419. if (data instanceof Uint8Array) {
  25420. dest.set(data, offset);
  25421. } else if (typeof data === 'string') {
  25422. for (i = 0, ii = data.length; i < ii; i++) {
  25423. dest[offset++] = data.charCodeAt(i) & 0xFF;
  25424. }
  25425. } else {
  25426. // treating everything else as array
  25427. for (i = 0, ii = data.length; i < ii; i++) {
  25428. dest[offset++] = data[i] & 0xFF;
  25429. }
  25430. }
  25431. }
  25432. function OpenTypeFileBuilder(sfnt) {
  25433. this.sfnt = sfnt;
  25434. this.tables = Object.create(null);
  25435. }
  25436. OpenTypeFileBuilder.getSearchParams =
  25437. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  25438. var maxPower2 = 1, log2 = 0;
  25439. while ((maxPower2 ^ entriesCount) > maxPower2) {
  25440. maxPower2 <<= 1;
  25441. log2++;
  25442. }
  25443. var searchRange = maxPower2 * entrySize;
  25444. return {
  25445. range: searchRange,
  25446. entry: log2,
  25447. rangeShift: entrySize * entriesCount - searchRange
  25448. };
  25449. };
  25450. var OTF_HEADER_SIZE = 12;
  25451. var OTF_TABLE_ENTRY_SIZE = 16;
  25452. OpenTypeFileBuilder.prototype = {
  25453. toArray: function OpenTypeFileBuilder_toArray() {
  25454. var sfnt = this.sfnt;
  25455. // Tables needs to be written by ascendant alphabetic order
  25456. var tables = this.tables;
  25457. var tablesNames = Object.keys(tables);
  25458. tablesNames.sort();
  25459. var numTables = tablesNames.length;
  25460. var i, j, jj, table, tableName;
  25461. // layout the tables data
  25462. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  25463. var tableOffsets = [offset];
  25464. for (i = 0; i < numTables; i++) {
  25465. table = tables[tablesNames[i]];
  25466. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  25467. offset += paddedLength;
  25468. tableOffsets.push(offset);
  25469. }
  25470. var file = new Uint8Array(offset);
  25471. // write the table data first (mostly for checksum)
  25472. for (i = 0; i < numTables; i++) {
  25473. table = tables[tablesNames[i]];
  25474. writeData(file, tableOffsets[i], table);
  25475. }
  25476. // sfnt version (4 bytes)
  25477. if (sfnt === 'true') {
  25478. // Windows hates the Mac TrueType sfnt version number
  25479. sfnt = string32(0x00010000);
  25480. }
  25481. file[0] = sfnt.charCodeAt(0) & 0xFF;
  25482. file[1] = sfnt.charCodeAt(1) & 0xFF;
  25483. file[2] = sfnt.charCodeAt(2) & 0xFF;
  25484. file[3] = sfnt.charCodeAt(3) & 0xFF;
  25485. // numTables (2 bytes)
  25486. writeInt16(file, 4, numTables);
  25487. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  25488. // searchRange (2 bytes)
  25489. writeInt16(file, 6, searchParams.range);
  25490. // entrySelector (2 bytes)
  25491. writeInt16(file, 8, searchParams.entry);
  25492. // rangeShift (2 bytes)
  25493. writeInt16(file, 10, searchParams.rangeShift);
  25494. offset = OTF_HEADER_SIZE;
  25495. // writing table entries
  25496. for (i = 0; i < numTables; i++) {
  25497. tableName = tablesNames[i];
  25498. file[offset] = tableName.charCodeAt(0) & 0xFF;
  25499. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  25500. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  25501. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  25502. // checksum
  25503. var checksum = 0;
  25504. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  25505. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  25506. (file[j + 2] << 8) + file[j + 3];
  25507. checksum = (checksum + quad) | 0;
  25508. }
  25509. writeInt32(file, offset + 4, checksum);
  25510. // offset
  25511. writeInt32(file, offset + 8, tableOffsets[i]);
  25512. // length
  25513. writeInt32(file, offset + 12, tables[tableName].length);
  25514. offset += OTF_TABLE_ENTRY_SIZE;
  25515. }
  25516. return file;
  25517. },
  25518. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  25519. if (tag in this.tables) {
  25520. throw new Error('Table ' + tag + ' already exists');
  25521. }
  25522. this.tables[tag] = data;
  25523. }
  25524. };
  25525. return OpenTypeFileBuilder;
  25526. })();
  25527. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  25528. // issues when they are painted on the canvas, e.g. complex-script shaping or
  25529. // control/whitespace characters. The ranges are listed in pairs: the first item
  25530. // is a code of the first problematic code, the second one is the next
  25531. // non-problematic code. The ranges must be in sorted order.
  25532. var ProblematicCharRanges = new Int32Array([
  25533. // Control characters.
  25534. 0x0000, 0x0020,
  25535. 0x007F, 0x00A1,
  25536. 0x00AD, 0x00AE,
  25537. // Chars that is used in complex-script shaping.
  25538. 0x0600, 0x0780,
  25539. 0x08A0, 0x10A0,
  25540. 0x1780, 0x1800,
  25541. // General punctuation chars.
  25542. 0x2000, 0x2010,
  25543. 0x2011, 0x2012,
  25544. 0x2028, 0x2030,
  25545. 0x205F, 0x2070,
  25546. 0x25CC, 0x25CD,
  25547. // Chars that is used in complex-script shaping.
  25548. 0xAA60, 0xAA80,
  25549. // Specials Unicode block.
  25550. 0xFFF0, 0x10000
  25551. ]);
  25552. /**
  25553. * 'Font' is the class the outside world should use, it encapsulate all the font
  25554. * decoding logics whatever type it is (assuming the font type is supported).
  25555. *
  25556. * For example to read a Type1 font and to attach it to the document:
  25557. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  25558. * type1Font.bind();
  25559. */
  25560. var Font = (function FontClosure() {
  25561. function Font(name, file, properties) {
  25562. var charCode, glyphName, fontChar;
  25563. this.name = name;
  25564. this.loadedName = properties.loadedName;
  25565. this.isType3Font = properties.isType3Font;
  25566. this.sizes = [];
  25567. this.glyphCache = {};
  25568. var names = name.split('+');
  25569. names = names.length > 1 ? names[1] : names[0];
  25570. names = names.split(/[-,_]/g)[0];
  25571. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  25572. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  25573. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  25574. var type = properties.type;
  25575. var subtype = properties.subtype;
  25576. this.type = type;
  25577. this.fallbackName = (this.isMonospace ? 'monospace' :
  25578. (this.isSerifFont ? 'serif' : 'sans-serif'));
  25579. this.differences = properties.differences;
  25580. this.widths = properties.widths;
  25581. this.defaultWidth = properties.defaultWidth;
  25582. this.composite = properties.composite;
  25583. this.wideChars = properties.wideChars;
  25584. this.cMap = properties.cMap;
  25585. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  25586. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  25587. this.fontMatrix = properties.fontMatrix;
  25588. this.bbox = properties.bbox;
  25589. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  25590. this.toFontChar = [];
  25591. if (properties.type === 'Type3') {
  25592. for (charCode = 0; charCode < 256; charCode++) {
  25593. this.toFontChar[charCode] = (this.differences[charCode] ||
  25594. properties.defaultEncoding[charCode]);
  25595. }
  25596. this.fontType = FontType.TYPE3;
  25597. return;
  25598. }
  25599. this.cidEncoding = properties.cidEncoding;
  25600. this.vertical = properties.vertical;
  25601. if (this.vertical) {
  25602. this.vmetrics = properties.vmetrics;
  25603. this.defaultVMetrics = properties.defaultVMetrics;
  25604. }
  25605. if (!file || file.isEmpty) {
  25606. if (file) {
  25607. // Some bad PDF generators will include empty font files,
  25608. // attempting to recover by assuming that no file exists.
  25609. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  25610. }
  25611. this.missingFile = true;
  25612. // The file data is not specified. Trying to fix the font name
  25613. // to be used with the canvas.font.
  25614. var fontName = name.replace(/[,_]/g, '-');
  25615. var isStandardFont = !!stdFontMap[fontName] ||
  25616. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  25617. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  25618. this.bold = (fontName.search(/bold/gi) !== -1);
  25619. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  25620. (fontName.search(/italic/gi) !== -1));
  25621. // Use 'name' instead of 'fontName' here because the original
  25622. // name ArialBlack for example will be replaced by Helvetica.
  25623. this.black = (name.search(/Black/g) !== -1);
  25624. // if at least one width is present, remeasure all chars when exists
  25625. this.remeasure = Object.keys(this.widths).length > 0;
  25626. if (isStandardFont && type === 'CIDFontType2' &&
  25627. properties.cidEncoding.indexOf('Identity-') === 0) {
  25628. // Standard fonts might be embedded as CID font without glyph mapping.
  25629. // Building one based on GlyphMapForStandardFonts.
  25630. var map = [];
  25631. for (charCode in GlyphMapForStandardFonts) {
  25632. map[+charCode] = GlyphMapForStandardFonts[charCode];
  25633. }
  25634. if (/ArialBlack/i.test(name)) {
  25635. for (charCode in SupplementalGlyphMapForArialBlack) {
  25636. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  25637. }
  25638. }
  25639. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  25640. if (!isIdentityUnicode) {
  25641. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25642. map[+charCode] = unicodeCharCode;
  25643. });
  25644. }
  25645. this.toFontChar = map;
  25646. this.toUnicode = new ToUnicodeMap(map);
  25647. } else if (/Symbol/i.test(fontName)) {
  25648. var symbols = Encodings.SymbolSetEncoding;
  25649. for (charCode in symbols) {
  25650. fontChar = GlyphsUnicode[symbols[charCode]];
  25651. if (!fontChar) {
  25652. continue;
  25653. }
  25654. this.toFontChar[charCode] = fontChar;
  25655. }
  25656. for (charCode in properties.differences) {
  25657. fontChar = GlyphsUnicode[properties.differences[charCode]];
  25658. if (!fontChar) {
  25659. continue;
  25660. }
  25661. this.toFontChar[charCode] = fontChar;
  25662. }
  25663. } else if (/Dingbats/i.test(fontName)) {
  25664. if (/Wingdings/i.test(name)) {
  25665. warn('Wingdings font without embedded font file, ' +
  25666. 'falling back to the ZapfDingbats encoding.');
  25667. }
  25668. var dingbats = Encodings.ZapfDingbatsEncoding;
  25669. for (charCode in dingbats) {
  25670. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  25671. if (!fontChar) {
  25672. continue;
  25673. }
  25674. this.toFontChar[charCode] = fontChar;
  25675. }
  25676. for (charCode in properties.differences) {
  25677. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  25678. if (!fontChar) {
  25679. continue;
  25680. }
  25681. this.toFontChar[charCode] = fontChar;
  25682. }
  25683. } else if (isStandardFont) {
  25684. this.toFontChar = [];
  25685. for (charCode in properties.defaultEncoding) {
  25686. glyphName = (properties.differences[charCode] ||
  25687. properties.defaultEncoding[charCode]);
  25688. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  25689. }
  25690. } else {
  25691. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25692. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25693. if (notCidFont) {
  25694. glyphName = (properties.differences[charCode] ||
  25695. properties.defaultEncoding[charCode]);
  25696. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  25697. }
  25698. this.toFontChar[charCode] = unicodeCharCode;
  25699. }.bind(this));
  25700. }
  25701. this.loadedName = fontName.split('-')[0];
  25702. this.loading = false;
  25703. this.fontType = getFontType(type, subtype);
  25704. return;
  25705. }
  25706. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25707. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25708. // Some TrueType fonts by mistake claim Type1C
  25709. if (isTrueTypeFile(file)) {
  25710. subtype = 'TrueType';
  25711. } else {
  25712. type = 'Type1';
  25713. }
  25714. }
  25715. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25716. type = 'CIDFontType0';
  25717. }
  25718. if (subtype === 'OpenType') {
  25719. type = 'OpenType';
  25720. }
  25721. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25722. if (type === 'CIDFontType0') {
  25723. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  25724. }
  25725. var data;
  25726. switch (type) {
  25727. case 'MMType1':
  25728. info('MMType1 font (' + name + '), falling back to Type1.');
  25729. /* falls through */
  25730. case 'Type1':
  25731. case 'CIDFontType0':
  25732. this.mimetype = 'font/opentype';
  25733. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25734. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25735. adjustWidths(properties);
  25736. // Wrap the CFF data inside an OTF font file
  25737. data = this.convert(name, cff, properties);
  25738. break;
  25739. case 'OpenType':
  25740. case 'TrueType':
  25741. case 'CIDFontType2':
  25742. this.mimetype = 'font/opentype';
  25743. // Repair the TrueType file. It is can be damaged in the point of
  25744. // view of the sanitizer
  25745. data = this.checkAndRepair(name, file, properties);
  25746. if (this.isOpenType) {
  25747. adjustWidths(properties);
  25748. type = 'OpenType';
  25749. }
  25750. break;
  25751. default:
  25752. error('Font ' + type + ' is not supported');
  25753. break;
  25754. }
  25755. this.data = data;
  25756. this.fontType = getFontType(type, subtype);
  25757. // Transfer some properties again that could change during font conversion
  25758. this.fontMatrix = properties.fontMatrix;
  25759. this.widths = properties.widths;
  25760. this.defaultWidth = properties.defaultWidth;
  25761. this.encoding = properties.baseEncoding;
  25762. this.seacMap = properties.seacMap;
  25763. this.loading = true;
  25764. }
  25765. Font.getFontID = (function () {
  25766. var ID = 1;
  25767. return function Font_getFontID() {
  25768. return String(ID++);
  25769. };
  25770. })();
  25771. function int16(b0, b1) {
  25772. return (b0 << 8) + b1;
  25773. }
  25774. function int32(b0, b1, b2, b3) {
  25775. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25776. }
  25777. function string16(value) {
  25778. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25779. }
  25780. function safeString16(value) {
  25781. // clamp value to the 16-bit int range
  25782. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25783. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25784. }
  25785. function isTrueTypeFile(file) {
  25786. var header = file.peekBytes(4);
  25787. return readUint32(header, 0) === 0x00010000;
  25788. }
  25789. function isType1File(file) {
  25790. var header = file.peekBytes(2);
  25791. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25792. if (header[0] === 0x25 && header[1] === 0x21) {
  25793. return true;
  25794. }
  25795. // ... obviously some fonts violate that part of the specification,
  25796. // please refer to the comment in |Type1Font| below.
  25797. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25798. return true;
  25799. }
  25800. return false;
  25801. }
  25802. /**
  25803. * Helper function for |adjustMapping|.
  25804. * @return {boolean}
  25805. */
  25806. function isProblematicUnicodeLocation(code) {
  25807. // Using binary search to find a range start.
  25808. var i = 0, j = ProblematicCharRanges.length - 1;
  25809. while (i < j) {
  25810. var c = (i + j + 1) >> 1;
  25811. if (code < ProblematicCharRanges[c]) {
  25812. j = c - 1;
  25813. } else {
  25814. i = c;
  25815. }
  25816. }
  25817. // Even index means code in problematic range.
  25818. return !(i & 1);
  25819. }
  25820. /**
  25821. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25822. * with their unicode value. It also moves char codes that are in known
  25823. * problematic locations.
  25824. * @return {Object} Two properties:
  25825. * 'toFontChar' - maps original char codes(the value that will be read
  25826. * from commands such as show text) to the char codes that will be used in the
  25827. * font that we build
  25828. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25829. */
  25830. function adjustMapping(charCodeToGlyphId, properties) {
  25831. var toUnicode = properties.toUnicode;
  25832. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25833. var isIdentityUnicode =
  25834. properties.toUnicode instanceof IdentityToUnicodeMap;
  25835. var newMap = Object.create(null);
  25836. var toFontChar = [];
  25837. var usedFontCharCodes = [];
  25838. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25839. for (var originalCharCode in charCodeToGlyphId) {
  25840. originalCharCode |= 0;
  25841. var glyphId = charCodeToGlyphId[originalCharCode];
  25842. var fontCharCode = originalCharCode;
  25843. // First try to map the value to a unicode position if a non identity map
  25844. // was created.
  25845. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25846. var unicode = toUnicode.get(fontCharCode);
  25847. // TODO: Try to map ligatures to the correct spot.
  25848. if (unicode.length === 1) {
  25849. fontCharCode = unicode.charCodeAt(0);
  25850. }
  25851. }
  25852. // Try to move control characters, special characters and already mapped
  25853. // characters to the private use area since they will not be drawn by
  25854. // canvas if left in their current position. Also, move characters if the
  25855. // font was symbolic and there is only an identity unicode map since the
  25856. // characters probably aren't in the correct position (fixes an issue
  25857. // with firefox and thuluthfont).
  25858. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25859. isProblematicUnicodeLocation(fontCharCode) ||
  25860. (isSymbolic && isIdentityUnicode)) &&
  25861. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25862. // Loop to try and find a free spot in the private use area.
  25863. do {
  25864. fontCharCode = nextAvailableFontCharCode++;
  25865. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25866. fontCharCode = 0xF020;
  25867. nextAvailableFontCharCode = fontCharCode + 1;
  25868. }
  25869. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25870. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25871. }
  25872. newMap[fontCharCode] = glyphId;
  25873. toFontChar[originalCharCode] = fontCharCode;
  25874. usedFontCharCodes[fontCharCode] = true;
  25875. }
  25876. return {
  25877. toFontChar: toFontChar,
  25878. charCodeToGlyphId: newMap,
  25879. nextAvailableFontCharCode: nextAvailableFontCharCode
  25880. };
  25881. }
  25882. function getRanges(glyphs, numGlyphs) {
  25883. // Array.sort() sorts by characters, not numerically, so convert to an
  25884. // array of characters.
  25885. var codes = [];
  25886. for (var charCode in glyphs) {
  25887. // Remove an invalid glyph ID mappings to make OTS happy.
  25888. if (glyphs[charCode] >= numGlyphs) {
  25889. continue;
  25890. }
  25891. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  25892. }
  25893. codes.sort(function fontGetRangesSort(a, b) {
  25894. return a.fontCharCode - b.fontCharCode;
  25895. });
  25896. // Split the sorted codes into ranges.
  25897. var ranges = [];
  25898. var length = codes.length;
  25899. for (var n = 0; n < length; ) {
  25900. var start = codes[n].fontCharCode;
  25901. var codeIndices = [codes[n].glyphId];
  25902. ++n;
  25903. var end = start;
  25904. while (n < length && end + 1 === codes[n].fontCharCode) {
  25905. codeIndices.push(codes[n].glyphId);
  25906. ++end;
  25907. ++n;
  25908. if (end === 0xFFFF) {
  25909. break;
  25910. }
  25911. }
  25912. ranges.push([start, end, codeIndices]);
  25913. }
  25914. return ranges;
  25915. }
  25916. function createCmapTable(glyphs, numGlyphs) {
  25917. var ranges = getRanges(glyphs, numGlyphs);
  25918. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  25919. var cmap = '\x00\x00' + // version
  25920. string16(numTables) + // numTables
  25921. '\x00\x03' + // platformID
  25922. '\x00\x01' + // encodingID
  25923. string32(4 + numTables * 8); // start of the table record
  25924. var i, ii, j, jj;
  25925. for (i = ranges.length - 1; i >= 0; --i) {
  25926. if (ranges[i][0] <= 0xFFFF) { break; }
  25927. }
  25928. var bmpLength = i + 1;
  25929. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  25930. ranges[i][1] = 0xFFFE;
  25931. }
  25932. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  25933. var segCount = bmpLength + trailingRangesCount;
  25934. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  25935. // Fill up the 4 parallel arrays describing the segments.
  25936. var startCount = '';
  25937. var endCount = '';
  25938. var idDeltas = '';
  25939. var idRangeOffsets = '';
  25940. var glyphsIds = '';
  25941. var bias = 0;
  25942. var range, start, end, codes;
  25943. for (i = 0, ii = bmpLength; i < ii; i++) {
  25944. range = ranges[i];
  25945. start = range[0];
  25946. end = range[1];
  25947. startCount += string16(start);
  25948. endCount += string16(end);
  25949. codes = range[2];
  25950. var contiguous = true;
  25951. for (j = 1, jj = codes.length; j < jj; ++j) {
  25952. if (codes[j] !== codes[j - 1] + 1) {
  25953. contiguous = false;
  25954. break;
  25955. }
  25956. }
  25957. if (!contiguous) {
  25958. var offset = (segCount - i) * 2 + bias * 2;
  25959. bias += (end - start + 1);
  25960. idDeltas += string16(0);
  25961. idRangeOffsets += string16(offset);
  25962. for (j = 0, jj = codes.length; j < jj; ++j) {
  25963. glyphsIds += string16(codes[j]);
  25964. }
  25965. } else {
  25966. var startCode = codes[0];
  25967. idDeltas += string16((startCode - start) & 0xFFFF);
  25968. idRangeOffsets += string16(0);
  25969. }
  25970. }
  25971. if (trailingRangesCount > 0) {
  25972. endCount += '\xFF\xFF';
  25973. startCount += '\xFF\xFF';
  25974. idDeltas += '\x00\x01';
  25975. idRangeOffsets += '\x00\x00';
  25976. }
  25977. var format314 = '\x00\x00' + // language
  25978. string16(2 * segCount) +
  25979. string16(searchParams.range) +
  25980. string16(searchParams.entry) +
  25981. string16(searchParams.rangeShift) +
  25982. endCount + '\x00\x00' + startCount +
  25983. idDeltas + idRangeOffsets + glyphsIds;
  25984. var format31012 = '';
  25985. var header31012 = '';
  25986. if (numTables > 1) {
  25987. cmap += '\x00\x03' + // platformID
  25988. '\x00\x0A' + // encodingID
  25989. string32(4 + numTables * 8 +
  25990. 4 + format314.length); // start of the table record
  25991. format31012 = '';
  25992. for (i = 0, ii = ranges.length; i < ii; i++) {
  25993. range = ranges[i];
  25994. start = range[0];
  25995. codes = range[2];
  25996. var code = codes[0];
  25997. for (j = 1, jj = codes.length; j < jj; ++j) {
  25998. if (codes[j] !== codes[j - 1] + 1) {
  25999. end = range[0] + j - 1;
  26000. format31012 += string32(start) + // startCharCode
  26001. string32(end) + // endCharCode
  26002. string32(code); // startGlyphID
  26003. start = end + 1;
  26004. code = codes[j];
  26005. }
  26006. }
  26007. format31012 += string32(start) + // startCharCode
  26008. string32(range[1]) + // endCharCode
  26009. string32(code); // startGlyphID
  26010. }
  26011. header31012 = '\x00\x0C' + // format
  26012. '\x00\x00' + // reserved
  26013. string32(format31012.length + 16) + // length
  26014. '\x00\x00\x00\x00' + // language
  26015. string32(format31012.length / 12); // nGroups
  26016. }
  26017. return cmap + '\x00\x04' + // format
  26018. string16(format314.length + 4) + // length
  26019. format314 + header31012 + format31012;
  26020. }
  26021. function validateOS2Table(os2) {
  26022. var stream = new Stream(os2.data);
  26023. var version = stream.getUint16();
  26024. // TODO verify all OS/2 tables fields, but currently we validate only those
  26025. // that give us issues
  26026. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  26027. var selection = stream.getUint16();
  26028. if (version < 4 && (selection & 0x0300)) {
  26029. return false;
  26030. }
  26031. var firstChar = stream.getUint16();
  26032. var lastChar = stream.getUint16();
  26033. if (firstChar > lastChar) {
  26034. return false;
  26035. }
  26036. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  26037. var usWinAscent = stream.getUint16();
  26038. if (usWinAscent === 0) { // makes font unreadable by windows
  26039. return false;
  26040. }
  26041. // OS/2 appears to be valid, resetting some fields
  26042. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  26043. return true;
  26044. }
  26045. function createOS2Table(properties, charstrings, override) {
  26046. override = override || {
  26047. unitsPerEm: 0,
  26048. yMax: 0,
  26049. yMin: 0,
  26050. ascent: 0,
  26051. descent: 0
  26052. };
  26053. var ulUnicodeRange1 = 0;
  26054. var ulUnicodeRange2 = 0;
  26055. var ulUnicodeRange3 = 0;
  26056. var ulUnicodeRange4 = 0;
  26057. var firstCharIndex = null;
  26058. var lastCharIndex = 0;
  26059. if (charstrings) {
  26060. for (var code in charstrings) {
  26061. code |= 0;
  26062. if (firstCharIndex > code || !firstCharIndex) {
  26063. firstCharIndex = code;
  26064. }
  26065. if (lastCharIndex < code) {
  26066. lastCharIndex = code;
  26067. }
  26068. var position = getUnicodeRangeFor(code);
  26069. if (position < 32) {
  26070. ulUnicodeRange1 |= 1 << position;
  26071. } else if (position < 64) {
  26072. ulUnicodeRange2 |= 1 << position - 32;
  26073. } else if (position < 96) {
  26074. ulUnicodeRange3 |= 1 << position - 64;
  26075. } else if (position < 123) {
  26076. ulUnicodeRange4 |= 1 << position - 96;
  26077. } else {
  26078. error('Unicode ranges Bits > 123 are reserved for internal usage');
  26079. }
  26080. }
  26081. } else {
  26082. // TODO
  26083. firstCharIndex = 0;
  26084. lastCharIndex = 255;
  26085. }
  26086. var bbox = properties.bbox || [0, 0, 0, 0];
  26087. var unitsPerEm = (override.unitsPerEm ||
  26088. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  26089. // if the font units differ to the PDF glyph space units
  26090. // then scale up the values
  26091. var scale = (properties.ascentScaled ? 1.0 :
  26092. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  26093. var typoAscent = (override.ascent ||
  26094. Math.round(scale * (properties.ascent || bbox[3])));
  26095. var typoDescent = (override.descent ||
  26096. Math.round(scale * (properties.descent || bbox[1])));
  26097. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  26098. typoDescent = -typoDescent; // fixing incorrect descent
  26099. }
  26100. var winAscent = override.yMax || typoAscent;
  26101. var winDescent = -override.yMin || -typoDescent;
  26102. return '\x00\x03' + // version
  26103. '\x02\x24' + // xAvgCharWidth
  26104. '\x01\xF4' + // usWeightClass
  26105. '\x00\x05' + // usWidthClass
  26106. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  26107. '\x02\x8A' + // ySubscriptXSize
  26108. '\x02\xBB' + // ySubscriptYSize
  26109. '\x00\x00' + // ySubscriptXOffset
  26110. '\x00\x8C' + // ySubscriptYOffset
  26111. '\x02\x8A' + // ySuperScriptXSize
  26112. '\x02\xBB' + // ySuperScriptYSize
  26113. '\x00\x00' + // ySuperScriptXOffset
  26114. '\x01\xDF' + // ySuperScriptYOffset
  26115. '\x00\x31' + // yStrikeOutSize
  26116. '\x01\x02' + // yStrikeOutPosition
  26117. '\x00\x00' + // sFamilyClass
  26118. '\x00\x00\x06' +
  26119. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  26120. '\x00\x00\x00\x00\x00\x00' + // Panose
  26121. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  26122. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  26123. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  26124. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  26125. '\x2A\x32\x31\x2A' + // achVendID
  26126. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  26127. string16(firstCharIndex ||
  26128. properties.firstChar) + // usFirstCharIndex
  26129. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  26130. string16(typoAscent) + // sTypoAscender
  26131. string16(typoDescent) + // sTypoDescender
  26132. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  26133. string16(winAscent) + // usWinAscent
  26134. string16(winDescent) + // usWinDescent
  26135. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  26136. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  26137. string16(properties.xHeight) + // sxHeight
  26138. string16(properties.capHeight) + // sCapHeight
  26139. string16(0) + // usDefaultChar
  26140. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  26141. '\x00\x03'; // usMaxContext
  26142. }
  26143. function createPostTable(properties) {
  26144. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  26145. return ('\x00\x03\x00\x00' + // Version number
  26146. string32(angle) + // italicAngle
  26147. '\x00\x00' + // underlinePosition
  26148. '\x00\x00' + // underlineThickness
  26149. string32(properties.fixedPitch) + // isFixedPitch
  26150. '\x00\x00\x00\x00' + // minMemType42
  26151. '\x00\x00\x00\x00' + // maxMemType42
  26152. '\x00\x00\x00\x00' + // minMemType1
  26153. '\x00\x00\x00\x00'); // maxMemType1
  26154. }
  26155. function createNameTable(name, proto) {
  26156. if (!proto) {
  26157. proto = [[], []]; // no strings and unicode strings
  26158. }
  26159. var strings = [
  26160. proto[0][0] || 'Original licence', // 0.Copyright
  26161. proto[0][1] || name, // 1.Font family
  26162. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  26163. proto[0][3] || 'uniqueID', // 3.Unique ID
  26164. proto[0][4] || name, // 4.Full font name
  26165. proto[0][5] || 'Version 0.11', // 5.Version
  26166. proto[0][6] || '', // 6.Postscript name
  26167. proto[0][7] || 'Unknown', // 7.Trademark
  26168. proto[0][8] || 'Unknown', // 8.Manufacturer
  26169. proto[0][9] || 'Unknown' // 9.Designer
  26170. ];
  26171. // Mac want 1-byte per character strings while Windows want
  26172. // 2-bytes per character, so duplicate the names table
  26173. var stringsUnicode = [];
  26174. var i, ii, j, jj, str;
  26175. for (i = 0, ii = strings.length; i < ii; i++) {
  26176. str = proto[1][i] || strings[i];
  26177. var strBufUnicode = [];
  26178. for (j = 0, jj = str.length; j < jj; j++) {
  26179. strBufUnicode.push(string16(str.charCodeAt(j)));
  26180. }
  26181. stringsUnicode.push(strBufUnicode.join(''));
  26182. }
  26183. var names = [strings, stringsUnicode];
  26184. var platforms = ['\x00\x01', '\x00\x03'];
  26185. var encodings = ['\x00\x00', '\x00\x01'];
  26186. var languages = ['\x00\x00', '\x04\x09'];
  26187. var namesRecordCount = strings.length * platforms.length;
  26188. var nameTable =
  26189. '\x00\x00' + // format
  26190. string16(namesRecordCount) + // Number of names Record
  26191. string16(namesRecordCount * 12 + 6); // Storage
  26192. // Build the name records field
  26193. var strOffset = 0;
  26194. for (i = 0, ii = platforms.length; i < ii; i++) {
  26195. var strs = names[i];
  26196. for (j = 0, jj = strs.length; j < jj; j++) {
  26197. str = strs[j];
  26198. var nameRecord =
  26199. platforms[i] + // platform ID
  26200. encodings[i] + // encoding ID
  26201. languages[i] + // language ID
  26202. string16(j) + // name ID
  26203. string16(str.length) +
  26204. string16(strOffset);
  26205. nameTable += nameRecord;
  26206. strOffset += str.length;
  26207. }
  26208. }
  26209. nameTable += strings.join('') + stringsUnicode.join('');
  26210. return nameTable;
  26211. }
  26212. Font.prototype = {
  26213. name: null,
  26214. font: null,
  26215. mimetype: null,
  26216. encoding: null,
  26217. get renderer() {
  26218. var renderer = FontRendererFactory.create(this);
  26219. return shadow(this, 'renderer', renderer);
  26220. },
  26221. exportData: function Font_exportData() {
  26222. var data = {};
  26223. for (var i in this) {
  26224. if (this.hasOwnProperty(i)) {
  26225. data[i] = this[i];
  26226. }
  26227. }
  26228. return data;
  26229. },
  26230. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  26231. function readTableEntry(file) {
  26232. var tag = bytesToString(file.getBytes(4));
  26233. var checksum = file.getInt32();
  26234. var offset = file.getInt32() >>> 0;
  26235. var length = file.getInt32() >>> 0;
  26236. // Read the table associated data
  26237. var previousPosition = file.pos;
  26238. file.pos = file.start ? file.start : 0;
  26239. file.skip(offset);
  26240. var data = file.getBytes(length);
  26241. file.pos = previousPosition;
  26242. if (tag === 'head') {
  26243. // clearing checksum adjustment
  26244. data[8] = data[9] = data[10] = data[11] = 0;
  26245. data[17] |= 0x20; //Set font optimized for cleartype flag
  26246. }
  26247. return {
  26248. tag: tag,
  26249. checksum: checksum,
  26250. length: length,
  26251. offset: offset,
  26252. data: data
  26253. };
  26254. }
  26255. function readOpenTypeHeader(ttf) {
  26256. return {
  26257. version: bytesToString(ttf.getBytes(4)),
  26258. numTables: ttf.getUint16(),
  26259. searchRange: ttf.getUint16(),
  26260. entrySelector: ttf.getUint16(),
  26261. rangeShift: ttf.getUint16()
  26262. };
  26263. }
  26264. /**
  26265. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  26266. * PDF spec
  26267. */
  26268. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  26269. if (!cmap) {
  26270. warn('No cmap table available.');
  26271. return {
  26272. platformId: -1,
  26273. encodingId: -1,
  26274. mappings: [],
  26275. hasShortCmap: false
  26276. };
  26277. }
  26278. var segment;
  26279. var start = (font.start ? font.start : 0) + cmap.offset;
  26280. font.pos = start;
  26281. var version = font.getUint16();
  26282. var numTables = font.getUint16();
  26283. var potentialTable;
  26284. var canBreak = false;
  26285. // There's an order of preference in terms of which cmap subtable to
  26286. // use:
  26287. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  26288. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  26289. // The following takes advantage of the fact that the tables are sorted
  26290. // to work.
  26291. for (var i = 0; i < numTables; i++) {
  26292. var platformId = font.getUint16();
  26293. var encodingId = font.getUint16();
  26294. var offset = font.getInt32() >>> 0;
  26295. var useTable = false;
  26296. if (platformId === 0 && encodingId === 0) {
  26297. useTable = true;
  26298. // Continue the loop since there still may be a higher priority
  26299. // table.
  26300. } else if (platformId === 1 && encodingId === 0) {
  26301. useTable = true;
  26302. // Continue the loop since there still may be a higher priority
  26303. // table.
  26304. } else if (platformId === 3 && encodingId === 1 &&
  26305. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  26306. useTable = true;
  26307. if (!isSymbolicFont) {
  26308. canBreak = true;
  26309. }
  26310. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  26311. useTable = true;
  26312. canBreak = true;
  26313. }
  26314. if (useTable) {
  26315. potentialTable = {
  26316. platformId: platformId,
  26317. encodingId: encodingId,
  26318. offset: offset
  26319. };
  26320. }
  26321. if (canBreak) {
  26322. break;
  26323. }
  26324. }
  26325. if (potentialTable) {
  26326. font.pos = start + potentialTable.offset;
  26327. }
  26328. if (!potentialTable || font.peekByte() === -1) {
  26329. warn('Could not find a preferred cmap table.');
  26330. return {
  26331. platformId: -1,
  26332. encodingId: -1,
  26333. mappings: [],
  26334. hasShortCmap: false
  26335. };
  26336. }
  26337. var format = font.getUint16();
  26338. var length = font.getUint16();
  26339. var language = font.getUint16();
  26340. var hasShortCmap = false;
  26341. var mappings = [];
  26342. var j, glyphId;
  26343. // TODO(mack): refactor this cmap subtable reading logic out
  26344. if (format === 0) {
  26345. for (j = 0; j < 256; j++) {
  26346. var index = font.getByte();
  26347. if (!index) {
  26348. continue;
  26349. }
  26350. mappings.push({
  26351. charCode: j,
  26352. glyphId: index
  26353. });
  26354. }
  26355. hasShortCmap = true;
  26356. } else if (format === 4) {
  26357. // re-creating the table in format 4 since the encoding
  26358. // might be changed
  26359. var segCount = (font.getUint16() >> 1);
  26360. font.getBytes(6); // skipping range fields
  26361. var segIndex, segments = [];
  26362. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26363. segments.push({ end: font.getUint16() });
  26364. }
  26365. font.getUint16();
  26366. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26367. segments[segIndex].start = font.getUint16();
  26368. }
  26369. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26370. segments[segIndex].delta = font.getUint16();
  26371. }
  26372. var offsetsCount = 0;
  26373. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26374. segment = segments[segIndex];
  26375. var rangeOffset = font.getUint16();
  26376. if (!rangeOffset) {
  26377. segment.offsetIndex = -1;
  26378. continue;
  26379. }
  26380. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  26381. segment.offsetIndex = offsetIndex;
  26382. offsetsCount = Math.max(offsetsCount, offsetIndex +
  26383. segment.end - segment.start + 1);
  26384. }
  26385. var offsets = [];
  26386. for (j = 0; j < offsetsCount; j++) {
  26387. offsets.push(font.getUint16());
  26388. }
  26389. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26390. segment = segments[segIndex];
  26391. start = segment.start;
  26392. var end = segment.end;
  26393. var delta = segment.delta;
  26394. offsetIndex = segment.offsetIndex;
  26395. for (j = start; j <= end; j++) {
  26396. if (j === 0xFFFF) {
  26397. continue;
  26398. }
  26399. glyphId = (offsetIndex < 0 ?
  26400. j : offsets[offsetIndex + j - start]);
  26401. glyphId = (glyphId + delta) & 0xFFFF;
  26402. if (glyphId === 0) {
  26403. continue;
  26404. }
  26405. mappings.push({
  26406. charCode: j,
  26407. glyphId: glyphId
  26408. });
  26409. }
  26410. }
  26411. } else if (format === 6) {
  26412. // Format 6 is a 2-bytes dense mapping, which means the font data
  26413. // lives glue together even if they are pretty far in the unicode
  26414. // table. (This looks weird, so I can have missed something), this
  26415. // works on Linux but seems to fails on Mac so let's rewrite the
  26416. // cmap table to a 3-1-4 style
  26417. var firstCode = font.getUint16();
  26418. var entryCount = font.getUint16();
  26419. for (j = 0; j < entryCount; j++) {
  26420. glyphId = font.getUint16();
  26421. var charCode = firstCode + j;
  26422. mappings.push({
  26423. charCode: charCode,
  26424. glyphId: glyphId
  26425. });
  26426. }
  26427. } else {
  26428. warn('cmap table has unsupported format: ' + format);
  26429. return {
  26430. platformId: -1,
  26431. encodingId: -1,
  26432. mappings: [],
  26433. hasShortCmap: false
  26434. };
  26435. }
  26436. // removing duplicate entries
  26437. mappings.sort(function (a, b) {
  26438. return a.charCode - b.charCode;
  26439. });
  26440. for (i = 1; i < mappings.length; i++) {
  26441. if (mappings[i - 1].charCode === mappings[i].charCode) {
  26442. mappings.splice(i, 1);
  26443. i--;
  26444. }
  26445. }
  26446. return {
  26447. platformId: potentialTable.platformId,
  26448. encodingId: potentialTable.encodingId,
  26449. mappings: mappings,
  26450. hasShortCmap: hasShortCmap
  26451. };
  26452. }
  26453. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  26454. if (!header) {
  26455. if (metrics) {
  26456. metrics.data = null;
  26457. }
  26458. return;
  26459. }
  26460. font.pos = (font.start ? font.start : 0) + header.offset;
  26461. font.pos += header.length - 2;
  26462. var numOfMetrics = font.getUint16();
  26463. if (numOfMetrics > numGlyphs) {
  26464. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  26465. 'greater than the numGlyphs (' + numGlyphs + ')');
  26466. // Reduce numOfMetrics if it is greater than numGlyphs
  26467. numOfMetrics = numGlyphs;
  26468. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  26469. header.data[35] = numOfMetrics & 0x00ff;
  26470. }
  26471. var numOfSidebearings = numGlyphs - numOfMetrics;
  26472. var numMissing = numOfSidebearings -
  26473. ((metrics.length - numOfMetrics * 4) >> 1);
  26474. if (numMissing > 0) {
  26475. // For each missing glyph, we set both the width and lsb to 0 (zero).
  26476. // Since we need to add two properties for each glyph, this explains
  26477. // the use of |numMissing * 2| when initializing the typed array.
  26478. var entries = new Uint8Array(metrics.length + numMissing * 2);
  26479. entries.set(metrics.data);
  26480. metrics.data = entries;
  26481. }
  26482. }
  26483. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  26484. hintsValid) {
  26485. if (sourceEnd - sourceStart <= 12) {
  26486. // glyph with data less than 12 is invalid one
  26487. return 0;
  26488. }
  26489. var glyf = source.subarray(sourceStart, sourceEnd);
  26490. var contoursCount = (glyf[0] << 8) | glyf[1];
  26491. if (contoursCount & 0x8000) {
  26492. // complex glyph, writing as is
  26493. dest.set(glyf, destStart);
  26494. return glyf.length;
  26495. }
  26496. var i, j = 10, flagsCount = 0;
  26497. for (i = 0; i < contoursCount; i++) {
  26498. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  26499. flagsCount = endPoint + 1;
  26500. j += 2;
  26501. }
  26502. // skipping instructions
  26503. var instructionsStart = j;
  26504. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  26505. j += 2 + instructionsLength;
  26506. var instructionsEnd = j;
  26507. // validating flags
  26508. var coordinatesLength = 0;
  26509. for (i = 0; i < flagsCount; i++) {
  26510. var flag = glyf[j++];
  26511. if (flag & 0xC0) {
  26512. // reserved flags must be zero, cleaning up
  26513. glyf[j - 1] = flag & 0x3F;
  26514. }
  26515. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  26516. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  26517. coordinatesLength += xyLength;
  26518. if (flag & 8) {
  26519. var repeat = glyf[j++];
  26520. i += repeat;
  26521. coordinatesLength += repeat * xyLength;
  26522. }
  26523. }
  26524. // glyph without coordinates will be rejected
  26525. if (coordinatesLength === 0) {
  26526. return 0;
  26527. }
  26528. var glyphDataLength = j + coordinatesLength;
  26529. if (glyphDataLength > glyf.length) {
  26530. // not enough data for coordinates
  26531. return 0;
  26532. }
  26533. if (!hintsValid && instructionsLength > 0) {
  26534. dest.set(glyf.subarray(0, instructionsStart), destStart);
  26535. dest.set([0, 0], destStart + instructionsStart);
  26536. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  26537. destStart + instructionsStart + 2);
  26538. glyphDataLength -= instructionsLength;
  26539. if (glyf.length - glyphDataLength > 3) {
  26540. glyphDataLength = (glyphDataLength + 3) & ~3;
  26541. }
  26542. return glyphDataLength;
  26543. }
  26544. if (glyf.length - glyphDataLength > 3) {
  26545. // truncating and aligning to 4 bytes the long glyph data
  26546. glyphDataLength = (glyphDataLength + 3) & ~3;
  26547. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  26548. return glyphDataLength;
  26549. }
  26550. // glyph data is fine
  26551. dest.set(glyf, destStart);
  26552. return glyf.length;
  26553. }
  26554. function sanitizeHead(head, numGlyphs, locaLength) {
  26555. var data = head.data;
  26556. // Validate version:
  26557. // Should always be 0x00010000
  26558. var version = int32(data[0], data[1], data[2], data[3]);
  26559. if (version >> 16 !== 1) {
  26560. info('Attempting to fix invalid version in head table: ' + version);
  26561. data[0] = 0;
  26562. data[1] = 1;
  26563. data[2] = 0;
  26564. data[3] = 0;
  26565. }
  26566. var indexToLocFormat = int16(data[50], data[51]);
  26567. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  26568. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  26569. indexToLocFormat);
  26570. // The value of indexToLocFormat should be 0 if the loca table
  26571. // consists of short offsets, and should be 1 if the loca table
  26572. // consists of long offsets.
  26573. //
  26574. // The number of entries in the loca table should be numGlyphs + 1.
  26575. //
  26576. // Using this information, we can work backwards to deduce if the
  26577. // size of each offset in the loca table, and thus figure out the
  26578. // appropriate value for indexToLocFormat.
  26579. var numGlyphsPlusOne = numGlyphs + 1;
  26580. if (locaLength === numGlyphsPlusOne << 1) {
  26581. // 0x0000 indicates the loca table consists of short offsets
  26582. data[50] = 0;
  26583. data[51] = 0;
  26584. } else if (locaLength === numGlyphsPlusOne << 2) {
  26585. // 0x0001 indicates the loca table consists of long offsets
  26586. data[50] = 0;
  26587. data[51] = 1;
  26588. } else {
  26589. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  26590. }
  26591. }
  26592. }
  26593. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  26594. isGlyphLocationsLong, hintsValid,
  26595. dupFirstEntry) {
  26596. var itemSize, itemDecode, itemEncode;
  26597. if (isGlyphLocationsLong) {
  26598. itemSize = 4;
  26599. itemDecode = function fontItemDecodeLong(data, offset) {
  26600. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26601. (data[offset + 2] << 8) | data[offset + 3];
  26602. };
  26603. itemEncode = function fontItemEncodeLong(data, offset, value) {
  26604. data[offset] = (value >>> 24) & 0xFF;
  26605. data[offset + 1] = (value >> 16) & 0xFF;
  26606. data[offset + 2] = (value >> 8) & 0xFF;
  26607. data[offset + 3] = value & 0xFF;
  26608. };
  26609. } else {
  26610. itemSize = 2;
  26611. itemDecode = function fontItemDecode(data, offset) {
  26612. return (data[offset] << 9) | (data[offset + 1] << 1);
  26613. };
  26614. itemEncode = function fontItemEncode(data, offset, value) {
  26615. data[offset] = (value >> 9) & 0xFF;
  26616. data[offset + 1] = (value >> 1) & 0xFF;
  26617. };
  26618. }
  26619. var locaData = loca.data;
  26620. var locaDataSize = itemSize * (1 + numGlyphs);
  26621. // is loca.data too short or long?
  26622. if (locaData.length !== locaDataSize) {
  26623. locaData = new Uint8Array(locaDataSize);
  26624. locaData.set(loca.data.subarray(0, locaDataSize));
  26625. loca.data = locaData;
  26626. }
  26627. // removing the invalid glyphs
  26628. var oldGlyfData = glyf.data;
  26629. var oldGlyfDataLength = oldGlyfData.length;
  26630. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  26631. var startOffset = itemDecode(locaData, 0);
  26632. var writeOffset = 0;
  26633. var missingGlyphData = {};
  26634. itemEncode(locaData, 0, writeOffset);
  26635. var i, j;
  26636. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26637. var endOffset = itemDecode(locaData, j);
  26638. if (endOffset > oldGlyfDataLength &&
  26639. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  26640. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  26641. // the glyf table size, which makes last glyph out of range.
  26642. endOffset = oldGlyfDataLength;
  26643. }
  26644. if (endOffset > oldGlyfDataLength) {
  26645. // glyph end offset points outside glyf data, rejecting the glyph
  26646. itemEncode(locaData, j, writeOffset);
  26647. startOffset = endOffset;
  26648. continue;
  26649. }
  26650. if (startOffset === endOffset) {
  26651. missingGlyphData[i] = true;
  26652. }
  26653. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  26654. newGlyfData, writeOffset, hintsValid);
  26655. writeOffset += newLength;
  26656. itemEncode(locaData, j, writeOffset);
  26657. startOffset = endOffset;
  26658. }
  26659. if (writeOffset === 0) {
  26660. // glyf table cannot be empty -- redoing the glyf and loca tables
  26661. // to have single glyph with one point
  26662. var simpleGlyph = new Uint8Array(
  26663. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26664. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26665. itemEncode(locaData, j, simpleGlyph.length);
  26666. }
  26667. glyf.data = simpleGlyph;
  26668. return missingGlyphData;
  26669. }
  26670. if (dupFirstEntry) {
  26671. var firstEntryLength = itemDecode(locaData, itemSize);
  26672. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26673. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26674. } else {
  26675. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26676. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26677. }
  26678. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26679. itemEncode(loca.data, locaData.length - itemSize,
  26680. writeOffset + firstEntryLength);
  26681. } else {
  26682. glyf.data = newGlyfData.subarray(0, writeOffset);
  26683. }
  26684. return missingGlyphData;
  26685. }
  26686. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26687. var start = (font.start ? font.start : 0) + post.offset;
  26688. font.pos = start;
  26689. var length = post.length, end = start + length;
  26690. var version = font.getInt32();
  26691. // skip rest to the tables
  26692. font.getBytes(28);
  26693. var glyphNames;
  26694. var valid = true;
  26695. var i;
  26696. switch (version) {
  26697. case 0x00010000:
  26698. glyphNames = MacStandardGlyphOrdering;
  26699. break;
  26700. case 0x00020000:
  26701. var numGlyphs = font.getUint16();
  26702. if (numGlyphs !== maxpNumGlyphs) {
  26703. valid = false;
  26704. break;
  26705. }
  26706. var glyphNameIndexes = [];
  26707. for (i = 0; i < numGlyphs; ++i) {
  26708. var index = font.getUint16();
  26709. if (index >= 32768) {
  26710. valid = false;
  26711. break;
  26712. }
  26713. glyphNameIndexes.push(index);
  26714. }
  26715. if (!valid) {
  26716. break;
  26717. }
  26718. var customNames = [];
  26719. var strBuf = [];
  26720. while (font.pos < end) {
  26721. var stringLength = font.getByte();
  26722. strBuf.length = stringLength;
  26723. for (i = 0; i < stringLength; ++i) {
  26724. strBuf[i] = String.fromCharCode(font.getByte());
  26725. }
  26726. customNames.push(strBuf.join(''));
  26727. }
  26728. glyphNames = [];
  26729. for (i = 0; i < numGlyphs; ++i) {
  26730. var j = glyphNameIndexes[i];
  26731. if (j < 258) {
  26732. glyphNames.push(MacStandardGlyphOrdering[j]);
  26733. continue;
  26734. }
  26735. glyphNames.push(customNames[j - 258]);
  26736. }
  26737. break;
  26738. case 0x00030000:
  26739. break;
  26740. default:
  26741. warn('Unknown/unsupported post table version ' + version);
  26742. valid = false;
  26743. if (properties.defaultEncoding) {
  26744. glyphNames = properties.defaultEncoding;
  26745. }
  26746. break;
  26747. }
  26748. properties.glyphNames = glyphNames;
  26749. return valid;
  26750. }
  26751. function readNameTable(nameTable) {
  26752. var start = (font.start ? font.start : 0) + nameTable.offset;
  26753. font.pos = start;
  26754. var names = [[], []];
  26755. var length = nameTable.length, end = start + length;
  26756. var format = font.getUint16();
  26757. var FORMAT_0_HEADER_LENGTH = 6;
  26758. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26759. // unsupported name table format or table "too" small
  26760. return names;
  26761. }
  26762. var numRecords = font.getUint16();
  26763. var stringsStart = font.getUint16();
  26764. var records = [];
  26765. var NAME_RECORD_LENGTH = 12;
  26766. var i, ii;
  26767. for (i = 0; i < numRecords &&
  26768. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26769. var r = {
  26770. platform: font.getUint16(),
  26771. encoding: font.getUint16(),
  26772. language: font.getUint16(),
  26773. name: font.getUint16(),
  26774. length: font.getUint16(),
  26775. offset: font.getUint16()
  26776. };
  26777. // using only Macintosh and Windows platform/encoding names
  26778. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26779. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26780. records.push(r);
  26781. }
  26782. }
  26783. for (i = 0, ii = records.length; i < ii; i++) {
  26784. var record = records[i];
  26785. var pos = start + stringsStart + record.offset;
  26786. if (pos + record.length > end) {
  26787. continue; // outside of name table, ignoring
  26788. }
  26789. font.pos = pos;
  26790. var nameIndex = record.name;
  26791. if (record.encoding) {
  26792. // unicode
  26793. var str = '';
  26794. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26795. str += String.fromCharCode(font.getUint16());
  26796. }
  26797. names[1][nameIndex] = str;
  26798. } else {
  26799. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26800. }
  26801. }
  26802. return names;
  26803. }
  26804. var TTOpsStackDeltas = [
  26805. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26806. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26807. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26808. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26809. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26810. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26811. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26812. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26813. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26814. // 0xC0-DF == -1 and 0xE0-FF == -2
  26815. function sanitizeTTProgram(table, ttContext) {
  26816. var data = table.data;
  26817. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26818. var stack = [];
  26819. var callstack = [];
  26820. var functionsCalled = [];
  26821. var tooComplexToFollowFunctions =
  26822. ttContext.tooComplexToFollowFunctions;
  26823. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26824. for (var ii = data.length; i < ii;) {
  26825. var op = data[i++];
  26826. // The TrueType instruction set docs can be found at
  26827. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26828. if (op === 0x40) { // NPUSHB - pushes n bytes
  26829. n = data[i++];
  26830. if (inFDEF || inELSE) {
  26831. i += n;
  26832. } else {
  26833. for (j = 0; j < n; j++) {
  26834. stack.push(data[i++]);
  26835. }
  26836. }
  26837. } else if (op === 0x41) { // NPUSHW - pushes n words
  26838. n = data[i++];
  26839. if (inFDEF || inELSE) {
  26840. i += n * 2;
  26841. } else {
  26842. for (j = 0; j < n; j++) {
  26843. b = data[i++];
  26844. stack.push((b << 8) | data[i++]);
  26845. }
  26846. }
  26847. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26848. n = op - 0xB0 + 1;
  26849. if (inFDEF || inELSE) {
  26850. i += n;
  26851. } else {
  26852. for (j = 0; j < n; j++) {
  26853. stack.push(data[i++]);
  26854. }
  26855. }
  26856. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26857. n = op - 0xB8 + 1;
  26858. if (inFDEF || inELSE) {
  26859. i += n * 2;
  26860. } else {
  26861. for (j = 0; j < n; j++) {
  26862. b = data[i++];
  26863. stack.push((b << 8) | data[i++]);
  26864. }
  26865. }
  26866. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26867. if (!inFDEF && !inELSE) {
  26868. // collecting inforamtion about which functions are used
  26869. funcId = stack[stack.length - 1];
  26870. ttContext.functionsUsed[funcId] = true;
  26871. if (funcId in ttContext.functionsStackDeltas) {
  26872. stack.length += ttContext.functionsStackDeltas[funcId];
  26873. } else if (funcId in ttContext.functionsDefined &&
  26874. functionsCalled.indexOf(funcId) < 0) {
  26875. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26876. functionsCalled.push(funcId);
  26877. pc = ttContext.functionsDefined[funcId];
  26878. if (!pc) {
  26879. warn('TT: CALL non-existent function');
  26880. ttContext.hintsValid = false;
  26881. return;
  26882. }
  26883. data = pc.data;
  26884. i = pc.i;
  26885. }
  26886. }
  26887. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  26888. if (inFDEF || inELSE) {
  26889. warn('TT: nested FDEFs not allowed');
  26890. tooComplexToFollowFunctions = true;
  26891. }
  26892. inFDEF = true;
  26893. // collecting inforamtion about which functions are defined
  26894. lastDeff = i;
  26895. funcId = stack.pop();
  26896. ttContext.functionsDefined[funcId] = {data: data, i: i};
  26897. } else if (op === 0x2D) { // ENDF - end of function
  26898. if (inFDEF) {
  26899. inFDEF = false;
  26900. lastEndf = i;
  26901. } else {
  26902. pc = callstack.pop();
  26903. if (!pc) {
  26904. warn('TT: ENDF bad stack');
  26905. ttContext.hintsValid = false;
  26906. return;
  26907. }
  26908. funcId = functionsCalled.pop();
  26909. data = pc.data;
  26910. i = pc.i;
  26911. ttContext.functionsStackDeltas[funcId] =
  26912. stack.length - pc.stackTop;
  26913. }
  26914. } else if (op === 0x89) { // IDEF - instruction definition
  26915. if (inFDEF || inELSE) {
  26916. warn('TT: nested IDEFs not allowed');
  26917. tooComplexToFollowFunctions = true;
  26918. }
  26919. inFDEF = true;
  26920. // recording it as a function to track ENDF
  26921. lastDeff = i;
  26922. } else if (op === 0x58) { // IF
  26923. ++ifLevel;
  26924. } else if (op === 0x1B) { // ELSE
  26925. inELSE = ifLevel;
  26926. } else if (op === 0x59) { // EIF
  26927. if (inELSE === ifLevel) {
  26928. inELSE = 0;
  26929. }
  26930. --ifLevel;
  26931. } else if (op === 0x1C) { // JMPR
  26932. if (!inFDEF && !inELSE) {
  26933. var offset = stack[stack.length - 1];
  26934. // only jumping forward to prevent infinite loop
  26935. if (offset > 0) {
  26936. i += offset - 1;
  26937. }
  26938. }
  26939. }
  26940. // Adjusting stack not extactly, but just enough to get function id
  26941. if (!inFDEF && !inELSE) {
  26942. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  26943. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  26944. if (op >= 0x71 && op <= 0x75) {
  26945. n = stack.pop();
  26946. if (n === n) {
  26947. stackDelta = -n * 2;
  26948. }
  26949. }
  26950. while (stackDelta < 0 && stack.length > 0) {
  26951. stack.pop();
  26952. stackDelta++;
  26953. }
  26954. while (stackDelta > 0) {
  26955. stack.push(NaN); // pushing any number into stack
  26956. stackDelta--;
  26957. }
  26958. }
  26959. }
  26960. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  26961. var content = [data];
  26962. if (i > data.length) {
  26963. content.push(new Uint8Array(i - data.length));
  26964. }
  26965. if (lastDeff > lastEndf) {
  26966. warn('TT: complementing a missing function tail');
  26967. // new function definition started, but not finished
  26968. // complete function by [CLEAR, ENDF]
  26969. content.push(new Uint8Array([0x22, 0x2D]));
  26970. }
  26971. foldTTTable(table, content);
  26972. }
  26973. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  26974. if (ttContext.tooComplexToFollowFunctions) {
  26975. return;
  26976. }
  26977. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  26978. warn('TT: more functions defined than expected');
  26979. ttContext.hintsValid = false;
  26980. return;
  26981. }
  26982. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  26983. if (j > maxFunctionDefs) {
  26984. warn('TT: invalid function id: ' + j);
  26985. ttContext.hintsValid = false;
  26986. return;
  26987. }
  26988. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  26989. warn('TT: undefined function: ' + j);
  26990. ttContext.hintsValid = false;
  26991. return;
  26992. }
  26993. }
  26994. }
  26995. function foldTTTable(table, content) {
  26996. if (content.length > 1) {
  26997. // concatenating the content items
  26998. var newLength = 0;
  26999. var j, jj;
  27000. for (j = 0, jj = content.length; j < jj; j++) {
  27001. newLength += content[j].length;
  27002. }
  27003. newLength = (newLength + 3) & ~3;
  27004. var result = new Uint8Array(newLength);
  27005. var pos = 0;
  27006. for (j = 0, jj = content.length; j < jj; j++) {
  27007. result.set(content[j], pos);
  27008. pos += content[j].length;
  27009. }
  27010. table.data = result;
  27011. table.length = newLength;
  27012. }
  27013. }
  27014. function sanitizeTTPrograms(fpgm, prep, cvt) {
  27015. var ttContext = {
  27016. functionsDefined: [],
  27017. functionsUsed: [],
  27018. functionsStackDeltas: [],
  27019. tooComplexToFollowFunctions: false,
  27020. hintsValid: true
  27021. };
  27022. if (fpgm) {
  27023. sanitizeTTProgram(fpgm, ttContext);
  27024. }
  27025. if (prep) {
  27026. sanitizeTTProgram(prep, ttContext);
  27027. }
  27028. if (fpgm) {
  27029. checkInvalidFunctions(ttContext, maxFunctionDefs);
  27030. }
  27031. if (cvt && (cvt.length & 1)) {
  27032. var cvtData = new Uint8Array(cvt.length + 1);
  27033. cvtData.set(cvt.data);
  27034. cvt.data = cvtData;
  27035. }
  27036. return ttContext.hintsValid;
  27037. }
  27038. // The following steps modify the original font data, making copy
  27039. font = new Stream(new Uint8Array(font.getBytes()));
  27040. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  27041. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  27042. var header = readOpenTypeHeader(font);
  27043. var numTables = header.numTables;
  27044. var cff, cffFile;
  27045. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  27046. hmtx: null, maxp: null, name: null, post: null };
  27047. var table;
  27048. for (var i = 0; i < numTables; i++) {
  27049. table = readTableEntry(font);
  27050. if (VALID_TABLES.indexOf(table.tag) < 0) {
  27051. continue; // skipping table if it's not a required or optional table
  27052. }
  27053. if (table.length === 0) {
  27054. continue; // skipping empty tables
  27055. }
  27056. tables[table.tag] = table;
  27057. }
  27058. var isTrueType = !tables['CFF '];
  27059. if (!isTrueType) {
  27060. // OpenType font
  27061. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  27062. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  27063. // no major tables: throwing everything at CFFFont
  27064. cffFile = new Stream(tables['CFF '].data);
  27065. cff = new CFFFont(cffFile, properties);
  27066. adjustWidths(properties);
  27067. return this.convert(name, cff, properties);
  27068. }
  27069. delete tables.glyf;
  27070. delete tables.loca;
  27071. delete tables.fpgm;
  27072. delete tables.prep;
  27073. delete tables['cvt '];
  27074. this.isOpenType = true;
  27075. } else {
  27076. if (!tables.glyf || !tables.loca) {
  27077. error('Required "glyf" or "loca" tables are not found');
  27078. }
  27079. this.isOpenType = false;
  27080. }
  27081. if (!tables.maxp) {
  27082. error('Required "maxp" table is not found');
  27083. }
  27084. font.pos = (font.start || 0) + tables.maxp.offset;
  27085. var version = font.getInt32();
  27086. var numGlyphs = font.getUint16();
  27087. var maxFunctionDefs = 0;
  27088. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  27089. // maxZones can be invalid
  27090. font.pos += 8;
  27091. var maxZones = font.getUint16();
  27092. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  27093. tables.maxp.data[14] = 0;
  27094. tables.maxp.data[15] = 2;
  27095. }
  27096. font.pos += 4;
  27097. maxFunctionDefs = font.getUint16();
  27098. }
  27099. var dupFirstEntry = false;
  27100. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  27101. properties.toUnicode.get(0) > '\u0000') {
  27102. // oracle's defect (see 3427), duplicating first entry
  27103. dupFirstEntry = true;
  27104. numGlyphs++;
  27105. tables.maxp.data[4] = numGlyphs >> 8;
  27106. tables.maxp.data[5] = numGlyphs & 255;
  27107. }
  27108. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  27109. tables['cvt '], maxFunctionDefs);
  27110. if (!hintsValid) {
  27111. delete tables.fpgm;
  27112. delete tables.prep;
  27113. delete tables['cvt '];
  27114. }
  27115. // Ensure the hmtx table contains the advance width and
  27116. // sidebearings information for numGlyphs in the maxp table
  27117. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  27118. if (!tables.head) {
  27119. error('Required "head" table is not found');
  27120. }
  27121. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  27122. var missingGlyphs = {};
  27123. if (isTrueType) {
  27124. var isGlyphLocationsLong = int16(tables.head.data[50],
  27125. tables.head.data[51]);
  27126. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  27127. numGlyphs, isGlyphLocationsLong,
  27128. hintsValid, dupFirstEntry);
  27129. }
  27130. if (!tables.hhea) {
  27131. error('Required "hhea" table is not found');
  27132. }
  27133. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  27134. // Sometimes it's 0. That needs to be fixed
  27135. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  27136. tables.hhea.data[10] = 0xFF;
  27137. tables.hhea.data[11] = 0xFF;
  27138. }
  27139. // Extract some more font properties from the OpenType head and
  27140. // hhea tables; yMin and descent value are always negative.
  27141. var metricsOverride = {
  27142. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  27143. yMax: int16(tables.head.data[42], tables.head.data[43]),
  27144. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  27145. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  27146. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  27147. };
  27148. // PDF FontDescriptor metrics lie -- using data from actual font.
  27149. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  27150. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  27151. // The 'post' table has glyphs names.
  27152. if (tables.post) {
  27153. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  27154. if (!valid) {
  27155. tables.post = null;
  27156. }
  27157. }
  27158. var charCodeToGlyphId = [], charCode;
  27159. var toUnicode = properties.toUnicode, widths = properties.widths;
  27160. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  27161. toUnicode.length === 0x10000);
  27162. // Helper function to try to skip mapping of empty glyphs.
  27163. // Note: In some cases, just relying on the glyph data doesn't work,
  27164. // hence we also use a few heuristics to fix various PDF files.
  27165. function hasGlyph(glyphId, charCode, widthCode) {
  27166. if (!missingGlyphs[glyphId]) {
  27167. return true;
  27168. }
  27169. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  27170. return true;
  27171. }
  27172. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  27173. return true;
  27174. }
  27175. return false;
  27176. }
  27177. if (properties.type === 'CIDFontType2') {
  27178. var cidToGidMap = properties.cidToGidMap || [];
  27179. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  27180. properties.cMap.forEach(function(charCode, cid) {
  27181. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27182. var glyphId = -1;
  27183. if (isCidToGidMapEmpty) {
  27184. glyphId = charCode;
  27185. } else if (cidToGidMap[cid] !== undefined) {
  27186. glyphId = cidToGidMap[cid];
  27187. }
  27188. if (glyphId >= 0 && glyphId < numGlyphs &&
  27189. hasGlyph(glyphId, charCode, cid)) {
  27190. charCodeToGlyphId[charCode] = glyphId;
  27191. }
  27192. });
  27193. if (dupFirstEntry) {
  27194. charCodeToGlyphId[0] = numGlyphs - 1;
  27195. }
  27196. } else {
  27197. // Most of the following logic in this code branch is based on the
  27198. // 9.6.6.4 of the PDF spec.
  27199. var hasEncoding =
  27200. properties.differences.length > 0 || !!properties.baseEncodingName;
  27201. var cmapTable =
  27202. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  27203. var cmapPlatformId = cmapTable.platformId;
  27204. var cmapEncodingId = cmapTable.encodingId;
  27205. var cmapMappings = cmapTable.mappings;
  27206. var cmapMappingsLength = cmapMappings.length;
  27207. // The spec seems to imply that if the font is symbolic the encoding
  27208. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  27209. // where the the font is symbolic and it has an encoding.
  27210. if (hasEncoding &&
  27211. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  27212. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  27213. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  27214. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  27215. // When no preferred cmap table was found and |baseEncodingName| is
  27216. // one of the predefined encodings, we seem to obtain a better
  27217. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  27218. // TODO: Note that this is a hack which should be removed as soon as
  27219. // we have proper support for more exotic cmap tables.
  27220. var baseEncoding = [];
  27221. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  27222. properties.baseEncodingName === 'WinAnsiEncoding') {
  27223. baseEncoding = Encodings[properties.baseEncodingName];
  27224. }
  27225. for (charCode = 0; charCode < 256; charCode++) {
  27226. var glyphName;
  27227. if (this.differences && charCode in this.differences) {
  27228. glyphName = this.differences[charCode];
  27229. } else if (charCode in baseEncoding &&
  27230. baseEncoding[charCode] !== '') {
  27231. glyphName = baseEncoding[charCode];
  27232. } else {
  27233. glyphName = Encodings.StandardEncoding[charCode];
  27234. }
  27235. if (!glyphName) {
  27236. continue;
  27237. }
  27238. var unicodeOrCharCode, isUnicode = false;
  27239. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  27240. unicodeOrCharCode = GlyphsUnicode[glyphName];
  27241. isUnicode = true;
  27242. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  27243. // TODO: the encoding needs to be updated with mac os table.
  27244. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  27245. }
  27246. var found = false;
  27247. for (i = 0; i < cmapMappingsLength; ++i) {
  27248. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  27249. continue;
  27250. }
  27251. var code = isUnicode ? charCode : unicodeOrCharCode;
  27252. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  27253. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27254. found = true;
  27255. break;
  27256. }
  27257. }
  27258. if (!found && properties.glyphNames) {
  27259. // Try to map using the post table.
  27260. var glyphId = properties.glyphNames.indexOf(glyphName);
  27261. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  27262. charCodeToGlyphId[charCode] = glyphId;
  27263. } else {
  27264. charCodeToGlyphId[charCode] = 0; // notdef
  27265. }
  27266. }
  27267. }
  27268. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  27269. // Default Unicode semantics, use the charcodes as is.
  27270. for (i = 0; i < cmapMappingsLength; ++i) {
  27271. charCodeToGlyphId[cmapMappings[i].charCode] =
  27272. cmapMappings[i].glyphId;
  27273. }
  27274. } else {
  27275. // For (3, 0) cmap tables:
  27276. // The charcode key being stored in charCodeToGlyphId is the lower
  27277. // byte of the two-byte charcodes of the cmap table since according to
  27278. // the spec: 'each byte from the string shall be prepended with the
  27279. // high byte of the range [of charcodes in the cmap table], to form
  27280. // a two-byte character, which shall be used to select the
  27281. // associated glyph description from the subtable'.
  27282. //
  27283. // For (1, 0) cmap tables:
  27284. // 'single bytes from the string shall be used to look up the
  27285. // associated glyph descriptions from the subtable'. This means
  27286. // charcodes in the cmap will be single bytes, so no-op since
  27287. // glyph.charCode & 0xFF === glyph.charCode
  27288. for (i = 0; i < cmapMappingsLength; ++i) {
  27289. charCode = cmapMappings[i].charCode & 0xFF;
  27290. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27291. }
  27292. }
  27293. }
  27294. if (charCodeToGlyphId.length === 0) {
  27295. // defines at least one glyph
  27296. charCodeToGlyphId[0] = 0;
  27297. }
  27298. // Converting glyphs and ids into font's cmap table
  27299. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  27300. this.toFontChar = newMapping.toFontChar;
  27301. tables.cmap = {
  27302. tag: 'cmap',
  27303. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  27304. };
  27305. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  27306. tables['OS/2'] = {
  27307. tag: 'OS/2',
  27308. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  27309. metricsOverride)
  27310. };
  27311. }
  27312. // Rewrite the 'post' table if needed
  27313. if (!tables.post) {
  27314. tables.post = {
  27315. tag: 'post',
  27316. data: createPostTable(properties)
  27317. };
  27318. }
  27319. if (!isTrueType) {
  27320. try {
  27321. // Trying to repair CFF file
  27322. cffFile = new Stream(tables['CFF '].data);
  27323. var parser = new CFFParser(cffFile, properties);
  27324. cff = parser.parse();
  27325. var compiler = new CFFCompiler(cff);
  27326. tables['CFF '].data = compiler.compile();
  27327. } catch (e) {
  27328. warn('Failed to compile font ' + properties.loadedName);
  27329. }
  27330. }
  27331. // Re-creating 'name' table
  27332. if (!tables.name) {
  27333. tables.name = {
  27334. tag: 'name',
  27335. data: createNameTable(this.name)
  27336. };
  27337. } else {
  27338. // ... using existing 'name' table as prototype
  27339. var namePrototype = readNameTable(tables.name);
  27340. tables.name.data = createNameTable(name, namePrototype);
  27341. }
  27342. var builder = new OpenTypeFileBuilder(header.version);
  27343. for (var tableTag in tables) {
  27344. builder.addTable(tableTag, tables[tableTag].data);
  27345. }
  27346. return builder.toArray();
  27347. },
  27348. convert: function Font_convert(fontName, font, properties) {
  27349. // TODO: Check the charstring widths to determine this.
  27350. properties.fixedPitch = false;
  27351. var mapping = font.getGlyphMapping(properties);
  27352. var newMapping = adjustMapping(mapping, properties);
  27353. this.toFontChar = newMapping.toFontChar;
  27354. var numGlyphs = font.numGlyphs;
  27355. function getCharCodes(charCodeToGlyphId, glyphId) {
  27356. var charCodes = null;
  27357. for (var charCode in charCodeToGlyphId) {
  27358. if (glyphId === charCodeToGlyphId[charCode]) {
  27359. if (!charCodes) {
  27360. charCodes = [];
  27361. }
  27362. charCodes.push(charCode | 0);
  27363. }
  27364. }
  27365. return charCodes;
  27366. }
  27367. function createCharCode(charCodeToGlyphId, glyphId) {
  27368. for (var charCode in charCodeToGlyphId) {
  27369. if (glyphId === charCodeToGlyphId[charCode]) {
  27370. return charCode | 0;
  27371. }
  27372. }
  27373. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  27374. glyphId;
  27375. return newMapping.nextAvailableFontCharCode++;
  27376. }
  27377. var seacs = font.seacs;
  27378. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  27379. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  27380. var charset = font.getCharset();
  27381. var seacMap = Object.create(null);
  27382. for (var glyphId in seacs) {
  27383. glyphId |= 0;
  27384. var seac = seacs[glyphId];
  27385. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  27386. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  27387. var baseGlyphId = charset.indexOf(baseGlyphName);
  27388. var accentGlyphId = charset.indexOf(accentGlyphName);
  27389. if (baseGlyphId < 0 || accentGlyphId < 0) {
  27390. continue;
  27391. }
  27392. var accentOffset = {
  27393. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  27394. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  27395. };
  27396. var charCodes = getCharCodes(mapping, glyphId);
  27397. if (!charCodes) {
  27398. // There's no point in mapping it if the char code was never mapped
  27399. // to begin with.
  27400. continue;
  27401. }
  27402. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  27403. var charCode = charCodes[i];
  27404. // Find a fontCharCode that maps to the base and accent glyphs.
  27405. // If one doesn't exists, create it.
  27406. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  27407. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  27408. baseGlyphId);
  27409. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  27410. accentGlyphId);
  27411. seacMap[charCode] = {
  27412. baseFontCharCode: baseFontCharCode,
  27413. accentFontCharCode: accentFontCharCode,
  27414. accentOffset: accentOffset
  27415. };
  27416. }
  27417. }
  27418. properties.seacMap = seacMap;
  27419. }
  27420. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  27421. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  27422. // PostScript Font Program
  27423. builder.addTable('CFF ', font.data);
  27424. // OS/2 and Windows Specific metrics
  27425. builder.addTable('OS/2', createOS2Table(properties,
  27426. newMapping.charCodeToGlyphId));
  27427. // Character to glyphs mapping
  27428. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  27429. numGlyphs));
  27430. // Font header
  27431. builder.addTable('head',
  27432. '\x00\x01\x00\x00' + // Version number
  27433. '\x00\x00\x10\x00' + // fontRevision
  27434. '\x00\x00\x00\x00' + // checksumAdjustement
  27435. '\x5F\x0F\x3C\xF5' + // magicNumber
  27436. '\x00\x00' + // Flags
  27437. safeString16(unitsPerEm) + // unitsPerEM
  27438. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  27439. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  27440. '\x00\x00' + // xMin
  27441. safeString16(properties.descent) + // yMin
  27442. '\x0F\xFF' + // xMax
  27443. safeString16(properties.ascent) + // yMax
  27444. string16(properties.italicAngle ? 2 : 0) + // macStyle
  27445. '\x00\x11' + // lowestRecPPEM
  27446. '\x00\x00' + // fontDirectionHint
  27447. '\x00\x00' + // indexToLocFormat
  27448. '\x00\x00'); // glyphDataFormat
  27449. // Horizontal header
  27450. builder.addTable('hhea',
  27451. '\x00\x01\x00\x00' + // Version number
  27452. safeString16(properties.ascent) + // Typographic Ascent
  27453. safeString16(properties.descent) + // Typographic Descent
  27454. '\x00\x00' + // Line Gap
  27455. '\xFF\xFF' + // advanceWidthMax
  27456. '\x00\x00' + // minLeftSidebearing
  27457. '\x00\x00' + // minRightSidebearing
  27458. '\x00\x00' + // xMaxExtent
  27459. safeString16(properties.capHeight) + // caretSlopeRise
  27460. safeString16(Math.tan(properties.italicAngle) *
  27461. properties.xHeight) + // caretSlopeRun
  27462. '\x00\x00' + // caretOffset
  27463. '\x00\x00' + // -reserved-
  27464. '\x00\x00' + // -reserved-
  27465. '\x00\x00' + // -reserved-
  27466. '\x00\x00' + // -reserved-
  27467. '\x00\x00' + // metricDataFormat
  27468. string16(numGlyphs)); // Number of HMetrics
  27469. // Horizontal metrics
  27470. builder.addTable('hmtx', (function fontFieldsHmtx() {
  27471. var charstrings = font.charstrings;
  27472. var cffWidths = font.cff ? font.cff.widths : null;
  27473. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  27474. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  27475. var width = 0;
  27476. if (charstrings) {
  27477. var charstring = charstrings[i - 1];
  27478. width = 'width' in charstring ? charstring.width : 0;
  27479. } else if (cffWidths) {
  27480. width = Math.ceil(cffWidths[i] || 0);
  27481. }
  27482. hmtx += string16(width) + string16(0);
  27483. }
  27484. return hmtx;
  27485. })());
  27486. // Maximum profile
  27487. builder.addTable('maxp',
  27488. '\x00\x00\x50\x00' + // Version number
  27489. string16(numGlyphs)); // Num of glyphs
  27490. // Naming tables
  27491. builder.addTable('name', createNameTable(fontName));
  27492. // PostScript informations
  27493. builder.addTable('post', createPostTable(properties));
  27494. return builder.toArray();
  27495. },
  27496. /**
  27497. * Builds a char code to unicode map based on section 9.10 of the spec.
  27498. * @param {Object} properties Font properties object.
  27499. * @return {Object} A ToUnicodeMap object.
  27500. */
  27501. buildToUnicode: function Font_buildToUnicode(properties) {
  27502. // Section 9.10.2 Mapping Character Codes to Unicode Values
  27503. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  27504. return properties.toUnicode;
  27505. }
  27506. // According to the spec if the font is a simple font we should only map
  27507. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  27508. // the differences array only contains adobe standard or symbol set names,
  27509. // in pratice it seems better to always try to create a toUnicode
  27510. // map based of the default encoding.
  27511. var toUnicode, charcode;
  27512. if (!properties.composite /* is simple font */) {
  27513. toUnicode = [];
  27514. var encoding = properties.defaultEncoding.slice();
  27515. var baseEncodingName = properties.baseEncodingName;
  27516. // Merge in the differences array.
  27517. var differences = properties.differences;
  27518. for (charcode in differences) {
  27519. encoding[charcode] = differences[charcode];
  27520. }
  27521. for (charcode in encoding) {
  27522. // a) Map the character code to a character name.
  27523. var glyphName = encoding[charcode];
  27524. // b) Look up the character name in the Adobe Glyph List (see the
  27525. // Bibliography) to obtain the corresponding Unicode value.
  27526. if (glyphName === '') {
  27527. continue;
  27528. } else if (GlyphsUnicode[glyphName] === undefined) {
  27529. // (undocumented) c) Few heuristics to recognize unknown glyphs
  27530. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  27531. var code = 0;
  27532. switch (glyphName[0]) {
  27533. case 'G': // Gxx glyph
  27534. if (glyphName.length === 3) {
  27535. code = parseInt(glyphName.substr(1), 16);
  27536. }
  27537. break;
  27538. case 'g': // g00xx glyph
  27539. if (glyphName.length === 5) {
  27540. code = parseInt(glyphName.substr(1), 16);
  27541. }
  27542. break;
  27543. case 'C': // Cddd glyph
  27544. case 'c': // cddd glyph
  27545. if (glyphName.length >= 3) {
  27546. code = +glyphName.substr(1);
  27547. }
  27548. break;
  27549. }
  27550. if (code) {
  27551. // If |baseEncodingName| is one the predefined encodings,
  27552. // and |code| equals |charcode|, using the glyph defined in the
  27553. // baseEncoding seems to yield a better |toUnicode| mapping
  27554. // (fixes issue 5070).
  27555. if (baseEncodingName && code === +charcode) {
  27556. var baseEncoding = Encodings[baseEncodingName];
  27557. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  27558. toUnicode[charcode] =
  27559. String.fromCharCode(GlyphsUnicode[glyphName]);
  27560. continue;
  27561. }
  27562. }
  27563. toUnicode[charcode] = String.fromCharCode(code);
  27564. }
  27565. continue;
  27566. }
  27567. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  27568. }
  27569. return new ToUnicodeMap(toUnicode);
  27570. }
  27571. // If the font is a composite font that uses one of the predefined CMaps
  27572. // listed in Table 118 (except Identity–H and Identity–V) or whose
  27573. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  27574. // Adobe-Korea1 character collection:
  27575. if (properties.composite && (
  27576. (properties.cMap.builtInCMap &&
  27577. !(properties.cMap instanceof IdentityCMap)) ||
  27578. (properties.cidSystemInfo.registry === 'Adobe' &&
  27579. (properties.cidSystemInfo.ordering === 'GB1' ||
  27580. properties.cidSystemInfo.ordering === 'CNS1' ||
  27581. properties.cidSystemInfo.ordering === 'Japan1' ||
  27582. properties.cidSystemInfo.ordering === 'Korea1')))) {
  27583. // Then:
  27584. // a) Map the character code to a character identifier (CID) according
  27585. // to the font’s CMap.
  27586. // b) Obtain the registry and ordering of the character collection used
  27587. // by the font’s CMap (for example, Adobe and Japan1) from its
  27588. // CIDSystemInfo dictionary.
  27589. var registry = properties.cidSystemInfo.registry;
  27590. var ordering = properties.cidSystemInfo.ordering;
  27591. // c) Construct a second CMap name by concatenating the registry and
  27592. // ordering obtained in step (b) in the format registry–ordering–UCS2
  27593. // (for example, Adobe–Japan1–UCS2).
  27594. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  27595. // d) Obtain the CMap with the name constructed in step (c) (available
  27596. // from the ASN Web site; see the Bibliography).
  27597. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  27598. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  27599. var cMap = properties.cMap;
  27600. toUnicode = [];
  27601. cMap.forEach(function(charcode, cid) {
  27602. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27603. // e) Map the CID obtained in step (a) according to the CMap obtained
  27604. // in step (d), producing a Unicode value.
  27605. var ucs2 = ucs2CMap.lookup(cid);
  27606. if (ucs2) {
  27607. toUnicode[charcode] =
  27608. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  27609. ucs2.charCodeAt(1));
  27610. }
  27611. });
  27612. return new ToUnicodeMap(toUnicode);
  27613. }
  27614. // The viewer's choice, just use an identity map.
  27615. return new IdentityToUnicodeMap(properties.firstChar,
  27616. properties.lastChar);
  27617. },
  27618. get spaceWidth() {
  27619. if ('_shadowWidth' in this) {
  27620. return this._shadowWidth;
  27621. }
  27622. // trying to estimate space character width
  27623. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  27624. var width;
  27625. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  27626. var glyphName = possibleSpaceReplacements[i];
  27627. // if possible, getting width by glyph name
  27628. if (glyphName in this.widths) {
  27629. width = this.widths[glyphName];
  27630. break;
  27631. }
  27632. var glyphUnicode = GlyphsUnicode[glyphName];
  27633. // finding the charcode via unicodeToCID map
  27634. var charcode = 0;
  27635. if (this.composite) {
  27636. if (this.cMap.contains(glyphUnicode)) {
  27637. charcode = this.cMap.lookup(glyphUnicode);
  27638. }
  27639. }
  27640. // ... via toUnicode map
  27641. if (!charcode && this.toUnicode) {
  27642. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27643. }
  27644. // setting it to unicode if negative or undefined
  27645. if (charcode <= 0) {
  27646. charcode = glyphUnicode;
  27647. }
  27648. // trying to get width via charcode
  27649. width = this.widths[charcode];
  27650. if (width) {
  27651. break; // the non-zero width found
  27652. }
  27653. }
  27654. width = width || this.defaultWidth;
  27655. // Do not shadow the property here. See discussion:
  27656. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27657. this._shadowWidth = width;
  27658. return width;
  27659. },
  27660. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27661. var fontCharCode, width, operatorListId;
  27662. var widthCode = charcode;
  27663. if (this.cMap && this.cMap.contains(charcode)) {
  27664. widthCode = this.cMap.lookup(charcode);
  27665. }
  27666. width = this.widths[widthCode];
  27667. width = isNum(width) ? width : this.defaultWidth;
  27668. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27669. var unicode = this.toUnicode.get(charcode) || charcode;
  27670. if (typeof unicode === 'number') {
  27671. unicode = String.fromCharCode(unicode);
  27672. }
  27673. // First try the toFontChar map, if it's not there then try falling
  27674. // back to the char code.
  27675. fontCharCode = this.toFontChar[charcode] || charcode;
  27676. if (this.missingFile) {
  27677. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27678. }
  27679. if (this.isType3Font) {
  27680. // Font char code in this case is actually a glyph name.
  27681. operatorListId = fontCharCode;
  27682. }
  27683. var accent = null;
  27684. if (this.seacMap && this.seacMap[charcode]) {
  27685. var seac = this.seacMap[charcode];
  27686. fontCharCode = seac.baseFontCharCode;
  27687. accent = {
  27688. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27689. offset: seac.accentOffset
  27690. };
  27691. }
  27692. var fontChar = String.fromCharCode(fontCharCode);
  27693. var glyph = this.glyphCache[charcode];
  27694. if (!glyph ||
  27695. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27696. operatorListId, isSpace)) {
  27697. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27698. operatorListId, isSpace);
  27699. this.glyphCache[charcode] = glyph;
  27700. }
  27701. return glyph;
  27702. },
  27703. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27704. var charsCache = this.charsCache;
  27705. var glyphs, glyph, charcode;
  27706. // if we translated this string before, just grab it from the cache
  27707. if (charsCache) {
  27708. glyphs = charsCache[chars];
  27709. if (glyphs) {
  27710. return glyphs;
  27711. }
  27712. }
  27713. // lazily create the translation cache
  27714. if (!charsCache) {
  27715. charsCache = this.charsCache = Object.create(null);
  27716. }
  27717. glyphs = [];
  27718. var charsCacheKey = chars;
  27719. var i = 0, ii;
  27720. if (this.cMap) {
  27721. // composite fonts have multi-byte strings convert the string from
  27722. // single-byte to multi-byte
  27723. var c = {};
  27724. while (i < chars.length) {
  27725. this.cMap.readCharCode(chars, i, c);
  27726. charcode = c.charcode;
  27727. var length = c.length;
  27728. i += length;
  27729. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27730. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27731. glyph = this.charToGlyph(charcode, isSpace);
  27732. glyphs.push(glyph);
  27733. }
  27734. } else {
  27735. for (i = 0, ii = chars.length; i < ii; ++i) {
  27736. charcode = chars.charCodeAt(i);
  27737. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27738. glyphs.push(glyph);
  27739. }
  27740. }
  27741. // Enter the translated string into the cache
  27742. return (charsCache[charsCacheKey] = glyphs);
  27743. }
  27744. };
  27745. return Font;
  27746. })();
  27747. var ErrorFont = (function ErrorFontClosure() {
  27748. function ErrorFont(error) {
  27749. this.error = error;
  27750. this.loadedName = 'g_font_error';
  27751. this.loading = false;
  27752. }
  27753. ErrorFont.prototype = {
  27754. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27755. return [];
  27756. },
  27757. exportData: function ErrorFont_exportData() {
  27758. return {error: this.error};
  27759. }
  27760. };
  27761. return ErrorFont;
  27762. })();
  27763. /**
  27764. * Shared logic for building a char code to glyph id mapping for Type1 and
  27765. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27766. * @param {Object} properties Font properties object.
  27767. * @param {Object} builtInEncoding The encoding contained within the actual font
  27768. * data.
  27769. * @param {Array} Array of glyph names where the index is the glyph ID.
  27770. * @returns {Object} A char code to glyph ID map.
  27771. */
  27772. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27773. var charCodeToGlyphId = Object.create(null);
  27774. var glyphId, charCode, baseEncoding;
  27775. if (properties.baseEncodingName) {
  27776. // If a valid base encoding name was used, the mapping is initialized with
  27777. // that.
  27778. baseEncoding = Encodings[properties.baseEncodingName];
  27779. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27780. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27781. if (glyphId >= 0) {
  27782. charCodeToGlyphId[charCode] = glyphId;
  27783. } else {
  27784. charCodeToGlyphId[charCode] = 0; // notdef
  27785. }
  27786. }
  27787. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27788. // For a symbolic font the encoding should be the fonts built-in
  27789. // encoding.
  27790. for (charCode in builtInEncoding) {
  27791. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27792. }
  27793. } else {
  27794. // For non-symbolic fonts that don't have a base encoding the standard
  27795. // encoding should be used.
  27796. baseEncoding = Encodings.StandardEncoding;
  27797. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27798. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27799. if (glyphId >= 0) {
  27800. charCodeToGlyphId[charCode] = glyphId;
  27801. } else {
  27802. charCodeToGlyphId[charCode] = 0; // notdef
  27803. }
  27804. }
  27805. }
  27806. // Lastly, merge in the differences.
  27807. var differences = properties.differences;
  27808. if (differences) {
  27809. for (charCode in differences) {
  27810. var glyphName = differences[charCode];
  27811. glyphId = glyphNames.indexOf(glyphName);
  27812. if (glyphId >= 0) {
  27813. charCodeToGlyphId[charCode] = glyphId;
  27814. } else {
  27815. charCodeToGlyphId[charCode] = 0; // notdef
  27816. }
  27817. }
  27818. }
  27819. return charCodeToGlyphId;
  27820. }
  27821. /*
  27822. * CharStrings are encoded following the the CharString Encoding sequence
  27823. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27824. * The value in a byte indicates a command, a number, or subsequent bytes
  27825. * that are to be interpreted in a special way.
  27826. *
  27827. * CharString Number Encoding:
  27828. * A CharString byte containing the values from 32 through 255 inclusive
  27829. * indicate an integer. These values are decoded in four ranges.
  27830. *
  27831. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27832. * indicate the integer v - 139. Thus, the integer values from -107 through
  27833. * 107 inclusive may be encoded in single byte.
  27834. *
  27835. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27836. * indicates an integer involving the next byte, w, according to the formula:
  27837. * [(v - 247) x 256] + w + 108
  27838. *
  27839. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27840. * indicates an integer involving the next byte, w, according to the formula:
  27841. * -[(v - 251) * 256] - w - 108
  27842. *
  27843. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27844. * are a two complement signed integer. The first of these bytes contains the
  27845. * highest order bits, the second byte contains the next higher order bits
  27846. * and the fourth byte contain the lowest order bits.
  27847. *
  27848. *
  27849. * CharString Command Encoding:
  27850. * CharStrings commands are encoded in 1 or 2 bytes.
  27851. *
  27852. * Single byte commands are encoded in 1 byte that contains a value between
  27853. * 0 and 31 inclusive.
  27854. * If a command byte contains the value 12, then the value in the next byte
  27855. * indicates a command. This "escape" mechanism allows many extra commands
  27856. * to be encoded and this encoding technique helps to minimize the length of
  27857. * the charStrings.
  27858. */
  27859. var Type1CharString = (function Type1CharStringClosure() {
  27860. var COMMAND_MAP = {
  27861. 'hstem': [1],
  27862. 'vstem': [3],
  27863. 'vmoveto': [4],
  27864. 'rlineto': [5],
  27865. 'hlineto': [6],
  27866. 'vlineto': [7],
  27867. 'rrcurveto': [8],
  27868. 'callsubr': [10],
  27869. 'flex': [12, 35],
  27870. 'drop' : [12, 18],
  27871. 'endchar': [14],
  27872. 'rmoveto': [21],
  27873. 'hmoveto': [22],
  27874. 'vhcurveto': [30],
  27875. 'hvcurveto': [31]
  27876. };
  27877. function Type1CharString() {
  27878. this.width = 0;
  27879. this.lsb = 0;
  27880. this.flexing = false;
  27881. this.output = [];
  27882. this.stack = [];
  27883. }
  27884. Type1CharString.prototype = {
  27885. convert: function Type1CharString_convert(encoded, subrs) {
  27886. var count = encoded.length;
  27887. var error = false;
  27888. var wx, sbx, subrNumber;
  27889. for (var i = 0; i < count; i++) {
  27890. var value = encoded[i];
  27891. if (value < 32) {
  27892. if (value === 12) {
  27893. value = (value << 8) + encoded[++i];
  27894. }
  27895. switch (value) {
  27896. case 1: // hstem
  27897. if (!HINTING_ENABLED) {
  27898. this.stack = [];
  27899. break;
  27900. }
  27901. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27902. break;
  27903. case 3: // vstem
  27904. if (!HINTING_ENABLED) {
  27905. this.stack = [];
  27906. break;
  27907. }
  27908. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27909. break;
  27910. case 4: // vmoveto
  27911. if (this.flexing) {
  27912. if (this.stack.length < 1) {
  27913. error = true;
  27914. break;
  27915. }
  27916. // Add the dx for flex and but also swap the values so they are
  27917. // the right order.
  27918. var dy = this.stack.pop();
  27919. this.stack.push(0, dy);
  27920. break;
  27921. }
  27922. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  27923. break;
  27924. case 5: // rlineto
  27925. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  27926. break;
  27927. case 6: // hlineto
  27928. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  27929. break;
  27930. case 7: // vlineto
  27931. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  27932. break;
  27933. case 8: // rrcurveto
  27934. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  27935. break;
  27936. case 9: // closepath
  27937. // closepath is a Type1 command that does not take argument and is
  27938. // useless in Type2 and it can simply be ignored.
  27939. this.stack = [];
  27940. break;
  27941. case 10: // callsubr
  27942. if (this.stack.length < 1) {
  27943. error = true;
  27944. break;
  27945. }
  27946. subrNumber = this.stack.pop();
  27947. error = this.convert(subrs[subrNumber], subrs);
  27948. break;
  27949. case 11: // return
  27950. return error;
  27951. case 13: // hsbw
  27952. if (this.stack.length < 2) {
  27953. error = true;
  27954. break;
  27955. }
  27956. // To convert to type2 we have to move the width value to the
  27957. // first part of the charstring and then use hmoveto with lsb.
  27958. wx = this.stack.pop();
  27959. sbx = this.stack.pop();
  27960. this.lsb = sbx;
  27961. this.width = wx;
  27962. this.stack.push(wx, sbx);
  27963. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  27964. break;
  27965. case 14: // endchar
  27966. this.output.push(COMMAND_MAP.endchar[0]);
  27967. break;
  27968. case 21: // rmoveto
  27969. if (this.flexing) {
  27970. break;
  27971. }
  27972. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  27973. break;
  27974. case 22: // hmoveto
  27975. if (this.flexing) {
  27976. // Add the dy for flex.
  27977. this.stack.push(0);
  27978. break;
  27979. }
  27980. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  27981. break;
  27982. case 30: // vhcurveto
  27983. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  27984. break;
  27985. case 31: // hvcurveto
  27986. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  27987. break;
  27988. case (12 << 8) + 0: // dotsection
  27989. // dotsection is a Type1 command to specify some hinting feature
  27990. // for dots that do not take a parameter and it can safely be
  27991. // ignored for Type2.
  27992. this.stack = [];
  27993. break;
  27994. case (12 << 8) + 1: // vstem3
  27995. if (!HINTING_ENABLED) {
  27996. this.stack = [];
  27997. break;
  27998. }
  27999. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28000. // multiple parameters, so instead of returning [vh]stem3 take a
  28001. // shortcut and return [vhstem] instead.
  28002. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28003. break;
  28004. case (12 << 8) + 2: // hstem3
  28005. if (!HINTING_ENABLED) {
  28006. this.stack = [];
  28007. break;
  28008. }
  28009. // See vstem3.
  28010. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28011. break;
  28012. case (12 << 8) + 6: // seac
  28013. // seac is like type 2's special endchar but it doesn't use the
  28014. // first argument asb, so remove it.
  28015. if (SEAC_ANALYSIS_ENABLED) {
  28016. this.seac = this.stack.splice(-4, 4);
  28017. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28018. } else {
  28019. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28020. }
  28021. break;
  28022. case (12 << 8) + 7: // sbw
  28023. if (this.stack.length < 4) {
  28024. error = true;
  28025. break;
  28026. }
  28027. // To convert to type2 we have to move the width value to the
  28028. // first part of the charstring and then use rmoveto with
  28029. // (dx, dy). The height argument will not be used for vmtx and
  28030. // vhea tables reconstruction -- ignoring it.
  28031. var wy = this.stack.pop();
  28032. wx = this.stack.pop();
  28033. var sby = this.stack.pop();
  28034. sbx = this.stack.pop();
  28035. this.lsb = sbx;
  28036. this.width = wx;
  28037. this.stack.push(wx, sbx, sby);
  28038. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28039. break;
  28040. case (12 << 8) + 12: // div
  28041. if (this.stack.length < 2) {
  28042. error = true;
  28043. break;
  28044. }
  28045. var num2 = this.stack.pop();
  28046. var num1 = this.stack.pop();
  28047. this.stack.push(num1 / num2);
  28048. break;
  28049. case (12 << 8) + 16: // callothersubr
  28050. if (this.stack.length < 2) {
  28051. error = true;
  28052. break;
  28053. }
  28054. subrNumber = this.stack.pop();
  28055. var numArgs = this.stack.pop();
  28056. if (subrNumber === 0 && numArgs === 3) {
  28057. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28058. this.stack.push(
  28059. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28060. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28061. flexArgs[4], // bcp2x
  28062. flexArgs[5], // bcp2y
  28063. flexArgs[6], // p2x
  28064. flexArgs[7], // p2y
  28065. flexArgs[8], // bcp3x
  28066. flexArgs[9], // bcp3y
  28067. flexArgs[10], // bcp4x
  28068. flexArgs[11], // bcp4y
  28069. flexArgs[12], // p3x
  28070. flexArgs[13], // p3y
  28071. flexArgs[14] // flexDepth
  28072. // 15 = finalx unused by flex
  28073. // 16 = finaly unused by flex
  28074. );
  28075. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28076. this.flexing = false;
  28077. this.stack.push(flexArgs[15], flexArgs[16]);
  28078. } else if (subrNumber === 1 && numArgs === 0) {
  28079. this.flexing = true;
  28080. }
  28081. break;
  28082. case (12 << 8) + 17: // pop
  28083. // Ignore this since it is only used with othersubr.
  28084. break;
  28085. case (12 << 8) + 33: // setcurrentpoint
  28086. // Ignore for now.
  28087. this.stack = [];
  28088. break;
  28089. default:
  28090. warn('Unknown type 1 charstring command of "' + value + '"');
  28091. break;
  28092. }
  28093. if (error) {
  28094. break;
  28095. }
  28096. continue;
  28097. } else if (value <= 246) {
  28098. value = value - 139;
  28099. } else if (value <= 250) {
  28100. value = ((value - 247) * 256) + encoded[++i] + 108;
  28101. } else if (value <= 254) {
  28102. value = -((value - 251) * 256) - encoded[++i] - 108;
  28103. } else {
  28104. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28105. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28106. }
  28107. this.stack.push(value);
  28108. }
  28109. return error;
  28110. },
  28111. executeCommand: function(howManyArgs, command, keepStack) {
  28112. var stackLength = this.stack.length;
  28113. if (howManyArgs > stackLength) {
  28114. return true;
  28115. }
  28116. var start = stackLength - howManyArgs;
  28117. for (var i = start; i < stackLength; i++) {
  28118. var value = this.stack[i];
  28119. if (value === (value | 0)) { // int
  28120. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28121. } else { // fixed point
  28122. value = (65536 * value) | 0;
  28123. this.output.push(255,
  28124. (value >> 24) & 0xFF,
  28125. (value >> 16) & 0xFF,
  28126. (value >> 8) & 0xFF,
  28127. value & 0xFF);
  28128. }
  28129. }
  28130. this.output.push.apply(this.output, command);
  28131. if (keepStack) {
  28132. this.stack.splice(start, howManyArgs);
  28133. } else {
  28134. this.stack.length = 0;
  28135. }
  28136. return false;
  28137. }
  28138. };
  28139. return Type1CharString;
  28140. })();
  28141. /*
  28142. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28143. * program. Some of its logic depends on the Type2 charstrings
  28144. * structure.
  28145. * Note: this doesn't really parse the font since that would require evaluation
  28146. * of PostScript, but it is possible in most cases to extract what we need
  28147. * without a full parse.
  28148. */
  28149. var Type1Parser = (function Type1ParserClosure() {
  28150. /*
  28151. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28152. * of Plaintext Bytes. The function took a key as a parameter which can be
  28153. * for decrypting the eexec block of for decoding charStrings.
  28154. */
  28155. var EEXEC_ENCRYPT_KEY = 55665;
  28156. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28157. function isHexDigit(code) {
  28158. return code >= 48 && code <= 57 || // '0'-'9'
  28159. code >= 65 && code <= 70 || // 'A'-'F'
  28160. code >= 97 && code <= 102; // 'a'-'f'
  28161. }
  28162. function decrypt(data, key, discardNumber) {
  28163. var r = key | 0, c1 = 52845, c2 = 22719;
  28164. var count = data.length;
  28165. var decrypted = new Uint8Array(count);
  28166. for (var i = 0; i < count; i++) {
  28167. var value = data[i];
  28168. decrypted[i] = value ^ (r >> 8);
  28169. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28170. }
  28171. return Array.prototype.slice.call(decrypted, discardNumber);
  28172. }
  28173. function decryptAscii(data, key, discardNumber) {
  28174. var r = key | 0, c1 = 52845, c2 = 22719;
  28175. var count = data.length, maybeLength = count >>> 1;
  28176. var decrypted = new Uint8Array(maybeLength);
  28177. var i, j;
  28178. for (i = 0, j = 0; i < count; i++) {
  28179. var digit1 = data[i];
  28180. if (!isHexDigit(digit1)) {
  28181. continue;
  28182. }
  28183. i++;
  28184. var digit2;
  28185. while (i < count && !isHexDigit(digit2 = data[i])) {
  28186. i++;
  28187. }
  28188. if (i < count) {
  28189. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28190. decrypted[j++] = value ^ (r >> 8);
  28191. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28192. }
  28193. }
  28194. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28195. }
  28196. function isSpecial(c) {
  28197. return c === 0x2F || // '/'
  28198. c === 0x5B || c === 0x5D || // '[', ']'
  28199. c === 0x7B || c === 0x7D || // '{', '}'
  28200. c === 0x28 || c === 0x29; // '(', ')'
  28201. }
  28202. function Type1Parser(stream, encrypted) {
  28203. if (encrypted) {
  28204. var data = stream.getBytes();
  28205. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28206. isHexDigit(data[2]) && isHexDigit(data[3]));
  28207. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28208. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28209. }
  28210. this.stream = stream;
  28211. this.nextChar();
  28212. }
  28213. Type1Parser.prototype = {
  28214. readNumberArray: function Type1Parser_readNumberArray() {
  28215. this.getToken(); // read '[' or '{' (arrays can start with either)
  28216. var array = [];
  28217. while (true) {
  28218. var token = this.getToken();
  28219. if (token === null || token === ']' || token === '}') {
  28220. break;
  28221. }
  28222. array.push(parseFloat(token || 0));
  28223. }
  28224. return array;
  28225. },
  28226. readNumber: function Type1Parser_readNumber() {
  28227. var token = this.getToken();
  28228. return parseFloat(token || 0);
  28229. },
  28230. readInt: function Type1Parser_readInt() {
  28231. // Use '| 0' to prevent setting a double into length such as the double
  28232. // does not flow into the loop variable.
  28233. var token = this.getToken();
  28234. return parseInt(token || 0, 10) | 0;
  28235. },
  28236. readBoolean: function Type1Parser_readBoolean() {
  28237. var token = this.getToken();
  28238. // Use 1 and 0 since that's what type2 charstrings use.
  28239. return token === 'true' ? 1 : 0;
  28240. },
  28241. nextChar : function Type1_nextChar() {
  28242. return (this.currentChar = this.stream.getByte());
  28243. },
  28244. getToken: function Type1Parser_getToken() {
  28245. // Eat whitespace and comments.
  28246. var comment = false;
  28247. var ch = this.currentChar;
  28248. while (true) {
  28249. if (ch === -1) {
  28250. return null;
  28251. }
  28252. if (comment) {
  28253. if (ch === 0x0A || ch === 0x0D) {
  28254. comment = false;
  28255. }
  28256. } else if (ch === 0x25) { // '%'
  28257. comment = true;
  28258. } else if (!Lexer.isSpace(ch)) {
  28259. break;
  28260. }
  28261. ch = this.nextChar();
  28262. }
  28263. if (isSpecial(ch)) {
  28264. this.nextChar();
  28265. return String.fromCharCode(ch);
  28266. }
  28267. var token = '';
  28268. do {
  28269. token += String.fromCharCode(ch);
  28270. ch = this.nextChar();
  28271. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  28272. return token;
  28273. },
  28274. /*
  28275. * Returns an object containing a Subrs array and a CharStrings
  28276. * array extracted from and eexec encrypted block of data
  28277. */
  28278. extractFontProgram: function Type1Parser_extractFontProgram() {
  28279. var stream = this.stream;
  28280. var subrs = [], charstrings = [];
  28281. var program = {
  28282. subrs: [],
  28283. charstrings: [],
  28284. properties: {
  28285. 'privateData': {
  28286. 'lenIV': 4
  28287. }
  28288. }
  28289. };
  28290. var token, length, data, lenIV, encoded;
  28291. while ((token = this.getToken()) !== null) {
  28292. if (token !== '/') {
  28293. continue;
  28294. }
  28295. token = this.getToken();
  28296. switch (token) {
  28297. case 'CharStrings':
  28298. // The number immediately following CharStrings must be greater or
  28299. // equal to the number of CharStrings.
  28300. this.getToken();
  28301. this.getToken(); // read in 'dict'
  28302. this.getToken(); // read in 'dup'
  28303. this.getToken(); // read in 'begin'
  28304. while(true) {
  28305. token = this.getToken();
  28306. if (token === null || token === 'end') {
  28307. break;
  28308. }
  28309. if (token !== '/') {
  28310. continue;
  28311. }
  28312. var glyph = this.getToken();
  28313. length = this.readInt();
  28314. this.getToken(); // read in 'RD' or '-|'
  28315. data = stream.makeSubStream(stream.pos, length);
  28316. lenIV = program.properties.privateData['lenIV'];
  28317. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28318. // Skip past the required space and binary data.
  28319. stream.skip(length);
  28320. this.nextChar();
  28321. token = this.getToken(); // read in 'ND' or '|-'
  28322. if (token === 'noaccess') {
  28323. this.getToken(); // read in 'def'
  28324. }
  28325. charstrings.push({
  28326. glyph: glyph,
  28327. encoded: encoded
  28328. });
  28329. }
  28330. break;
  28331. case 'Subrs':
  28332. var num = this.readInt();
  28333. this.getToken(); // read in 'array'
  28334. while ((token = this.getToken()) === 'dup') {
  28335. var index = this.readInt();
  28336. length = this.readInt();
  28337. this.getToken(); // read in 'RD' or '-|'
  28338. data = stream.makeSubStream(stream.pos, length);
  28339. lenIV = program.properties.privateData['lenIV'];
  28340. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28341. // Skip past the required space and binary data.
  28342. stream.skip(length);
  28343. this.nextChar();
  28344. token = this.getToken(); // read in 'NP' or '|'
  28345. if (token === 'noaccess') {
  28346. this.getToken(); // read in 'put'
  28347. }
  28348. subrs[index] = encoded;
  28349. }
  28350. break;
  28351. case 'BlueValues':
  28352. case 'OtherBlues':
  28353. case 'FamilyBlues':
  28354. case 'FamilyOtherBlues':
  28355. var blueArray = this.readNumberArray();
  28356. // *Blue* values may contain invalid data: disables reading of
  28357. // those values when hinting is disabled.
  28358. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28359. HINTING_ENABLED) {
  28360. program.properties.privateData[token] = blueArray;
  28361. }
  28362. break;
  28363. case 'StemSnapH':
  28364. case 'StemSnapV':
  28365. program.properties.privateData[token] = this.readNumberArray();
  28366. break;
  28367. case 'StdHW':
  28368. case 'StdVW':
  28369. program.properties.privateData[token] =
  28370. this.readNumberArray()[0];
  28371. break;
  28372. case 'BlueShift':
  28373. case 'lenIV':
  28374. case 'BlueFuzz':
  28375. case 'BlueScale':
  28376. case 'LanguageGroup':
  28377. case 'ExpansionFactor':
  28378. program.properties.privateData[token] = this.readNumber();
  28379. break;
  28380. case 'ForceBold':
  28381. program.properties.privateData[token] = this.readBoolean();
  28382. break;
  28383. }
  28384. }
  28385. for (var i = 0; i < charstrings.length; i++) {
  28386. glyph = charstrings[i].glyph;
  28387. encoded = charstrings[i].encoded;
  28388. var charString = new Type1CharString();
  28389. var error = charString.convert(encoded, subrs);
  28390. var output = charString.output;
  28391. if (error) {
  28392. // It seems when FreeType encounters an error while evaluating a glyph
  28393. // that it completely ignores the glyph so we'll mimic that behaviour
  28394. // here and put an endchar to make the validator happy.
  28395. output = [14];
  28396. }
  28397. program.charstrings.push({
  28398. glyphName: glyph,
  28399. charstring: output,
  28400. width: charString.width,
  28401. lsb: charString.lsb,
  28402. seac: charString.seac
  28403. });
  28404. }
  28405. return program;
  28406. },
  28407. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28408. var token;
  28409. while ((token = this.getToken()) !== null) {
  28410. if (token !== '/') {
  28411. continue;
  28412. }
  28413. token = this.getToken();
  28414. switch (token) {
  28415. case 'FontMatrix':
  28416. var matrix = this.readNumberArray();
  28417. properties.fontMatrix = matrix;
  28418. break;
  28419. case 'Encoding':
  28420. var encodingArg = this.getToken();
  28421. var encoding;
  28422. if (!/^\d+$/.test(encodingArg)) {
  28423. // encoding name is specified
  28424. encoding = Encodings[encodingArg];
  28425. } else {
  28426. encoding = [];
  28427. var size = parseInt(encodingArg, 10) | 0;
  28428. this.getToken(); // read in 'array'
  28429. for (var j = 0; j < size; j++) {
  28430. token = this.getToken();
  28431. // skipping till first dup or def (e.g. ignoring for statement)
  28432. while (token !== 'dup' && token !== 'def') {
  28433. token = this.getToken();
  28434. if (token === null) {
  28435. return; // invalid header
  28436. }
  28437. }
  28438. if (token === 'def') {
  28439. break; // read all array data
  28440. }
  28441. var index = this.readInt();
  28442. this.getToken(); // read in '/'
  28443. var glyph = this.getToken();
  28444. encoding[index] = glyph;
  28445. this.getToken(); // read the in 'put'
  28446. }
  28447. }
  28448. properties.builtInEncoding = encoding;
  28449. break;
  28450. case 'FontBBox':
  28451. var fontBBox = this.readNumberArray();
  28452. // adjusting ascent/descent
  28453. properties.ascent = fontBBox[3];
  28454. properties.descent = fontBBox[1];
  28455. properties.ascentScaled = true;
  28456. break;
  28457. }
  28458. }
  28459. }
  28460. };
  28461. return Type1Parser;
  28462. })();
  28463. /**
  28464. * The CFF class takes a Type1 file and wrap it into a
  28465. * 'Compact Font Format' which itself embed Type2 charstrings.
  28466. */
  28467. var CFFStandardStrings = [
  28468. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  28469. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  28470. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  28471. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  28472. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  28473. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  28474. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  28475. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  28476. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  28477. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  28478. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  28479. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  28480. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  28481. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  28482. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  28483. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  28484. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  28485. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  28486. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  28487. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  28488. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  28489. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  28490. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  28491. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  28492. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  28493. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  28494. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  28495. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  28496. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  28497. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  28498. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  28499. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  28500. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  28501. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  28502. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  28503. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  28504. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  28505. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  28506. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  28507. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  28508. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  28509. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  28510. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  28511. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  28512. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  28513. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  28514. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  28515. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  28516. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  28517. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  28518. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  28519. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  28520. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  28521. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  28522. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  28523. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  28524. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  28525. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  28526. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  28527. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  28528. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  28529. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  28530. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  28531. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  28532. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  28533. ];
  28534. // Type1Font is also a CIDFontType0.
  28535. var Type1Font = function Type1Font(name, file, properties) {
  28536. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  28537. // Also, length1 and length2 might be off by 6 bytes as well.
  28538. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  28539. var PFB_HEADER_SIZE = 6;
  28540. var headerBlockLength = properties.length1;
  28541. var eexecBlockLength = properties.length2;
  28542. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  28543. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  28544. if (pfbHeaderPresent) {
  28545. file.skip(PFB_HEADER_SIZE);
  28546. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28547. (pfbHeader[3] << 8) | pfbHeader[2];
  28548. }
  28549. // Get the data block containing glyphs and subrs informations
  28550. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  28551. var headerBlockParser = new Type1Parser(headerBlock);
  28552. headerBlockParser.extractFontHeader(properties);
  28553. if (pfbHeaderPresent) {
  28554. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  28555. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28556. (pfbHeader[3] << 8) | pfbHeader[2];
  28557. }
  28558. // Decrypt the data blocks and retrieve it's content
  28559. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  28560. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  28561. var data = eexecBlockParser.extractFontProgram();
  28562. for (var info in data.properties) {
  28563. properties[info] = data.properties[info];
  28564. }
  28565. var charstrings = data.charstrings;
  28566. var type2Charstrings = this.getType2Charstrings(charstrings);
  28567. var subrs = this.getType2Subrs(data.subrs);
  28568. this.charstrings = charstrings;
  28569. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  28570. subrs, properties);
  28571. this.seacs = this.getSeacs(data.charstrings);
  28572. };
  28573. Type1Font.prototype = {
  28574. get numGlyphs() {
  28575. return this.charstrings.length + 1;
  28576. },
  28577. getCharset: function Type1Font_getCharset() {
  28578. var charset = ['.notdef'];
  28579. var charstrings = this.charstrings;
  28580. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28581. charset.push(charstrings[glyphId].glyphName);
  28582. }
  28583. return charset;
  28584. },
  28585. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  28586. var charstrings = this.charstrings;
  28587. var glyphNames = ['.notdef'], glyphId;
  28588. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28589. glyphNames.push(charstrings[glyphId].glyphName);
  28590. }
  28591. var encoding = properties.builtInEncoding;
  28592. if (encoding) {
  28593. var builtInEncoding = {};
  28594. for (var charCode in encoding) {
  28595. glyphId = glyphNames.indexOf(encoding[charCode]);
  28596. if (glyphId >= 0) {
  28597. builtInEncoding[charCode] = glyphId;
  28598. }
  28599. }
  28600. }
  28601. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  28602. },
  28603. getSeacs: function Type1Font_getSeacs(charstrings) {
  28604. var i, ii;
  28605. var seacMap = [];
  28606. for (i = 0, ii = charstrings.length; i < ii; i++) {
  28607. var charstring = charstrings[i];
  28608. if (charstring.seac) {
  28609. // Offset by 1 for .notdef
  28610. seacMap[i + 1] = charstring.seac;
  28611. }
  28612. }
  28613. return seacMap;
  28614. },
  28615. getType2Charstrings: function Type1Font_getType2Charstrings(
  28616. type1Charstrings) {
  28617. var type2Charstrings = [];
  28618. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  28619. type2Charstrings.push(type1Charstrings[i].charstring);
  28620. }
  28621. return type2Charstrings;
  28622. },
  28623. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28624. var bias = 0;
  28625. var count = type1Subrs.length;
  28626. if (count < 1133) {
  28627. bias = 107;
  28628. } else if (count < 33769) {
  28629. bias = 1131;
  28630. } else {
  28631. bias = 32768;
  28632. }
  28633. // Add a bunch of empty subrs to deal with the Type2 bias
  28634. var type2Subrs = [];
  28635. var i;
  28636. for (i = 0; i < bias; i++) {
  28637. type2Subrs.push([0x0B]);
  28638. }
  28639. for (i = 0; i < count; i++) {
  28640. type2Subrs.push(type1Subrs[i]);
  28641. }
  28642. return type2Subrs;
  28643. },
  28644. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28645. var cff = new CFF();
  28646. cff.header = new CFFHeader(1, 0, 4, 4);
  28647. cff.names = [name];
  28648. var topDict = new CFFTopDict();
  28649. // CFF strings IDs 0...390 are predefined names, so refering
  28650. // to entries in our own String INDEX starts at SID 391.
  28651. topDict.setByName('version', 391);
  28652. topDict.setByName('Notice', 392);
  28653. topDict.setByName('FullName', 393);
  28654. topDict.setByName('FamilyName', 394);
  28655. topDict.setByName('Weight', 395);
  28656. topDict.setByName('Encoding', null); // placeholder
  28657. topDict.setByName('FontMatrix', properties.fontMatrix);
  28658. topDict.setByName('FontBBox', properties.bbox);
  28659. topDict.setByName('charset', null); // placeholder
  28660. topDict.setByName('CharStrings', null); // placeholder
  28661. topDict.setByName('Private', null); // placeholder
  28662. cff.topDict = topDict;
  28663. var strings = new CFFStrings();
  28664. strings.add('Version 0.11'); // Version
  28665. strings.add('See original notice'); // Notice
  28666. strings.add(name); // FullName
  28667. strings.add(name); // FamilyName
  28668. strings.add('Medium'); // Weight
  28669. cff.strings = strings;
  28670. cff.globalSubrIndex = new CFFIndex();
  28671. var count = glyphs.length;
  28672. var charsetArray = [0];
  28673. var i, ii;
  28674. for (i = 0; i < count; i++) {
  28675. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28676. // TODO: Insert the string and correctly map it. Previously it was
  28677. // thought mapping names that aren't in the standard strings to .notdef
  28678. // was fine, however in issue818 when mapping them all to .notdef the
  28679. // adieresis glyph no longer worked.
  28680. if (index === -1) {
  28681. index = 0;
  28682. }
  28683. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28684. }
  28685. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28686. var charStringsIndex = new CFFIndex();
  28687. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28688. for (i = 0; i < count; i++) {
  28689. charStringsIndex.add(glyphs[i]);
  28690. }
  28691. cff.charStrings = charStringsIndex;
  28692. var privateDict = new CFFPrivateDict();
  28693. privateDict.setByName('Subrs', null); // placeholder
  28694. var fields = [
  28695. 'BlueValues',
  28696. 'OtherBlues',
  28697. 'FamilyBlues',
  28698. 'FamilyOtherBlues',
  28699. 'StemSnapH',
  28700. 'StemSnapV',
  28701. 'BlueShift',
  28702. 'BlueFuzz',
  28703. 'BlueScale',
  28704. 'LanguageGroup',
  28705. 'ExpansionFactor',
  28706. 'ForceBold',
  28707. 'StdHW',
  28708. 'StdVW'
  28709. ];
  28710. for (i = 0, ii = fields.length; i < ii; i++) {
  28711. var field = fields[i];
  28712. if (!properties.privateData.hasOwnProperty(field)) {
  28713. continue;
  28714. }
  28715. var value = properties.privateData[field];
  28716. if (isArray(value)) {
  28717. // All of the private dictionary array data in CFF must be stored as
  28718. // "delta-encoded" numbers.
  28719. for (var j = value.length - 1; j > 0; j--) {
  28720. value[j] -= value[j - 1]; // ... difference from previous value
  28721. }
  28722. }
  28723. privateDict.setByName(field, value);
  28724. }
  28725. cff.topDict.privateDict = privateDict;
  28726. var subrIndex = new CFFIndex();
  28727. for (i = 0, ii = subrs.length; i < ii; i++) {
  28728. subrIndex.add(subrs[i]);
  28729. }
  28730. privateDict.subrsIndex = subrIndex;
  28731. var compiler = new CFFCompiler(cff);
  28732. return compiler.compile();
  28733. }
  28734. };
  28735. var CFFFont = (function CFFFontClosure() {
  28736. function CFFFont(file, properties) {
  28737. this.properties = properties;
  28738. var parser = new CFFParser(file, properties);
  28739. this.cff = parser.parse();
  28740. var compiler = new CFFCompiler(this.cff);
  28741. this.seacs = this.cff.seacs;
  28742. try {
  28743. this.data = compiler.compile();
  28744. } catch (e) {
  28745. warn('Failed to compile font ' + properties.loadedName);
  28746. // There may have just been an issue with the compiler, set the data
  28747. // anyway and hope the font loaded.
  28748. this.data = file;
  28749. }
  28750. }
  28751. CFFFont.prototype = {
  28752. get numGlyphs() {
  28753. return this.cff.charStrings.count;
  28754. },
  28755. getCharset: function CFFFont_getCharset() {
  28756. return this.cff.charset.charset;
  28757. },
  28758. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28759. var cff = this.cff;
  28760. var properties = this.properties;
  28761. var charsets = cff.charset.charset;
  28762. var charCodeToGlyphId;
  28763. var glyphId;
  28764. if (properties.composite) {
  28765. charCodeToGlyphId = Object.create(null);
  28766. if (cff.isCIDFont) {
  28767. // If the font is actually a CID font then we should use the charset
  28768. // to map CIDs to GIDs.
  28769. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28770. var cid = charsets[glyphId];
  28771. var charCode = properties.cMap.charCodeOf(cid);
  28772. charCodeToGlyphId[charCode] = glyphId;
  28773. }
  28774. } else {
  28775. // If it is NOT actually a CID font then CIDs should be mapped
  28776. // directly to GIDs.
  28777. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28778. charCodeToGlyphId[glyphId] = glyphId;
  28779. }
  28780. }
  28781. return charCodeToGlyphId;
  28782. }
  28783. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28784. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28785. return charCodeToGlyphId;
  28786. }
  28787. };
  28788. return CFFFont;
  28789. })();
  28790. var CFFParser = (function CFFParserClosure() {
  28791. var CharstringValidationData = [
  28792. null,
  28793. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28794. null,
  28795. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28796. { id: 'vmoveto', min: 1, stackClearing: true },
  28797. { id: 'rlineto', min: 2, resetStack: true },
  28798. { id: 'hlineto', min: 1, resetStack: true },
  28799. { id: 'vlineto', min: 1, resetStack: true },
  28800. { id: 'rrcurveto', min: 6, resetStack: true },
  28801. null,
  28802. { id: 'callsubr', min: 1, undefStack: true },
  28803. { id: 'return', min: 0, undefStack: true },
  28804. null, // 12
  28805. null,
  28806. { id: 'endchar', min: 0, stackClearing: true },
  28807. null,
  28808. null,
  28809. null,
  28810. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28811. { id: 'hintmask', min: 0, stackClearing: true },
  28812. { id: 'cntrmask', min: 0, stackClearing: true },
  28813. { id: 'rmoveto', min: 2, stackClearing: true },
  28814. { id: 'hmoveto', min: 1, stackClearing: true },
  28815. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28816. { id: 'rcurveline', min: 8, resetStack: true },
  28817. { id: 'rlinecurve', min: 8, resetStack: true },
  28818. { id: 'vvcurveto', min: 4, resetStack: true },
  28819. { id: 'hhcurveto', min: 4, resetStack: true },
  28820. null, // shortint
  28821. { id: 'callgsubr', min: 1, undefStack: true },
  28822. { id: 'vhcurveto', min: 4, resetStack: true },
  28823. { id: 'hvcurveto', min: 4, resetStack: true }
  28824. ];
  28825. var CharstringValidationData12 = [
  28826. null,
  28827. null,
  28828. null,
  28829. { id: 'and', min: 2, stackDelta: -1 },
  28830. { id: 'or', min: 2, stackDelta: -1 },
  28831. { id: 'not', min: 1, stackDelta: 0 },
  28832. null,
  28833. null,
  28834. null,
  28835. { id: 'abs', min: 1, stackDelta: 0 },
  28836. { id: 'add', min: 2, stackDelta: -1,
  28837. stackFn: function stack_div(stack, index) {
  28838. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28839. }
  28840. },
  28841. { id: 'sub', min: 2, stackDelta: -1,
  28842. stackFn: function stack_div(stack, index) {
  28843. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28844. }
  28845. },
  28846. { id: 'div', min: 2, stackDelta: -1,
  28847. stackFn: function stack_div(stack, index) {
  28848. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28849. }
  28850. },
  28851. null,
  28852. { id: 'neg', min: 1, stackDelta: 0,
  28853. stackFn: function stack_div(stack, index) {
  28854. stack[index - 1] = -stack[index - 1];
  28855. }
  28856. },
  28857. { id: 'eq', min: 2, stackDelta: -1 },
  28858. null,
  28859. null,
  28860. { id: 'drop', min: 1, stackDelta: -1 },
  28861. null,
  28862. { id: 'put', min: 2, stackDelta: -2 },
  28863. { id: 'get', min: 1, stackDelta: 0 },
  28864. { id: 'ifelse', min: 4, stackDelta: -3 },
  28865. { id: 'random', min: 0, stackDelta: 1 },
  28866. { id: 'mul', min: 2, stackDelta: -1,
  28867. stackFn: function stack_div(stack, index) {
  28868. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28869. }
  28870. },
  28871. null,
  28872. { id: 'sqrt', min: 1, stackDelta: 0 },
  28873. { id: 'dup', min: 1, stackDelta: 1 },
  28874. { id: 'exch', min: 2, stackDelta: 0 },
  28875. { id: 'index', min: 2, stackDelta: 0 },
  28876. { id: 'roll', min: 3, stackDelta: -2 },
  28877. null,
  28878. null,
  28879. null,
  28880. { id: 'hflex', min: 7, resetStack: true },
  28881. { id: 'flex', min: 13, resetStack: true },
  28882. { id: 'hflex1', min: 9, resetStack: true },
  28883. { id: 'flex1', min: 11, resetStack: true }
  28884. ];
  28885. function CFFParser(file, properties) {
  28886. this.bytes = file.getBytes();
  28887. this.properties = properties;
  28888. }
  28889. CFFParser.prototype = {
  28890. parse: function CFFParser_parse() {
  28891. var properties = this.properties;
  28892. var cff = new CFF();
  28893. this.cff = cff;
  28894. // The first five sections must be in order, all the others are reached
  28895. // via offsets contained in one of the below.
  28896. var header = this.parseHeader();
  28897. var nameIndex = this.parseIndex(header.endPos);
  28898. var topDictIndex = this.parseIndex(nameIndex.endPos);
  28899. var stringIndex = this.parseIndex(topDictIndex.endPos);
  28900. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  28901. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  28902. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  28903. cff.header = header.obj;
  28904. cff.names = this.parseNameIndex(nameIndex.obj);
  28905. cff.strings = this.parseStringIndex(stringIndex.obj);
  28906. cff.topDict = topDict;
  28907. cff.globalSubrIndex = globalSubrIndex.obj;
  28908. this.parsePrivateDict(cff.topDict);
  28909. cff.isCIDFont = topDict.hasName('ROS');
  28910. var charStringOffset = topDict.getByName('CharStrings');
  28911. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  28912. cff.charStrings = charStringsAndSeacs.charStrings;
  28913. cff.seacs = charStringsAndSeacs.seacs;
  28914. cff.widths = charStringsAndSeacs.widths;
  28915. var fontMatrix = topDict.getByName('FontMatrix');
  28916. if (fontMatrix) {
  28917. properties.fontMatrix = fontMatrix;
  28918. }
  28919. var fontBBox = topDict.getByName('FontBBox');
  28920. if (fontBBox) {
  28921. // adjusting ascent/descent
  28922. properties.ascent = fontBBox[3];
  28923. properties.descent = fontBBox[1];
  28924. properties.ascentScaled = true;
  28925. }
  28926. var charset, encoding;
  28927. if (cff.isCIDFont) {
  28928. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  28929. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  28930. var dictRaw = fdArrayIndex.get(i);
  28931. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  28932. cff.strings);
  28933. this.parsePrivateDict(fontDict);
  28934. cff.fdArray.push(fontDict);
  28935. }
  28936. // cid fonts don't have an encoding
  28937. encoding = null;
  28938. charset = this.parseCharsets(topDict.getByName('charset'),
  28939. cff.charStrings.count, cff.strings, true);
  28940. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  28941. cff.charStrings.count);
  28942. } else {
  28943. charset = this.parseCharsets(topDict.getByName('charset'),
  28944. cff.charStrings.count, cff.strings, false);
  28945. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  28946. properties,
  28947. cff.strings, charset.charset);
  28948. }
  28949. cff.charset = charset;
  28950. cff.encoding = encoding;
  28951. return cff;
  28952. },
  28953. parseHeader: function CFFParser_parseHeader() {
  28954. var bytes = this.bytes;
  28955. var bytesLength = bytes.length;
  28956. var offset = 0;
  28957. // Prevent an infinite loop, by checking that the offset is within the
  28958. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  28959. while (offset < bytesLength && bytes[offset] !== 1) {
  28960. ++offset;
  28961. }
  28962. if (offset >= bytesLength) {
  28963. error('Invalid CFF header');
  28964. } else if (offset !== 0) {
  28965. info('cff data is shifted');
  28966. bytes = bytes.subarray(offset);
  28967. this.bytes = bytes;
  28968. }
  28969. var major = bytes[0];
  28970. var minor = bytes[1];
  28971. var hdrSize = bytes[2];
  28972. var offSize = bytes[3];
  28973. var header = new CFFHeader(major, minor, hdrSize, offSize);
  28974. return { obj: header, endPos: hdrSize };
  28975. },
  28976. parseDict: function CFFParser_parseDict(dict) {
  28977. var pos = 0;
  28978. function parseOperand() {
  28979. var value = dict[pos++];
  28980. if (value === 30) {
  28981. return parseFloatOperand(pos);
  28982. } else if (value === 28) {
  28983. value = dict[pos++];
  28984. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  28985. return value;
  28986. } else if (value === 29) {
  28987. value = dict[pos++];
  28988. value = (value << 8) | dict[pos++];
  28989. value = (value << 8) | dict[pos++];
  28990. value = (value << 8) | dict[pos++];
  28991. return value;
  28992. } else if (value >= 32 && value <= 246) {
  28993. return value - 139;
  28994. } else if (value >= 247 && value <= 250) {
  28995. return ((value - 247) * 256) + dict[pos++] + 108;
  28996. } else if (value >= 251 && value <= 254) {
  28997. return -((value - 251) * 256) - dict[pos++] - 108;
  28998. } else {
  28999. error('255 is not a valid DICT command');
  29000. }
  29001. return -1;
  29002. }
  29003. function parseFloatOperand() {
  29004. var str = '';
  29005. var eof = 15;
  29006. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  29007. '9', '.', 'E', 'E-', null, '-'];
  29008. var length = dict.length;
  29009. while (pos < length) {
  29010. var b = dict[pos++];
  29011. var b1 = b >> 4;
  29012. var b2 = b & 15;
  29013. if (b1 === eof) {
  29014. break;
  29015. }
  29016. str += lookup[b1];
  29017. if (b2 === eof) {
  29018. break;
  29019. }
  29020. str += lookup[b2];
  29021. }
  29022. return parseFloat(str);
  29023. }
  29024. var operands = [];
  29025. var entries = [];
  29026. pos = 0;
  29027. var end = dict.length;
  29028. while (pos < end) {
  29029. var b = dict[pos];
  29030. if (b <= 21) {
  29031. if (b === 12) {
  29032. b = (b << 8) | dict[++pos];
  29033. }
  29034. entries.push([b, operands]);
  29035. operands = [];
  29036. ++pos;
  29037. } else {
  29038. operands.push(parseOperand());
  29039. }
  29040. }
  29041. return entries;
  29042. },
  29043. parseIndex: function CFFParser_parseIndex(pos) {
  29044. var cffIndex = new CFFIndex();
  29045. var bytes = this.bytes;
  29046. var count = (bytes[pos++] << 8) | bytes[pos++];
  29047. var offsets = [];
  29048. var end = pos;
  29049. var i, ii;
  29050. if (count !== 0) {
  29051. var offsetSize = bytes[pos++];
  29052. // add 1 for offset to determine size of last object
  29053. var startPos = pos + ((count + 1) * offsetSize) - 1;
  29054. for (i = 0, ii = count + 1; i < ii; ++i) {
  29055. var offset = 0;
  29056. for (var j = 0; j < offsetSize; ++j) {
  29057. offset <<= 8;
  29058. offset += bytes[pos++];
  29059. }
  29060. offsets.push(startPos + offset);
  29061. }
  29062. end = offsets[count];
  29063. }
  29064. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  29065. var offsetStart = offsets[i];
  29066. var offsetEnd = offsets[i + 1];
  29067. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  29068. }
  29069. return {obj: cffIndex, endPos: end};
  29070. },
  29071. parseNameIndex: function CFFParser_parseNameIndex(index) {
  29072. var names = [];
  29073. for (var i = 0, ii = index.count; i < ii; ++i) {
  29074. var name = index.get(i);
  29075. // OTS doesn't allow names to be over 127 characters.
  29076. var length = Math.min(name.length, 127);
  29077. var data = [];
  29078. // OTS also only permits certain characters in the name.
  29079. for (var j = 0; j < length; ++j) {
  29080. var c = name[j];
  29081. if (j === 0 && c === 0) {
  29082. data[j] = c;
  29083. continue;
  29084. }
  29085. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  29086. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  29087. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  29088. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  29089. data[j] = 95;
  29090. continue;
  29091. }
  29092. data[j] = c;
  29093. }
  29094. names.push(bytesToString(data));
  29095. }
  29096. return names;
  29097. },
  29098. parseStringIndex: function CFFParser_parseStringIndex(index) {
  29099. var strings = new CFFStrings();
  29100. for (var i = 0, ii = index.count; i < ii; ++i) {
  29101. var data = index.get(i);
  29102. strings.add(bytesToString(data));
  29103. }
  29104. return strings;
  29105. },
  29106. createDict: function CFFParser_createDict(Type, dict, strings) {
  29107. var cffDict = new Type(strings);
  29108. for (var i = 0, ii = dict.length; i < ii; ++i) {
  29109. var pair = dict[i];
  29110. var key = pair[0];
  29111. var value = pair[1];
  29112. cffDict.setByKey(key, value);
  29113. }
  29114. return cffDict;
  29115. },
  29116. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  29117. var charStrings = this.parseIndex(charStringOffset).obj;
  29118. var seacs = [];
  29119. var widths = [];
  29120. var count = charStrings.count;
  29121. for (var i = 0; i < count; i++) {
  29122. var charstring = charStrings.get(i);
  29123. var stackSize = 0;
  29124. var stack = [];
  29125. var undefStack = true;
  29126. var hints = 0;
  29127. var valid = true;
  29128. var data = charstring;
  29129. var length = data.length;
  29130. var firstStackClearing = true;
  29131. for (var j = 0; j < length;) {
  29132. var value = data[j++];
  29133. var validationCommand = null;
  29134. if (value === 12) {
  29135. var q = data[j++];
  29136. if (q === 0) {
  29137. // The CFF specification state that the 'dotsection' command
  29138. // (12, 0) is deprecated and treated as a no-op, but all Type2
  29139. // charstrings processors should support them. Unfortunately
  29140. // the font sanitizer don't. As a workaround the sequence (12, 0)
  29141. // is replaced by a useless (0, hmoveto).
  29142. data[j - 2] = 139;
  29143. data[j - 1] = 22;
  29144. stackSize = 0;
  29145. } else {
  29146. validationCommand = CharstringValidationData12[q];
  29147. }
  29148. } else if (value === 28) { // number (16 bit)
  29149. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  29150. j += 2;
  29151. stackSize++;
  29152. } else if (value === 14) {
  29153. if (stackSize >= 4) {
  29154. stackSize -= 4;
  29155. if (SEAC_ANALYSIS_ENABLED) {
  29156. seacs[i] = stack.slice(stackSize, stackSize + 4);
  29157. valid = false;
  29158. }
  29159. }
  29160. validationCommand = CharstringValidationData[value];
  29161. } else if (value >= 32 && value <= 246) { // number
  29162. stack[stackSize] = value - 139;
  29163. stackSize++;
  29164. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  29165. stack[stackSize] = (value < 251 ?
  29166. ((value - 247) << 8) + data[j] + 108 :
  29167. -((value - 251) << 8) - data[j] - 108);
  29168. j++;
  29169. stackSize++;
  29170. } else if (value === 255) { // number (32 bit)
  29171. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  29172. (data[j + 2] << 8) | data[j + 3]) / 65536;
  29173. j += 4;
  29174. stackSize++;
  29175. } else if (value === 19 || value === 20) {
  29176. hints += stackSize >> 1;
  29177. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  29178. stackSize %= 2;
  29179. validationCommand = CharstringValidationData[value];
  29180. } else {
  29181. validationCommand = CharstringValidationData[value];
  29182. }
  29183. if (validationCommand) {
  29184. if (validationCommand.stem) {
  29185. hints += stackSize >> 1;
  29186. }
  29187. if ('min' in validationCommand) {
  29188. if (!undefStack && stackSize < validationCommand.min) {
  29189. warn('Not enough parameters for ' + validationCommand.id +
  29190. '; actual: ' + stackSize +
  29191. ', expected: ' + validationCommand.min);
  29192. valid = false;
  29193. break;
  29194. }
  29195. }
  29196. if (firstStackClearing && validationCommand.stackClearing) {
  29197. firstStackClearing = false;
  29198. // the optional character width can be found before the first
  29199. // stack-clearing command arguments
  29200. stackSize -= validationCommand.min;
  29201. if (stackSize >= 2 && validationCommand.stem) {
  29202. // there are even amount of arguments for stem commands
  29203. stackSize %= 2;
  29204. } else if (stackSize > 1) {
  29205. warn('Found too many parameters for stack-clearing command');
  29206. }
  29207. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  29208. widths[i] = stack[stackSize - 1];
  29209. }
  29210. }
  29211. if ('stackDelta' in validationCommand) {
  29212. if ('stackFn' in validationCommand) {
  29213. validationCommand.stackFn(stack, stackSize);
  29214. }
  29215. stackSize += validationCommand.stackDelta;
  29216. } else if (validationCommand.stackClearing) {
  29217. stackSize = 0;
  29218. } else if (validationCommand.resetStack) {
  29219. stackSize = 0;
  29220. undefStack = false;
  29221. } else if (validationCommand.undefStack) {
  29222. stackSize = 0;
  29223. undefStack = true;
  29224. firstStackClearing = false;
  29225. }
  29226. }
  29227. }
  29228. if (!valid) {
  29229. // resetting invalid charstring to single 'endchar'
  29230. charStrings.set(i, new Uint8Array([14]));
  29231. }
  29232. }
  29233. return { charStrings: charStrings, seacs: seacs, widths: widths };
  29234. },
  29235. emptyPrivateDictionary:
  29236. function CFFParser_emptyPrivateDictionary(parentDict) {
  29237. var privateDict = this.createDict(CFFPrivateDict, [],
  29238. parentDict.strings);
  29239. parentDict.setByKey(18, [0, 0]);
  29240. parentDict.privateDict = privateDict;
  29241. },
  29242. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  29243. // no private dict, do nothing
  29244. if (!parentDict.hasName('Private')) {
  29245. this.emptyPrivateDictionary(parentDict);
  29246. return;
  29247. }
  29248. var privateOffset = parentDict.getByName('Private');
  29249. // make sure the params are formatted correctly
  29250. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  29251. parentDict.removeByName('Private');
  29252. return;
  29253. }
  29254. var size = privateOffset[0];
  29255. var offset = privateOffset[1];
  29256. // remove empty dicts or ones that refer to invalid location
  29257. if (size === 0 || offset >= this.bytes.length) {
  29258. this.emptyPrivateDictionary(parentDict);
  29259. return;
  29260. }
  29261. var privateDictEnd = offset + size;
  29262. var dictData = this.bytes.subarray(offset, privateDictEnd);
  29263. var dict = this.parseDict(dictData);
  29264. var privateDict = this.createDict(CFFPrivateDict, dict,
  29265. parentDict.strings);
  29266. parentDict.privateDict = privateDict;
  29267. // Parse the Subrs index also since it's relative to the private dict.
  29268. if (!privateDict.getByName('Subrs')) {
  29269. return;
  29270. }
  29271. var subrsOffset = privateDict.getByName('Subrs');
  29272. var relativeOffset = offset + subrsOffset;
  29273. // Validate the offset.
  29274. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  29275. this.emptyPrivateDictionary(parentDict);
  29276. return;
  29277. }
  29278. var subrsIndex = this.parseIndex(relativeOffset);
  29279. privateDict.subrsIndex = subrsIndex.obj;
  29280. },
  29281. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  29282. if (pos === 0) {
  29283. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  29284. ISOAdobeCharset);
  29285. } else if (pos === 1) {
  29286. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  29287. ExpertCharset);
  29288. } else if (pos === 2) {
  29289. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  29290. ExpertSubsetCharset);
  29291. }
  29292. var bytes = this.bytes;
  29293. var start = pos;
  29294. var format = bytes[pos++];
  29295. var charset = ['.notdef'];
  29296. var id, count, i;
  29297. // subtract 1 for the .notdef glyph
  29298. length -= 1;
  29299. switch (format) {
  29300. case 0:
  29301. for (i = 0; i < length; i++) {
  29302. id = (bytes[pos++] << 8) | bytes[pos++];
  29303. charset.push(cid ? id : strings.get(id));
  29304. }
  29305. break;
  29306. case 1:
  29307. while (charset.length <= length) {
  29308. id = (bytes[pos++] << 8) | bytes[pos++];
  29309. count = bytes[pos++];
  29310. for (i = 0; i <= count; i++) {
  29311. charset.push(cid ? id++ : strings.get(id++));
  29312. }
  29313. }
  29314. break;
  29315. case 2:
  29316. while (charset.length <= length) {
  29317. id = (bytes[pos++] << 8) | bytes[pos++];
  29318. count = (bytes[pos++] << 8) | bytes[pos++];
  29319. for (i = 0; i <= count; i++) {
  29320. charset.push(cid ? id++ : strings.get(id++));
  29321. }
  29322. }
  29323. break;
  29324. default:
  29325. error('Unknown charset format');
  29326. }
  29327. // Raw won't be needed if we actually compile the charset.
  29328. var end = pos;
  29329. var raw = bytes.subarray(start, end);
  29330. return new CFFCharset(false, format, charset, raw);
  29331. },
  29332. parseEncoding: function CFFParser_parseEncoding(pos,
  29333. properties,
  29334. strings,
  29335. charset) {
  29336. var encoding = {};
  29337. var bytes = this.bytes;
  29338. var predefined = false;
  29339. var hasSupplement = false;
  29340. var format, i, ii;
  29341. var raw = null;
  29342. function readSupplement() {
  29343. var supplementsCount = bytes[pos++];
  29344. for (i = 0; i < supplementsCount; i++) {
  29345. var code = bytes[pos++];
  29346. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  29347. encoding[code] = charset.indexOf(strings.get(sid));
  29348. }
  29349. }
  29350. if (pos === 0 || pos === 1) {
  29351. predefined = true;
  29352. format = pos;
  29353. var baseEncoding = pos ? Encodings.ExpertEncoding :
  29354. Encodings.StandardEncoding;
  29355. for (i = 0, ii = charset.length; i < ii; i++) {
  29356. var index = baseEncoding.indexOf(charset[i]);
  29357. if (index !== -1) {
  29358. encoding[index] = i;
  29359. }
  29360. }
  29361. } else {
  29362. var dataStart = pos;
  29363. format = bytes[pos++];
  29364. switch (format & 0x7f) {
  29365. case 0:
  29366. var glyphsCount = bytes[pos++];
  29367. for (i = 1; i <= glyphsCount; i++) {
  29368. encoding[bytes[pos++]] = i;
  29369. }
  29370. break;
  29371. case 1:
  29372. var rangesCount = bytes[pos++];
  29373. var gid = 1;
  29374. for (i = 0; i < rangesCount; i++) {
  29375. var start = bytes[pos++];
  29376. var left = bytes[pos++];
  29377. for (var j = start; j <= start + left; j++) {
  29378. encoding[j] = gid++;
  29379. }
  29380. }
  29381. break;
  29382. default:
  29383. error('Unknow encoding format: ' + format + ' in CFF');
  29384. break;
  29385. }
  29386. var dataEnd = pos;
  29387. if (format & 0x80) {
  29388. // The font sanitizer does not support CFF encoding with a
  29389. // supplement, since the encoding is not really used to map
  29390. // between gid to glyph, let's overwrite what is declared in
  29391. // the top dictionary to let the sanitizer think the font use
  29392. // StandardEncoding, that's a lie but that's ok.
  29393. bytes[dataStart] &= 0x7f;
  29394. readSupplement();
  29395. hasSupplement = true;
  29396. }
  29397. raw = bytes.subarray(dataStart, dataEnd);
  29398. }
  29399. format = format & 0x7f;
  29400. return new CFFEncoding(predefined, format, encoding, raw);
  29401. },
  29402. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  29403. var start = pos;
  29404. var bytes = this.bytes;
  29405. var format = bytes[pos++];
  29406. var fdSelect = [];
  29407. var i;
  29408. switch (format) {
  29409. case 0:
  29410. for (i = 0; i < length; ++i) {
  29411. var id = bytes[pos++];
  29412. fdSelect.push(id);
  29413. }
  29414. break;
  29415. case 3:
  29416. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  29417. for (i = 0; i < rangesCount; ++i) {
  29418. var first = (bytes[pos++] << 8) | bytes[pos++];
  29419. var fdIndex = bytes[pos++];
  29420. var next = (bytes[pos] << 8) | bytes[pos + 1];
  29421. for (var j = first; j < next; ++j) {
  29422. fdSelect.push(fdIndex);
  29423. }
  29424. }
  29425. // Advance past the sentinel(next).
  29426. pos += 2;
  29427. break;
  29428. default:
  29429. error('Unknown fdselect format ' + format);
  29430. break;
  29431. }
  29432. var end = pos;
  29433. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  29434. }
  29435. };
  29436. return CFFParser;
  29437. })();
  29438. // Compact Font Format
  29439. var CFF = (function CFFClosure() {
  29440. function CFF() {
  29441. this.header = null;
  29442. this.names = [];
  29443. this.topDict = null;
  29444. this.strings = new CFFStrings();
  29445. this.globalSubrIndex = null;
  29446. // The following could really be per font, but since we only have one font
  29447. // store them here.
  29448. this.encoding = null;
  29449. this.charset = null;
  29450. this.charStrings = null;
  29451. this.fdArray = [];
  29452. this.fdSelect = null;
  29453. this.isCIDFont = false;
  29454. }
  29455. return CFF;
  29456. })();
  29457. var CFFHeader = (function CFFHeaderClosure() {
  29458. function CFFHeader(major, minor, hdrSize, offSize) {
  29459. this.major = major;
  29460. this.minor = minor;
  29461. this.hdrSize = hdrSize;
  29462. this.offSize = offSize;
  29463. }
  29464. return CFFHeader;
  29465. })();
  29466. var CFFStrings = (function CFFStringsClosure() {
  29467. function CFFStrings() {
  29468. this.strings = [];
  29469. }
  29470. CFFStrings.prototype = {
  29471. get: function CFFStrings_get(index) {
  29472. if (index >= 0 && index <= 390) {
  29473. return CFFStandardStrings[index];
  29474. }
  29475. if (index - 391 <= this.strings.length) {
  29476. return this.strings[index - 391];
  29477. }
  29478. return CFFStandardStrings[0];
  29479. },
  29480. add: function CFFStrings_add(value) {
  29481. this.strings.push(value);
  29482. },
  29483. get count() {
  29484. return this.strings.length;
  29485. }
  29486. };
  29487. return CFFStrings;
  29488. })();
  29489. var CFFIndex = (function CFFIndexClosure() {
  29490. function CFFIndex() {
  29491. this.objects = [];
  29492. this.length = 0;
  29493. }
  29494. CFFIndex.prototype = {
  29495. add: function CFFIndex_add(data) {
  29496. this.length += data.length;
  29497. this.objects.push(data);
  29498. },
  29499. set: function CFFIndex_set(index, data) {
  29500. this.length += data.length - this.objects[index].length;
  29501. this.objects[index] = data;
  29502. },
  29503. get: function CFFIndex_get(index) {
  29504. return this.objects[index];
  29505. },
  29506. get count() {
  29507. return this.objects.length;
  29508. }
  29509. };
  29510. return CFFIndex;
  29511. })();
  29512. var CFFDict = (function CFFDictClosure() {
  29513. function CFFDict(tables, strings) {
  29514. this.keyToNameMap = tables.keyToNameMap;
  29515. this.nameToKeyMap = tables.nameToKeyMap;
  29516. this.defaults = tables.defaults;
  29517. this.types = tables.types;
  29518. this.opcodes = tables.opcodes;
  29519. this.order = tables.order;
  29520. this.strings = strings;
  29521. this.values = {};
  29522. }
  29523. CFFDict.prototype = {
  29524. // value should always be an array
  29525. setByKey: function CFFDict_setByKey(key, value) {
  29526. if (!(key in this.keyToNameMap)) {
  29527. return false;
  29528. }
  29529. // ignore empty values
  29530. if (value.length === 0) {
  29531. return true;
  29532. }
  29533. var type = this.types[key];
  29534. // remove the array wrapping these types of values
  29535. if (type === 'num' || type === 'sid' || type === 'offset') {
  29536. value = value[0];
  29537. }
  29538. this.values[key] = value;
  29539. return true;
  29540. },
  29541. setByName: function CFFDict_setByName(name, value) {
  29542. if (!(name in this.nameToKeyMap)) {
  29543. error('Invalid dictionary name "' + name + '"');
  29544. }
  29545. this.values[this.nameToKeyMap[name]] = value;
  29546. },
  29547. hasName: function CFFDict_hasName(name) {
  29548. return this.nameToKeyMap[name] in this.values;
  29549. },
  29550. getByName: function CFFDict_getByName(name) {
  29551. if (!(name in this.nameToKeyMap)) {
  29552. error('Invalid dictionary name "' + name + '"');
  29553. }
  29554. var key = this.nameToKeyMap[name];
  29555. if (!(key in this.values)) {
  29556. return this.defaults[key];
  29557. }
  29558. return this.values[key];
  29559. },
  29560. removeByName: function CFFDict_removeByName(name) {
  29561. delete this.values[this.nameToKeyMap[name]];
  29562. }
  29563. };
  29564. CFFDict.createTables = function CFFDict_createTables(layout) {
  29565. var tables = {
  29566. keyToNameMap: {},
  29567. nameToKeyMap: {},
  29568. defaults: {},
  29569. types: {},
  29570. opcodes: {},
  29571. order: []
  29572. };
  29573. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29574. var entry = layout[i];
  29575. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29576. tables.keyToNameMap[key] = entry[1];
  29577. tables.nameToKeyMap[entry[1]] = key;
  29578. tables.types[key] = entry[2];
  29579. tables.defaults[key] = entry[3];
  29580. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29581. tables.order.push(key);
  29582. }
  29583. return tables;
  29584. };
  29585. return CFFDict;
  29586. })();
  29587. var CFFTopDict = (function CFFTopDictClosure() {
  29588. var layout = [
  29589. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29590. [[12, 20], 'SyntheticBase', 'num', null],
  29591. [0, 'version', 'sid', null],
  29592. [1, 'Notice', 'sid', null],
  29593. [[12, 0], 'Copyright', 'sid', null],
  29594. [2, 'FullName', 'sid', null],
  29595. [3, 'FamilyName', 'sid', null],
  29596. [4, 'Weight', 'sid', null],
  29597. [[12, 1], 'isFixedPitch', 'num', 0],
  29598. [[12, 2], 'ItalicAngle', 'num', 0],
  29599. [[12, 3], 'UnderlinePosition', 'num', -100],
  29600. [[12, 4], 'UnderlineThickness', 'num', 50],
  29601. [[12, 5], 'PaintType', 'num', 0],
  29602. [[12, 6], 'CharstringType', 'num', 2],
  29603. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29604. [0.001, 0, 0, 0.001, 0, 0]],
  29605. [13, 'UniqueID', 'num', null],
  29606. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29607. [[12, 8], 'StrokeWidth', 'num', 0],
  29608. [14, 'XUID', 'array', null],
  29609. [15, 'charset', 'offset', 0],
  29610. [16, 'Encoding', 'offset', 0],
  29611. [17, 'CharStrings', 'offset', 0],
  29612. [18, 'Private', ['offset', 'offset'], null],
  29613. [[12, 21], 'PostScript', 'sid', null],
  29614. [[12, 22], 'BaseFontName', 'sid', null],
  29615. [[12, 23], 'BaseFontBlend', 'delta', null],
  29616. [[12, 31], 'CIDFontVersion', 'num', 0],
  29617. [[12, 32], 'CIDFontRevision', 'num', 0],
  29618. [[12, 33], 'CIDFontType', 'num', 0],
  29619. [[12, 34], 'CIDCount', 'num', 8720],
  29620. [[12, 35], 'UIDBase', 'num', null],
  29621. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29622. // before FDArray.
  29623. [[12, 37], 'FDSelect', 'offset', null],
  29624. [[12, 36], 'FDArray', 'offset', null],
  29625. [[12, 38], 'FontName', 'sid', null]
  29626. ];
  29627. var tables = null;
  29628. function CFFTopDict(strings) {
  29629. if (tables === null) {
  29630. tables = CFFDict.createTables(layout);
  29631. }
  29632. CFFDict.call(this, tables, strings);
  29633. this.privateDict = null;
  29634. }
  29635. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29636. return CFFTopDict;
  29637. })();
  29638. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29639. var layout = [
  29640. [6, 'BlueValues', 'delta', null],
  29641. [7, 'OtherBlues', 'delta', null],
  29642. [8, 'FamilyBlues', 'delta', null],
  29643. [9, 'FamilyOtherBlues', 'delta', null],
  29644. [[12, 9], 'BlueScale', 'num', 0.039625],
  29645. [[12, 10], 'BlueShift', 'num', 7],
  29646. [[12, 11], 'BlueFuzz', 'num', 1],
  29647. [10, 'StdHW', 'num', null],
  29648. [11, 'StdVW', 'num', null],
  29649. [[12, 12], 'StemSnapH', 'delta', null],
  29650. [[12, 13], 'StemSnapV', 'delta', null],
  29651. [[12, 14], 'ForceBold', 'num', 0],
  29652. [[12, 17], 'LanguageGroup', 'num', 0],
  29653. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29654. [[12, 19], 'initialRandomSeed', 'num', 0],
  29655. [20, 'defaultWidthX', 'num', 0],
  29656. [21, 'nominalWidthX', 'num', 0],
  29657. [19, 'Subrs', 'offset', null]
  29658. ];
  29659. var tables = null;
  29660. function CFFPrivateDict(strings) {
  29661. if (tables === null) {
  29662. tables = CFFDict.createTables(layout);
  29663. }
  29664. CFFDict.call(this, tables, strings);
  29665. this.subrsIndex = null;
  29666. }
  29667. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29668. return CFFPrivateDict;
  29669. })();
  29670. var CFFCharsetPredefinedTypes = {
  29671. ISO_ADOBE: 0,
  29672. EXPERT: 1,
  29673. EXPERT_SUBSET: 2
  29674. };
  29675. var CFFCharset = (function CFFCharsetClosure() {
  29676. function CFFCharset(predefined, format, charset, raw) {
  29677. this.predefined = predefined;
  29678. this.format = format;
  29679. this.charset = charset;
  29680. this.raw = raw;
  29681. }
  29682. return CFFCharset;
  29683. })();
  29684. var CFFEncoding = (function CFFEncodingClosure() {
  29685. function CFFEncoding(predefined, format, encoding, raw) {
  29686. this.predefined = predefined;
  29687. this.format = format;
  29688. this.encoding = encoding;
  29689. this.raw = raw;
  29690. }
  29691. return CFFEncoding;
  29692. })();
  29693. var CFFFDSelect = (function CFFFDSelectClosure() {
  29694. function CFFFDSelect(fdSelect, raw) {
  29695. this.fdSelect = fdSelect;
  29696. this.raw = raw;
  29697. }
  29698. return CFFFDSelect;
  29699. })();
  29700. // Helper class to keep track of where an offset is within the data and helps
  29701. // filling in that offset once it's known.
  29702. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29703. function CFFOffsetTracker() {
  29704. this.offsets = {};
  29705. }
  29706. CFFOffsetTracker.prototype = {
  29707. isTracking: function CFFOffsetTracker_isTracking(key) {
  29708. return key in this.offsets;
  29709. },
  29710. track: function CFFOffsetTracker_track(key, location) {
  29711. if (key in this.offsets) {
  29712. error('Already tracking location of ' + key);
  29713. }
  29714. this.offsets[key] = location;
  29715. },
  29716. offset: function CFFOffsetTracker_offset(value) {
  29717. for (var key in this.offsets) {
  29718. this.offsets[key] += value;
  29719. }
  29720. },
  29721. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29722. values,
  29723. output) {
  29724. if (!(key in this.offsets)) {
  29725. error('Not tracking location of ' + key);
  29726. }
  29727. var data = output.data;
  29728. var dataOffset = this.offsets[key];
  29729. var size = 5;
  29730. for (var i = 0, ii = values.length; i < ii; ++i) {
  29731. var offset0 = i * size + dataOffset;
  29732. var offset1 = offset0 + 1;
  29733. var offset2 = offset0 + 2;
  29734. var offset3 = offset0 + 3;
  29735. var offset4 = offset0 + 4;
  29736. // It's easy to screw up offsets so perform this sanity check.
  29737. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29738. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29739. error('writing to an offset that is not empty');
  29740. }
  29741. var value = values[i];
  29742. data[offset0] = 0x1d;
  29743. data[offset1] = (value >> 24) & 0xFF;
  29744. data[offset2] = (value >> 16) & 0xFF;
  29745. data[offset3] = (value >> 8) & 0xFF;
  29746. data[offset4] = value & 0xFF;
  29747. }
  29748. }
  29749. };
  29750. return CFFOffsetTracker;
  29751. })();
  29752. // Takes a CFF and converts it to the binary representation.
  29753. var CFFCompiler = (function CFFCompilerClosure() {
  29754. function CFFCompiler(cff) {
  29755. this.cff = cff;
  29756. }
  29757. CFFCompiler.prototype = {
  29758. compile: function CFFCompiler_compile() {
  29759. var cff = this.cff;
  29760. var output = {
  29761. data: [],
  29762. length: 0,
  29763. add: function CFFCompiler_add(data) {
  29764. this.data = this.data.concat(data);
  29765. this.length = this.data.length;
  29766. }
  29767. };
  29768. // Compile the five entries that must be in order.
  29769. var header = this.compileHeader(cff.header);
  29770. output.add(header);
  29771. var nameIndex = this.compileNameIndex(cff.names);
  29772. output.add(nameIndex);
  29773. if (cff.isCIDFont) {
  29774. // The spec is unclear on how font matrices should relate to each other
  29775. // when there is one in the main top dict and the sub top dicts.
  29776. // Windows handles this differently than linux and osx so we have to
  29777. // normalize to work on all.
  29778. // Rules based off of some mailing list discussions:
  29779. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29780. // - If no main font matrix and there is a subfont matrix, use the
  29781. // subfont matrix.
  29782. // - If both have matrices, concat together.
  29783. // - If neither have matrices, use default.
  29784. // To make this work on all platforms we move the top matrix into each
  29785. // sub top dict and concat if necessary.
  29786. if (cff.topDict.hasName('FontMatrix')) {
  29787. var base = cff.topDict.getByName('FontMatrix');
  29788. cff.topDict.removeByName('FontMatrix');
  29789. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29790. var subDict = cff.fdArray[i];
  29791. var matrix = base.slice(0);
  29792. if (subDict.hasName('FontMatrix')) {
  29793. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29794. }
  29795. subDict.setByName('FontMatrix', matrix);
  29796. }
  29797. }
  29798. }
  29799. var compiled = this.compileTopDicts([cff.topDict],
  29800. output.length,
  29801. cff.isCIDFont);
  29802. output.add(compiled.output);
  29803. var topDictTracker = compiled.trackers[0];
  29804. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29805. output.add(stringIndex);
  29806. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29807. output.add(globalSubrIndex);
  29808. // Now start on the other entries that have no specfic order.
  29809. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29810. if (cff.encoding.predefined) {
  29811. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29812. output);
  29813. } else {
  29814. var encoding = this.compileEncoding(cff.encoding);
  29815. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29816. output.add(encoding);
  29817. }
  29818. }
  29819. if (cff.charset && cff.topDict.hasName('charset')) {
  29820. if (cff.charset.predefined) {
  29821. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29822. output);
  29823. } else {
  29824. var charset = this.compileCharset(cff.charset);
  29825. topDictTracker.setEntryLocation('charset', [output.length], output);
  29826. output.add(charset);
  29827. }
  29828. }
  29829. var charStrings = this.compileCharStrings(cff.charStrings);
  29830. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29831. output.add(charStrings);
  29832. if (cff.isCIDFont) {
  29833. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29834. // and linux don't seem to care.
  29835. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29836. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29837. output.add(fdSelect);
  29838. // It is unclear if the sub font dictionary can have CID related
  29839. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29840. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29841. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29842. output.add(compiled.output);
  29843. var fontDictTrackers = compiled.trackers;
  29844. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29845. }
  29846. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29847. // If the font data ends with INDEX whose object data is zero-length,
  29848. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29849. output.add([0]);
  29850. return output.data;
  29851. },
  29852. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29853. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29854. return this.encodeInteger(value);
  29855. } else {
  29856. return this.encodeFloat(value);
  29857. }
  29858. },
  29859. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29860. var value = num.toString();
  29861. // rounding inaccurate doubles
  29862. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  29863. if (m) {
  29864. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  29865. value = (Math.round(num * epsilon) / epsilon).toString();
  29866. }
  29867. var nibbles = '';
  29868. var i, ii;
  29869. for (i = 0, ii = value.length; i < ii; ++i) {
  29870. var a = value[i];
  29871. if (a === 'e') {
  29872. nibbles += value[++i] === '-' ? 'c' : 'b';
  29873. } else if (a === '.') {
  29874. nibbles += 'a';
  29875. } else if (a === '-') {
  29876. nibbles += 'e';
  29877. } else {
  29878. nibbles += a;
  29879. }
  29880. }
  29881. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  29882. var out = [30];
  29883. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  29884. out.push(parseInt(nibbles.substr(i, 2), 16));
  29885. }
  29886. return out;
  29887. },
  29888. encodeInteger: function CFFCompiler_encodeInteger(value) {
  29889. var code;
  29890. if (value >= -107 && value <= 107) {
  29891. code = [value + 139];
  29892. } else if (value >= 108 && value <= 1131) {
  29893. value = [value - 108];
  29894. code = [(value >> 8) + 247, value & 0xFF];
  29895. } else if (value >= -1131 && value <= -108) {
  29896. value = -value - 108;
  29897. code = [(value >> 8) + 251, value & 0xFF];
  29898. } else if (value >= -32768 && value <= 32767) {
  29899. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  29900. } else {
  29901. code = [0x1d,
  29902. (value >> 24) & 0xFF,
  29903. (value >> 16) & 0xFF,
  29904. (value >> 8) & 0xFF,
  29905. value & 0xFF];
  29906. }
  29907. return code;
  29908. },
  29909. compileHeader: function CFFCompiler_compileHeader(header) {
  29910. return [
  29911. header.major,
  29912. header.minor,
  29913. header.hdrSize,
  29914. header.offSize
  29915. ];
  29916. },
  29917. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  29918. var nameIndex = new CFFIndex();
  29919. for (var i = 0, ii = names.length; i < ii; ++i) {
  29920. nameIndex.add(stringToBytes(names[i]));
  29921. }
  29922. return this.compileIndex(nameIndex);
  29923. },
  29924. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  29925. length,
  29926. removeCidKeys) {
  29927. var fontDictTrackers = [];
  29928. var fdArrayIndex = new CFFIndex();
  29929. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29930. var fontDict = dicts[i];
  29931. if (removeCidKeys) {
  29932. fontDict.removeByName('CIDFontVersion');
  29933. fontDict.removeByName('CIDFontRevision');
  29934. fontDict.removeByName('CIDFontType');
  29935. fontDict.removeByName('CIDCount');
  29936. fontDict.removeByName('UIDBase');
  29937. }
  29938. var fontDictTracker = new CFFOffsetTracker();
  29939. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  29940. fontDictTrackers.push(fontDictTracker);
  29941. fdArrayIndex.add(fontDictData);
  29942. fontDictTracker.offset(length);
  29943. }
  29944. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  29945. return {
  29946. trackers: fontDictTrackers,
  29947. output: fdArrayIndex
  29948. };
  29949. },
  29950. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  29951. trackers,
  29952. output) {
  29953. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29954. var fontDict = dicts[i];
  29955. assert(fontDict.privateDict && fontDict.hasName('Private'),
  29956. 'There must be an private dictionary.');
  29957. var privateDict = fontDict.privateDict;
  29958. var privateDictTracker = new CFFOffsetTracker();
  29959. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  29960. var outputLength = output.length;
  29961. privateDictTracker.offset(outputLength);
  29962. if (!privateDictData.length) {
  29963. // The private dictionary was empty, set the output length to zero to
  29964. // ensure the offset length isn't out of bounds in the eyes of the
  29965. // sanitizer.
  29966. outputLength = 0;
  29967. }
  29968. trackers[i].setEntryLocation('Private',
  29969. [privateDictData.length, outputLength],
  29970. output);
  29971. output.add(privateDictData);
  29972. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  29973. var subrs = this.compileIndex(privateDict.subrsIndex);
  29974. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  29975. output);
  29976. output.add(subrs);
  29977. }
  29978. }
  29979. },
  29980. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  29981. var out = [];
  29982. // The dictionary keys must be in a certain order.
  29983. var order = dict.order;
  29984. for (var i = 0; i < order.length; ++i) {
  29985. var key = order[i];
  29986. if (!(key in dict.values)) {
  29987. continue;
  29988. }
  29989. var values = dict.values[key];
  29990. var types = dict.types[key];
  29991. if (!isArray(types)) {
  29992. types = [types];
  29993. }
  29994. if (!isArray(values)) {
  29995. values = [values];
  29996. }
  29997. // Remove any empty dict values.
  29998. if (values.length === 0) {
  29999. continue;
  30000. }
  30001. for (var j = 0, jj = types.length; j < jj; ++j) {
  30002. var type = types[j];
  30003. var value = values[j];
  30004. switch (type) {
  30005. case 'num':
  30006. case 'sid':
  30007. out = out.concat(this.encodeNumber(value));
  30008. break;
  30009. case 'offset':
  30010. // For offsets we just insert a 32bit integer so we don't have to
  30011. // deal with figuring out the length of the offset when it gets
  30012. // replaced later on by the compiler.
  30013. var name = dict.keyToNameMap[key];
  30014. // Some offsets have the offset and the length, so just record the
  30015. // position of the first one.
  30016. if (!offsetTracker.isTracking(name)) {
  30017. offsetTracker.track(name, out.length);
  30018. }
  30019. out = out.concat([0x1d, 0, 0, 0, 0]);
  30020. break;
  30021. case 'array':
  30022. case 'delta':
  30023. out = out.concat(this.encodeNumber(value));
  30024. for (var k = 1, kk = values.length; k < kk; ++k) {
  30025. out = out.concat(this.encodeNumber(values[k]));
  30026. }
  30027. break;
  30028. default:
  30029. error('Unknown data type of ' + type);
  30030. break;
  30031. }
  30032. }
  30033. out = out.concat(dict.opcodes[key]);
  30034. }
  30035. return out;
  30036. },
  30037. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  30038. var stringIndex = new CFFIndex();
  30039. for (var i = 0, ii = strings.length; i < ii; ++i) {
  30040. stringIndex.add(stringToBytes(strings[i]));
  30041. }
  30042. return this.compileIndex(stringIndex);
  30043. },
  30044. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  30045. var globalSubrIndex = this.cff.globalSubrIndex;
  30046. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  30047. },
  30048. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  30049. return this.compileIndex(charStrings);
  30050. },
  30051. compileCharset: function CFFCompiler_compileCharset(charset) {
  30052. return this.compileTypedArray(charset.raw);
  30053. },
  30054. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  30055. return this.compileTypedArray(encoding.raw);
  30056. },
  30057. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  30058. return this.compileTypedArray(fdSelect);
  30059. },
  30060. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  30061. var out = [];
  30062. for (var i = 0, ii = data.length; i < ii; ++i) {
  30063. out[i] = data[i];
  30064. }
  30065. return out;
  30066. },
  30067. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  30068. trackers = trackers || [];
  30069. var objects = index.objects;
  30070. // First 2 bytes contains the number of objects contained into this index
  30071. var count = objects.length;
  30072. // If there is no object, just create an index. This technically
  30073. // should just be [0, 0] but OTS has an issue with that.
  30074. if (count === 0) {
  30075. return [0, 0, 0];
  30076. }
  30077. var data = [(count >> 8) & 0xFF, count & 0xff];
  30078. var lastOffset = 1, i;
  30079. for (i = 0; i < count; ++i) {
  30080. lastOffset += objects[i].length;
  30081. }
  30082. var offsetSize;
  30083. if (lastOffset < 0x100) {
  30084. offsetSize = 1;
  30085. } else if (lastOffset < 0x10000) {
  30086. offsetSize = 2;
  30087. } else if (lastOffset < 0x1000000) {
  30088. offsetSize = 3;
  30089. } else {
  30090. offsetSize = 4;
  30091. }
  30092. // Next byte contains the offset size use to reference object in the file
  30093. data.push(offsetSize);
  30094. // Add another offset after this one because we need a new offset
  30095. var relativeOffset = 1;
  30096. for (i = 0; i < count + 1; i++) {
  30097. if (offsetSize === 1) {
  30098. data.push(relativeOffset & 0xFF);
  30099. } else if (offsetSize === 2) {
  30100. data.push((relativeOffset >> 8) & 0xFF,
  30101. relativeOffset & 0xFF);
  30102. } else if (offsetSize === 3) {
  30103. data.push((relativeOffset >> 16) & 0xFF,
  30104. (relativeOffset >> 8) & 0xFF,
  30105. relativeOffset & 0xFF);
  30106. } else {
  30107. data.push((relativeOffset >>> 24) & 0xFF,
  30108. (relativeOffset >> 16) & 0xFF,
  30109. (relativeOffset >> 8) & 0xFF,
  30110. relativeOffset & 0xFF);
  30111. }
  30112. if (objects[i]) {
  30113. relativeOffset += objects[i].length;
  30114. }
  30115. }
  30116. for (i = 0; i < count; i++) {
  30117. // Notify the tracker where the object will be offset in the data.
  30118. if (trackers[i]) {
  30119. trackers[i].offset(data.length);
  30120. }
  30121. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  30122. data.push(objects[i][j]);
  30123. }
  30124. }
  30125. return data;
  30126. }
  30127. };
  30128. return CFFCompiler;
  30129. })();
  30130. function _enableSeacAnalysis(enabled) {
  30131. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  30132. }
  30133. // Workaround for seac on Windows.
  30134. (function checkSeacSupport() {
  30135. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  30136. SEAC_ANALYSIS_ENABLED = true;
  30137. }
  30138. })();
  30139. // Workaround for Private Use Area characters in Chrome on Windows
  30140. // http://code.google.com/p/chromium/issues/detail?id=122465
  30141. // https://github.com/mozilla/pdf.js/issues/1689
  30142. (function checkChromeWindows() {
  30143. if (typeof navigator !== 'undefined' &&
  30144. /Windows.*Chrome/.test(navigator.userAgent)) {
  30145. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  30146. }
  30147. })();
  30148. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  30149. exports.CFFCompiler = CFFCompiler;
  30150. exports.CFFIndex = CFFIndex;
  30151. exports.CFFParser = CFFParser;
  30152. exports.CFFStrings = CFFStrings;
  30153. exports.Encodings = Encodings;
  30154. exports.ErrorFont = ErrorFont;
  30155. exports.FontFlags = FontFlags;
  30156. exports.Font = Font;
  30157. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  30158. exports.NormalizedUnicodes = NormalizedUnicodes;
  30159. exports.ToUnicodeMap = ToUnicodeMap;
  30160. exports.Type1Parser = Type1Parser;
  30161. exports.getFontType = getFontType;
  30162. exports.reverseIfRtl = reverseIfRtl;
  30163. exports.serifFonts = serifFonts;
  30164. exports.symbolsFonts = symbolsFonts;
  30165. exports.stdFontMap = stdFontMap;
  30166. exports._enableSeacAnalysis = _enableSeacAnalysis;
  30167. // TODO refactor to remove cyclic dependency on font_renderer.js
  30168. coreFontRenderer._setCoreFonts(exports);
  30169. }));
  30170. (function (root, factory) {
  30171. {
  30172. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  30173. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  30174. }
  30175. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  30176. var error = sharedUtil.error;
  30177. var info = sharedUtil.info;
  30178. var isArray = sharedUtil.isArray;
  30179. var isBool = sharedUtil.isBool;
  30180. var isDict = corePrimitives.isDict;
  30181. var isStream = corePrimitives.isStream;
  30182. var PostScriptLexer = corePsParser.PostScriptLexer;
  30183. var PostScriptParser = corePsParser.PostScriptParser;
  30184. var PDFFunction = (function PDFFunctionClosure() {
  30185. var CONSTRUCT_SAMPLED = 0;
  30186. var CONSTRUCT_INTERPOLATED = 2;
  30187. var CONSTRUCT_STICHED = 3;
  30188. var CONSTRUCT_POSTSCRIPT = 4;
  30189. return {
  30190. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  30191. str) {
  30192. var i, ii;
  30193. var length = 1;
  30194. for (i = 0, ii = size.length; i < ii; i++) {
  30195. length *= size[i];
  30196. }
  30197. length *= outputSize;
  30198. var array = new Array(length);
  30199. var codeSize = 0;
  30200. var codeBuf = 0;
  30201. // 32 is a valid bps so shifting won't work
  30202. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  30203. var strBytes = str.getBytes((length * bps + 7) / 8);
  30204. var strIdx = 0;
  30205. for (i = 0; i < length; i++) {
  30206. while (codeSize < bps) {
  30207. codeBuf <<= 8;
  30208. codeBuf |= strBytes[strIdx++];
  30209. codeSize += 8;
  30210. }
  30211. codeSize -= bps;
  30212. array[i] = (codeBuf >> codeSize) * sampleMul;
  30213. codeBuf &= (1 << codeSize) - 1;
  30214. }
  30215. return array;
  30216. },
  30217. getIR: function PDFFunction_getIR(xref, fn) {
  30218. var dict = fn.dict;
  30219. if (!dict) {
  30220. dict = fn;
  30221. }
  30222. var types = [this.constructSampled,
  30223. null,
  30224. this.constructInterpolated,
  30225. this.constructStiched,
  30226. this.constructPostScript];
  30227. var typeNum = dict.get('FunctionType');
  30228. var typeFn = types[typeNum];
  30229. if (!typeFn) {
  30230. error('Unknown type of function');
  30231. }
  30232. return typeFn.call(this, fn, dict, xref);
  30233. },
  30234. fromIR: function PDFFunction_fromIR(IR) {
  30235. var type = IR[0];
  30236. switch (type) {
  30237. case CONSTRUCT_SAMPLED:
  30238. return this.constructSampledFromIR(IR);
  30239. case CONSTRUCT_INTERPOLATED:
  30240. return this.constructInterpolatedFromIR(IR);
  30241. case CONSTRUCT_STICHED:
  30242. return this.constructStichedFromIR(IR);
  30243. //case CONSTRUCT_POSTSCRIPT:
  30244. default:
  30245. return this.constructPostScriptFromIR(IR);
  30246. }
  30247. },
  30248. parse: function PDFFunction_parse(xref, fn) {
  30249. var IR = this.getIR(xref, fn);
  30250. return this.fromIR(IR);
  30251. },
  30252. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  30253. if (!isArray(fnObj)) {
  30254. // not an array -- parsing as regular function
  30255. return this.parse(xref, fnObj);
  30256. }
  30257. var fnArray = [];
  30258. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  30259. var obj = xref.fetchIfRef(fnObj[j]);
  30260. fnArray.push(PDFFunction.parse(xref, obj));
  30261. }
  30262. return function (src, srcOffset, dest, destOffset) {
  30263. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  30264. fnArray[i](src, srcOffset, dest, destOffset + i);
  30265. }
  30266. };
  30267. },
  30268. constructSampled: function PDFFunction_constructSampled(str, dict) {
  30269. function toMultiArray(arr) {
  30270. var inputLength = arr.length;
  30271. var out = [];
  30272. var index = 0;
  30273. for (var i = 0; i < inputLength; i += 2) {
  30274. out[index] = [arr[i], arr[i + 1]];
  30275. ++index;
  30276. }
  30277. return out;
  30278. }
  30279. var domain = dict.get('Domain');
  30280. var range = dict.get('Range');
  30281. if (!domain || !range) {
  30282. error('No domain or range');
  30283. }
  30284. var inputSize = domain.length / 2;
  30285. var outputSize = range.length / 2;
  30286. domain = toMultiArray(domain);
  30287. range = toMultiArray(range);
  30288. var size = dict.get('Size');
  30289. var bps = dict.get('BitsPerSample');
  30290. var order = dict.get('Order') || 1;
  30291. if (order !== 1) {
  30292. // No description how cubic spline interpolation works in PDF32000:2008
  30293. // As in poppler, ignoring order, linear interpolation may work as good
  30294. info('No support for cubic spline interpolation: ' + order);
  30295. }
  30296. var encode = dict.get('Encode');
  30297. if (!encode) {
  30298. encode = [];
  30299. for (var i = 0; i < inputSize; ++i) {
  30300. encode.push(0);
  30301. encode.push(size[i] - 1);
  30302. }
  30303. }
  30304. encode = toMultiArray(encode);
  30305. var decode = dict.get('Decode');
  30306. if (!decode) {
  30307. decode = range;
  30308. } else {
  30309. decode = toMultiArray(decode);
  30310. }
  30311. var samples = this.getSampleArray(size, outputSize, bps, str);
  30312. return [
  30313. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  30314. outputSize, Math.pow(2, bps) - 1, range
  30315. ];
  30316. },
  30317. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  30318. // See chapter 3, page 109 of the PDF reference
  30319. function interpolate(x, xmin, xmax, ymin, ymax) {
  30320. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  30321. }
  30322. return function constructSampledFromIRResult(src, srcOffset,
  30323. dest, destOffset) {
  30324. // See chapter 3, page 110 of the PDF reference.
  30325. var m = IR[1];
  30326. var domain = IR[2];
  30327. var encode = IR[3];
  30328. var decode = IR[4];
  30329. var samples = IR[5];
  30330. var size = IR[6];
  30331. var n = IR[7];
  30332. //var mask = IR[8];
  30333. var range = IR[9];
  30334. // Building the cube vertices: its part and sample index
  30335. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  30336. var cubeVertices = 1 << m;
  30337. var cubeN = new Float64Array(cubeVertices);
  30338. var cubeVertex = new Uint32Array(cubeVertices);
  30339. var i, j;
  30340. for (j = 0; j < cubeVertices; j++) {
  30341. cubeN[j] = 1;
  30342. }
  30343. var k = n, pos = 1;
  30344. // Map x_i to y_j for 0 <= i < m using the sampled function.
  30345. for (i = 0; i < m; ++i) {
  30346. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  30347. var domain_2i = domain[i][0];
  30348. var domain_2i_1 = domain[i][1];
  30349. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  30350. domain_2i_1);
  30351. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  30352. // Encode_2i, Encode_2i+1)
  30353. var e = interpolate(xi, domain_2i, domain_2i_1,
  30354. encode[i][0], encode[i][1]);
  30355. // e_i' = min(max(e_i, 0), Size_i - 1)
  30356. var size_i = size[i];
  30357. e = Math.min(Math.max(e, 0), size_i - 1);
  30358. // Adjusting the cube: N and vertex sample index
  30359. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  30360. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  30361. var n1 = e - e0; // (e - e0) / (e1 - e0);
  30362. var offset0 = e0 * k;
  30363. var offset1 = offset0 + k; // e1 * k
  30364. for (j = 0; j < cubeVertices; j++) {
  30365. if (j & pos) {
  30366. cubeN[j] *= n1;
  30367. cubeVertex[j] += offset1;
  30368. } else {
  30369. cubeN[j] *= n0;
  30370. cubeVertex[j] += offset0;
  30371. }
  30372. }
  30373. k *= size_i;
  30374. pos <<= 1;
  30375. }
  30376. for (j = 0; j < n; ++j) {
  30377. // Sum all cube vertices' samples portions
  30378. var rj = 0;
  30379. for (i = 0; i < cubeVertices; i++) {
  30380. rj += samples[cubeVertex[i] + j] * cubeN[i];
  30381. }
  30382. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  30383. // Decode_2j, Decode_2j+1)
  30384. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  30385. // y_j = min(max(r_j, range_2j), range_2j+1)
  30386. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  30387. range[j][1]);
  30388. }
  30389. };
  30390. },
  30391. constructInterpolated: function PDFFunction_constructInterpolated(str,
  30392. dict) {
  30393. var c0 = dict.get('C0') || [0];
  30394. var c1 = dict.get('C1') || [1];
  30395. var n = dict.get('N');
  30396. if (!isArray(c0) || !isArray(c1)) {
  30397. error('Illegal dictionary for interpolated function');
  30398. }
  30399. var length = c0.length;
  30400. var diff = [];
  30401. for (var i = 0; i < length; ++i) {
  30402. diff.push(c1[i] - c0[i]);
  30403. }
  30404. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30405. },
  30406. constructInterpolatedFromIR:
  30407. function PDFFunction_constructInterpolatedFromIR(IR) {
  30408. var c0 = IR[1];
  30409. var diff = IR[2];
  30410. var n = IR[3];
  30411. var length = diff.length;
  30412. return function constructInterpolatedFromIRResult(src, srcOffset,
  30413. dest, destOffset) {
  30414. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30415. for (var j = 0; j < length; ++j) {
  30416. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30417. }
  30418. };
  30419. },
  30420. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30421. var domain = dict.get('Domain');
  30422. if (!domain) {
  30423. error('No domain');
  30424. }
  30425. var inputSize = domain.length / 2;
  30426. if (inputSize !== 1) {
  30427. error('Bad domain for stiched function');
  30428. }
  30429. var fnRefs = dict.get('Functions');
  30430. var fns = [];
  30431. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30432. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30433. }
  30434. var bounds = dict.get('Bounds');
  30435. var encode = dict.get('Encode');
  30436. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30437. },
  30438. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30439. var domain = IR[1];
  30440. var bounds = IR[2];
  30441. var encode = IR[3];
  30442. var fnsIR = IR[4];
  30443. var fns = [];
  30444. var tmpBuf = new Float32Array(1);
  30445. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30446. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30447. }
  30448. return function constructStichedFromIRResult(src, srcOffset,
  30449. dest, destOffset) {
  30450. var clip = function constructStichedFromIRClip(v, min, max) {
  30451. if (v > max) {
  30452. v = max;
  30453. } else if (v < min) {
  30454. v = min;
  30455. }
  30456. return v;
  30457. };
  30458. // clip to domain
  30459. var v = clip(src[srcOffset], domain[0], domain[1]);
  30460. // calulate which bound the value is in
  30461. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30462. if (v < bounds[i]) {
  30463. break;
  30464. }
  30465. }
  30466. // encode value into domain of function
  30467. var dmin = domain[0];
  30468. if (i > 0) {
  30469. dmin = bounds[i - 1];
  30470. }
  30471. var dmax = domain[1];
  30472. if (i < bounds.length) {
  30473. dmax = bounds[i];
  30474. }
  30475. var rmin = encode[2 * i];
  30476. var rmax = encode[2 * i + 1];
  30477. // Prevent the value from becoming NaN as a result
  30478. // of division by zero (fixes issue6113.pdf).
  30479. tmpBuf[0] = dmin === dmax ? rmin :
  30480. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30481. // call the appropriate function
  30482. fns[i](tmpBuf, 0, dest, destOffset);
  30483. };
  30484. },
  30485. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30486. xref) {
  30487. var domain = dict.get('Domain');
  30488. var range = dict.get('Range');
  30489. if (!domain) {
  30490. error('No domain.');
  30491. }
  30492. if (!range) {
  30493. error('No range.');
  30494. }
  30495. var lexer = new PostScriptLexer(fn);
  30496. var parser = new PostScriptParser(lexer);
  30497. var code = parser.parse();
  30498. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30499. },
  30500. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30501. IR) {
  30502. var domain = IR[1];
  30503. var range = IR[2];
  30504. var code = IR[3];
  30505. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30506. if (compiled) {
  30507. // Compiled function consists of simple expressions such as addition,
  30508. // subtraction, Math.max, and also contains 'var' and 'return'
  30509. // statements. See the generation in the PostScriptCompiler below.
  30510. /*jshint -W054 */
  30511. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30512. }
  30513. info('Unable to compile PS function');
  30514. var numOutputs = range.length >> 1;
  30515. var numInputs = domain.length >> 1;
  30516. var evaluator = new PostScriptEvaluator(code);
  30517. // Cache the values for a big speed up, the cache size is limited though
  30518. // since the number of possible values can be huge from a PS function.
  30519. var cache = {};
  30520. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30521. // seen in our tests.
  30522. var MAX_CACHE_SIZE = 2048 * 4;
  30523. var cache_available = MAX_CACHE_SIZE;
  30524. var tmpBuf = new Float32Array(numInputs);
  30525. return function constructPostScriptFromIRResult(src, srcOffset,
  30526. dest, destOffset) {
  30527. var i, value;
  30528. var key = '';
  30529. var input = tmpBuf;
  30530. for (i = 0; i < numInputs; i++) {
  30531. value = src[srcOffset + i];
  30532. input[i] = value;
  30533. key += value + '_';
  30534. }
  30535. var cachedValue = cache[key];
  30536. if (cachedValue !== undefined) {
  30537. dest.set(cachedValue, destOffset);
  30538. return;
  30539. }
  30540. var output = new Float32Array(numOutputs);
  30541. var stack = evaluator.execute(input);
  30542. var stackIndex = stack.length - numOutputs;
  30543. for (i = 0; i < numOutputs; i++) {
  30544. value = stack[stackIndex + i];
  30545. var bound = range[i * 2];
  30546. if (value < bound) {
  30547. value = bound;
  30548. } else {
  30549. bound = range[i * 2 +1];
  30550. if (value > bound) {
  30551. value = bound;
  30552. }
  30553. }
  30554. output[i] = value;
  30555. }
  30556. if (cache_available > 0) {
  30557. cache_available--;
  30558. cache[key] = output;
  30559. }
  30560. dest.set(output, destOffset);
  30561. };
  30562. }
  30563. };
  30564. })();
  30565. function isPDFFunction(v) {
  30566. var fnDict;
  30567. if (typeof v !== 'object') {
  30568. return false;
  30569. } else if (isDict(v)) {
  30570. fnDict = v;
  30571. } else if (isStream(v)) {
  30572. fnDict = v.dict;
  30573. } else {
  30574. return false;
  30575. }
  30576. return fnDict.has('FunctionType');
  30577. }
  30578. var PostScriptStack = (function PostScriptStackClosure() {
  30579. var MAX_STACK_SIZE = 100;
  30580. function PostScriptStack(initialStack) {
  30581. this.stack = !initialStack ? [] :
  30582. Array.prototype.slice.call(initialStack, 0);
  30583. }
  30584. PostScriptStack.prototype = {
  30585. push: function PostScriptStack_push(value) {
  30586. if (this.stack.length >= MAX_STACK_SIZE) {
  30587. error('PostScript function stack overflow.');
  30588. }
  30589. this.stack.push(value);
  30590. },
  30591. pop: function PostScriptStack_pop() {
  30592. if (this.stack.length <= 0) {
  30593. error('PostScript function stack underflow.');
  30594. }
  30595. return this.stack.pop();
  30596. },
  30597. copy: function PostScriptStack_copy(n) {
  30598. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30599. error('PostScript function stack overflow.');
  30600. }
  30601. var stack = this.stack;
  30602. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30603. stack.push(stack[i]);
  30604. }
  30605. },
  30606. index: function PostScriptStack_index(n) {
  30607. this.push(this.stack[this.stack.length - n - 1]);
  30608. },
  30609. // rotate the last n stack elements p times
  30610. roll: function PostScriptStack_roll(n, p) {
  30611. var stack = this.stack;
  30612. var l = stack.length - n;
  30613. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30614. for (i = l, j = r; i < j; i++, j--) {
  30615. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30616. }
  30617. for (i = l, j = c - 1; i < j; i++, j--) {
  30618. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30619. }
  30620. for (i = c, j = r; i < j; i++, j--) {
  30621. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30622. }
  30623. }
  30624. };
  30625. return PostScriptStack;
  30626. })();
  30627. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30628. function PostScriptEvaluator(operators) {
  30629. this.operators = operators;
  30630. }
  30631. PostScriptEvaluator.prototype = {
  30632. execute: function PostScriptEvaluator_execute(initialStack) {
  30633. var stack = new PostScriptStack(initialStack);
  30634. var counter = 0;
  30635. var operators = this.operators;
  30636. var length = operators.length;
  30637. var operator, a, b;
  30638. while (counter < length) {
  30639. operator = operators[counter++];
  30640. if (typeof operator === 'number') {
  30641. // Operator is really an operand and should be pushed to the stack.
  30642. stack.push(operator);
  30643. continue;
  30644. }
  30645. switch (operator) {
  30646. // non standard ps operators
  30647. case 'jz': // jump if false
  30648. b = stack.pop();
  30649. a = stack.pop();
  30650. if (!a) {
  30651. counter = b;
  30652. }
  30653. break;
  30654. case 'j': // jump
  30655. a = stack.pop();
  30656. counter = a;
  30657. break;
  30658. // all ps operators in alphabetical order (excluding if/ifelse)
  30659. case 'abs':
  30660. a = stack.pop();
  30661. stack.push(Math.abs(a));
  30662. break;
  30663. case 'add':
  30664. b = stack.pop();
  30665. a = stack.pop();
  30666. stack.push(a + b);
  30667. break;
  30668. case 'and':
  30669. b = stack.pop();
  30670. a = stack.pop();
  30671. if (isBool(a) && isBool(b)) {
  30672. stack.push(a && b);
  30673. } else {
  30674. stack.push(a & b);
  30675. }
  30676. break;
  30677. case 'atan':
  30678. a = stack.pop();
  30679. stack.push(Math.atan(a));
  30680. break;
  30681. case 'bitshift':
  30682. b = stack.pop();
  30683. a = stack.pop();
  30684. if (a > 0) {
  30685. stack.push(a << b);
  30686. } else {
  30687. stack.push(a >> b);
  30688. }
  30689. break;
  30690. case 'ceiling':
  30691. a = stack.pop();
  30692. stack.push(Math.ceil(a));
  30693. break;
  30694. case 'copy':
  30695. a = stack.pop();
  30696. stack.copy(a);
  30697. break;
  30698. case 'cos':
  30699. a = stack.pop();
  30700. stack.push(Math.cos(a));
  30701. break;
  30702. case 'cvi':
  30703. a = stack.pop() | 0;
  30704. stack.push(a);
  30705. break;
  30706. case 'cvr':
  30707. // noop
  30708. break;
  30709. case 'div':
  30710. b = stack.pop();
  30711. a = stack.pop();
  30712. stack.push(a / b);
  30713. break;
  30714. case 'dup':
  30715. stack.copy(1);
  30716. break;
  30717. case 'eq':
  30718. b = stack.pop();
  30719. a = stack.pop();
  30720. stack.push(a === b);
  30721. break;
  30722. case 'exch':
  30723. stack.roll(2, 1);
  30724. break;
  30725. case 'exp':
  30726. b = stack.pop();
  30727. a = stack.pop();
  30728. stack.push(Math.pow(a, b));
  30729. break;
  30730. case 'false':
  30731. stack.push(false);
  30732. break;
  30733. case 'floor':
  30734. a = stack.pop();
  30735. stack.push(Math.floor(a));
  30736. break;
  30737. case 'ge':
  30738. b = stack.pop();
  30739. a = stack.pop();
  30740. stack.push(a >= b);
  30741. break;
  30742. case 'gt':
  30743. b = stack.pop();
  30744. a = stack.pop();
  30745. stack.push(a > b);
  30746. break;
  30747. case 'idiv':
  30748. b = stack.pop();
  30749. a = stack.pop();
  30750. stack.push((a / b) | 0);
  30751. break;
  30752. case 'index':
  30753. a = stack.pop();
  30754. stack.index(a);
  30755. break;
  30756. case 'le':
  30757. b = stack.pop();
  30758. a = stack.pop();
  30759. stack.push(a <= b);
  30760. break;
  30761. case 'ln':
  30762. a = stack.pop();
  30763. stack.push(Math.log(a));
  30764. break;
  30765. case 'log':
  30766. a = stack.pop();
  30767. stack.push(Math.log(a) / Math.LN10);
  30768. break;
  30769. case 'lt':
  30770. b = stack.pop();
  30771. a = stack.pop();
  30772. stack.push(a < b);
  30773. break;
  30774. case 'mod':
  30775. b = stack.pop();
  30776. a = stack.pop();
  30777. stack.push(a % b);
  30778. break;
  30779. case 'mul':
  30780. b = stack.pop();
  30781. a = stack.pop();
  30782. stack.push(a * b);
  30783. break;
  30784. case 'ne':
  30785. b = stack.pop();
  30786. a = stack.pop();
  30787. stack.push(a !== b);
  30788. break;
  30789. case 'neg':
  30790. a = stack.pop();
  30791. stack.push(-a);
  30792. break;
  30793. case 'not':
  30794. a = stack.pop();
  30795. if (isBool(a)) {
  30796. stack.push(!a);
  30797. } else {
  30798. stack.push(~a);
  30799. }
  30800. break;
  30801. case 'or':
  30802. b = stack.pop();
  30803. a = stack.pop();
  30804. if (isBool(a) && isBool(b)) {
  30805. stack.push(a || b);
  30806. } else {
  30807. stack.push(a | b);
  30808. }
  30809. break;
  30810. case 'pop':
  30811. stack.pop();
  30812. break;
  30813. case 'roll':
  30814. b = stack.pop();
  30815. a = stack.pop();
  30816. stack.roll(a, b);
  30817. break;
  30818. case 'round':
  30819. a = stack.pop();
  30820. stack.push(Math.round(a));
  30821. break;
  30822. case 'sin':
  30823. a = stack.pop();
  30824. stack.push(Math.sin(a));
  30825. break;
  30826. case 'sqrt':
  30827. a = stack.pop();
  30828. stack.push(Math.sqrt(a));
  30829. break;
  30830. case 'sub':
  30831. b = stack.pop();
  30832. a = stack.pop();
  30833. stack.push(a - b);
  30834. break;
  30835. case 'true':
  30836. stack.push(true);
  30837. break;
  30838. case 'truncate':
  30839. a = stack.pop();
  30840. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30841. stack.push(a);
  30842. break;
  30843. case 'xor':
  30844. b = stack.pop();
  30845. a = stack.pop();
  30846. if (isBool(a) && isBool(b)) {
  30847. stack.push(a !== b);
  30848. } else {
  30849. stack.push(a ^ b);
  30850. }
  30851. break;
  30852. default:
  30853. error('Unknown operator ' + operator);
  30854. break;
  30855. }
  30856. }
  30857. return stack.stack;
  30858. }
  30859. };
  30860. return PostScriptEvaluator;
  30861. })();
  30862. // Most of the PDFs functions consist of simple operations such as:
  30863. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30864. //
  30865. // We can compile most of such programs, and at the same moment, we can
  30866. // optimize some expressions using basic math properties. Keeping track of
  30867. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30868. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30869. function AstNode(type) {
  30870. this.type = type;
  30871. }
  30872. AstNode.prototype.visit = function (visitor) {
  30873. throw new Error('abstract method');
  30874. };
  30875. function AstArgument(index, min, max) {
  30876. AstNode.call(this, 'args');
  30877. this.index = index;
  30878. this.min = min;
  30879. this.max = max;
  30880. }
  30881. AstArgument.prototype = Object.create(AstNode.prototype);
  30882. AstArgument.prototype.visit = function (visitor) {
  30883. visitor.visitArgument(this);
  30884. };
  30885. function AstLiteral(number) {
  30886. AstNode.call(this, 'literal');
  30887. this.number = number;
  30888. this.min = number;
  30889. this.max = number;
  30890. }
  30891. AstLiteral.prototype = Object.create(AstNode.prototype);
  30892. AstLiteral.prototype.visit = function (visitor) {
  30893. visitor.visitLiteral(this);
  30894. };
  30895. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30896. AstNode.call(this, 'binary');
  30897. this.op = op;
  30898. this.arg1 = arg1;
  30899. this.arg2 = arg2;
  30900. this.min = min;
  30901. this.max = max;
  30902. }
  30903. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30904. AstBinaryOperation.prototype.visit = function (visitor) {
  30905. visitor.visitBinaryOperation(this);
  30906. };
  30907. function AstMin(arg, max) {
  30908. AstNode.call(this, 'max');
  30909. this.arg = arg;
  30910. this.min = arg.min;
  30911. this.max = max;
  30912. }
  30913. AstMin.prototype = Object.create(AstNode.prototype);
  30914. AstMin.prototype.visit = function (visitor) {
  30915. visitor.visitMin(this);
  30916. };
  30917. function AstVariable(index, min, max) {
  30918. AstNode.call(this, 'var');
  30919. this.index = index;
  30920. this.min = min;
  30921. this.max = max;
  30922. }
  30923. AstVariable.prototype = Object.create(AstNode.prototype);
  30924. AstVariable.prototype.visit = function (visitor) {
  30925. visitor.visitVariable(this);
  30926. };
  30927. function AstVariableDefinition(variable, arg) {
  30928. AstNode.call(this, 'definition');
  30929. this.variable = variable;
  30930. this.arg = arg;
  30931. }
  30932. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30933. AstVariableDefinition.prototype.visit = function (visitor) {
  30934. visitor.visitVariableDefinition(this);
  30935. };
  30936. function ExpressionBuilderVisitor() {
  30937. this.parts = [];
  30938. }
  30939. ExpressionBuilderVisitor.prototype = {
  30940. visitArgument: function (arg) {
  30941. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30942. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30943. },
  30944. visitVariable: function (variable) {
  30945. this.parts.push('v', variable.index);
  30946. },
  30947. visitLiteral: function (literal) {
  30948. this.parts.push(literal.number);
  30949. },
  30950. visitBinaryOperation: function (operation) {
  30951. this.parts.push('(');
  30952. operation.arg1.visit(this);
  30953. this.parts.push(' ', operation.op, ' ');
  30954. operation.arg2.visit(this);
  30955. this.parts.push(')');
  30956. },
  30957. visitVariableDefinition: function (definition) {
  30958. this.parts.push('var ');
  30959. definition.variable.visit(this);
  30960. this.parts.push(' = ');
  30961. definition.arg.visit(this);
  30962. this.parts.push(';');
  30963. },
  30964. visitMin: function (max) {
  30965. this.parts.push('Math.min(');
  30966. max.arg.visit(this);
  30967. this.parts.push(', ', max.max, ')');
  30968. },
  30969. toString: function () {
  30970. return this.parts.join('');
  30971. }
  30972. };
  30973. function buildAddOperation(num1, num2) {
  30974. if (num2.type === 'literal' && num2.number === 0) {
  30975. // optimization: second operand is 0
  30976. return num1;
  30977. }
  30978. if (num1.type === 'literal' && num1.number === 0) {
  30979. // optimization: first operand is 0
  30980. return num2;
  30981. }
  30982. if (num2.type === 'literal' && num1.type === 'literal') {
  30983. // optimization: operands operand are literals
  30984. return new AstLiteral(num1.number + num2.number);
  30985. }
  30986. return new AstBinaryOperation('+', num1, num2,
  30987. num1.min + num2.min, num1.max + num2.max);
  30988. }
  30989. function buildMulOperation(num1, num2) {
  30990. if (num2.type === 'literal') {
  30991. // optimization: second operands is a literal...
  30992. if (num2.number === 0) {
  30993. return new AstLiteral(0); // and it's 0
  30994. } else if (num2.number === 1) {
  30995. return num1; // and it's 1
  30996. } else if (num1.type === 'literal') {
  30997. // ... and first operands is a literal too
  30998. return new AstLiteral(num1.number * num2.number);
  30999. }
  31000. }
  31001. if (num1.type === 'literal') {
  31002. // optimization: first operands is a literal...
  31003. if (num1.number === 0) {
  31004. return new AstLiteral(0); // and it's 0
  31005. } else if (num1.number === 1) {
  31006. return num2; // and it's 1
  31007. }
  31008. }
  31009. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  31010. num1.max * num2.min, num1.max * num2.max);
  31011. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  31012. num1.max * num2.min, num1.max * num2.max);
  31013. return new AstBinaryOperation('*', num1, num2, min, max);
  31014. }
  31015. function buildSubOperation(num1, num2) {
  31016. if (num2.type === 'literal') {
  31017. // optimization: second operands is a literal...
  31018. if (num2.number === 0) {
  31019. return num1; // ... and it's 0
  31020. } else if (num1.type === 'literal') {
  31021. // ... and first operands is a literal too
  31022. return new AstLiteral(num1.number - num2.number);
  31023. }
  31024. }
  31025. if (num2.type === 'binary' && num2.op === '-' &&
  31026. num1.type === 'literal' && num1.number === 1 &&
  31027. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  31028. // optimization for case: 1 - (1 - x)
  31029. return num2.arg2;
  31030. }
  31031. return new AstBinaryOperation('-', num1, num2,
  31032. num1.min - num2.max, num1.max - num2.min);
  31033. }
  31034. function buildMinOperation(num1, max) {
  31035. if (num1.min >= max) {
  31036. // optimization: num1 min value is not less than required max
  31037. return new AstLiteral(max); // just returning max
  31038. } else if (num1.max <= max) {
  31039. // optimization: num1 max value is not greater than required max
  31040. return num1; // just returning an argument
  31041. }
  31042. return new AstMin(num1, max);
  31043. }
  31044. function PostScriptCompiler() {}
  31045. PostScriptCompiler.prototype = {
  31046. compile: function PostScriptCompiler_compile(code, domain, range) {
  31047. var stack = [];
  31048. var i, ii;
  31049. var instructions = [];
  31050. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  31051. var lastRegister = 0;
  31052. var n, j;
  31053. var num1, num2, ast1, ast2, tmpVar, item;
  31054. for (i = 0; i < inputSize; i++) {
  31055. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  31056. }
  31057. for (i = 0, ii = code.length; i < ii; i++) {
  31058. item = code[i];
  31059. if (typeof item === 'number') {
  31060. stack.push(new AstLiteral(item));
  31061. continue;
  31062. }
  31063. switch (item) {
  31064. case 'add':
  31065. if (stack.length < 2) {
  31066. return null;
  31067. }
  31068. num2 = stack.pop();
  31069. num1 = stack.pop();
  31070. stack.push(buildAddOperation(num1, num2));
  31071. break;
  31072. case 'cvr':
  31073. if (stack.length < 1) {
  31074. return null;
  31075. }
  31076. break;
  31077. case 'mul':
  31078. if (stack.length < 2) {
  31079. return null;
  31080. }
  31081. num2 = stack.pop();
  31082. num1 = stack.pop();
  31083. stack.push(buildMulOperation(num1, num2));
  31084. break;
  31085. case 'sub':
  31086. if (stack.length < 2) {
  31087. return null;
  31088. }
  31089. num2 = stack.pop();
  31090. num1 = stack.pop();
  31091. stack.push(buildSubOperation(num1, num2));
  31092. break;
  31093. case 'exch':
  31094. if (stack.length < 2) {
  31095. return null;
  31096. }
  31097. ast1 = stack.pop(); ast2 = stack.pop();
  31098. stack.push(ast1, ast2);
  31099. break;
  31100. case 'pop':
  31101. if (stack.length < 1) {
  31102. return null;
  31103. }
  31104. stack.pop();
  31105. break;
  31106. case 'index':
  31107. if (stack.length < 1) {
  31108. return null;
  31109. }
  31110. num1 = stack.pop();
  31111. if (num1.type !== 'literal') {
  31112. return null;
  31113. }
  31114. n = num1.number;
  31115. if (n < 0 || (n|0) !== n || stack.length < n) {
  31116. return null;
  31117. }
  31118. ast1 = stack[stack.length - n - 1];
  31119. if (ast1.type === 'literal' || ast1.type === 'var') {
  31120. stack.push(ast1);
  31121. break;
  31122. }
  31123. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31124. stack[stack.length - n - 1] = tmpVar;
  31125. stack.push(tmpVar);
  31126. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31127. break;
  31128. case 'dup':
  31129. if (stack.length < 1) {
  31130. return null;
  31131. }
  31132. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  31133. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  31134. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  31135. // special case of the commands sequence for the min operation
  31136. num1 = stack.pop();
  31137. stack.push(buildMinOperation(num1, code[i + 1]));
  31138. i += 6;
  31139. break;
  31140. }
  31141. ast1 = stack[stack.length - 1];
  31142. if (ast1.type === 'literal' || ast1.type === 'var') {
  31143. // we don't have to save into intermediate variable a literal or
  31144. // variable.
  31145. stack.push(ast1);
  31146. break;
  31147. }
  31148. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31149. stack[stack.length - 1] = tmpVar;
  31150. stack.push(tmpVar);
  31151. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31152. break;
  31153. case 'roll':
  31154. if (stack.length < 2) {
  31155. return null;
  31156. }
  31157. num2 = stack.pop();
  31158. num1 = stack.pop();
  31159. if (num2.type !== 'literal' || num1.type !== 'literal') {
  31160. // both roll operands must be numbers
  31161. return null;
  31162. }
  31163. j = num2.number;
  31164. n = num1.number;
  31165. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  31166. // ... and integers
  31167. return null;
  31168. }
  31169. j = ((j % n) + n) % n;
  31170. if (j === 0) {
  31171. break; // just skipping -- there are nothing to rotate
  31172. }
  31173. Array.prototype.push.apply(stack,
  31174. stack.splice(stack.length - n, n - j));
  31175. break;
  31176. default:
  31177. return null; // unsupported operator
  31178. }
  31179. }
  31180. if (stack.length !== outputSize) {
  31181. return null;
  31182. }
  31183. var result = [];
  31184. instructions.forEach(function (instruction) {
  31185. var statementBuilder = new ExpressionBuilderVisitor();
  31186. instruction.visit(statementBuilder);
  31187. result.push(statementBuilder.toString());
  31188. });
  31189. stack.forEach(function (expr, i) {
  31190. var statementBuilder = new ExpressionBuilderVisitor();
  31191. expr.visit(statementBuilder);
  31192. var min = range[i * 2], max = range[i * 2 + 1];
  31193. var out = [statementBuilder.toString()];
  31194. if (min > expr.min) {
  31195. out.unshift('Math.max(', min, ', ');
  31196. out.push(')');
  31197. }
  31198. if (max < expr.max) {
  31199. out.unshift('Math.min(', max, ', ');
  31200. out.push(')');
  31201. }
  31202. out.unshift('dest[destOffset + ', i, '] = ');
  31203. out.push(';');
  31204. result.push(out.join(''));
  31205. });
  31206. return result.join('\n');
  31207. }
  31208. };
  31209. return PostScriptCompiler;
  31210. })();
  31211. exports.isPDFFunction = isPDFFunction;
  31212. exports.PDFFunction = PDFFunction;
  31213. exports.PostScriptEvaluator = PostScriptEvaluator;
  31214. exports.PostScriptCompiler = PostScriptCompiler;
  31215. }));
  31216. (function (root, factory) {
  31217. {
  31218. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  31219. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  31220. }
  31221. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  31222. coreStream) {
  31223. var error = sharedUtil.error;
  31224. var info = sharedUtil.info;
  31225. var isArray = sharedUtil.isArray;
  31226. var isString = sharedUtil.isString;
  31227. var shadow = sharedUtil.shadow;
  31228. var warn = sharedUtil.warn;
  31229. var isDict = corePrimitives.isDict;
  31230. var isName = corePrimitives.isName;
  31231. var isStream = corePrimitives.isStream;
  31232. var PDFFunction = coreFunction.PDFFunction;
  31233. var coreImage; // see _setCoreImage below
  31234. var PDFImage; // = coreImage.PDFImage;
  31235. var ColorSpace = (function ColorSpaceClosure() {
  31236. // Constructor should define this.numComps, this.defaultColor, this.name
  31237. function ColorSpace() {
  31238. error('should not call ColorSpace constructor');
  31239. }
  31240. ColorSpace.prototype = {
  31241. /**
  31242. * Converts the color value to the RGB color. The color components are
  31243. * located in the src array starting from the srcOffset. Returns the array
  31244. * of the rgb components, each value ranging from [0,255].
  31245. */
  31246. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  31247. var rgb = new Uint8Array(3);
  31248. this.getRgbItem(src, srcOffset, rgb, 0);
  31249. return rgb;
  31250. },
  31251. /**
  31252. * Converts the color value to the RGB color, similar to the getRgb method.
  31253. * The result placed into the dest array starting from the destOffset.
  31254. */
  31255. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  31256. dest, destOffset) {
  31257. error('Should not call ColorSpace.getRgbItem');
  31258. },
  31259. /**
  31260. * Converts the specified number of the color values to the RGB colors.
  31261. * The colors are located in the src array starting from the srcOffset.
  31262. * The result is placed into the dest array starting from the destOffset.
  31263. * The src array items shall be in [0,2^bits) range, the dest array items
  31264. * will be in [0,255] range. alpha01 indicates how many alpha components
  31265. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  31266. * array).
  31267. */
  31268. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  31269. dest, destOffset, bits,
  31270. alpha01) {
  31271. error('Should not call ColorSpace.getRgbBuffer');
  31272. },
  31273. /**
  31274. * Determines the number of bytes required to store the result of the
  31275. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  31276. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  31277. */
  31278. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  31279. alpha01) {
  31280. error('Should not call ColorSpace.getOutputLength');
  31281. },
  31282. /**
  31283. * Returns true if source data will be equal the result/output data.
  31284. */
  31285. isPassthrough: function ColorSpace_isPassthrough(bits) {
  31286. return false;
  31287. },
  31288. /**
  31289. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  31290. * how many alpha components there are in the dest array; it will be either
  31291. * 0 (RGB array) or 1 (RGBA array).
  31292. */
  31293. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  31294. originalHeight, width, height,
  31295. actualHeight, bpc, comps, alpha01) {
  31296. var count = originalWidth * originalHeight;
  31297. var rgbBuf = null;
  31298. var numComponentColors = 1 << bpc;
  31299. var needsResizing = originalHeight !== height || originalWidth !== width;
  31300. var i, ii;
  31301. if (this.isPassthrough(bpc)) {
  31302. rgbBuf = comps;
  31303. } else if (this.numComps === 1 && count > numComponentColors &&
  31304. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  31305. // Optimization: create a color map when there is just one component and
  31306. // we are converting more colors than the size of the color map. We
  31307. // don't build the map if the colorspace is gray or rgb since those
  31308. // methods are faster than building a map. This mainly offers big speed
  31309. // ups for indexed and alternate colorspaces.
  31310. //
  31311. // TODO it may be worth while to cache the color map. While running
  31312. // testing I never hit a cache so I will leave that out for now (perhaps
  31313. // we are reparsing colorspaces too much?).
  31314. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  31315. new Uint16Array(numComponentColors);
  31316. var key;
  31317. for (i = 0; i < numComponentColors; i++) {
  31318. allColors[i] = i;
  31319. }
  31320. var colorMap = new Uint8Array(numComponentColors * 3);
  31321. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  31322. /* alpha01 = */ 0);
  31323. var destPos, rgbPos;
  31324. if (!needsResizing) {
  31325. // Fill in the RGB values directly into |dest|.
  31326. destPos = 0;
  31327. for (i = 0; i < count; ++i) {
  31328. key = comps[i] * 3;
  31329. dest[destPos++] = colorMap[key];
  31330. dest[destPos++] = colorMap[key + 1];
  31331. dest[destPos++] = colorMap[key + 2];
  31332. destPos += alpha01;
  31333. }
  31334. } else {
  31335. rgbBuf = new Uint8Array(count * 3);
  31336. rgbPos = 0;
  31337. for (i = 0; i < count; ++i) {
  31338. key = comps[i] * 3;
  31339. rgbBuf[rgbPos++] = colorMap[key];
  31340. rgbBuf[rgbPos++] = colorMap[key + 1];
  31341. rgbBuf[rgbPos++] = colorMap[key + 2];
  31342. }
  31343. }
  31344. } else {
  31345. if (!needsResizing) {
  31346. // Fill in the RGB values directly into |dest|.
  31347. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  31348. alpha01);
  31349. } else {
  31350. rgbBuf = new Uint8Array(count * 3);
  31351. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  31352. /* alpha01 = */ 0);
  31353. }
  31354. }
  31355. if (rgbBuf) {
  31356. if (needsResizing) {
  31357. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  31358. height, dest, alpha01);
  31359. } else {
  31360. rgbPos = 0;
  31361. destPos = 0;
  31362. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  31363. dest[destPos++] = rgbBuf[rgbPos++];
  31364. dest[destPos++] = rgbBuf[rgbPos++];
  31365. dest[destPos++] = rgbBuf[rgbPos++];
  31366. destPos += alpha01;
  31367. }
  31368. }
  31369. }
  31370. },
  31371. /**
  31372. * True if the colorspace has components in the default range of [0, 1].
  31373. * This should be true for all colorspaces except for lab color spaces
  31374. * which are [0,100], [-128, 127], [-128, 127].
  31375. */
  31376. usesZeroToOneRange: true
  31377. };
  31378. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31379. var IR = ColorSpace.parseToIR(cs, xref, res);
  31380. if (IR instanceof AlternateCS) {
  31381. return IR;
  31382. }
  31383. return ColorSpace.fromIR(IR);
  31384. };
  31385. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31386. var name = isArray(IR) ? IR[0] : IR;
  31387. var whitePoint, blackPoint, gamma;
  31388. switch (name) {
  31389. case 'DeviceGrayCS':
  31390. return this.singletons.gray;
  31391. case 'DeviceRgbCS':
  31392. return this.singletons.rgb;
  31393. case 'DeviceCmykCS':
  31394. return this.singletons.cmyk;
  31395. case 'CalGrayCS':
  31396. whitePoint = IR[1].WhitePoint;
  31397. blackPoint = IR[1].BlackPoint;
  31398. gamma = IR[1].Gamma;
  31399. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31400. case 'CalRGBCS':
  31401. whitePoint = IR[1].WhitePoint;
  31402. blackPoint = IR[1].BlackPoint;
  31403. gamma = IR[1].Gamma;
  31404. var matrix = IR[1].Matrix;
  31405. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31406. case 'PatternCS':
  31407. var basePatternCS = IR[1];
  31408. if (basePatternCS) {
  31409. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31410. }
  31411. return new PatternCS(basePatternCS);
  31412. case 'IndexedCS':
  31413. var baseIndexedCS = IR[1];
  31414. var hiVal = IR[2];
  31415. var lookup = IR[3];
  31416. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31417. case 'AlternateCS':
  31418. var numComps = IR[1];
  31419. var alt = IR[2];
  31420. var tintFnIR = IR[3];
  31421. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31422. PDFFunction.fromIR(tintFnIR));
  31423. case 'LabCS':
  31424. whitePoint = IR[1].WhitePoint;
  31425. blackPoint = IR[1].BlackPoint;
  31426. var range = IR[1].Range;
  31427. return new LabCS(whitePoint, blackPoint, range);
  31428. default:
  31429. error('Unknown name ' + name);
  31430. }
  31431. return null;
  31432. };
  31433. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31434. if (isName(cs)) {
  31435. var colorSpaces = res.get('ColorSpace');
  31436. if (isDict(colorSpaces)) {
  31437. var refcs = colorSpaces.get(cs.name);
  31438. if (refcs) {
  31439. cs = refcs;
  31440. }
  31441. }
  31442. }
  31443. cs = xref.fetchIfRef(cs);
  31444. var mode;
  31445. if (isName(cs)) {
  31446. mode = cs.name;
  31447. this.mode = mode;
  31448. switch (mode) {
  31449. case 'DeviceGray':
  31450. case 'G':
  31451. return 'DeviceGrayCS';
  31452. case 'DeviceRGB':
  31453. case 'RGB':
  31454. return 'DeviceRgbCS';
  31455. case 'DeviceCMYK':
  31456. case 'CMYK':
  31457. return 'DeviceCmykCS';
  31458. case 'Pattern':
  31459. return ['PatternCS', null];
  31460. default:
  31461. error('unrecognized colorspace ' + mode);
  31462. }
  31463. } else if (isArray(cs)) {
  31464. mode = xref.fetchIfRef(cs[0]).name;
  31465. this.mode = mode;
  31466. var numComps, params, alt;
  31467. switch (mode) {
  31468. case 'DeviceGray':
  31469. case 'G':
  31470. return 'DeviceGrayCS';
  31471. case 'DeviceRGB':
  31472. case 'RGB':
  31473. return 'DeviceRgbCS';
  31474. case 'DeviceCMYK':
  31475. case 'CMYK':
  31476. return 'DeviceCmykCS';
  31477. case 'CalGray':
  31478. params = xref.fetchIfRef(cs[1]).getAll();
  31479. return ['CalGrayCS', params];
  31480. case 'CalRGB':
  31481. params = xref.fetchIfRef(cs[1]).getAll();
  31482. return ['CalRGBCS', params];
  31483. case 'ICCBased':
  31484. var stream = xref.fetchIfRef(cs[1]);
  31485. var dict = stream.dict;
  31486. numComps = dict.get('N');
  31487. alt = dict.get('Alternate');
  31488. if (alt) {
  31489. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31490. // Parse the /Alternate CS to ensure that the number of components
  31491. // are correct, and also (indirectly) that it is not a PatternCS.
  31492. var altCS = ColorSpace.fromIR(altIR);
  31493. if (altCS.numComps === numComps) {
  31494. return altIR;
  31495. }
  31496. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31497. }
  31498. if (numComps === 1) {
  31499. return 'DeviceGrayCS';
  31500. } else if (numComps === 3) {
  31501. return 'DeviceRgbCS';
  31502. } else if (numComps === 4) {
  31503. return 'DeviceCmykCS';
  31504. }
  31505. break;
  31506. case 'Pattern':
  31507. var basePatternCS = cs[1] || null;
  31508. if (basePatternCS) {
  31509. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31510. }
  31511. return ['PatternCS', basePatternCS];
  31512. case 'Indexed':
  31513. case 'I':
  31514. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31515. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31516. var lookup = xref.fetchIfRef(cs[3]);
  31517. if (isStream(lookup)) {
  31518. lookup = lookup.getBytes();
  31519. }
  31520. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31521. case 'Separation':
  31522. case 'DeviceN':
  31523. var name = xref.fetchIfRef(cs[1]);
  31524. numComps = 1;
  31525. if (isName(name)) {
  31526. numComps = 1;
  31527. } else if (isArray(name)) {
  31528. numComps = name.length;
  31529. }
  31530. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31531. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31532. return ['AlternateCS', numComps, alt, tintFnIR];
  31533. case 'Lab':
  31534. params = xref.fetchIfRef(cs[1]).getAll();
  31535. return ['LabCS', params];
  31536. default:
  31537. error('unimplemented color space object "' + mode + '"');
  31538. }
  31539. } else {
  31540. error('unrecognized color space object: "' + cs + '"');
  31541. }
  31542. return null;
  31543. };
  31544. /**
  31545. * Checks if a decode map matches the default decode map for a color space.
  31546. * This handles the general decode maps where there are two values per
  31547. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31548. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31549. * slightly different.
  31550. * @param {Array} decode Decode map (usually from an image).
  31551. * @param {Number} n Number of components the color space has.
  31552. */
  31553. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31554. if (!isArray(decode)) {
  31555. return true;
  31556. }
  31557. if (n * 2 !== decode.length) {
  31558. warn('The decode map is not the correct length');
  31559. return true;
  31560. }
  31561. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31562. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31563. return false;
  31564. }
  31565. }
  31566. return true;
  31567. };
  31568. ColorSpace.singletons = {
  31569. get gray() {
  31570. return shadow(this, 'gray', new DeviceGrayCS());
  31571. },
  31572. get rgb() {
  31573. return shadow(this, 'rgb', new DeviceRgbCS());
  31574. },
  31575. get cmyk() {
  31576. return shadow(this, 'cmyk', new DeviceCmykCS());
  31577. }
  31578. };
  31579. return ColorSpace;
  31580. })();
  31581. /**
  31582. * Alternate color space handles both Separation and DeviceN color spaces. A
  31583. * Separation color space is actually just a DeviceN with one color component.
  31584. * Both color spaces use a tinting function to convert colors to a base color
  31585. * space.
  31586. */
  31587. var AlternateCS = (function AlternateCSClosure() {
  31588. function AlternateCS(numComps, base, tintFn) {
  31589. this.name = 'Alternate';
  31590. this.numComps = numComps;
  31591. this.defaultColor = new Float32Array(numComps);
  31592. for (var i = 0; i < numComps; ++i) {
  31593. this.defaultColor[i] = 1;
  31594. }
  31595. this.base = base;
  31596. this.tintFn = tintFn;
  31597. this.tmpBuf = new Float32Array(base.numComps);
  31598. }
  31599. AlternateCS.prototype = {
  31600. getRgb: ColorSpace.prototype.getRgb,
  31601. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31602. dest, destOffset) {
  31603. var tmpBuf = this.tmpBuf;
  31604. this.tintFn(src, srcOffset, tmpBuf, 0);
  31605. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31606. },
  31607. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31608. dest, destOffset, bits,
  31609. alpha01) {
  31610. var tintFn = this.tintFn;
  31611. var base = this.base;
  31612. var scale = 1 / ((1 << bits) - 1);
  31613. var baseNumComps = base.numComps;
  31614. var usesZeroToOneRange = base.usesZeroToOneRange;
  31615. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31616. alpha01 === 0;
  31617. var pos = isPassthrough ? destOffset : 0;
  31618. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31619. var numComps = this.numComps;
  31620. var scaled = new Float32Array(numComps);
  31621. var tinted = new Float32Array(baseNumComps);
  31622. var i, j;
  31623. if (usesZeroToOneRange) {
  31624. for (i = 0; i < count; i++) {
  31625. for (j = 0; j < numComps; j++) {
  31626. scaled[j] = src[srcOffset++] * scale;
  31627. }
  31628. tintFn(scaled, 0, tinted, 0);
  31629. for (j = 0; j < baseNumComps; j++) {
  31630. baseBuf[pos++] = tinted[j] * 255;
  31631. }
  31632. }
  31633. } else {
  31634. for (i = 0; i < count; i++) {
  31635. for (j = 0; j < numComps; j++) {
  31636. scaled[j] = src[srcOffset++] * scale;
  31637. }
  31638. tintFn(scaled, 0, tinted, 0);
  31639. base.getRgbItem(tinted, 0, baseBuf, pos);
  31640. pos += baseNumComps;
  31641. }
  31642. }
  31643. if (!isPassthrough) {
  31644. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31645. }
  31646. },
  31647. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31648. alpha01) {
  31649. return this.base.getOutputLength(inputLength *
  31650. this.base.numComps / this.numComps,
  31651. alpha01);
  31652. },
  31653. isPassthrough: ColorSpace.prototype.isPassthrough,
  31654. fillRgb: ColorSpace.prototype.fillRgb,
  31655. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31656. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31657. },
  31658. usesZeroToOneRange: true
  31659. };
  31660. return AlternateCS;
  31661. })();
  31662. var PatternCS = (function PatternCSClosure() {
  31663. function PatternCS(baseCS) {
  31664. this.name = 'Pattern';
  31665. this.base = baseCS;
  31666. }
  31667. PatternCS.prototype = {};
  31668. return PatternCS;
  31669. })();
  31670. var IndexedCS = (function IndexedCSClosure() {
  31671. function IndexedCS(base, highVal, lookup) {
  31672. this.name = 'Indexed';
  31673. this.numComps = 1;
  31674. this.defaultColor = new Uint8Array([0]);
  31675. this.base = base;
  31676. this.highVal = highVal;
  31677. var baseNumComps = base.numComps;
  31678. var length = baseNumComps * highVal;
  31679. var lookupArray;
  31680. if (isStream(lookup)) {
  31681. lookupArray = new Uint8Array(length);
  31682. var bytes = lookup.getBytes(length);
  31683. lookupArray.set(bytes);
  31684. } else if (isString(lookup)) {
  31685. lookupArray = new Uint8Array(length);
  31686. for (var i = 0; i < length; ++i) {
  31687. lookupArray[i] = lookup.charCodeAt(i);
  31688. }
  31689. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31690. lookupArray = lookup;
  31691. } else {
  31692. error('Unrecognized lookup table: ' + lookup);
  31693. }
  31694. this.lookup = lookupArray;
  31695. }
  31696. IndexedCS.prototype = {
  31697. getRgb: ColorSpace.prototype.getRgb,
  31698. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31699. dest, destOffset) {
  31700. var numComps = this.base.numComps;
  31701. var start = src[srcOffset] * numComps;
  31702. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31703. },
  31704. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31705. dest, destOffset, bits,
  31706. alpha01) {
  31707. var base = this.base;
  31708. var numComps = base.numComps;
  31709. var outputDelta = base.getOutputLength(numComps, alpha01);
  31710. var lookup = this.lookup;
  31711. for (var i = 0; i < count; ++i) {
  31712. var lookupPos = src[srcOffset++] * numComps;
  31713. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31714. destOffset += outputDelta;
  31715. }
  31716. },
  31717. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31718. return this.base.getOutputLength(inputLength * this.base.numComps,
  31719. alpha01);
  31720. },
  31721. isPassthrough: ColorSpace.prototype.isPassthrough,
  31722. fillRgb: ColorSpace.prototype.fillRgb,
  31723. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31724. // indexed color maps shouldn't be changed
  31725. return true;
  31726. },
  31727. usesZeroToOneRange: true
  31728. };
  31729. return IndexedCS;
  31730. })();
  31731. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31732. function DeviceGrayCS() {
  31733. this.name = 'DeviceGray';
  31734. this.numComps = 1;
  31735. this.defaultColor = new Float32Array([0]);
  31736. }
  31737. DeviceGrayCS.prototype = {
  31738. getRgb: ColorSpace.prototype.getRgb,
  31739. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31740. dest, destOffset) {
  31741. var c = (src[srcOffset] * 255) | 0;
  31742. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31743. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31744. },
  31745. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31746. dest, destOffset, bits,
  31747. alpha01) {
  31748. var scale = 255 / ((1 << bits) - 1);
  31749. var j = srcOffset, q = destOffset;
  31750. for (var i = 0; i < count; ++i) {
  31751. var c = (scale * src[j++]) | 0;
  31752. dest[q++] = c;
  31753. dest[q++] = c;
  31754. dest[q++] = c;
  31755. q += alpha01;
  31756. }
  31757. },
  31758. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31759. alpha01) {
  31760. return inputLength * (3 + alpha01);
  31761. },
  31762. isPassthrough: ColorSpace.prototype.isPassthrough,
  31763. fillRgb: ColorSpace.prototype.fillRgb,
  31764. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31765. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31766. },
  31767. usesZeroToOneRange: true
  31768. };
  31769. return DeviceGrayCS;
  31770. })();
  31771. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31772. function DeviceRgbCS() {
  31773. this.name = 'DeviceRGB';
  31774. this.numComps = 3;
  31775. this.defaultColor = new Float32Array([0, 0, 0]);
  31776. }
  31777. DeviceRgbCS.prototype = {
  31778. getRgb: ColorSpace.prototype.getRgb,
  31779. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31780. dest, destOffset) {
  31781. var r = (src[srcOffset] * 255) | 0;
  31782. var g = (src[srcOffset + 1] * 255) | 0;
  31783. var b = (src[srcOffset + 2] * 255) | 0;
  31784. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31785. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31786. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31787. },
  31788. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31789. dest, destOffset, bits,
  31790. alpha01) {
  31791. if (bits === 8 && alpha01 === 0) {
  31792. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31793. return;
  31794. }
  31795. var scale = 255 / ((1 << bits) - 1);
  31796. var j = srcOffset, q = destOffset;
  31797. for (var i = 0; i < count; ++i) {
  31798. dest[q++] = (scale * src[j++]) | 0;
  31799. dest[q++] = (scale * src[j++]) | 0;
  31800. dest[q++] = (scale * src[j++]) | 0;
  31801. q += alpha01;
  31802. }
  31803. },
  31804. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31805. alpha01) {
  31806. return (inputLength * (3 + alpha01) / 3) | 0;
  31807. },
  31808. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31809. return bits === 8;
  31810. },
  31811. fillRgb: ColorSpace.prototype.fillRgb,
  31812. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31813. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31814. },
  31815. usesZeroToOneRange: true
  31816. };
  31817. return DeviceRgbCS;
  31818. })();
  31819. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31820. // The coefficients below was found using numerical analysis: the method of
  31821. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31822. // where color_value is the tabular value from the table of sampled RGB colors
  31823. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31824. // CMYK color conversion using the estimation below:
  31825. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31826. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31827. var c = src[srcOffset + 0] * srcScale;
  31828. var m = src[srcOffset + 1] * srcScale;
  31829. var y = src[srcOffset + 2] * srcScale;
  31830. var k = src[srcOffset + 3] * srcScale;
  31831. var r =
  31832. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31833. 18.82290502165302 * y + 212.25662451639585 * k +
  31834. -285.2331026137004) +
  31835. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31836. -17.873870861415444 * k - 5.497006427196366) +
  31837. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31838. 17.5119270841813) +
  31839. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31840. var g =
  31841. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31842. 6.871425592049007 * y + 31.159100130055922 * k +
  31843. -79.2970844816548) +
  31844. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31845. 131.35250912493976 * k - 190.9453302588951) +
  31846. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31847. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31848. var b =
  31849. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31850. 30.89978309703729 * y - 0.23883238689178934 * k +
  31851. -14.183576799673286) +
  31852. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31853. 50.606957656360734 * k - 112.23884253719248) +
  31854. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31855. -193.58209356861505) +
  31856. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31857. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31858. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31859. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31860. }
  31861. function DeviceCmykCS() {
  31862. this.name = 'DeviceCMYK';
  31863. this.numComps = 4;
  31864. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31865. }
  31866. DeviceCmykCS.prototype = {
  31867. getRgb: ColorSpace.prototype.getRgb,
  31868. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31869. dest, destOffset) {
  31870. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31871. },
  31872. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31873. dest, destOffset, bits,
  31874. alpha01) {
  31875. var scale = 1 / ((1 << bits) - 1);
  31876. for (var i = 0; i < count; i++) {
  31877. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31878. srcOffset += 4;
  31879. destOffset += 3 + alpha01;
  31880. }
  31881. },
  31882. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31883. alpha01) {
  31884. return (inputLength / 4 * (3 + alpha01)) | 0;
  31885. },
  31886. isPassthrough: ColorSpace.prototype.isPassthrough,
  31887. fillRgb: ColorSpace.prototype.fillRgb,
  31888. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31889. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31890. },
  31891. usesZeroToOneRange: true
  31892. };
  31893. return DeviceCmykCS;
  31894. })();
  31895. //
  31896. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31897. //
  31898. var CalGrayCS = (function CalGrayCSClosure() {
  31899. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31900. this.name = 'CalGray';
  31901. this.numComps = 1;
  31902. this.defaultColor = new Float32Array([0]);
  31903. if (!whitePoint) {
  31904. error('WhitePoint missing - required for color space CalGray');
  31905. }
  31906. blackPoint = blackPoint || [0, 0, 0];
  31907. gamma = gamma || 1;
  31908. // Translate arguments to spec variables.
  31909. this.XW = whitePoint[0];
  31910. this.YW = whitePoint[1];
  31911. this.ZW = whitePoint[2];
  31912. this.XB = blackPoint[0];
  31913. this.YB = blackPoint[1];
  31914. this.ZB = blackPoint[2];
  31915. this.G = gamma;
  31916. // Validate variables as per spec.
  31917. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31918. error('Invalid WhitePoint components for ' + this.name +
  31919. ', no fallback available');
  31920. }
  31921. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31922. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31923. this.XB = this.YB = this.ZB = 0;
  31924. }
  31925. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31926. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31927. ', ZB: ' + this.ZB + ', only default values are supported.');
  31928. }
  31929. if (this.G < 1) {
  31930. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31931. ', falling back to default');
  31932. this.G = 1;
  31933. }
  31934. }
  31935. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31936. // A represents a gray component of a calibrated gray space.
  31937. // A <---> AG in the spec
  31938. var A = src[srcOffset] * scale;
  31939. var AG = Math.pow(A, cs.G);
  31940. // Computes L as per spec. ( = cs.YW * AG )
  31941. // Except if other than default BlackPoint values are used.
  31942. var L = cs.YW * AG;
  31943. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31944. // Convert values to rgb range [0, 255].
  31945. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31946. dest[destOffset] = val;
  31947. dest[destOffset + 1] = val;
  31948. dest[destOffset + 2] = val;
  31949. }
  31950. CalGrayCS.prototype = {
  31951. getRgb: ColorSpace.prototype.getRgb,
  31952. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31953. dest, destOffset) {
  31954. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31955. },
  31956. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31957. dest, destOffset, bits,
  31958. alpha01) {
  31959. var scale = 1 / ((1 << bits) - 1);
  31960. for (var i = 0; i < count; ++i) {
  31961. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31962. srcOffset += 1;
  31963. destOffset += 3 + alpha01;
  31964. }
  31965. },
  31966. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31967. return inputLength * (3 + alpha01);
  31968. },
  31969. isPassthrough: ColorSpace.prototype.isPassthrough,
  31970. fillRgb: ColorSpace.prototype.fillRgb,
  31971. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31972. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31973. },
  31974. usesZeroToOneRange: true
  31975. };
  31976. return CalGrayCS;
  31977. })();
  31978. //
  31979. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31980. //
  31981. var CalRGBCS = (function CalRGBCSClosure() {
  31982. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31983. // matrices.
  31984. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31985. 0.8951, 0.2664, -0.1614,
  31986. -0.7502, 1.7135, 0.0367,
  31987. 0.0389, -0.0685, 1.0296]);
  31988. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31989. 0.9869929, -0.1470543, 0.1599627,
  31990. 0.4323053, 0.5183603, 0.0492912,
  31991. -0.0085287, 0.0400428, 0.9684867]);
  31992. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31993. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31994. 3.2404542, -1.5371385, -0.4985314,
  31995. -0.9692660, 1.8760108, 0.0415560,
  31996. 0.0556434, -0.2040259, 1.0572252]);
  31997. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31998. var tempNormalizeMatrix = new Float32Array(3);
  31999. var tempConvertMatrix1 = new Float32Array(3);
  32000. var tempConvertMatrix2 = new Float32Array(3);
  32001. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  32002. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  32003. this.name = 'CalRGB';
  32004. this.numComps = 3;
  32005. this.defaultColor = new Float32Array(3);
  32006. if (!whitePoint) {
  32007. error('WhitePoint missing - required for color space CalRGB');
  32008. }
  32009. blackPoint = blackPoint || new Float32Array(3);
  32010. gamma = gamma || new Float32Array([1, 1, 1]);
  32011. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  32012. // Translate arguments to spec variables.
  32013. var XW = whitePoint[0];
  32014. var YW = whitePoint[1];
  32015. var ZW = whitePoint[2];
  32016. this.whitePoint = whitePoint;
  32017. var XB = blackPoint[0];
  32018. var YB = blackPoint[1];
  32019. var ZB = blackPoint[2];
  32020. this.blackPoint = blackPoint;
  32021. this.GR = gamma[0];
  32022. this.GG = gamma[1];
  32023. this.GB = gamma[2];
  32024. this.MXA = matrix[0];
  32025. this.MYA = matrix[1];
  32026. this.MZA = matrix[2];
  32027. this.MXB = matrix[3];
  32028. this.MYB = matrix[4];
  32029. this.MZB = matrix[5];
  32030. this.MXC = matrix[6];
  32031. this.MYC = matrix[7];
  32032. this.MZC = matrix[8];
  32033. // Validate variables as per spec.
  32034. if (XW < 0 || ZW < 0 || YW !== 1) {
  32035. error('Invalid WhitePoint components for ' + this.name +
  32036. ', no fallback available');
  32037. }
  32038. if (XB < 0 || YB < 0 || ZB < 0) {
  32039. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  32040. ', ' + ZB + '], falling back to default');
  32041. this.blackPoint = new Float32Array(3);
  32042. }
  32043. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  32044. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  32045. '] for ' + this.name + ', falling back to default');
  32046. this.GR = this.GG = this.GB = 1;
  32047. }
  32048. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  32049. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  32050. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  32051. info('Invalid Matrix for ' + this.name + ' [' +
  32052. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  32053. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  32054. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  32055. '], falling back to default');
  32056. this.MXA = this.MYB = this.MZC = 1;
  32057. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  32058. }
  32059. }
  32060. function matrixProduct(a, b, result) {
  32061. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  32062. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  32063. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  32064. }
  32065. function convertToFlat(sourceWhitePoint, LMS, result) {
  32066. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  32067. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  32068. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  32069. }
  32070. function convertToD65(sourceWhitePoint, LMS, result) {
  32071. var D65X = 0.95047;
  32072. var D65Y = 1;
  32073. var D65Z = 1.08883;
  32074. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  32075. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  32076. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  32077. }
  32078. function sRGBTransferFunction(color) {
  32079. // See http://en.wikipedia.org/wiki/SRGB.
  32080. if (color <= 0.0031308){
  32081. return adjustToRange(0, 1, 12.92 * color);
  32082. }
  32083. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  32084. }
  32085. function adjustToRange(min, max, value) {
  32086. return Math.max(min, Math.min(max, value));
  32087. }
  32088. function decodeL(L) {
  32089. if (L < 0) {
  32090. return -decodeL(-L);
  32091. }
  32092. if (L > 8.0) {
  32093. return Math.pow(((L + 16) / 116), 3);
  32094. }
  32095. return L * DECODE_L_CONSTANT;
  32096. }
  32097. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  32098. // In case the blackPoint is already the default blackPoint then there is
  32099. // no need to do compensation.
  32100. if (sourceBlackPoint[0] === 0 &&
  32101. sourceBlackPoint[1] === 0 &&
  32102. sourceBlackPoint[2] === 0) {
  32103. result[0] = XYZ_Flat[0];
  32104. result[1] = XYZ_Flat[1];
  32105. result[2] = XYZ_Flat[2];
  32106. return;
  32107. }
  32108. // For the blackPoint calculation details, please see
  32109. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32110. // AdobeBPC.pdf.
  32111. // The destination blackPoint is the default blackPoint [0, 0, 0].
  32112. var zeroDecodeL = decodeL(0);
  32113. var X_DST = zeroDecodeL;
  32114. var X_SRC = decodeL(sourceBlackPoint[0]);
  32115. var Y_DST = zeroDecodeL;
  32116. var Y_SRC = decodeL(sourceBlackPoint[1]);
  32117. var Z_DST = zeroDecodeL;
  32118. var Z_SRC = decodeL(sourceBlackPoint[2]);
  32119. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  32120. var X_Offset = 1 - X_Scale;
  32121. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  32122. var Y_Offset = 1 - Y_Scale;
  32123. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  32124. var Z_Offset = 1 - Z_Scale;
  32125. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  32126. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  32127. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  32128. }
  32129. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  32130. // In case the whitePoint is already flat then there is no need to do
  32131. // normalization.
  32132. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  32133. result[0] = XYZ_In[0];
  32134. result[1] = XYZ_In[1];
  32135. result[2] = XYZ_In[2];
  32136. return;
  32137. }
  32138. var LMS = result;
  32139. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32140. var LMS_Flat = tempNormalizeMatrix;
  32141. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  32142. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  32143. }
  32144. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  32145. var LMS = result;
  32146. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32147. var LMS_D65 = tempNormalizeMatrix;
  32148. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  32149. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  32150. }
  32151. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32152. // A, B and C represent a red, green and blue components of a calibrated
  32153. // rgb space.
  32154. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  32155. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  32156. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  32157. // A <---> AGR in the spec
  32158. // B <---> BGG in the spec
  32159. // C <---> CGB in the spec
  32160. var AGR = Math.pow(A, cs.GR);
  32161. var BGG = Math.pow(B, cs.GG);
  32162. var CGB = Math.pow(C, cs.GB);
  32163. // Computes intermediate variables L, M, N as per spec.
  32164. // To decode X, Y, Z values map L, M, N directly to them.
  32165. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  32166. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  32167. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  32168. // The following calculations are based on this document:
  32169. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32170. // AdobeBPC.pdf.
  32171. var XYZ = tempConvertMatrix1;
  32172. XYZ[0] = X;
  32173. XYZ[1] = Y;
  32174. XYZ[2] = Z;
  32175. var XYZ_Flat = tempConvertMatrix2;
  32176. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  32177. var XYZ_Black = tempConvertMatrix1;
  32178. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  32179. var XYZ_D65 = tempConvertMatrix2;
  32180. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  32181. var SRGB = tempConvertMatrix1;
  32182. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  32183. var sR = sRGBTransferFunction(SRGB[0]);
  32184. var sG = sRGBTransferFunction(SRGB[1]);
  32185. var sB = sRGBTransferFunction(SRGB[2]);
  32186. // Convert the values to rgb range [0, 255].
  32187. dest[destOffset] = Math.round(sR * 255);
  32188. dest[destOffset + 1] = Math.round(sG * 255);
  32189. dest[destOffset + 2] = Math.round(sB * 255);
  32190. }
  32191. CalRGBCS.prototype = {
  32192. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  32193. var rgb = new Uint8Array(3);
  32194. this.getRgbItem(src, srcOffset, rgb, 0);
  32195. return rgb;
  32196. },
  32197. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  32198. dest, destOffset) {
  32199. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32200. },
  32201. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  32202. dest, destOffset, bits,
  32203. alpha01) {
  32204. var scale = 1 / ((1 << bits) - 1);
  32205. for (var i = 0; i < count; ++i) {
  32206. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32207. srcOffset += 3;
  32208. destOffset += 3 + alpha01;
  32209. }
  32210. },
  32211. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  32212. return (inputLength * (3 + alpha01) / 3) | 0;
  32213. },
  32214. isPassthrough: ColorSpace.prototype.isPassthrough,
  32215. fillRgb: ColorSpace.prototype.fillRgb,
  32216. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  32217. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32218. },
  32219. usesZeroToOneRange: true
  32220. };
  32221. return CalRGBCS;
  32222. })();
  32223. //
  32224. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  32225. //
  32226. var LabCS = (function LabCSClosure() {
  32227. function LabCS(whitePoint, blackPoint, range) {
  32228. this.name = 'Lab';
  32229. this.numComps = 3;
  32230. this.defaultColor = new Float32Array([0, 0, 0]);
  32231. if (!whitePoint) {
  32232. error('WhitePoint missing - required for color space Lab');
  32233. }
  32234. blackPoint = blackPoint || [0, 0, 0];
  32235. range = range || [-100, 100, -100, 100];
  32236. // Translate args to spec variables
  32237. this.XW = whitePoint[0];
  32238. this.YW = whitePoint[1];
  32239. this.ZW = whitePoint[2];
  32240. this.amin = range[0];
  32241. this.amax = range[1];
  32242. this.bmin = range[2];
  32243. this.bmax = range[3];
  32244. // These are here just for completeness - the spec doesn't offer any
  32245. // formulas that use BlackPoint in Lab
  32246. this.XB = blackPoint[0];
  32247. this.YB = blackPoint[1];
  32248. this.ZB = blackPoint[2];
  32249. // Validate vars as per spec
  32250. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32251. error('Invalid WhitePoint components, no fallback available');
  32252. }
  32253. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32254. info('Invalid BlackPoint, falling back to default');
  32255. this.XB = this.YB = this.ZB = 0;
  32256. }
  32257. if (this.amin > this.amax || this.bmin > this.bmax) {
  32258. info('Invalid Range, falling back to defaults');
  32259. this.amin = -100;
  32260. this.amax = 100;
  32261. this.bmin = -100;
  32262. this.bmax = 100;
  32263. }
  32264. }
  32265. // Function g(x) from spec
  32266. function fn_g(x) {
  32267. if (x >= 6 / 29) {
  32268. return x * x * x;
  32269. } else {
  32270. return (108 / 841) * (x - 4 / 29);
  32271. }
  32272. }
  32273. function decode(value, high1, low2, high2) {
  32274. return low2 + (value) * (high2 - low2) / (high1);
  32275. }
  32276. // If decoding is needed maxVal should be 2^bits per component - 1.
  32277. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  32278. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  32279. // not the usual [0, 1]. If a command like setFillColor is used the src
  32280. // values will already be within the correct range. However, if we are
  32281. // converting an image we have to map the values to the correct range given
  32282. // above.
  32283. // Ls,as,bs <---> L*,a*,b* in the spec
  32284. var Ls = src[srcOffset];
  32285. var as = src[srcOffset + 1];
  32286. var bs = src[srcOffset + 2];
  32287. if (maxVal !== false) {
  32288. Ls = decode(Ls, maxVal, 0, 100);
  32289. as = decode(as, maxVal, cs.amin, cs.amax);
  32290. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  32291. }
  32292. // Adjust limits of 'as' and 'bs'
  32293. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  32294. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  32295. // Computes intermediate variables X,Y,Z as per spec
  32296. var M = (Ls + 16) / 116;
  32297. var L = M + (as / 500);
  32298. var N = M - (bs / 200);
  32299. var X = cs.XW * fn_g(L);
  32300. var Y = cs.YW * fn_g(M);
  32301. var Z = cs.ZW * fn_g(N);
  32302. var r, g, b;
  32303. // Using different conversions for D50 and D65 white points,
  32304. // per http://www.color.org/srgb.pdf
  32305. if (cs.ZW < 1) {
  32306. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  32307. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  32308. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  32309. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  32310. } else {
  32311. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  32312. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  32313. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  32314. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  32315. }
  32316. // clamp color values to [0,1] range then convert to [0,255] range.
  32317. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  32318. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  32319. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  32320. }
  32321. LabCS.prototype = {
  32322. getRgb: ColorSpace.prototype.getRgb,
  32323. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  32324. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  32325. },
  32326. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  32327. dest, destOffset, bits,
  32328. alpha01) {
  32329. var maxVal = (1 << bits) - 1;
  32330. for (var i = 0; i < count; i++) {
  32331. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  32332. srcOffset += 3;
  32333. destOffset += 3 + alpha01;
  32334. }
  32335. },
  32336. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  32337. return (inputLength * (3 + alpha01) / 3) | 0;
  32338. },
  32339. isPassthrough: ColorSpace.prototype.isPassthrough,
  32340. fillRgb: ColorSpace.prototype.fillRgb,
  32341. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  32342. // XXX: Decoding is handled with the lab conversion because of the strange
  32343. // ranges that are used.
  32344. return true;
  32345. },
  32346. usesZeroToOneRange: false
  32347. };
  32348. return LabCS;
  32349. })();
  32350. // TODO refactor to remove dependency on image.js
  32351. function _setCoreImage(coreImage_) {
  32352. coreImage = coreImage_;
  32353. PDFImage = coreImage_.PDFImage;
  32354. }
  32355. exports._setCoreImage = _setCoreImage;
  32356. exports.ColorSpace = ColorSpace;
  32357. // TODO refactor to remove dependency on colorspace.js
  32358. coreStream._setCoreColorSpace(exports);
  32359. }));
  32360. (function (root, factory) {
  32361. {
  32362. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  32363. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  32364. root.pdfjsCoreJpx);
  32365. }
  32366. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  32367. coreStream, coreJpx) {
  32368. var ImageKind = sharedUtil.ImageKind;
  32369. var assert = sharedUtil.assert;
  32370. var error = sharedUtil.error;
  32371. var info = sharedUtil.info;
  32372. var isArray = sharedUtil.isArray;
  32373. var warn = sharedUtil.warn;
  32374. var Name = corePrimitives.Name;
  32375. var isStream = corePrimitives.isStream;
  32376. var ColorSpace = coreColorSpace.ColorSpace;
  32377. var DecodeStream = coreStream.DecodeStream;
  32378. var Stream = coreStream.Stream;
  32379. var JpegStream = coreStream.JpegStream;
  32380. var JpxImage = coreJpx.JpxImage;
  32381. var PDFImage = (function PDFImageClosure() {
  32382. /**
  32383. * Decode the image in the main thread if it supported. Resovles the promise
  32384. * when the image data is ready.
  32385. */
  32386. function handleImageData(handler, xref, res, image) {
  32387. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  32388. // For natively supported jpegs send them to the main thread for decoding.
  32389. var dict = image.dict;
  32390. var colorSpace = dict.get('ColorSpace', 'CS');
  32391. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32392. var numComps = colorSpace.numComps;
  32393. var decodePromise = handler.sendWithPromise('JpegDecode',
  32394. [image.getIR(), numComps]);
  32395. return decodePromise.then(function (message) {
  32396. var data = message.data;
  32397. return new Stream(data, 0, data.length, image.dict);
  32398. });
  32399. } else {
  32400. return Promise.resolve(image);
  32401. }
  32402. }
  32403. /**
  32404. * Decode and clamp a value. The formula is different from the spec because we
  32405. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32406. */
  32407. function decodeAndClamp(value, addend, coefficient, max) {
  32408. value = addend + value * coefficient;
  32409. // Clamp the value to the range
  32410. return (value < 0 ? 0 : (value > max ? max : value));
  32411. }
  32412. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32413. this.image = image;
  32414. var dict = image.dict;
  32415. if (dict.has('Filter')) {
  32416. var filter = dict.get('Filter').name;
  32417. if (filter === 'JPXDecode') {
  32418. var jpxImage = new JpxImage();
  32419. jpxImage.parseImageProperties(image.stream);
  32420. image.stream.reset();
  32421. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32422. image.numComps = jpxImage.componentsCount;
  32423. } else if (filter === 'JBIG2Decode') {
  32424. image.bitsPerComponent = 1;
  32425. image.numComps = 1;
  32426. }
  32427. }
  32428. // TODO cache rendered images?
  32429. this.width = dict.get('Width', 'W');
  32430. this.height = dict.get('Height', 'H');
  32431. if (this.width < 1 || this.height < 1) {
  32432. error('Invalid image width: ' + this.width + ' or height: ' +
  32433. this.height);
  32434. }
  32435. this.interpolate = dict.get('Interpolate', 'I') || false;
  32436. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32437. this.matte = dict.get('Matte') || false;
  32438. var bitsPerComponent = image.bitsPerComponent;
  32439. if (!bitsPerComponent) {
  32440. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32441. if (!bitsPerComponent) {
  32442. if (this.imageMask) {
  32443. bitsPerComponent = 1;
  32444. } else {
  32445. error('Bits per component missing in image: ' + this.imageMask);
  32446. }
  32447. }
  32448. }
  32449. this.bpc = bitsPerComponent;
  32450. if (!this.imageMask) {
  32451. var colorSpace = dict.get('ColorSpace', 'CS');
  32452. if (!colorSpace) {
  32453. info('JPX images (which do not require color spaces)');
  32454. switch (image.numComps) {
  32455. case 1:
  32456. colorSpace = Name.get('DeviceGray');
  32457. break;
  32458. case 3:
  32459. colorSpace = Name.get('DeviceRGB');
  32460. break;
  32461. case 4:
  32462. colorSpace = Name.get('DeviceCMYK');
  32463. break;
  32464. default:
  32465. error('JPX images with ' + this.numComps +
  32466. ' color components not supported.');
  32467. }
  32468. }
  32469. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32470. this.numComps = this.colorSpace.numComps;
  32471. }
  32472. this.decode = dict.get('Decode', 'D');
  32473. this.needsDecode = false;
  32474. if (this.decode &&
  32475. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32476. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32477. this.needsDecode = true;
  32478. // Do some preprocessing to avoid more math.
  32479. var max = (1 << bitsPerComponent) - 1;
  32480. this.decodeCoefficients = [];
  32481. this.decodeAddends = [];
  32482. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32483. var dmin = this.decode[i];
  32484. var dmax = this.decode[i + 1];
  32485. this.decodeCoefficients[j] = dmax - dmin;
  32486. this.decodeAddends[j] = max * dmin;
  32487. }
  32488. }
  32489. if (smask) {
  32490. this.smask = new PDFImage(xref, res, smask, false);
  32491. } else if (mask) {
  32492. if (isStream(mask)) {
  32493. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32494. if (!imageMask) {
  32495. warn('Ignoring /Mask in image without /ImageMask.');
  32496. } else {
  32497. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32498. }
  32499. } else {
  32500. // Color key mask (just an array).
  32501. this.mask = mask;
  32502. }
  32503. }
  32504. }
  32505. /**
  32506. * Handles processing of image data and returns the Promise that is resolved
  32507. * with a PDFImage when the image is ready to be used.
  32508. */
  32509. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32510. res, image, inline) {
  32511. var imagePromise = handleImageData(handler, xref, res, image);
  32512. var smaskPromise;
  32513. var maskPromise;
  32514. var smask = image.dict.get('SMask');
  32515. var mask = image.dict.get('Mask');
  32516. if (smask) {
  32517. smaskPromise = handleImageData(handler, xref, res, smask);
  32518. maskPromise = Promise.resolve(null);
  32519. } else {
  32520. smaskPromise = Promise.resolve(null);
  32521. if (mask) {
  32522. if (isStream(mask)) {
  32523. maskPromise = handleImageData(handler, xref, res, mask);
  32524. } else if (isArray(mask)) {
  32525. maskPromise = Promise.resolve(mask);
  32526. } else {
  32527. warn('Unsupported mask format.');
  32528. maskPromise = Promise.resolve(null);
  32529. }
  32530. } else {
  32531. maskPromise = Promise.resolve(null);
  32532. }
  32533. }
  32534. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32535. function(results) {
  32536. var imageData = results[0];
  32537. var smaskData = results[1];
  32538. var maskData = results[2];
  32539. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32540. });
  32541. };
  32542. /**
  32543. * Resize an image using the nearest neighbor algorithm. Currently only
  32544. * supports one and three component images.
  32545. * @param {TypedArray} pixels The original image with one component.
  32546. * @param {Number} bpc Number of bits per component.
  32547. * @param {Number} components Number of color components, 1 or 3 is supported.
  32548. * @param {Number} w1 Original width.
  32549. * @param {Number} h1 Original height.
  32550. * @param {Number} w2 New width.
  32551. * @param {Number} h2 New height.
  32552. * @param {TypedArray} dest (Optional) The destination buffer.
  32553. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32554. * @return {TypedArray} Resized image data.
  32555. */
  32556. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32557. w1, h1, w2, h2, dest, alpha01) {
  32558. if (components !== 1 && components !== 3) {
  32559. error('Unsupported component count for resizing.');
  32560. }
  32561. var length = w2 * h2 * components;
  32562. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32563. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32564. var xRatio = w1 / w2;
  32565. var yRatio = h1 / h2;
  32566. var i, j, py, newIndex = 0, oldIndex;
  32567. var xScaled = new Uint16Array(w2);
  32568. var w1Scanline = w1 * components;
  32569. if (alpha01 !== 1) {
  32570. alpha01 = 0;
  32571. }
  32572. for (j = 0; j < w2; j++) {
  32573. xScaled[j] = Math.floor(j * xRatio) * components;
  32574. }
  32575. if (components === 1) {
  32576. for (i = 0; i < h2; i++) {
  32577. py = Math.floor(i * yRatio) * w1Scanline;
  32578. for (j = 0; j < w2; j++) {
  32579. oldIndex = py + xScaled[j];
  32580. temp[newIndex++] = pixels[oldIndex];
  32581. }
  32582. }
  32583. } else if (components === 3) {
  32584. for (i = 0; i < h2; i++) {
  32585. py = Math.floor(i * yRatio) * w1Scanline;
  32586. for (j = 0; j < w2; j++) {
  32587. oldIndex = py + xScaled[j];
  32588. temp[newIndex++] = pixels[oldIndex++];
  32589. temp[newIndex++] = pixels[oldIndex++];
  32590. temp[newIndex++] = pixels[oldIndex++];
  32591. newIndex += alpha01;
  32592. }
  32593. }
  32594. }
  32595. return temp;
  32596. };
  32597. PDFImage.createMask =
  32598. function PDFImage_createMask(imgArray, width, height,
  32599. imageIsFromDecodeStream, inverseDecode) {
  32600. // |imgArray| might not contain full data for every pixel of the mask, so
  32601. // we need to distinguish between |computedLength| and |actualLength|.
  32602. // In particular, if inverseDecode is true, then the array we return must
  32603. // have a length of |computedLength|.
  32604. var computedLength = ((width + 7) >> 3) * height;
  32605. var actualLength = imgArray.byteLength;
  32606. var haveFullData = computedLength === actualLength;
  32607. var data, i;
  32608. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32609. // imgArray came from a DecodeStream and its data is in an appropriate
  32610. // form, so we can just transfer it.
  32611. data = imgArray;
  32612. } else if (!inverseDecode) {
  32613. data = new Uint8Array(actualLength);
  32614. data.set(imgArray);
  32615. } else {
  32616. data = new Uint8Array(computedLength);
  32617. data.set(imgArray);
  32618. for (i = actualLength; i < computedLength; i++) {
  32619. data[i] = 0xff;
  32620. }
  32621. }
  32622. // If necessary, invert the original mask data (but not any extra we might
  32623. // have added above). It's safe to modify the array -- whether it's the
  32624. // original or a copy, we're about to transfer it anyway, so nothing else
  32625. // in this thread can be relying on its contents.
  32626. if (inverseDecode) {
  32627. for (i = 0; i < actualLength; i++) {
  32628. data[i] = ~data[i];
  32629. }
  32630. }
  32631. return {data: data, width: width, height: height};
  32632. };
  32633. PDFImage.prototype = {
  32634. get drawWidth() {
  32635. return Math.max(this.width,
  32636. this.smask && this.smask.width || 0,
  32637. this.mask && this.mask.width || 0);
  32638. },
  32639. get drawHeight() {
  32640. return Math.max(this.height,
  32641. this.smask && this.smask.height || 0,
  32642. this.mask && this.mask.height || 0);
  32643. },
  32644. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32645. var bpc = this.bpc;
  32646. var numComps = this.numComps;
  32647. var decodeAddends = this.decodeAddends;
  32648. var decodeCoefficients = this.decodeCoefficients;
  32649. var max = (1 << bpc) - 1;
  32650. var i, ii;
  32651. if (bpc === 1) {
  32652. // If the buffer needed decode that means it just needs to be inverted.
  32653. for (i = 0, ii = buffer.length; i < ii; i++) {
  32654. buffer[i] = +!(buffer[i]);
  32655. }
  32656. return;
  32657. }
  32658. var index = 0;
  32659. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32660. for (var j = 0; j < numComps; j++) {
  32661. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32662. decodeCoefficients[j], max);
  32663. index++;
  32664. }
  32665. }
  32666. },
  32667. getComponents: function PDFImage_getComponents(buffer) {
  32668. var bpc = this.bpc;
  32669. // This image doesn't require any extra work.
  32670. if (bpc === 8) {
  32671. return buffer;
  32672. }
  32673. var width = this.width;
  32674. var height = this.height;
  32675. var numComps = this.numComps;
  32676. var length = width * height * numComps;
  32677. var bufferPos = 0;
  32678. var output = (bpc <= 8 ? new Uint8Array(length) :
  32679. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32680. var rowComps = width * numComps;
  32681. var max = (1 << bpc) - 1;
  32682. var i = 0, ii, buf;
  32683. if (bpc === 1) {
  32684. // Optimization for reading 1 bpc images.
  32685. var mask, loop1End, loop2End;
  32686. for (var j = 0; j < height; j++) {
  32687. loop1End = i + (rowComps & ~7);
  32688. loop2End = i + rowComps;
  32689. // unroll loop for all full bytes
  32690. while (i < loop1End) {
  32691. buf = buffer[bufferPos++];
  32692. output[i] = (buf >> 7) & 1;
  32693. output[i + 1] = (buf >> 6) & 1;
  32694. output[i + 2] = (buf >> 5) & 1;
  32695. output[i + 3] = (buf >> 4) & 1;
  32696. output[i + 4] = (buf >> 3) & 1;
  32697. output[i + 5] = (buf >> 2) & 1;
  32698. output[i + 6] = (buf >> 1) & 1;
  32699. output[i + 7] = buf & 1;
  32700. i += 8;
  32701. }
  32702. // handle remaing bits
  32703. if (i < loop2End) {
  32704. buf = buffer[bufferPos++];
  32705. mask = 128;
  32706. while (i < loop2End) {
  32707. output[i++] = +!!(buf & mask);
  32708. mask >>= 1;
  32709. }
  32710. }
  32711. }
  32712. } else {
  32713. // The general case that handles all other bpc values.
  32714. var bits = 0;
  32715. buf = 0;
  32716. for (i = 0, ii = length; i < ii; ++i) {
  32717. if (i % rowComps === 0) {
  32718. buf = 0;
  32719. bits = 0;
  32720. }
  32721. while (bits < bpc) {
  32722. buf = (buf << 8) | buffer[bufferPos++];
  32723. bits += 8;
  32724. }
  32725. var remainingBits = bits - bpc;
  32726. var value = buf >> remainingBits;
  32727. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32728. buf = buf & ((1 << remainingBits) - 1);
  32729. bits = remainingBits;
  32730. }
  32731. }
  32732. return output;
  32733. },
  32734. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32735. actualHeight, image) {
  32736. var smask = this.smask;
  32737. var mask = this.mask;
  32738. var alphaBuf, sw, sh, i, ii, j;
  32739. if (smask) {
  32740. sw = smask.width;
  32741. sh = smask.height;
  32742. alphaBuf = new Uint8Array(sw * sh);
  32743. smask.fillGrayBuffer(alphaBuf);
  32744. if (sw !== width || sh !== height) {
  32745. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32746. height);
  32747. }
  32748. } else if (mask) {
  32749. if (mask instanceof PDFImage) {
  32750. sw = mask.width;
  32751. sh = mask.height;
  32752. alphaBuf = new Uint8Array(sw * sh);
  32753. mask.numComps = 1;
  32754. mask.fillGrayBuffer(alphaBuf);
  32755. // Need to invert values in rgbaBuf
  32756. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32757. alphaBuf[i] = 255 - alphaBuf[i];
  32758. }
  32759. if (sw !== width || sh !== height) {
  32760. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32761. height);
  32762. }
  32763. } else if (isArray(mask)) {
  32764. // Color key mask: if any of the compontents are outside the range
  32765. // then they should be painted.
  32766. alphaBuf = new Uint8Array(width * height);
  32767. var numComps = this.numComps;
  32768. for (i = 0, ii = width * height; i < ii; ++i) {
  32769. var opacity = 0;
  32770. var imageOffset = i * numComps;
  32771. for (j = 0; j < numComps; ++j) {
  32772. var color = image[imageOffset + j];
  32773. var maskOffset = j * 2;
  32774. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32775. opacity = 255;
  32776. break;
  32777. }
  32778. }
  32779. alphaBuf[i] = opacity;
  32780. }
  32781. } else {
  32782. error('Unknown mask format.');
  32783. }
  32784. }
  32785. if (alphaBuf) {
  32786. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32787. rgbaBuf[j] = alphaBuf[i];
  32788. }
  32789. } else {
  32790. // No mask.
  32791. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32792. rgbaBuf[j] = 255;
  32793. }
  32794. }
  32795. },
  32796. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32797. var matte = this.smask && this.smask.matte;
  32798. if (!matte) {
  32799. return;
  32800. }
  32801. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32802. var matteR = matteRgb[0];
  32803. var matteG = matteRgb[1];
  32804. var matteB = matteRgb[2];
  32805. var length = width * height * 4;
  32806. var r, g, b;
  32807. for (var i = 0; i < length; i += 4) {
  32808. var alpha = buffer[i + 3];
  32809. if (alpha === 0) {
  32810. // according formula we have to get Infinity in all components
  32811. // making it white (typical paper color) should be okay
  32812. buffer[i] = 255;
  32813. buffer[i + 1] = 255;
  32814. buffer[i + 2] = 255;
  32815. continue;
  32816. }
  32817. var k = 255 / alpha;
  32818. r = (buffer[i] - matteR) * k + matteR;
  32819. g = (buffer[i + 1] - matteG) * k + matteG;
  32820. b = (buffer[i + 2] - matteB) * k + matteB;
  32821. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32822. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32823. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32824. }
  32825. },
  32826. createImageData: function PDFImage_createImageData(forceRGBA) {
  32827. var drawWidth = this.drawWidth;
  32828. var drawHeight = this.drawHeight;
  32829. var imgData = { // other fields are filled in below
  32830. width: drawWidth,
  32831. height: drawHeight
  32832. };
  32833. var numComps = this.numComps;
  32834. var originalWidth = this.width;
  32835. var originalHeight = this.height;
  32836. var bpc = this.bpc;
  32837. // Rows start at byte boundary.
  32838. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32839. var imgArray;
  32840. if (!forceRGBA) {
  32841. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32842. // without any complications, we pass a same-sized copy to the main
  32843. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32844. // of memory for many scanned documents. It's also much faster.
  32845. //
  32846. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32847. // complications, we avoid expanding by 1.333x to RGBA form.
  32848. var kind;
  32849. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32850. kind = ImageKind.GRAYSCALE_1BPP;
  32851. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32852. !this.needsDecode) {
  32853. kind = ImageKind.RGB_24BPP;
  32854. }
  32855. if (kind && !this.smask && !this.mask &&
  32856. drawWidth === originalWidth && drawHeight === originalHeight) {
  32857. imgData.kind = kind;
  32858. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32859. // If imgArray came from a DecodeStream, we're safe to transfer it
  32860. // (and thus neuter it) because it will constitute the entire
  32861. // DecodeStream's data. But if it came from a Stream, we need to
  32862. // copy it because it'll only be a portion of the Stream's data, and
  32863. // the rest will be read later on.
  32864. if (this.image instanceof DecodeStream) {
  32865. imgData.data = imgArray;
  32866. } else {
  32867. var newArray = new Uint8Array(imgArray.length);
  32868. newArray.set(imgArray);
  32869. imgData.data = newArray;
  32870. }
  32871. if (this.needsDecode) {
  32872. // Invert the buffer (which must be grayscale if we reached here).
  32873. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32874. var buffer = imgData.data;
  32875. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32876. buffer[i] ^= 0xff;
  32877. }
  32878. }
  32879. return imgData;
  32880. }
  32881. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32882. (this.colorSpace.name === 'DeviceGray' ||
  32883. this.colorSpace.name === 'DeviceRGB' ||
  32884. this.colorSpace.name === 'DeviceCMYK')) {
  32885. imgData.kind = ImageKind.RGB_24BPP;
  32886. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32887. drawWidth, drawHeight, true);
  32888. return imgData;
  32889. }
  32890. }
  32891. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32892. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32893. var actualHeight = 0 | (imgArray.length / rowBytes *
  32894. drawHeight / originalHeight);
  32895. var comps = this.getComponents(imgArray);
  32896. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32897. // more compact RGB_24BPP form if allowable.
  32898. var alpha01, maybeUndoPreblend;
  32899. if (!forceRGBA && !this.smask && !this.mask) {
  32900. imgData.kind = ImageKind.RGB_24BPP;
  32901. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32902. alpha01 = 0;
  32903. maybeUndoPreblend = false;
  32904. } else {
  32905. imgData.kind = ImageKind.RGBA_32BPP;
  32906. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32907. alpha01 = 1;
  32908. maybeUndoPreblend = true;
  32909. // Color key masking (opacity) must be performed before decoding.
  32910. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32911. comps);
  32912. }
  32913. if (this.needsDecode) {
  32914. this.decodeBuffer(comps);
  32915. }
  32916. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32917. drawWidth, drawHeight, actualHeight, bpc, comps,
  32918. alpha01);
  32919. if (maybeUndoPreblend) {
  32920. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32921. }
  32922. return imgData;
  32923. },
  32924. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32925. var numComps = this.numComps;
  32926. if (numComps !== 1) {
  32927. error('Reading gray scale from a color image: ' + numComps);
  32928. }
  32929. var width = this.width;
  32930. var height = this.height;
  32931. var bpc = this.bpc;
  32932. // rows start at byte boundary
  32933. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32934. var imgArray = this.getImageBytes(height * rowBytes);
  32935. var comps = this.getComponents(imgArray);
  32936. var i, length;
  32937. if (bpc === 1) {
  32938. // inline decoding (= inversion) for 1 bpc images
  32939. length = width * height;
  32940. if (this.needsDecode) {
  32941. // invert and scale to {0, 255}
  32942. for (i = 0; i < length; ++i) {
  32943. buffer[i] = (comps[i] - 1) & 255;
  32944. }
  32945. } else {
  32946. // scale to {0, 255}
  32947. for (i = 0; i < length; ++i) {
  32948. buffer[i] = (-comps[i]) & 255;
  32949. }
  32950. }
  32951. return;
  32952. }
  32953. if (this.needsDecode) {
  32954. this.decodeBuffer(comps);
  32955. }
  32956. length = width * height;
  32957. // we aren't using a colorspace so we need to scale the value
  32958. var scale = 255 / ((1 << bpc) - 1);
  32959. for (i = 0; i < length; ++i) {
  32960. buffer[i] = (scale * comps[i]) | 0;
  32961. }
  32962. },
  32963. getImageBytes: function PDFImage_getImageBytes(length,
  32964. drawWidth, drawHeight,
  32965. forceRGB) {
  32966. this.image.reset();
  32967. this.image.drawWidth = drawWidth || this.width;
  32968. this.image.drawHeight = drawHeight || this.height;
  32969. this.image.forceRGB = !!forceRGB;
  32970. return this.image.getBytes(length);
  32971. }
  32972. };
  32973. return PDFImage;
  32974. })();
  32975. exports.PDFImage = PDFImage;
  32976. // TODO refactor to remove dependency on colorspace.js
  32977. coreColorSpace._setCoreImage(exports);
  32978. }));
  32979. (function (root, factory) {
  32980. {
  32981. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  32982. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  32983. root.pdfjsCoreColorSpace);
  32984. }
  32985. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  32986. coreColorSpace) {
  32987. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  32988. var MissingDataException = sharedUtil.MissingDataException;
  32989. var Util = sharedUtil.Util;
  32990. var assert = sharedUtil.assert;
  32991. var error = sharedUtil.error;
  32992. var info = sharedUtil.info;
  32993. var warn = sharedUtil.warn;
  32994. var isStream = corePrimitives.isStream;
  32995. var PDFFunction = coreFunction.PDFFunction;
  32996. var ColorSpace = coreColorSpace.ColorSpace;
  32997. var ShadingType = {
  32998. FUNCTION_BASED: 1,
  32999. AXIAL: 2,
  33000. RADIAL: 3,
  33001. FREE_FORM_MESH: 4,
  33002. LATTICE_FORM_MESH: 5,
  33003. COONS_PATCH_MESH: 6,
  33004. TENSOR_PATCH_MESH: 7
  33005. };
  33006. var Pattern = (function PatternClosure() {
  33007. // Constructor should define this.getPattern
  33008. function Pattern() {
  33009. error('should not call Pattern constructor');
  33010. }
  33011. Pattern.prototype = {
  33012. // Input: current Canvas context
  33013. // Output: the appropriate fillStyle or strokeStyle
  33014. getPattern: function Pattern_getPattern(ctx) {
  33015. error('Should not call Pattern.getStyle: ' + ctx);
  33016. }
  33017. };
  33018. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33019. res, handler) {
  33020. var dict = isStream(shading) ? shading.dict : shading;
  33021. var type = dict.get('ShadingType');
  33022. try {
  33023. switch (type) {
  33024. case ShadingType.AXIAL:
  33025. case ShadingType.RADIAL:
  33026. // Both radial and axial shadings are handled by RadialAxial shading.
  33027. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33028. case ShadingType.FREE_FORM_MESH:
  33029. case ShadingType.LATTICE_FORM_MESH:
  33030. case ShadingType.COONS_PATCH_MESH:
  33031. case ShadingType.TENSOR_PATCH_MESH:
  33032. return new Shadings.Mesh(shading, matrix, xref, res);
  33033. default:
  33034. throw new Error('Unsupported ShadingType: ' + type);
  33035. }
  33036. } catch (ex) {
  33037. if (ex instanceof MissingDataException) {
  33038. throw ex;
  33039. }
  33040. handler.send('UnsupportedFeature',
  33041. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33042. warn(ex);
  33043. return new Shadings.Dummy();
  33044. }
  33045. };
  33046. return Pattern;
  33047. })();
  33048. var Shadings = {};
  33049. // A small number to offset the first/last color stops so we can insert ones to
  33050. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  33051. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  33052. // internally so we have to go bigger.
  33053. Shadings.SMALL_NUMBER = 1e-2;
  33054. // Radial and axial shading have very similar implementations
  33055. // If needed, the implementations can be broken into two classes
  33056. Shadings.RadialAxial = (function RadialAxialClosure() {
  33057. function RadialAxial(dict, matrix, xref, res) {
  33058. this.matrix = matrix;
  33059. this.coordsArr = dict.get('Coords');
  33060. this.shadingType = dict.get('ShadingType');
  33061. this.type = 'Pattern';
  33062. var cs = dict.get('ColorSpace', 'CS');
  33063. cs = ColorSpace.parse(cs, xref, res);
  33064. this.cs = cs;
  33065. var t0 = 0.0, t1 = 1.0;
  33066. if (dict.has('Domain')) {
  33067. var domainArr = dict.get('Domain');
  33068. t0 = domainArr[0];
  33069. t1 = domainArr[1];
  33070. }
  33071. var extendStart = false, extendEnd = false;
  33072. if (dict.has('Extend')) {
  33073. var extendArr = dict.get('Extend');
  33074. extendStart = extendArr[0];
  33075. extendEnd = extendArr[1];
  33076. }
  33077. if (this.shadingType === ShadingType.RADIAL &&
  33078. (!extendStart || !extendEnd)) {
  33079. // Radial gradient only currently works if either circle is fully within
  33080. // the other circle.
  33081. var x1 = this.coordsArr[0];
  33082. var y1 = this.coordsArr[1];
  33083. var r1 = this.coordsArr[2];
  33084. var x2 = this.coordsArr[3];
  33085. var y2 = this.coordsArr[4];
  33086. var r2 = this.coordsArr[5];
  33087. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  33088. if (r1 <= r2 + distance &&
  33089. r2 <= r1 + distance) {
  33090. warn('Unsupported radial gradient.');
  33091. }
  33092. }
  33093. this.extendStart = extendStart;
  33094. this.extendEnd = extendEnd;
  33095. var fnObj = dict.get('Function');
  33096. var fn = PDFFunction.parseArray(xref, fnObj);
  33097. // 10 samples seems good enough for now, but probably won't work
  33098. // if there are sharp color changes. Ideally, we would implement
  33099. // the spec faithfully and add lossless optimizations.
  33100. var diff = t1 - t0;
  33101. var step = diff / 10;
  33102. var colorStops = this.colorStops = [];
  33103. // Protect against bad domains so we don't end up in an infinte loop below.
  33104. if (t0 >= t1 || step <= 0) {
  33105. // Acrobat doesn't seem to handle these cases so we'll ignore for
  33106. // now.
  33107. info('Bad shading domain.');
  33108. return;
  33109. }
  33110. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  33111. var rgbColor;
  33112. for (var i = t0; i <= t1; i += step) {
  33113. ratio[0] = i;
  33114. fn(ratio, 0, color, 0);
  33115. rgbColor = cs.getRgb(color, 0);
  33116. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33117. colorStops.push([(i - t0) / diff, cssColor]);
  33118. }
  33119. var background = 'transparent';
  33120. if (dict.has('Background')) {
  33121. rgbColor = cs.getRgb(dict.get('Background'), 0);
  33122. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33123. }
  33124. if (!extendStart) {
  33125. // Insert a color stop at the front and offset the first real color stop
  33126. // so it doesn't conflict with the one we insert.
  33127. colorStops.unshift([0, background]);
  33128. colorStops[1][0] += Shadings.SMALL_NUMBER;
  33129. }
  33130. if (!extendEnd) {
  33131. // Same idea as above in extendStart but for the end.
  33132. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  33133. colorStops.push([1, background]);
  33134. }
  33135. this.colorStops = colorStops;
  33136. }
  33137. RadialAxial.prototype = {
  33138. getIR: function RadialAxial_getIR() {
  33139. var coordsArr = this.coordsArr;
  33140. var shadingType = this.shadingType;
  33141. var type, p0, p1, r0, r1;
  33142. if (shadingType === ShadingType.AXIAL) {
  33143. p0 = [coordsArr[0], coordsArr[1]];
  33144. p1 = [coordsArr[2], coordsArr[3]];
  33145. r0 = null;
  33146. r1 = null;
  33147. type = 'axial';
  33148. } else if (shadingType === ShadingType.RADIAL) {
  33149. p0 = [coordsArr[0], coordsArr[1]];
  33150. p1 = [coordsArr[3], coordsArr[4]];
  33151. r0 = coordsArr[2];
  33152. r1 = coordsArr[5];
  33153. type = 'radial';
  33154. } else {
  33155. error('getPattern type unknown: ' + shadingType);
  33156. }
  33157. var matrix = this.matrix;
  33158. if (matrix) {
  33159. p0 = Util.applyTransform(p0, matrix);
  33160. p1 = Util.applyTransform(p1, matrix);
  33161. if (shadingType === ShadingType.RADIAL) {
  33162. var scale = Util.singularValueDecompose2dScale(matrix);
  33163. r0 *= scale[0];
  33164. r1 *= scale[1];
  33165. }
  33166. }
  33167. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  33168. }
  33169. };
  33170. return RadialAxial;
  33171. })();
  33172. // All mesh shading. For now, they will be presented as set of the triangles
  33173. // to be drawn on the canvas and rgb color for each vertex.
  33174. Shadings.Mesh = (function MeshClosure() {
  33175. function MeshStreamReader(stream, context) {
  33176. this.stream = stream;
  33177. this.context = context;
  33178. this.buffer = 0;
  33179. this.bufferLength = 0;
  33180. var numComps = context.numComps;
  33181. this.tmpCompsBuf = new Float32Array(numComps);
  33182. var csNumComps = context.colorSpace.numComps;
  33183. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  33184. this.tmpCompsBuf;
  33185. }
  33186. MeshStreamReader.prototype = {
  33187. get hasData() {
  33188. if (this.stream.end) {
  33189. return this.stream.pos < this.stream.end;
  33190. }
  33191. if (this.bufferLength > 0) {
  33192. return true;
  33193. }
  33194. var nextByte = this.stream.getByte();
  33195. if (nextByte < 0) {
  33196. return false;
  33197. }
  33198. this.buffer = nextByte;
  33199. this.bufferLength = 8;
  33200. return true;
  33201. },
  33202. readBits: function MeshStreamReader_readBits(n) {
  33203. var buffer = this.buffer;
  33204. var bufferLength = this.bufferLength;
  33205. if (n === 32) {
  33206. if (bufferLength === 0) {
  33207. return ((this.stream.getByte() << 24) |
  33208. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  33209. this.stream.getByte()) >>> 0;
  33210. }
  33211. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  33212. (this.stream.getByte() << 8) | this.stream.getByte();
  33213. var nextByte = this.stream.getByte();
  33214. this.buffer = nextByte & ((1 << bufferLength) - 1);
  33215. return ((buffer << (8 - bufferLength)) |
  33216. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  33217. }
  33218. if (n === 8 && bufferLength === 0) {
  33219. return this.stream.getByte();
  33220. }
  33221. while (bufferLength < n) {
  33222. buffer = (buffer << 8) | this.stream.getByte();
  33223. bufferLength += 8;
  33224. }
  33225. bufferLength -= n;
  33226. this.bufferLength = bufferLength;
  33227. this.buffer = buffer & ((1 << bufferLength) - 1);
  33228. return buffer >> bufferLength;
  33229. },
  33230. align: function MeshStreamReader_align() {
  33231. this.buffer = 0;
  33232. this.bufferLength = 0;
  33233. },
  33234. readFlag: function MeshStreamReader_readFlag() {
  33235. return this.readBits(this.context.bitsPerFlag);
  33236. },
  33237. readCoordinate: function MeshStreamReader_readCoordinate() {
  33238. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  33239. var xi = this.readBits(bitsPerCoordinate);
  33240. var yi = this.readBits(bitsPerCoordinate);
  33241. var decode = this.context.decode;
  33242. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  33243. 2.3283064365386963e-10; // 2 ^ -32
  33244. return [
  33245. xi * scale * (decode[1] - decode[0]) + decode[0],
  33246. yi * scale * (decode[3] - decode[2]) + decode[2]
  33247. ];
  33248. },
  33249. readComponents: function MeshStreamReader_readComponents() {
  33250. var numComps = this.context.numComps;
  33251. var bitsPerComponent = this.context.bitsPerComponent;
  33252. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  33253. 2.3283064365386963e-10; // 2 ^ -32
  33254. var decode = this.context.decode;
  33255. var components = this.tmpCompsBuf;
  33256. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  33257. var ci = this.readBits(bitsPerComponent);
  33258. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  33259. }
  33260. var color = this.tmpCsCompsBuf;
  33261. if (this.context.colorFn) {
  33262. this.context.colorFn(components, 0, color, 0);
  33263. }
  33264. return this.context.colorSpace.getRgb(color, 0);
  33265. }
  33266. };
  33267. function decodeType4Shading(mesh, reader) {
  33268. var coords = mesh.coords;
  33269. var colors = mesh.colors;
  33270. var operators = [];
  33271. var ps = []; // not maintaining cs since that will match ps
  33272. var verticesLeft = 0; // assuming we have all data to start a new triangle
  33273. while (reader.hasData) {
  33274. var f = reader.readFlag();
  33275. var coord = reader.readCoordinate();
  33276. var color = reader.readComponents();
  33277. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  33278. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  33279. switch (f) {
  33280. case 0:
  33281. verticesLeft = 3;
  33282. break;
  33283. case 1:
  33284. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  33285. verticesLeft = 1;
  33286. break;
  33287. case 2:
  33288. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  33289. verticesLeft = 1;
  33290. break;
  33291. }
  33292. operators.push(f);
  33293. }
  33294. ps.push(coords.length);
  33295. coords.push(coord);
  33296. colors.push(color);
  33297. verticesLeft--;
  33298. reader.align();
  33299. }
  33300. mesh.figures.push({
  33301. type: 'triangles',
  33302. coords: new Int32Array(ps),
  33303. colors: new Int32Array(ps),
  33304. });
  33305. }
  33306. function decodeType5Shading(mesh, reader, verticesPerRow) {
  33307. var coords = mesh.coords;
  33308. var colors = mesh.colors;
  33309. var ps = []; // not maintaining cs since that will match ps
  33310. while (reader.hasData) {
  33311. var coord = reader.readCoordinate();
  33312. var color = reader.readComponents();
  33313. ps.push(coords.length);
  33314. coords.push(coord);
  33315. colors.push(color);
  33316. }
  33317. mesh.figures.push({
  33318. type: 'lattice',
  33319. coords: new Int32Array(ps),
  33320. colors: new Int32Array(ps),
  33321. verticesPerRow: verticesPerRow
  33322. });
  33323. }
  33324. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  33325. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  33326. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  33327. var getB = (function getBClosure() {
  33328. function buildB(count) {
  33329. var lut = [];
  33330. for (var i = 0; i <= count; i++) {
  33331. var t = i / count, t_ = 1 - t;
  33332. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  33333. 3 * t * t * t_, t * t * t]));
  33334. }
  33335. return lut;
  33336. }
  33337. var cache = [];
  33338. return function getB(count) {
  33339. if (!cache[count]) {
  33340. cache[count] = buildB(count);
  33341. }
  33342. return cache[count];
  33343. };
  33344. })();
  33345. function buildFigureFromPatch(mesh, index) {
  33346. var figure = mesh.figures[index];
  33347. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  33348. var coords = mesh.coords, colors = mesh.colors;
  33349. var pi = figure.coords;
  33350. var ci = figure.colors;
  33351. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  33352. coords[pi[12]][0], coords[pi[15]][0]);
  33353. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  33354. coords[pi[12]][1], coords[pi[15]][1]);
  33355. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  33356. coords[pi[12]][0], coords[pi[15]][0]);
  33357. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  33358. coords[pi[12]][1], coords[pi[15]][1]);
  33359. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  33360. (mesh.bounds[2] - mesh.bounds[0]));
  33361. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33362. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  33363. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  33364. (mesh.bounds[3] - mesh.bounds[1]));
  33365. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33366. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  33367. var verticesPerRow = splitXBy + 1;
  33368. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  33369. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  33370. var k = 0;
  33371. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  33372. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  33373. c2 = colors[ci[2]], c3 = colors[ci[3]];
  33374. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  33375. for (var row = 0; row <= splitYBy; row++) {
  33376. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  33377. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  33378. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  33379. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  33380. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  33381. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  33382. for (var col = 0; col <= splitXBy; col++, k++) {
  33383. if ((row === 0 || row === splitYBy) &&
  33384. (col === 0 || col === splitXBy)) {
  33385. continue;
  33386. }
  33387. var x = 0, y = 0;
  33388. var q = 0;
  33389. for (var i = 0; i <= 3; i++) {
  33390. for (var j = 0; j <= 3; j++, q++) {
  33391. var m = bRow[row][i] * bCol[col][j];
  33392. x += coords[pi[q]][0] * m;
  33393. y += coords[pi[q]][1] * m;
  33394. }
  33395. }
  33396. figureCoords[k] = coords.length;
  33397. coords.push([x, y]);
  33398. figureColors[k] = colors.length;
  33399. var newColor = new Uint8Array(3);
  33400. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  33401. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  33402. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  33403. colors.push(newColor);
  33404. }
  33405. }
  33406. figureCoords[0] = pi[0];
  33407. figureColors[0] = ci[0];
  33408. figureCoords[splitXBy] = pi[3];
  33409. figureColors[splitXBy] = ci[1];
  33410. figureCoords[verticesPerRow * splitYBy] = pi[12];
  33411. figureColors[verticesPerRow * splitYBy] = ci[2];
  33412. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  33413. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  33414. mesh.figures[index] = {
  33415. type: 'lattice',
  33416. coords: figureCoords,
  33417. colors: figureColors,
  33418. verticesPerRow: verticesPerRow
  33419. };
  33420. }
  33421. function decodeType6Shading(mesh, reader) {
  33422. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  33423. var coords = mesh.coords;
  33424. var colors = mesh.colors;
  33425. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33426. var cs = new Int32Array(4); // c00, c30, c03, c33
  33427. while (reader.hasData) {
  33428. var f = reader.readFlag();
  33429. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  33430. var i, ii;
  33431. var pi = coords.length;
  33432. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  33433. coords.push(reader.readCoordinate());
  33434. }
  33435. var ci = colors.length;
  33436. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33437. colors.push(reader.readComponents());
  33438. }
  33439. var tmp1, tmp2, tmp3, tmp4;
  33440. switch (f) {
  33441. case 0:
  33442. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33443. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  33444. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  33445. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33446. cs[2] = ci + 1; cs[3] = ci + 2;
  33447. cs[0] = ci; cs[1] = ci + 3;
  33448. break;
  33449. case 1:
  33450. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33451. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33452. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33453. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33454. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33455. tmp1 = cs[2]; tmp2 = cs[3];
  33456. cs[2] = tmp2; cs[3] = ci;
  33457. cs[0] = tmp1; cs[1] = ci + 1;
  33458. break;
  33459. case 2:
  33460. tmp1 = ps[15];
  33461. tmp2 = ps[11];
  33462. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33463. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33464. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33465. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33466. tmp1 = cs[3];
  33467. cs[2] = cs[1]; cs[3] = ci;
  33468. cs[0] = tmp1; cs[1] = ci + 1;
  33469. break;
  33470. case 3:
  33471. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33472. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33473. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  33474. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33475. cs[2] = cs[0]; cs[3] = ci;
  33476. cs[0] = cs[1]; cs[1] = ci + 1;
  33477. break;
  33478. }
  33479. // set p11, p12, p21, p22
  33480. ps[5] = coords.length;
  33481. coords.push([
  33482. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  33483. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  33484. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33485. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  33486. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  33487. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  33488. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33489. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  33490. ]);
  33491. ps[6] = coords.length;
  33492. coords.push([
  33493. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  33494. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  33495. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33496. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  33497. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  33498. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  33499. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33500. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  33501. ]);
  33502. ps[9] = coords.length;
  33503. coords.push([
  33504. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  33505. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  33506. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33507. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  33508. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  33509. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  33510. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33511. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  33512. ]);
  33513. ps[10] = coords.length;
  33514. coords.push([
  33515. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  33516. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  33517. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33518. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  33519. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  33520. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  33521. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33522. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  33523. ]);
  33524. mesh.figures.push({
  33525. type: 'patch',
  33526. coords: new Int32Array(ps), // making copies of ps and cs
  33527. colors: new Int32Array(cs)
  33528. });
  33529. }
  33530. }
  33531. function decodeType7Shading(mesh, reader) {
  33532. var coords = mesh.coords;
  33533. var colors = mesh.colors;
  33534. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33535. var cs = new Int32Array(4); // c00, c30, c03, c33
  33536. while (reader.hasData) {
  33537. var f = reader.readFlag();
  33538. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  33539. var i, ii;
  33540. var pi = coords.length;
  33541. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  33542. coords.push(reader.readCoordinate());
  33543. }
  33544. var ci = colors.length;
  33545. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33546. colors.push(reader.readComponents());
  33547. }
  33548. var tmp1, tmp2, tmp3, tmp4;
  33549. switch (f) {
  33550. case 0:
  33551. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33552. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  33553. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  33554. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33555. cs[2] = ci + 1; cs[3] = ci + 2;
  33556. cs[0] = ci; cs[1] = ci + 3;
  33557. break;
  33558. case 1:
  33559. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33560. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33561. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33562. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33563. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33564. tmp1 = cs[2]; tmp2 = cs[3];
  33565. cs[2] = tmp2; cs[3] = ci;
  33566. cs[0] = tmp1; cs[1] = ci + 1;
  33567. break;
  33568. case 2:
  33569. tmp1 = ps[15];
  33570. tmp2 = ps[11];
  33571. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33572. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33573. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33574. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33575. tmp1 = cs[3];
  33576. cs[2] = cs[1]; cs[3] = ci;
  33577. cs[0] = tmp1; cs[1] = ci + 1;
  33578. break;
  33579. case 3:
  33580. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33581. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33582. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33583. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33584. cs[2] = cs[0]; cs[3] = ci;
  33585. cs[0] = cs[1]; cs[1] = ci + 1;
  33586. break;
  33587. }
  33588. mesh.figures.push({
  33589. type: 'patch',
  33590. coords: new Int32Array(ps), // making copies of ps and cs
  33591. colors: new Int32Array(cs)
  33592. });
  33593. }
  33594. }
  33595. function updateBounds(mesh) {
  33596. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  33597. maxX = minX, maxY = minY;
  33598. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  33599. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  33600. minX = minX > x ? x : minX;
  33601. minY = minY > y ? y : minY;
  33602. maxX = maxX < x ? x : maxX;
  33603. maxY = maxY < y ? y : maxY;
  33604. }
  33605. mesh.bounds = [minX, minY, maxX, maxY];
  33606. }
  33607. function packData(mesh) {
  33608. var i, ii, j, jj;
  33609. var coords = mesh.coords;
  33610. var coordsPacked = new Float32Array(coords.length * 2);
  33611. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  33612. var xy = coords[i];
  33613. coordsPacked[j++] = xy[0];
  33614. coordsPacked[j++] = xy[1];
  33615. }
  33616. mesh.coords = coordsPacked;
  33617. var colors = mesh.colors;
  33618. var colorsPacked = new Uint8Array(colors.length * 3);
  33619. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  33620. var c = colors[i];
  33621. colorsPacked[j++] = c[0];
  33622. colorsPacked[j++] = c[1];
  33623. colorsPacked[j++] = c[2];
  33624. }
  33625. mesh.colors = colorsPacked;
  33626. var figures = mesh.figures;
  33627. for (i = 0, ii = figures.length; i < ii; i++) {
  33628. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  33629. for (j = 0, jj = ps.length; j < jj; j++) {
  33630. ps[j] *= 2;
  33631. cs[j] *= 3;
  33632. }
  33633. }
  33634. }
  33635. function Mesh(stream, matrix, xref, res) {
  33636. assert(isStream(stream), 'Mesh data is not a stream');
  33637. var dict = stream.dict;
  33638. this.matrix = matrix;
  33639. this.shadingType = dict.get('ShadingType');
  33640. this.type = 'Pattern';
  33641. this.bbox = dict.get('BBox');
  33642. var cs = dict.get('ColorSpace', 'CS');
  33643. cs = ColorSpace.parse(cs, xref, res);
  33644. this.cs = cs;
  33645. this.background = dict.has('Background') ?
  33646. cs.getRgb(dict.get('Background'), 0) : null;
  33647. var fnObj = dict.get('Function');
  33648. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  33649. this.coords = [];
  33650. this.colors = [];
  33651. this.figures = [];
  33652. var decodeContext = {
  33653. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  33654. bitsPerComponent: dict.get('BitsPerComponent'),
  33655. bitsPerFlag: dict.get('BitsPerFlag'),
  33656. decode: dict.get('Decode'),
  33657. colorFn: fn,
  33658. colorSpace: cs,
  33659. numComps: fn ? 1 : cs.numComps
  33660. };
  33661. var reader = new MeshStreamReader(stream, decodeContext);
  33662. var patchMesh = false;
  33663. switch (this.shadingType) {
  33664. case ShadingType.FREE_FORM_MESH:
  33665. decodeType4Shading(this, reader);
  33666. break;
  33667. case ShadingType.LATTICE_FORM_MESH:
  33668. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  33669. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  33670. decodeType5Shading(this, reader, verticesPerRow);
  33671. break;
  33672. case ShadingType.COONS_PATCH_MESH:
  33673. decodeType6Shading(this, reader);
  33674. patchMesh = true;
  33675. break;
  33676. case ShadingType.TENSOR_PATCH_MESH:
  33677. decodeType7Shading(this, reader);
  33678. patchMesh = true;
  33679. break;
  33680. default:
  33681. error('Unsupported mesh type.');
  33682. break;
  33683. }
  33684. if (patchMesh) {
  33685. // dirty bounds calculation for determining, how dense shall be triangles
  33686. updateBounds(this);
  33687. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  33688. buildFigureFromPatch(this, i);
  33689. }
  33690. }
  33691. // calculate bounds
  33692. updateBounds(this);
  33693. packData(this);
  33694. }
  33695. Mesh.prototype = {
  33696. getIR: function Mesh_getIR() {
  33697. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  33698. this.bounds, this.matrix, this.bbox, this.background];
  33699. }
  33700. };
  33701. return Mesh;
  33702. })();
  33703. Shadings.Dummy = (function DummyClosure() {
  33704. function Dummy() {
  33705. this.type = 'Pattern';
  33706. }
  33707. Dummy.prototype = {
  33708. getIR: function Dummy_getIR() {
  33709. return ['Dummy'];
  33710. }
  33711. };
  33712. return Dummy;
  33713. })();
  33714. function getTilingPatternIR(operatorList, dict, args) {
  33715. var matrix = dict.get('Matrix');
  33716. var bbox = dict.get('BBox');
  33717. var xstep = dict.get('XStep');
  33718. var ystep = dict.get('YStep');
  33719. var paintType = dict.get('PaintType');
  33720. var tilingType = dict.get('TilingType');
  33721. return [
  33722. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  33723. paintType, tilingType
  33724. ];
  33725. }
  33726. exports.Pattern = Pattern;
  33727. exports.getTilingPatternIR = getTilingPatternIR;
  33728. }));
  33729. (function (root, factory) {
  33730. {
  33731. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  33732. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  33733. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  33734. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  33735. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  33736. }
  33737. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  33738. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  33739. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  33740. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33741. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33742. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33743. var ImageKind = sharedUtil.ImageKind;
  33744. var OPS = sharedUtil.OPS;
  33745. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33746. var Util = sharedUtil.Util;
  33747. var assert = sharedUtil.assert;
  33748. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33749. var error = sharedUtil.error;
  33750. var info = sharedUtil.info;
  33751. var isArray = sharedUtil.isArray;
  33752. var isNum = sharedUtil.isNum;
  33753. var isString = sharedUtil.isString;
  33754. var warn = sharedUtil.warn;
  33755. var Dict = corePrimitives.Dict;
  33756. var Name = corePrimitives.Name;
  33757. var isCmd = corePrimitives.isCmd;
  33758. var isDict = corePrimitives.isDict;
  33759. var isName = corePrimitives.isName;
  33760. var isRef = corePrimitives.isRef;
  33761. var isStream = corePrimitives.isStream;
  33762. var DecodeStream = coreStream.DecodeStream;
  33763. var JpegStream = coreStream.JpegStream;
  33764. var Lexer = coreParser.Lexer;
  33765. var Parser = coreParser.Parser;
  33766. var isEOF = coreParser.isEOF;
  33767. var PDFImage = coreImage.PDFImage;
  33768. var ColorSpace = coreColorSpace.ColorSpace;
  33769. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  33770. var Encodings = coreFonts.Encodings;
  33771. var ErrorFont = coreFonts.ErrorFont;
  33772. var FontFlags = coreFonts.FontFlags;
  33773. var Font = coreFonts.Font;
  33774. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  33775. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  33776. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  33777. var getFontType = coreFonts.getFontType;
  33778. var reverseIfRtl = coreFonts.reverseIfRtl;
  33779. var serifFonts = coreFonts.serifFonts;
  33780. var symbolsFonts = coreFonts.symbolsFonts;
  33781. var stdFontMap = coreFonts.stdFontMap;
  33782. var isPDFFunction = coreFunction.isPDFFunction;
  33783. var PDFFunction = coreFunction.PDFFunction;
  33784. var Pattern = corePattern.Pattern;
  33785. var getTilingPatternIR = corePattern.getTilingPatternIR;
  33786. var CMapFactory = coreCMap.CMapFactory;
  33787. var IdentityCMap = coreCMap.IdentityCMap;
  33788. var Metrics = coreMetrics.Metrics;
  33789. var bidi = coreBidi.bidi;
  33790. var PartialEvaluator = (function PartialEvaluatorClosure() {
  33791. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  33792. uniquePrefix, idCounters, fontCache) {
  33793. this.pdfManager = pdfManager;
  33794. this.xref = xref;
  33795. this.handler = handler;
  33796. this.pageIndex = pageIndex;
  33797. this.uniquePrefix = uniquePrefix;
  33798. this.idCounters = idCounters;
  33799. this.fontCache = fontCache;
  33800. }
  33801. // Trying to minimize Date.now() usage and check every 100 time
  33802. var TIME_SLOT_DURATION_MS = 20;
  33803. var CHECK_TIME_EVERY = 100;
  33804. function TimeSlotManager() {
  33805. this.reset();
  33806. }
  33807. TimeSlotManager.prototype = {
  33808. check: function TimeSlotManager_check() {
  33809. if (++this.checked < CHECK_TIME_EVERY) {
  33810. return false;
  33811. }
  33812. this.checked = 0;
  33813. return this.endTime <= Date.now();
  33814. },
  33815. reset: function TimeSlotManager_reset() {
  33816. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  33817. this.checked = 0;
  33818. }
  33819. };
  33820. var deferred = Promise.resolve();
  33821. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  33822. PartialEvaluator.prototype = {
  33823. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  33824. if (!isDict(resources)) {
  33825. return false;
  33826. }
  33827. var processed = Object.create(null);
  33828. if (resources.objId) {
  33829. processed[resources.objId] = true;
  33830. }
  33831. var nodes = [resources];
  33832. while (nodes.length) {
  33833. var key;
  33834. var node = nodes.shift();
  33835. // First check the current resources for blend modes.
  33836. var graphicStates = node.get('ExtGState');
  33837. if (isDict(graphicStates)) {
  33838. graphicStates = graphicStates.getAll();
  33839. for (key in graphicStates) {
  33840. var graphicState = graphicStates[key];
  33841. var bm = graphicState['BM'];
  33842. if (isName(bm) && bm.name !== 'Normal') {
  33843. return true;
  33844. }
  33845. }
  33846. }
  33847. // Descend into the XObjects to look for more resources and blend modes.
  33848. var xObjects = node.get('XObject');
  33849. if (!isDict(xObjects)) {
  33850. continue;
  33851. }
  33852. xObjects = xObjects.getAll();
  33853. for (key in xObjects) {
  33854. var xObject = xObjects[key];
  33855. if (!isStream(xObject)) {
  33856. continue;
  33857. }
  33858. if (xObject.dict.objId) {
  33859. if (processed[xObject.dict.objId]) {
  33860. // stream has objId and is processed already
  33861. continue;
  33862. }
  33863. processed[xObject.dict.objId] = true;
  33864. }
  33865. var xResources = xObject.dict.get('Resources');
  33866. // Checking objId to detect an infinite loop.
  33867. if (isDict(xResources) &&
  33868. (!xResources.objId || !processed[xResources.objId])) {
  33869. nodes.push(xResources);
  33870. if (xResources.objId) {
  33871. processed[xResources.objId] = true;
  33872. }
  33873. }
  33874. }
  33875. }
  33876. return false;
  33877. },
  33878. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  33879. xobj, smask,
  33880. operatorList,
  33881. task,
  33882. initialState) {
  33883. var matrix = xobj.dict.getArray('Matrix');
  33884. var bbox = xobj.dict.getArray('BBox');
  33885. var group = xobj.dict.get('Group');
  33886. if (group) {
  33887. var groupOptions = {
  33888. matrix: matrix,
  33889. bbox: bbox,
  33890. smask: smask,
  33891. isolated: false,
  33892. knockout: false
  33893. };
  33894. var groupSubtype = group.get('S');
  33895. var colorSpace;
  33896. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  33897. groupOptions.isolated = (group.get('I') || false);
  33898. groupOptions.knockout = (group.get('K') || false);
  33899. colorSpace = (group.has('CS') ?
  33900. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  33901. }
  33902. if (smask && smask.backdrop) {
  33903. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  33904. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  33905. }
  33906. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  33907. }
  33908. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  33909. return this.getOperatorList(xobj, task,
  33910. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  33911. then(function () {
  33912. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  33913. if (group) {
  33914. operatorList.addOp(OPS.endGroup, [groupOptions]);
  33915. }
  33916. });
  33917. },
  33918. buildPaintImageXObject:
  33919. function PartialEvaluator_buildPaintImageXObject(resources, image,
  33920. inline, operatorList,
  33921. cacheKey, imageCache) {
  33922. var self = this;
  33923. var dict = image.dict;
  33924. var w = dict.get('Width', 'W');
  33925. var h = dict.get('Height', 'H');
  33926. if (!(w && isNum(w)) || !(h && isNum(h))) {
  33927. warn('Image dimensions are missing, or not numbers.');
  33928. return;
  33929. }
  33930. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  33931. warn('Image exceeded maximum allowed size and was removed.');
  33932. return;
  33933. }
  33934. var imageMask = (dict.get('ImageMask', 'IM') || false);
  33935. var imgData, args;
  33936. if (imageMask) {
  33937. // This depends on a tmpCanvas being filled with the
  33938. // current fillStyle, such that processing the pixel
  33939. // data can't be done here. Instead of creating a
  33940. // complete PDFImage, only read the information needed
  33941. // for later.
  33942. var width = dict.get('Width', 'W');
  33943. var height = dict.get('Height', 'H');
  33944. var bitStrideLength = (width + 7) >> 3;
  33945. var imgArray = image.getBytes(bitStrideLength * height);
  33946. var decode = dict.get('Decode', 'D');
  33947. var inverseDecode = (!!decode && decode[0] > 0);
  33948. imgData = PDFImage.createMask(imgArray, width, height,
  33949. image instanceof DecodeStream,
  33950. inverseDecode);
  33951. imgData.cached = true;
  33952. args = [imgData];
  33953. operatorList.addOp(OPS.paintImageMaskXObject, args);
  33954. if (cacheKey) {
  33955. imageCache[cacheKey] = {
  33956. fn: OPS.paintImageMaskXObject,
  33957. args: args
  33958. };
  33959. }
  33960. return;
  33961. }
  33962. var softMask = (dict.get('SMask', 'SM') || false);
  33963. var mask = (dict.get('Mask') || false);
  33964. var SMALL_IMAGE_DIMENSIONS = 200;
  33965. // Inlining small images into the queue as RGB data
  33966. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  33967. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  33968. var imageObj = new PDFImage(this.xref, resources, image,
  33969. inline, null, null);
  33970. // We force the use of RGBA_32BPP images here, because we can't handle
  33971. // any other kind.
  33972. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  33973. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  33974. return;
  33975. }
  33976. // If there is no imageMask, create the PDFImage and a lot
  33977. // of image processing can be done here.
  33978. var uniquePrefix = (this.uniquePrefix || '');
  33979. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  33980. operatorList.addDependency(objId);
  33981. args = [objId, w, h];
  33982. if (!softMask && !mask && image instanceof JpegStream &&
  33983. image.isNativelySupported(this.xref, resources)) {
  33984. // These JPEGs don't need any more processing so we can just send it.
  33985. operatorList.addOp(OPS.paintJpegXObject, args);
  33986. this.handler.send('obj',
  33987. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  33988. return;
  33989. }
  33990. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  33991. then(function(imageObj) {
  33992. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  33993. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  33994. [imgData.data.buffer]);
  33995. }).then(undefined, function (reason) {
  33996. warn('Unable to decode image: ' + reason);
  33997. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  33998. });
  33999. operatorList.addOp(OPS.paintImageXObject, args);
  34000. if (cacheKey) {
  34001. imageCache[cacheKey] = {
  34002. fn: OPS.paintImageXObject,
  34003. args: args
  34004. };
  34005. }
  34006. },
  34007. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34008. operatorList, task,
  34009. stateManager) {
  34010. var smaskContent = smask.get('G');
  34011. var smaskOptions = {
  34012. subtype: smask.get('S').name,
  34013. backdrop: smask.get('BC')
  34014. };
  34015. // The SMask might have a alpha/luminosity value transfer function --
  34016. // we will build a map of integer values in range 0..255 to be fast.
  34017. var transferObj = smask.get('TR');
  34018. if (isPDFFunction(transferObj)) {
  34019. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34020. var transferMap = new Uint8Array(256);
  34021. var tmp = new Float32Array(1);
  34022. for (var i = 0; i < 255; i++) {
  34023. tmp[0] = i / 255;
  34024. transferFn(tmp, 0, tmp, 0);
  34025. transferMap[i] = (tmp[0] * 255) | 0;
  34026. }
  34027. smaskOptions.transferMap = transferMap;
  34028. }
  34029. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34030. operatorList, task, stateManager.state.clone());
  34031. },
  34032. handleTilingType:
  34033. function PartialEvaluator_handleTilingType(fn, args, resources,
  34034. pattern, patternDict,
  34035. operatorList, task) {
  34036. // Create an IR of the pattern code.
  34037. var tilingOpList = new OperatorList();
  34038. // Merge the available resources, to prevent issues when the patternDict
  34039. // is missing some /Resources entries (fixes issue6541.pdf).
  34040. var resourcesArray = [patternDict.get('Resources'), resources];
  34041. var patternResources = Dict.merge(this.xref, resourcesArray);
  34042. return this.getOperatorList(pattern, task, patternResources,
  34043. tilingOpList).then(function () {
  34044. // Add the dependencies to the parent operator list so they are
  34045. // resolved before sub operator list is executed synchronously.
  34046. operatorList.addDependencies(tilingOpList.dependencies);
  34047. operatorList.addOp(fn, getTilingPatternIR({
  34048. fnArray: tilingOpList.fnArray,
  34049. argsArray: tilingOpList.argsArray
  34050. }, patternDict, args));
  34051. });
  34052. },
  34053. handleSetFont:
  34054. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  34055. operatorList, task, state) {
  34056. // TODO(mack): Not needed?
  34057. var fontName;
  34058. if (fontArgs) {
  34059. fontArgs = fontArgs.slice();
  34060. fontName = fontArgs[0].name;
  34061. }
  34062. var self = this;
  34063. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  34064. function (translated) {
  34065. if (!translated.font.isType3Font) {
  34066. return translated;
  34067. }
  34068. return translated.loadType3Data(self, resources, operatorList, task).
  34069. then(function () {
  34070. return translated;
  34071. }, function (reason) {
  34072. // Error in the font data -- sending unsupported feature notification.
  34073. self.handler.send('UnsupportedFeature',
  34074. {featureId: UNSUPPORTED_FEATURES.font});
  34075. return new TranslatedFont('g_font_error',
  34076. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  34077. });
  34078. }).then(function (translated) {
  34079. state.font = translated.font;
  34080. translated.send(self.handler);
  34081. return translated.loadedName;
  34082. });
  34083. },
  34084. handleText: function PartialEvaluator_handleText(chars, state) {
  34085. var font = state.font;
  34086. var glyphs = font.charsToGlyphs(chars);
  34087. var isAddToPathSet = !!(state.textRenderingMode &
  34088. TextRenderingMode.ADD_TO_PATH_FLAG);
  34089. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  34090. var buildPath = function (fontChar) {
  34091. if (!font.renderer.hasBuiltPath(fontChar)) {
  34092. var path = font.renderer.getPathJs(fontChar);
  34093. this.handler.send('commonobj', [
  34094. font.loadedName + '_path_' + fontChar,
  34095. 'FontPath',
  34096. path
  34097. ]);
  34098. }
  34099. }.bind(this);
  34100. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  34101. var glyph = glyphs[i];
  34102. buildPath(glyph.fontChar);
  34103. // If the glyph has an accent we need to build a path for its
  34104. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  34105. var accent = glyph.accent;
  34106. if (accent && accent.fontChar) {
  34107. buildPath(accent.fontChar);
  34108. }
  34109. }
  34110. }
  34111. return glyphs;
  34112. },
  34113. setGState: function PartialEvaluator_setGState(resources, gState,
  34114. operatorList, task,
  34115. xref, stateManager) {
  34116. // This array holds the converted/processed state data.
  34117. var gStateObj = [];
  34118. var gStateMap = gState.map;
  34119. var self = this;
  34120. var promise = Promise.resolve();
  34121. for (var key in gStateMap) {
  34122. var value = gStateMap[key];
  34123. switch (key) {
  34124. case 'Type':
  34125. break;
  34126. case 'LW':
  34127. case 'LC':
  34128. case 'LJ':
  34129. case 'ML':
  34130. case 'D':
  34131. case 'RI':
  34132. case 'FL':
  34133. case 'CA':
  34134. case 'ca':
  34135. gStateObj.push([key, value]);
  34136. break;
  34137. case 'Font':
  34138. promise = promise.then(function () {
  34139. return self.handleSetFont(resources, null, value[0], operatorList,
  34140. task, stateManager.state).
  34141. then(function (loadedName) {
  34142. operatorList.addDependency(loadedName);
  34143. gStateObj.push([key, [loadedName, value[1]]]);
  34144. });
  34145. });
  34146. break;
  34147. case 'BM':
  34148. gStateObj.push([key, value]);
  34149. break;
  34150. case 'SMask':
  34151. if (isName(value) && value.name === 'None') {
  34152. gStateObj.push([key, false]);
  34153. break;
  34154. }
  34155. var dict = xref.fetchIfRef(value);
  34156. if (isDict(dict)) {
  34157. promise = promise.then(function () {
  34158. return self.handleSMask(dict, resources, operatorList,
  34159. task, stateManager);
  34160. });
  34161. gStateObj.push([key, true]);
  34162. } else {
  34163. warn('Unsupported SMask type');
  34164. }
  34165. break;
  34166. // Only generate info log messages for the following since
  34167. // they are unlikely to have a big impact on the rendering.
  34168. case 'OP':
  34169. case 'op':
  34170. case 'OPM':
  34171. case 'BG':
  34172. case 'BG2':
  34173. case 'UCR':
  34174. case 'UCR2':
  34175. case 'TR':
  34176. case 'TR2':
  34177. case 'HT':
  34178. case 'SM':
  34179. case 'SA':
  34180. case 'AIS':
  34181. case 'TK':
  34182. // TODO implement these operators.
  34183. info('graphic state operator ' + key);
  34184. break;
  34185. default:
  34186. info('Unknown graphic state operator ' + key);
  34187. break;
  34188. }
  34189. }
  34190. return promise.then(function () {
  34191. if (gStateObj.length >= 0) {
  34192. operatorList.addOp(OPS.setGState, [gStateObj]);
  34193. }
  34194. });
  34195. },
  34196. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  34197. resources) {
  34198. function errorFont() {
  34199. return Promise.resolve(new TranslatedFont('g_font_error',
  34200. new ErrorFont('Font ' + fontName + ' is not available'), font));
  34201. }
  34202. var fontRef;
  34203. if (font) { // Loading by ref.
  34204. assert(isRef(font));
  34205. fontRef = font;
  34206. } else { // Loading by name.
  34207. var fontRes = resources.get('Font');
  34208. if (fontRes) {
  34209. fontRef = fontRes.getRaw(fontName);
  34210. } else {
  34211. warn('fontRes not available');
  34212. return errorFont();
  34213. }
  34214. }
  34215. if (!fontRef) {
  34216. warn('fontRef not available');
  34217. return errorFont();
  34218. }
  34219. if (this.fontCache.has(fontRef)) {
  34220. return this.fontCache.get(fontRef);
  34221. }
  34222. font = xref.fetchIfRef(fontRef);
  34223. if (!isDict(font)) {
  34224. return errorFont();
  34225. }
  34226. // We are holding font.translated references just for fontRef that are not
  34227. // dictionaries (Dict). See explanation below.
  34228. if (font.translated) {
  34229. return font.translated;
  34230. }
  34231. var fontCapability = createPromiseCapability();
  34232. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  34233. var descriptor = preEvaluatedFont.descriptor;
  34234. var fontID = fontRef.num + '_' + fontRef.gen;
  34235. if (isDict(descriptor)) {
  34236. if (!descriptor.fontAliases) {
  34237. descriptor.fontAliases = Object.create(null);
  34238. }
  34239. var fontAliases = descriptor.fontAliases;
  34240. var hash = preEvaluatedFont.hash;
  34241. if (fontAliases[hash]) {
  34242. var aliasFontRef = fontAliases[hash].aliasRef;
  34243. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  34244. this.fontCache.putAlias(fontRef, aliasFontRef);
  34245. return this.fontCache.get(fontRef);
  34246. }
  34247. }
  34248. if (!fontAliases[hash]) {
  34249. fontAliases[hash] = {
  34250. fontID: Font.getFontID()
  34251. };
  34252. }
  34253. fontAliases[hash].aliasRef = fontRef;
  34254. fontID = fontAliases[hash].fontID;
  34255. }
  34256. // Workaround for bad PDF generators that don't reference fonts
  34257. // properly, i.e. by not using an object identifier.
  34258. // Check if the fontRef is a Dict (as opposed to a standard object),
  34259. // in which case we don't cache the font and instead reference it by
  34260. // fontName in font.loadedName below.
  34261. var fontRefIsDict = isDict(fontRef);
  34262. if (!fontRefIsDict) {
  34263. this.fontCache.put(fontRef, fontCapability.promise);
  34264. }
  34265. // Keep track of each font we translated so the caller can
  34266. // load them asynchronously before calling display on a page.
  34267. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  34268. fontName.replace(/\W/g, '') : fontID);
  34269. font.translated = fontCapability.promise;
  34270. // TODO move promises into translate font
  34271. var translatedPromise;
  34272. try {
  34273. translatedPromise = Promise.resolve(
  34274. this.translateFont(preEvaluatedFont, xref));
  34275. } catch (e) {
  34276. translatedPromise = Promise.reject(e);
  34277. }
  34278. var self = this;
  34279. translatedPromise.then(function (translatedFont) {
  34280. if (translatedFont.fontType !== undefined) {
  34281. var xrefFontStats = xref.stats.fontTypes;
  34282. xrefFontStats[translatedFont.fontType] = true;
  34283. }
  34284. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34285. translatedFont, font));
  34286. }, function (reason) {
  34287. // TODO fontCapability.reject?
  34288. // Error in the font data -- sending unsupported feature notification.
  34289. self.handler.send('UnsupportedFeature',
  34290. {featureId: UNSUPPORTED_FEATURES.font});
  34291. try {
  34292. // error, but it's still nice to have font type reported
  34293. var descriptor = preEvaluatedFont.descriptor;
  34294. var fontFile3 = descriptor && descriptor.get('FontFile3');
  34295. var subtype = fontFile3 && fontFile3.get('Subtype');
  34296. var fontType = getFontType(preEvaluatedFont.type,
  34297. subtype && subtype.name);
  34298. var xrefFontStats = xref.stats.fontTypes;
  34299. xrefFontStats[fontType] = true;
  34300. } catch (ex) { }
  34301. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34302. new ErrorFont(reason instanceof Error ? reason.message : reason),
  34303. font));
  34304. });
  34305. return fontCapability.promise;
  34306. },
  34307. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  34308. var lastIndex = operatorList.length - 1;
  34309. if (!args) {
  34310. args = [];
  34311. }
  34312. if (lastIndex < 0 ||
  34313. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  34314. operatorList.addOp(OPS.constructPath, [[fn], args]);
  34315. } else {
  34316. var opArgs = operatorList.argsArray[lastIndex];
  34317. opArgs[0].push(fn);
  34318. Array.prototype.push.apply(opArgs[1], args);
  34319. }
  34320. },
  34321. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  34322. cs, patterns, resources, task, xref) {
  34323. // compile tiling patterns
  34324. var patternName = args[args.length - 1];
  34325. // SCN/scn applies patterns along with normal colors
  34326. var pattern;
  34327. if (isName(patternName) &&
  34328. (pattern = patterns.get(patternName.name))) {
  34329. var dict = (isStream(pattern) ? pattern.dict : pattern);
  34330. var typeNum = dict.get('PatternType');
  34331. if (typeNum === TILING_PATTERN) {
  34332. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  34333. return this.handleTilingType(fn, color, resources, pattern,
  34334. dict, operatorList, task);
  34335. } else if (typeNum === SHADING_PATTERN) {
  34336. var shading = dict.get('Shading');
  34337. var matrix = dict.get('Matrix');
  34338. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  34339. this.handler);
  34340. operatorList.addOp(fn, pattern.getIR());
  34341. return Promise.resolve();
  34342. } else {
  34343. return Promise.reject('Unknown PatternType: ' + typeNum);
  34344. }
  34345. }
  34346. // TODO shall we fail here?
  34347. operatorList.addOp(fn, args);
  34348. return Promise.resolve();
  34349. },
  34350. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  34351. task,
  34352. resources,
  34353. operatorList,
  34354. initialState) {
  34355. var self = this;
  34356. var xref = this.xref;
  34357. var imageCache = {};
  34358. assert(operatorList);
  34359. resources = (resources || Dict.empty);
  34360. var xobjs = (resources.get('XObject') || Dict.empty);
  34361. var patterns = (resources.get('Pattern') || Dict.empty);
  34362. var stateManager = new StateManager(initialState || new EvalState());
  34363. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34364. var timeSlotManager = new TimeSlotManager();
  34365. return new Promise(function next(resolve, reject) {
  34366. task.ensureNotTerminated();
  34367. timeSlotManager.reset();
  34368. var stop, operation = {}, i, ii, cs;
  34369. while (!(stop = timeSlotManager.check())) {
  34370. // The arguments parsed by read() are used beyond this loop, so we
  34371. // cannot reuse the same array on each iteration. Therefore we pass
  34372. // in |null| as the initial value (see the comment on
  34373. // EvaluatorPreprocessor_read() for why).
  34374. operation.args = null;
  34375. if (!(preprocessor.read(operation))) {
  34376. break;
  34377. }
  34378. var args = operation.args;
  34379. var fn = operation.fn;
  34380. switch (fn | 0) {
  34381. case OPS.paintXObject:
  34382. if (args[0].code) {
  34383. break;
  34384. }
  34385. // eagerly compile XForm objects
  34386. var name = args[0].name;
  34387. if (!name) {
  34388. warn('XObject must be referred to by name.');
  34389. continue;
  34390. }
  34391. if (imageCache[name] !== undefined) {
  34392. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  34393. args = null;
  34394. continue;
  34395. }
  34396. var xobj = xobjs.get(name);
  34397. if (xobj) {
  34398. assert(isStream(xobj), 'XObject should be a stream');
  34399. var type = xobj.dict.get('Subtype');
  34400. assert(isName(type),
  34401. 'XObject should have a Name subtype');
  34402. if (type.name === 'Form') {
  34403. stateManager.save();
  34404. return self.buildFormXObject(resources, xobj, null,
  34405. operatorList, task,
  34406. stateManager.state.clone()).
  34407. then(function () {
  34408. stateManager.restore();
  34409. next(resolve, reject);
  34410. }, reject);
  34411. } else if (type.name === 'Image') {
  34412. self.buildPaintImageXObject(resources, xobj, false,
  34413. operatorList, name, imageCache);
  34414. args = null;
  34415. continue;
  34416. } else if (type.name === 'PS') {
  34417. // PostScript XObjects are unused when viewing documents.
  34418. // See section 4.7.1 of Adobe's PDF reference.
  34419. info('Ignored XObject subtype PS');
  34420. continue;
  34421. } else {
  34422. error('Unhandled XObject subtype ' + type.name);
  34423. }
  34424. }
  34425. break;
  34426. case OPS.setFont:
  34427. var fontSize = args[1];
  34428. // eagerly collect all fonts
  34429. return self.handleSetFont(resources, args, null, operatorList,
  34430. task, stateManager.state).
  34431. then(function (loadedName) {
  34432. operatorList.addDependency(loadedName);
  34433. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  34434. next(resolve, reject);
  34435. }, reject);
  34436. case OPS.endInlineImage:
  34437. var cacheKey = args[0].cacheKey;
  34438. if (cacheKey) {
  34439. var cacheEntry = imageCache[cacheKey];
  34440. if (cacheEntry !== undefined) {
  34441. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  34442. args = null;
  34443. continue;
  34444. }
  34445. }
  34446. self.buildPaintImageXObject(resources, args[0], true,
  34447. operatorList, cacheKey, imageCache);
  34448. args = null;
  34449. continue;
  34450. case OPS.showText:
  34451. args[0] = self.handleText(args[0], stateManager.state);
  34452. break;
  34453. case OPS.showSpacedText:
  34454. var arr = args[0];
  34455. var combinedGlyphs = [];
  34456. var arrLength = arr.length;
  34457. var state = stateManager.state;
  34458. for (i = 0; i < arrLength; ++i) {
  34459. var arrItem = arr[i];
  34460. if (isString(arrItem)) {
  34461. Array.prototype.push.apply(combinedGlyphs,
  34462. self.handleText(arrItem, state));
  34463. } else if (isNum(arrItem)) {
  34464. combinedGlyphs.push(arrItem);
  34465. }
  34466. }
  34467. args[0] = combinedGlyphs;
  34468. fn = OPS.showText;
  34469. break;
  34470. case OPS.nextLineShowText:
  34471. operatorList.addOp(OPS.nextLine);
  34472. args[0] = self.handleText(args[0], stateManager.state);
  34473. fn = OPS.showText;
  34474. break;
  34475. case OPS.nextLineSetSpacingShowText:
  34476. operatorList.addOp(OPS.nextLine);
  34477. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  34478. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  34479. args[0] = self.handleText(args[0], stateManager.state);
  34480. fn = OPS.showText;
  34481. break;
  34482. case OPS.setTextRenderingMode:
  34483. stateManager.state.textRenderingMode = args[0];
  34484. break;
  34485. case OPS.setFillColorSpace:
  34486. stateManager.state.fillColorSpace =
  34487. ColorSpace.parse(args[0], xref, resources);
  34488. continue;
  34489. case OPS.setStrokeColorSpace:
  34490. stateManager.state.strokeColorSpace =
  34491. ColorSpace.parse(args[0], xref, resources);
  34492. continue;
  34493. case OPS.setFillColor:
  34494. cs = stateManager.state.fillColorSpace;
  34495. args = cs.getRgb(args, 0);
  34496. fn = OPS.setFillRGBColor;
  34497. break;
  34498. case OPS.setStrokeColor:
  34499. cs = stateManager.state.strokeColorSpace;
  34500. args = cs.getRgb(args, 0);
  34501. fn = OPS.setStrokeRGBColor;
  34502. break;
  34503. case OPS.setFillGray:
  34504. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  34505. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34506. fn = OPS.setFillRGBColor;
  34507. break;
  34508. case OPS.setStrokeGray:
  34509. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  34510. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34511. fn = OPS.setStrokeRGBColor;
  34512. break;
  34513. case OPS.setFillCMYKColor:
  34514. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  34515. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34516. fn = OPS.setFillRGBColor;
  34517. break;
  34518. case OPS.setStrokeCMYKColor:
  34519. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  34520. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34521. fn = OPS.setStrokeRGBColor;
  34522. break;
  34523. case OPS.setFillRGBColor:
  34524. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  34525. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34526. break;
  34527. case OPS.setStrokeRGBColor:
  34528. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  34529. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34530. break;
  34531. case OPS.setFillColorN:
  34532. cs = stateManager.state.fillColorSpace;
  34533. if (cs.name === 'Pattern') {
  34534. return self.handleColorN(operatorList, OPS.setFillColorN,
  34535. args, cs, patterns, resources, task, xref).then(function() {
  34536. next(resolve, reject);
  34537. }, reject);
  34538. }
  34539. args = cs.getRgb(args, 0);
  34540. fn = OPS.setFillRGBColor;
  34541. break;
  34542. case OPS.setStrokeColorN:
  34543. cs = stateManager.state.strokeColorSpace;
  34544. if (cs.name === 'Pattern') {
  34545. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  34546. args, cs, patterns, resources, task, xref).then(function() {
  34547. next(resolve, reject);
  34548. }, reject);
  34549. }
  34550. args = cs.getRgb(args, 0);
  34551. fn = OPS.setStrokeRGBColor;
  34552. break;
  34553. case OPS.shadingFill:
  34554. var shadingRes = resources.get('Shading');
  34555. if (!shadingRes) {
  34556. error('No shading resource found');
  34557. }
  34558. var shading = shadingRes.get(args[0].name);
  34559. if (!shading) {
  34560. error('No shading object found');
  34561. }
  34562. var shadingFill = Pattern.parseShading(shading, null, xref,
  34563. resources, self.handler);
  34564. var patternIR = shadingFill.getIR();
  34565. args = [patternIR];
  34566. fn = OPS.shadingFill;
  34567. break;
  34568. case OPS.setGState:
  34569. var dictName = args[0];
  34570. var extGState = resources.get('ExtGState');
  34571. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  34572. break;
  34573. }
  34574. var gState = extGState.get(dictName.name);
  34575. return self.setGState(resources, gState, operatorList, task,
  34576. xref, stateManager).then(function() {
  34577. next(resolve, reject);
  34578. }, reject);
  34579. case OPS.moveTo:
  34580. case OPS.lineTo:
  34581. case OPS.curveTo:
  34582. case OPS.curveTo2:
  34583. case OPS.curveTo3:
  34584. case OPS.closePath:
  34585. self.buildPath(operatorList, fn, args);
  34586. continue;
  34587. case OPS.rectangle:
  34588. self.buildPath(operatorList, fn, args);
  34589. continue;
  34590. case OPS.markPoint:
  34591. case OPS.markPointProps:
  34592. case OPS.beginMarkedContent:
  34593. case OPS.beginMarkedContentProps:
  34594. case OPS.endMarkedContent:
  34595. case OPS.beginCompat:
  34596. case OPS.endCompat:
  34597. // Ignore operators where the corresponding handlers are known to
  34598. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  34599. // serialization errors and is also a bit more efficient.
  34600. // We could also try to serialize all objects in a general way,
  34601. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  34602. // but doing so is meaningless without knowing the semantics.
  34603. continue;
  34604. default:
  34605. // Note: Let's hope that the ignored operator does not have any
  34606. // non-serializable arguments, otherwise postMessage will throw
  34607. // "An object could not be cloned.".
  34608. }
  34609. operatorList.addOp(fn, args);
  34610. }
  34611. if (stop) {
  34612. deferred.then(function () {
  34613. next(resolve, reject);
  34614. }, reject);
  34615. return;
  34616. }
  34617. // Some PDFs don't close all restores inside object/form.
  34618. // Closing those for them.
  34619. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  34620. operatorList.addOp(OPS.restore, []);
  34621. }
  34622. resolve();
  34623. });
  34624. },
  34625. getTextContent:
  34626. function PartialEvaluator_getTextContent(stream, task, resources,
  34627. stateManager,
  34628. normalizeWhitespace) {
  34629. stateManager = (stateManager || new StateManager(new TextState()));
  34630. var WhitespaceRegexp = /\s/g;
  34631. var textContent = {
  34632. items: [],
  34633. styles: Object.create(null)
  34634. };
  34635. var textContentItem = {
  34636. initialized: false,
  34637. str: [],
  34638. width: 0,
  34639. height: 0,
  34640. vertical: false,
  34641. lastAdvanceWidth: 0,
  34642. lastAdvanceHeight: 0,
  34643. textAdvanceScale: 0,
  34644. spaceWidth: 0,
  34645. fakeSpaceMin: Infinity,
  34646. fakeMultiSpaceMin: Infinity,
  34647. fakeMultiSpaceMax: -0,
  34648. textRunBreakAllowed: false,
  34649. transform: null,
  34650. fontName: null
  34651. };
  34652. var SPACE_FACTOR = 0.3;
  34653. var MULTI_SPACE_FACTOR = 1.5;
  34654. var MULTI_SPACE_FACTOR_MAX = 4;
  34655. var self = this;
  34656. var xref = this.xref;
  34657. resources = (xref.fetchIfRef(resources) || Dict.empty);
  34658. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  34659. var xobjs = null;
  34660. var xobjsCache = {};
  34661. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34662. var textState;
  34663. function ensureTextContentItem() {
  34664. if (textContentItem.initialized) {
  34665. return textContentItem;
  34666. }
  34667. var font = textState.font;
  34668. if (!(font.loadedName in textContent.styles)) {
  34669. textContent.styles[font.loadedName] = {
  34670. fontFamily: font.fallbackName,
  34671. ascent: font.ascent,
  34672. descent: font.descent,
  34673. vertical: font.vertical
  34674. };
  34675. }
  34676. textContentItem.fontName = font.loadedName;
  34677. // 9.4.4 Text Space Details
  34678. var tsm = [textState.fontSize * textState.textHScale, 0,
  34679. 0, textState.fontSize,
  34680. 0, textState.textRise];
  34681. if (font.isType3Font &&
  34682. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  34683. textState.fontSize === 1) {
  34684. var glyphHeight = font.bbox[3] - font.bbox[1];
  34685. if (glyphHeight > 0) {
  34686. glyphHeight = glyphHeight * textState.fontMatrix[3];
  34687. tsm[3] *= glyphHeight;
  34688. }
  34689. }
  34690. var trm = Util.transform(textState.ctm,
  34691. Util.transform(textState.textMatrix, tsm));
  34692. textContentItem.transform = trm;
  34693. if (!font.vertical) {
  34694. textContentItem.width = 0;
  34695. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  34696. textContentItem.vertical = false;
  34697. } else {
  34698. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  34699. textContentItem.height = 0;
  34700. textContentItem.vertical = true;
  34701. }
  34702. var a = textState.textLineMatrix[0];
  34703. var b = textState.textLineMatrix[1];
  34704. var scaleLineX = Math.sqrt(a * a + b * b);
  34705. a = textState.ctm[0];
  34706. b = textState.ctm[1];
  34707. var scaleCtmX = Math.sqrt(a * a + b * b);
  34708. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  34709. textContentItem.lastAdvanceWidth = 0;
  34710. textContentItem.lastAdvanceHeight = 0;
  34711. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  34712. if (spaceWidth) {
  34713. textContentItem.spaceWidth = spaceWidth;
  34714. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  34715. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  34716. textContentItem.fakeMultiSpaceMax =
  34717. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  34718. // It's okay for monospace fonts to fake as much space as needed.
  34719. textContentItem.textRunBreakAllowed = !font.isMonospace;
  34720. } else {
  34721. textContentItem.spaceWidth = 0;
  34722. textContentItem.fakeSpaceMin = Infinity;
  34723. textContentItem.fakeMultiSpaceMin = Infinity;
  34724. textContentItem.fakeMultiSpaceMax = 0;
  34725. textContentItem.textRunBreakAllowed = false;
  34726. }
  34727. textContentItem.initialized = true;
  34728. return textContentItem;
  34729. }
  34730. function replaceWhitespace(str) {
  34731. // Replaces all whitespaces with standard spaces (0x20), to avoid
  34732. // alignment issues between the textLayer and the canvas if the text
  34733. // contains e.g. tabs (fixes issue6612.pdf).
  34734. var i = 0, ii = str.length, code;
  34735. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  34736. i++;
  34737. }
  34738. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  34739. }
  34740. function runBidiTransform(textChunk) {
  34741. var str = textChunk.str.join('');
  34742. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  34743. return {
  34744. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  34745. bidiResult.str),
  34746. dir: bidiResult.dir,
  34747. width: textChunk.width,
  34748. height: textChunk.height,
  34749. transform: textChunk.transform,
  34750. fontName: textChunk.fontName
  34751. };
  34752. }
  34753. function handleSetFont(fontName, fontRef) {
  34754. return self.loadFont(fontName, fontRef, xref, resources).
  34755. then(function (translated) {
  34756. textState.font = translated.font;
  34757. textState.fontMatrix = translated.font.fontMatrix ||
  34758. FONT_IDENTITY_MATRIX;
  34759. });
  34760. }
  34761. function buildTextContentItem(chars) {
  34762. var font = textState.font;
  34763. var textChunk = ensureTextContentItem();
  34764. var width = 0;
  34765. var height = 0;
  34766. var glyphs = font.charsToGlyphs(chars);
  34767. var defaultVMetrics = font.defaultVMetrics;
  34768. for (var i = 0; i < glyphs.length; i++) {
  34769. var glyph = glyphs[i];
  34770. var vMetricX = null;
  34771. var vMetricY = null;
  34772. var glyphWidth = null;
  34773. if (font.vertical) {
  34774. if (glyph.vmetric) {
  34775. glyphWidth = glyph.vmetric[0];
  34776. vMetricX = glyph.vmetric[1];
  34777. vMetricY = glyph.vmetric[2];
  34778. } else {
  34779. glyphWidth = glyph.width;
  34780. vMetricX = glyph.width * 0.5;
  34781. vMetricY = defaultVMetrics[2];
  34782. }
  34783. } else {
  34784. glyphWidth = glyph.width;
  34785. }
  34786. var glyphUnicode = glyph.unicode;
  34787. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  34788. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  34789. }
  34790. glyphUnicode = reverseIfRtl(glyphUnicode);
  34791. // The following will calculate the x and y of the individual glyphs.
  34792. // if (font.vertical) {
  34793. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  34794. // textState.fontMatrix[0];
  34795. // tsm[5] -= vMetricY * textState.fontSize *
  34796. // textState.fontMatrix[0];
  34797. // }
  34798. // var trm = Util.transform(textState.textMatrix, tsm);
  34799. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  34800. // var x = pt[0];
  34801. // var y = pt[1];
  34802. var charSpacing = textState.charSpacing;
  34803. if (glyph.isSpace) {
  34804. var wordSpacing = textState.wordSpacing;
  34805. charSpacing += wordSpacing;
  34806. if (wordSpacing > 0) {
  34807. addFakeSpaces(wordSpacing, textChunk.str);
  34808. }
  34809. }
  34810. var tx = 0;
  34811. var ty = 0;
  34812. if (!font.vertical) {
  34813. var w0 = glyphWidth * textState.fontMatrix[0];
  34814. tx = (w0 * textState.fontSize + charSpacing) *
  34815. textState.textHScale;
  34816. width += tx;
  34817. } else {
  34818. var w1 = glyphWidth * textState.fontMatrix[0];
  34819. ty = w1 * textState.fontSize + charSpacing;
  34820. height += ty;
  34821. }
  34822. textState.translateTextMatrix(tx, ty);
  34823. textChunk.str.push(glyphUnicode);
  34824. }
  34825. if (!font.vertical) {
  34826. textChunk.lastAdvanceWidth = width;
  34827. textChunk.width += width * textChunk.textAdvanceScale;
  34828. } else {
  34829. textChunk.lastAdvanceHeight = height;
  34830. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  34831. }
  34832. return textChunk;
  34833. }
  34834. function addFakeSpaces(width, strBuf) {
  34835. if (width < textContentItem.fakeSpaceMin) {
  34836. return;
  34837. }
  34838. if (width < textContentItem.fakeMultiSpaceMin) {
  34839. strBuf.push(' ');
  34840. return;
  34841. }
  34842. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  34843. while (fakeSpaces-- > 0) {
  34844. strBuf.push(' ');
  34845. }
  34846. }
  34847. function flushTextContentItem() {
  34848. if (!textContentItem.initialized) {
  34849. return;
  34850. }
  34851. textContent.items.push(runBidiTransform(textContentItem));
  34852. textContentItem.initialized = false;
  34853. textContentItem.str.length = 0;
  34854. }
  34855. var timeSlotManager = new TimeSlotManager();
  34856. return new Promise(function next(resolve, reject) {
  34857. task.ensureNotTerminated();
  34858. timeSlotManager.reset();
  34859. var stop, operation = {}, args = [];
  34860. while (!(stop = timeSlotManager.check())) {
  34861. // The arguments parsed by read() are not used beyond this loop, so
  34862. // we can reuse the same array on every iteration, thus avoiding
  34863. // unnecessary allocations.
  34864. args.length = 0;
  34865. operation.args = args;
  34866. if (!(preprocessor.read(operation))) {
  34867. break;
  34868. }
  34869. textState = stateManager.state;
  34870. var fn = operation.fn;
  34871. args = operation.args;
  34872. var advance;
  34873. switch (fn | 0) {
  34874. case OPS.setFont:
  34875. flushTextContentItem();
  34876. textState.fontSize = args[1];
  34877. return handleSetFont(args[0].name).then(function() {
  34878. next(resolve, reject);
  34879. }, reject);
  34880. case OPS.setTextRise:
  34881. flushTextContentItem();
  34882. textState.textRise = args[0];
  34883. break;
  34884. case OPS.setHScale:
  34885. flushTextContentItem();
  34886. textState.textHScale = args[0] / 100;
  34887. break;
  34888. case OPS.setLeading:
  34889. flushTextContentItem();
  34890. textState.leading = args[0];
  34891. break;
  34892. case OPS.moveText:
  34893. // Optimization to treat same line movement as advance
  34894. var isSameTextLine = !textState.font ? false :
  34895. ((textState.font.vertical ? args[0] : args[1]) === 0);
  34896. advance = args[0] - args[1];
  34897. if (isSameTextLine && textContentItem.initialized &&
  34898. advance > 0 &&
  34899. advance <= textContentItem.fakeMultiSpaceMax) {
  34900. textState.translateTextLineMatrix(args[0], args[1]);
  34901. textContentItem.width +=
  34902. (args[0] - textContentItem.lastAdvanceWidth);
  34903. textContentItem.height +=
  34904. (args[1] - textContentItem.lastAdvanceHeight);
  34905. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  34906. (args[1] - textContentItem.lastAdvanceHeight);
  34907. addFakeSpaces(diff, textContentItem.str);
  34908. break;
  34909. }
  34910. flushTextContentItem();
  34911. textState.translateTextLineMatrix(args[0], args[1]);
  34912. textState.textMatrix = textState.textLineMatrix.slice();
  34913. break;
  34914. case OPS.setLeadingMoveText:
  34915. flushTextContentItem();
  34916. textState.leading = -args[1];
  34917. textState.translateTextLineMatrix(args[0], args[1]);
  34918. textState.textMatrix = textState.textLineMatrix.slice();
  34919. break;
  34920. case OPS.nextLine:
  34921. flushTextContentItem();
  34922. textState.carriageReturn();
  34923. break;
  34924. case OPS.setTextMatrix:
  34925. flushTextContentItem();
  34926. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  34927. args[4], args[5]);
  34928. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  34929. args[4], args[5]);
  34930. break;
  34931. case OPS.setCharSpacing:
  34932. textState.charSpacing = args[0];
  34933. break;
  34934. case OPS.setWordSpacing:
  34935. textState.wordSpacing = args[0];
  34936. break;
  34937. case OPS.beginText:
  34938. flushTextContentItem();
  34939. textState.textMatrix = IDENTITY_MATRIX.slice();
  34940. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  34941. break;
  34942. case OPS.showSpacedText:
  34943. var items = args[0];
  34944. var offset;
  34945. for (var j = 0, jj = items.length; j < jj; j++) {
  34946. if (typeof items[j] === 'string') {
  34947. buildTextContentItem(items[j]);
  34948. } else {
  34949. ensureTextContentItem();
  34950. // PDF Specification 5.3.2 states:
  34951. // The number is expressed in thousandths of a unit of text
  34952. // space.
  34953. // This amount is subtracted from the current horizontal or
  34954. // vertical coordinate, depending on the writing mode.
  34955. // In the default coordinate system, a positive adjustment
  34956. // has the effect of moving the next glyph painted either to
  34957. // the left or down by the given amount.
  34958. advance = items[j] * textState.fontSize / 1000;
  34959. var breakTextRun = false;
  34960. if (textState.font.vertical) {
  34961. offset = advance *
  34962. (textState.textHScale * textState.textMatrix[2] +
  34963. textState.textMatrix[3]);
  34964. textState.translateTextMatrix(0, advance);
  34965. breakTextRun = textContentItem.textRunBreakAllowed &&
  34966. advance > textContentItem.fakeMultiSpaceMax;
  34967. if (!breakTextRun) {
  34968. // Value needs to be added to height to paint down.
  34969. textContentItem.height += offset;
  34970. }
  34971. } else {
  34972. advance = -advance;
  34973. offset = advance * (
  34974. textState.textHScale * textState.textMatrix[0] +
  34975. textState.textMatrix[1]);
  34976. textState.translateTextMatrix(advance, 0);
  34977. breakTextRun = textContentItem.textRunBreakAllowed &&
  34978. advance > textContentItem.fakeMultiSpaceMax;
  34979. if (!breakTextRun) {
  34980. // Value needs to be subtracted from width to paint left.
  34981. textContentItem.width += offset;
  34982. }
  34983. }
  34984. if (breakTextRun) {
  34985. flushTextContentItem();
  34986. } else if (advance > 0) {
  34987. addFakeSpaces(advance, textContentItem.str);
  34988. }
  34989. }
  34990. }
  34991. break;
  34992. case OPS.showText:
  34993. buildTextContentItem(args[0]);
  34994. break;
  34995. case OPS.nextLineShowText:
  34996. flushTextContentItem();
  34997. textState.carriageReturn();
  34998. buildTextContentItem(args[0]);
  34999. break;
  35000. case OPS.nextLineSetSpacingShowText:
  35001. flushTextContentItem();
  35002. textState.wordSpacing = args[0];
  35003. textState.charSpacing = args[1];
  35004. textState.carriageReturn();
  35005. buildTextContentItem(args[2]);
  35006. break;
  35007. case OPS.paintXObject:
  35008. flushTextContentItem();
  35009. if (args[0].code) {
  35010. break;
  35011. }
  35012. if (!xobjs) {
  35013. xobjs = (resources.get('XObject') || Dict.empty);
  35014. }
  35015. var name = args[0].name;
  35016. if (xobjsCache.key === name) {
  35017. if (xobjsCache.texts) {
  35018. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35019. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35020. }
  35021. break;
  35022. }
  35023. var xobj = xobjs.get(name);
  35024. if (!xobj) {
  35025. break;
  35026. }
  35027. assert(isStream(xobj), 'XObject should be a stream');
  35028. var type = xobj.dict.get('Subtype');
  35029. assert(isName(type),
  35030. 'XObject should have a Name subtype');
  35031. if ('Form' !== type.name) {
  35032. xobjsCache.key = name;
  35033. xobjsCache.texts = null;
  35034. break;
  35035. }
  35036. stateManager.save();
  35037. var matrix = xobj.dict.get('Matrix');
  35038. if (isArray(matrix) && matrix.length === 6) {
  35039. stateManager.transform(matrix);
  35040. }
  35041. return self.getTextContent(xobj, task,
  35042. xobj.dict.get('Resources') || resources, stateManager,
  35043. normalizeWhitespace).then(function (formTextContent) {
  35044. Util.appendToArray(textContent.items, formTextContent.items);
  35045. Util.extendObj(textContent.styles, formTextContent.styles);
  35046. stateManager.restore();
  35047. xobjsCache.key = name;
  35048. xobjsCache.texts = formTextContent;
  35049. next(resolve, reject);
  35050. }, reject);
  35051. case OPS.setGState:
  35052. flushTextContentItem();
  35053. var dictName = args[0];
  35054. var extGState = resources.get('ExtGState');
  35055. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35056. break;
  35057. }
  35058. var gsStateMap = extGState.get(dictName.name);
  35059. var gsStateFont = null;
  35060. for (var key in gsStateMap) {
  35061. if (key === 'Font') {
  35062. assert(!gsStateFont);
  35063. gsStateFont = gsStateMap[key];
  35064. }
  35065. }
  35066. if (gsStateFont) {
  35067. textState.fontSize = gsStateFont[1];
  35068. return handleSetFont(gsStateFont[0]).then(function() {
  35069. next(resolve, reject);
  35070. }, reject);
  35071. }
  35072. break;
  35073. } // switch
  35074. } // while
  35075. if (stop) {
  35076. deferred.then(function () {
  35077. next(resolve, reject);
  35078. }, reject);
  35079. return;
  35080. }
  35081. flushTextContentItem();
  35082. resolve(textContent);
  35083. });
  35084. },
  35085. extractDataStructures: function
  35086. partialEvaluatorExtractDataStructures(dict, baseDict,
  35087. xref, properties) {
  35088. // 9.10.2
  35089. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  35090. if (toUnicode) {
  35091. properties.toUnicode = this.readToUnicode(toUnicode);
  35092. }
  35093. if (properties.composite) {
  35094. // CIDSystemInfo helps to match CID to glyphs
  35095. var cidSystemInfo = dict.get('CIDSystemInfo');
  35096. if (isDict(cidSystemInfo)) {
  35097. properties.cidSystemInfo = {
  35098. registry: cidSystemInfo.get('Registry'),
  35099. ordering: cidSystemInfo.get('Ordering'),
  35100. supplement: cidSystemInfo.get('Supplement')
  35101. };
  35102. }
  35103. var cidToGidMap = dict.get('CIDToGIDMap');
  35104. if (isStream(cidToGidMap)) {
  35105. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  35106. }
  35107. }
  35108. // Based on 9.6.6 of the spec the encoding can come from multiple places
  35109. // and depends on the font type. The base encoding and differences are
  35110. // read here, but the encoding that is actually used is chosen during
  35111. // glyph mapping in the font.
  35112. // TODO: Loading the built in encoding in the font would allow the
  35113. // differences to be merged in here not require us to hold on to it.
  35114. var differences = [];
  35115. var baseEncodingName = null;
  35116. var encoding;
  35117. if (dict.has('Encoding')) {
  35118. encoding = dict.get('Encoding');
  35119. if (isDict(encoding)) {
  35120. baseEncodingName = encoding.get('BaseEncoding');
  35121. baseEncodingName = (isName(baseEncodingName) ?
  35122. baseEncodingName.name : null);
  35123. // Load the differences between the base and original
  35124. if (encoding.has('Differences')) {
  35125. var diffEncoding = encoding.get('Differences');
  35126. var index = 0;
  35127. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  35128. var data = diffEncoding[j];
  35129. if (isNum(data)) {
  35130. index = data;
  35131. } else if (isName(data)) {
  35132. differences[index++] = data.name;
  35133. } else if (isRef(data)) {
  35134. diffEncoding[j--] = xref.fetch(data);
  35135. continue;
  35136. } else {
  35137. error('Invalid entry in \'Differences\' array: ' + data);
  35138. }
  35139. }
  35140. }
  35141. } else if (isName(encoding)) {
  35142. baseEncodingName = encoding.name;
  35143. } else {
  35144. error('Encoding is not a Name nor a Dict');
  35145. }
  35146. // According to table 114 if the encoding is a named encoding it must be
  35147. // one of these predefined encodings.
  35148. if ((baseEncodingName !== 'MacRomanEncoding' &&
  35149. baseEncodingName !== 'MacExpertEncoding' &&
  35150. baseEncodingName !== 'WinAnsiEncoding')) {
  35151. baseEncodingName = null;
  35152. }
  35153. }
  35154. if (baseEncodingName) {
  35155. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  35156. } else {
  35157. encoding = (properties.type === 'TrueType' ?
  35158. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  35159. // The Symbolic attribute can be misused for regular fonts
  35160. // Heuristic: we have to check if the font is a standard one also
  35161. if (!!(properties.flags & FontFlags.Symbolic)) {
  35162. encoding = Encodings.MacRomanEncoding;
  35163. if (!properties.file) {
  35164. if (/Symbol/i.test(properties.name)) {
  35165. encoding = Encodings.SymbolSetEncoding;
  35166. } else if (/Dingbats/i.test(properties.name)) {
  35167. encoding = Encodings.ZapfDingbatsEncoding;
  35168. }
  35169. }
  35170. }
  35171. properties.defaultEncoding = encoding;
  35172. }
  35173. properties.differences = differences;
  35174. properties.baseEncodingName = baseEncodingName;
  35175. properties.dict = dict;
  35176. },
  35177. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  35178. var cmap, cmapObj = toUnicode;
  35179. if (isName(cmapObj)) {
  35180. cmap = CMapFactory.create(cmapObj,
  35181. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35182. if (cmap instanceof IdentityCMap) {
  35183. return new IdentityToUnicodeMap(0, 0xFFFF);
  35184. }
  35185. return new ToUnicodeMap(cmap.getMap());
  35186. } else if (isStream(cmapObj)) {
  35187. cmap = CMapFactory.create(cmapObj,
  35188. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35189. if (cmap instanceof IdentityCMap) {
  35190. return new IdentityToUnicodeMap(0, 0xFFFF);
  35191. }
  35192. var map = new Array(cmap.length);
  35193. // Convert UTF-16BE
  35194. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  35195. // to iterate over all keys.
  35196. cmap.forEach(function(charCode, token) {
  35197. var str = [];
  35198. for (var k = 0; k < token.length; k += 2) {
  35199. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35200. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  35201. str.push(w1);
  35202. continue;
  35203. }
  35204. k += 2;
  35205. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35206. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  35207. }
  35208. map[charCode] = String.fromCharCode.apply(String, str);
  35209. });
  35210. return new ToUnicodeMap(map);
  35211. }
  35212. return null;
  35213. },
  35214. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  35215. // Extract the encoding from the CIDToGIDMap
  35216. var glyphsData = cidToGidStream.getBytes();
  35217. // Set encoding 0 to later verify the font has an encoding
  35218. var result = [];
  35219. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  35220. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  35221. if (glyphID === 0) {
  35222. continue;
  35223. }
  35224. var code = j >> 1;
  35225. result[code] = glyphID;
  35226. }
  35227. return result;
  35228. },
  35229. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  35230. descriptor,
  35231. properties) {
  35232. var glyphsWidths = [];
  35233. var defaultWidth = 0;
  35234. var glyphsVMetrics = [];
  35235. var defaultVMetrics;
  35236. var i, ii, j, jj, start, code, widths;
  35237. if (properties.composite) {
  35238. defaultWidth = dict.get('DW') || 1000;
  35239. widths = dict.get('W');
  35240. if (widths) {
  35241. for (i = 0, ii = widths.length; i < ii; i++) {
  35242. start = widths[i++];
  35243. code = xref.fetchIfRef(widths[i]);
  35244. if (isArray(code)) {
  35245. for (j = 0, jj = code.length; j < jj; j++) {
  35246. glyphsWidths[start++] = code[j];
  35247. }
  35248. } else {
  35249. var width = widths[++i];
  35250. for (j = start; j <= code; j++) {
  35251. glyphsWidths[j] = width;
  35252. }
  35253. }
  35254. }
  35255. }
  35256. if (properties.vertical) {
  35257. var vmetrics = (dict.get('DW2') || [880, -1000]);
  35258. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  35259. vmetrics = dict.get('W2');
  35260. if (vmetrics) {
  35261. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  35262. start = vmetrics[i++];
  35263. code = xref.fetchIfRef(vmetrics[i]);
  35264. if (isArray(code)) {
  35265. for (j = 0, jj = code.length; j < jj; j++) {
  35266. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  35267. }
  35268. } else {
  35269. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  35270. for (j = start; j <= code; j++) {
  35271. glyphsVMetrics[j] = vmetric;
  35272. }
  35273. }
  35274. }
  35275. }
  35276. }
  35277. } else {
  35278. var firstChar = properties.firstChar;
  35279. widths = dict.get('Widths');
  35280. if (widths) {
  35281. j = firstChar;
  35282. for (i = 0, ii = widths.length; i < ii; i++) {
  35283. glyphsWidths[j++] = widths[i];
  35284. }
  35285. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  35286. } else {
  35287. // Trying get the BaseFont metrics (see comment above).
  35288. var baseFontName = dict.get('BaseFont');
  35289. if (isName(baseFontName)) {
  35290. var metrics = this.getBaseFontMetrics(baseFontName.name);
  35291. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  35292. properties);
  35293. defaultWidth = metrics.defaultWidth;
  35294. }
  35295. }
  35296. }
  35297. // Heuristic: detection of monospace font by checking all non-zero widths
  35298. var isMonospace = true;
  35299. var firstWidth = defaultWidth;
  35300. for (var glyph in glyphsWidths) {
  35301. var glyphWidth = glyphsWidths[glyph];
  35302. if (!glyphWidth) {
  35303. continue;
  35304. }
  35305. if (!firstWidth) {
  35306. firstWidth = glyphWidth;
  35307. continue;
  35308. }
  35309. if (firstWidth !== glyphWidth) {
  35310. isMonospace = false;
  35311. break;
  35312. }
  35313. }
  35314. if (isMonospace) {
  35315. properties.flags |= FontFlags.FixedPitch;
  35316. }
  35317. properties.defaultWidth = defaultWidth;
  35318. properties.widths = glyphsWidths;
  35319. properties.defaultVMetrics = defaultVMetrics;
  35320. properties.vmetrics = glyphsVMetrics;
  35321. },
  35322. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  35323. // Simulating descriptor flags attribute
  35324. var fontNameWoStyle = baseFontName.split('-')[0];
  35325. return (fontNameWoStyle in serifFonts) ||
  35326. (fontNameWoStyle.search(/serif/gi) !== -1);
  35327. },
  35328. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  35329. var defaultWidth = 0;
  35330. var widths = [];
  35331. var monospace = false;
  35332. var lookupName = (stdFontMap[name] || name);
  35333. if (!(lookupName in Metrics)) {
  35334. // Use default fonts for looking up font metrics if the passed
  35335. // font is not a base font
  35336. if (this.isSerifFont(name)) {
  35337. lookupName = 'Times-Roman';
  35338. } else {
  35339. lookupName = 'Helvetica';
  35340. }
  35341. }
  35342. var glyphWidths = Metrics[lookupName];
  35343. if (isNum(glyphWidths)) {
  35344. defaultWidth = glyphWidths;
  35345. monospace = true;
  35346. } else {
  35347. widths = glyphWidths;
  35348. }
  35349. return {
  35350. defaultWidth: defaultWidth,
  35351. monospace: monospace,
  35352. widths: widths
  35353. };
  35354. },
  35355. buildCharCodeToWidth:
  35356. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  35357. properties) {
  35358. var widths = Object.create(null);
  35359. var differences = properties.differences;
  35360. var encoding = properties.defaultEncoding;
  35361. for (var charCode = 0; charCode < 256; charCode++) {
  35362. if (charCode in differences &&
  35363. widthsByGlyphName[differences[charCode]]) {
  35364. widths[charCode] = widthsByGlyphName[differences[charCode]];
  35365. continue;
  35366. }
  35367. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  35368. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  35369. continue;
  35370. }
  35371. }
  35372. return widths;
  35373. },
  35374. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  35375. var baseDict = dict;
  35376. var type = dict.get('Subtype');
  35377. assert(isName(type), 'invalid font Subtype');
  35378. var composite = false;
  35379. var uint8array;
  35380. if (type.name === 'Type0') {
  35381. // If font is a composite
  35382. // - get the descendant font
  35383. // - set the type according to the descendant font
  35384. // - get the FontDescriptor from the descendant font
  35385. var df = dict.get('DescendantFonts');
  35386. if (!df) {
  35387. error('Descendant fonts are not specified');
  35388. }
  35389. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  35390. type = dict.get('Subtype');
  35391. assert(isName(type), 'invalid font Subtype');
  35392. composite = true;
  35393. }
  35394. var descriptor = dict.get('FontDescriptor');
  35395. if (descriptor) {
  35396. var hash = new MurmurHash3_64();
  35397. var encoding = baseDict.getRaw('Encoding');
  35398. if (isName(encoding)) {
  35399. hash.update(encoding.name);
  35400. } else if (isRef(encoding)) {
  35401. hash.update(encoding.num + '_' + encoding.gen);
  35402. } else if (isDict(encoding)) {
  35403. var keys = encoding.getKeys();
  35404. for (var i = 0, ii = keys.length; i < ii; i++) {
  35405. var entry = encoding.getRaw(keys[i]);
  35406. if (isName(entry)) {
  35407. hash.update(entry.name);
  35408. } else if (isRef(entry)) {
  35409. hash.update(entry.num + '_' + entry.gen);
  35410. } else if (isArray(entry)) { // 'Differences' entry.
  35411. // Ideally we should check the contents of the array, but to avoid
  35412. // parsing it here and then again in |extractDataStructures|,
  35413. // we only use the array length for now (fixes bug1157493.pdf).
  35414. hash.update(entry.length.toString());
  35415. }
  35416. }
  35417. }
  35418. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  35419. if (isStream(toUnicode)) {
  35420. var stream = toUnicode.str || toUnicode;
  35421. uint8array = stream.buffer ?
  35422. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  35423. new Uint8Array(stream.bytes.buffer,
  35424. stream.start, stream.end - stream.start);
  35425. hash.update(uint8array);
  35426. } else if (isName(toUnicode)) {
  35427. hash.update(toUnicode.name);
  35428. }
  35429. var widths = dict.get('Widths') || baseDict.get('Widths');
  35430. if (widths) {
  35431. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  35432. hash.update(uint8array);
  35433. }
  35434. }
  35435. return {
  35436. descriptor: descriptor,
  35437. dict: dict,
  35438. baseDict: baseDict,
  35439. composite: composite,
  35440. type: type.name,
  35441. hash: hash ? hash.hexdigest() : ''
  35442. };
  35443. },
  35444. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  35445. xref) {
  35446. var baseDict = preEvaluatedFont.baseDict;
  35447. var dict = preEvaluatedFont.dict;
  35448. var composite = preEvaluatedFont.composite;
  35449. var descriptor = preEvaluatedFont.descriptor;
  35450. var type = preEvaluatedFont.type;
  35451. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  35452. var properties;
  35453. if (!descriptor) {
  35454. if (type === 'Type3') {
  35455. // FontDescriptor is only required for Type3 fonts when the document
  35456. // is a tagged pdf. Create a barbebones one to get by.
  35457. descriptor = new Dict(null);
  35458. descriptor.set('FontName', Name.get(type));
  35459. descriptor.set('FontBBox', dict.get('FontBBox'));
  35460. } else {
  35461. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  35462. // FontDescriptor was not required.
  35463. // This case is here for compatibility.
  35464. var baseFontName = dict.get('BaseFont');
  35465. if (!isName(baseFontName)) {
  35466. error('Base font is not specified');
  35467. }
  35468. // Using base font name as a font name.
  35469. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  35470. var metrics = this.getBaseFontMetrics(baseFontName);
  35471. // Simulating descriptor flags attribute
  35472. var fontNameWoStyle = baseFontName.split('-')[0];
  35473. var flags =
  35474. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  35475. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  35476. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  35477. FontFlags.Nonsymbolic);
  35478. properties = {
  35479. type: type,
  35480. name: baseFontName,
  35481. widths: metrics.widths,
  35482. defaultWidth: metrics.defaultWidth,
  35483. flags: flags,
  35484. firstChar: 0,
  35485. lastChar: maxCharIndex
  35486. };
  35487. this.extractDataStructures(dict, dict, xref, properties);
  35488. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  35489. properties);
  35490. return new Font(baseFontName, null, properties);
  35491. }
  35492. }
  35493. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  35494. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  35495. // to ignore this rule when a variant of a standart font is used.
  35496. // TODO Fill the width array depending on which of the base font this is
  35497. // a variant.
  35498. var firstChar = (dict.get('FirstChar') || 0);
  35499. var lastChar = (dict.get('LastChar') || maxCharIndex);
  35500. var fontName = descriptor.get('FontName');
  35501. var baseFont = dict.get('BaseFont');
  35502. // Some bad PDFs have a string as the font name.
  35503. if (isString(fontName)) {
  35504. fontName = Name.get(fontName);
  35505. }
  35506. if (isString(baseFont)) {
  35507. baseFont = Name.get(baseFont);
  35508. }
  35509. if (type !== 'Type3') {
  35510. var fontNameStr = fontName && fontName.name;
  35511. var baseFontStr = baseFont && baseFont.name;
  35512. if (fontNameStr !== baseFontStr) {
  35513. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  35514. '" but should be the same as the Font\'s BaseFont "' +
  35515. baseFontStr + '"');
  35516. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  35517. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  35518. if (fontNameStr && baseFontStr &&
  35519. baseFontStr.indexOf(fontNameStr) === 0) {
  35520. fontName = baseFont;
  35521. }
  35522. }
  35523. }
  35524. fontName = (fontName || baseFont);
  35525. assert(isName(fontName), 'invalid font name');
  35526. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  35527. if (fontFile) {
  35528. if (fontFile.dict) {
  35529. var subtype = fontFile.dict.get('Subtype');
  35530. if (subtype) {
  35531. subtype = subtype.name;
  35532. }
  35533. var length1 = fontFile.dict.get('Length1');
  35534. var length2 = fontFile.dict.get('Length2');
  35535. }
  35536. }
  35537. properties = {
  35538. type: type,
  35539. name: fontName.name,
  35540. subtype: subtype,
  35541. file: fontFile,
  35542. length1: length1,
  35543. length2: length2,
  35544. loadedName: baseDict.loadedName,
  35545. composite: composite,
  35546. wideChars: composite,
  35547. fixedPitch: false,
  35548. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  35549. firstChar: firstChar || 0,
  35550. lastChar: (lastChar || maxCharIndex),
  35551. bbox: descriptor.get('FontBBox'),
  35552. ascent: descriptor.get('Ascent'),
  35553. descent: descriptor.get('Descent'),
  35554. xHeight: descriptor.get('XHeight'),
  35555. capHeight: descriptor.get('CapHeight'),
  35556. flags: descriptor.get('Flags'),
  35557. italicAngle: descriptor.get('ItalicAngle'),
  35558. coded: false
  35559. };
  35560. if (composite) {
  35561. var cidEncoding = baseDict.get('Encoding');
  35562. if (isName(cidEncoding)) {
  35563. properties.cidEncoding = cidEncoding.name;
  35564. }
  35565. properties.cMap = CMapFactory.create(cidEncoding,
  35566. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35567. properties.vertical = properties.cMap.vertical;
  35568. }
  35569. this.extractDataStructures(dict, baseDict, xref, properties);
  35570. this.extractWidths(dict, xref, descriptor, properties);
  35571. if (type === 'Type3') {
  35572. properties.isType3Font = true;
  35573. }
  35574. return new Font(fontName.name, fontFile, properties);
  35575. }
  35576. };
  35577. return PartialEvaluator;
  35578. })();
  35579. var TranslatedFont = (function TranslatedFontClosure() {
  35580. function TranslatedFont(loadedName, font, dict) {
  35581. this.loadedName = loadedName;
  35582. this.font = font;
  35583. this.dict = dict;
  35584. this.type3Loaded = null;
  35585. this.sent = false;
  35586. }
  35587. TranslatedFont.prototype = {
  35588. send: function (handler) {
  35589. if (this.sent) {
  35590. return;
  35591. }
  35592. var fontData = this.font.exportData();
  35593. handler.send('commonobj', [
  35594. this.loadedName,
  35595. 'Font',
  35596. fontData
  35597. ]);
  35598. this.sent = true;
  35599. },
  35600. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  35601. assert(this.font.isType3Font);
  35602. if (this.type3Loaded) {
  35603. return this.type3Loaded;
  35604. }
  35605. var translatedFont = this.font;
  35606. var loadCharProcsPromise = Promise.resolve();
  35607. var charProcs = this.dict.get('CharProcs').getAll();
  35608. var fontResources = this.dict.get('Resources') || resources;
  35609. var charProcKeys = Object.keys(charProcs);
  35610. var charProcOperatorList = {};
  35611. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  35612. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  35613. var glyphStream = charProcs[key];
  35614. var operatorList = new OperatorList();
  35615. return evaluator.getOperatorList(glyphStream, task, fontResources,
  35616. operatorList).then(function () {
  35617. charProcOperatorList[key] = operatorList.getIR();
  35618. // Add the dependencies to the parent operator list so they are
  35619. // resolved before sub operator list is executed synchronously.
  35620. parentOperatorList.addDependencies(operatorList.dependencies);
  35621. }, function (reason) {
  35622. warn('Type3 font resource \"' + key + '\" is not available');
  35623. var operatorList = new OperatorList();
  35624. charProcOperatorList[key] = operatorList.getIR();
  35625. });
  35626. }.bind(this, charProcKeys[i]));
  35627. }
  35628. this.type3Loaded = loadCharProcsPromise.then(function () {
  35629. translatedFont.charProcOperatorList = charProcOperatorList;
  35630. });
  35631. return this.type3Loaded;
  35632. }
  35633. };
  35634. return TranslatedFont;
  35635. })();
  35636. var OperatorList = (function OperatorListClosure() {
  35637. var CHUNK_SIZE = 1000;
  35638. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  35639. function getTransfers(queue) {
  35640. var transfers = [];
  35641. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  35642. for (var i = 0, ii = queue.length; i < ii; i++) {
  35643. switch (fnArray[i]) {
  35644. case OPS.paintInlineImageXObject:
  35645. case OPS.paintInlineImageXObjectGroup:
  35646. case OPS.paintImageMaskXObject:
  35647. var arg = argsArray[i][0]; // first param in imgData
  35648. if (!arg.cached) {
  35649. transfers.push(arg.data.buffer);
  35650. }
  35651. break;
  35652. }
  35653. }
  35654. return transfers;
  35655. }
  35656. function OperatorList(intent, messageHandler, pageIndex) {
  35657. this.messageHandler = messageHandler;
  35658. this.fnArray = [];
  35659. this.argsArray = [];
  35660. this.dependencies = {};
  35661. this._totalLength = 0;
  35662. this.pageIndex = pageIndex;
  35663. this.intent = intent;
  35664. }
  35665. OperatorList.prototype = {
  35666. get length() {
  35667. return this.argsArray.length;
  35668. },
  35669. /**
  35670. * @returns {number} The total length of the entire operator list,
  35671. * since `this.length === 0` after flushing.
  35672. */
  35673. get totalLength() {
  35674. return (this._totalLength + this.length);
  35675. },
  35676. addOp: function(fn, args) {
  35677. this.fnArray.push(fn);
  35678. this.argsArray.push(args);
  35679. if (this.messageHandler) {
  35680. if (this.fnArray.length >= CHUNK_SIZE) {
  35681. this.flush();
  35682. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  35683. (fn === OPS.restore || fn === OPS.endText)) {
  35684. // heuristic to flush on boundary of restore or endText
  35685. this.flush();
  35686. }
  35687. }
  35688. },
  35689. addDependency: function(dependency) {
  35690. if (dependency in this.dependencies) {
  35691. return;
  35692. }
  35693. this.dependencies[dependency] = true;
  35694. this.addOp(OPS.dependency, [dependency]);
  35695. },
  35696. addDependencies: function(dependencies) {
  35697. for (var key in dependencies) {
  35698. this.addDependency(key);
  35699. }
  35700. },
  35701. addOpList: function(opList) {
  35702. Util.extendObj(this.dependencies, opList.dependencies);
  35703. for (var i = 0, ii = opList.length; i < ii; i++) {
  35704. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  35705. }
  35706. },
  35707. getIR: function() {
  35708. return {
  35709. fnArray: this.fnArray,
  35710. argsArray: this.argsArray,
  35711. length: this.length
  35712. };
  35713. },
  35714. flush: function(lastChunk) {
  35715. if (this.intent !== 'oplist') {
  35716. new QueueOptimizer().optimize(this);
  35717. }
  35718. var transfers = getTransfers(this);
  35719. var length = this.length;
  35720. this._totalLength += length;
  35721. this.messageHandler.send('RenderPageChunk', {
  35722. operatorList: {
  35723. fnArray: this.fnArray,
  35724. argsArray: this.argsArray,
  35725. lastChunk: lastChunk,
  35726. length: length
  35727. },
  35728. pageIndex: this.pageIndex,
  35729. intent: this.intent
  35730. }, transfers);
  35731. this.dependencies = {};
  35732. this.fnArray.length = 0;
  35733. this.argsArray.length = 0;
  35734. }
  35735. };
  35736. return OperatorList;
  35737. })();
  35738. var StateManager = (function StateManagerClosure() {
  35739. function StateManager(initialState) {
  35740. this.state = initialState;
  35741. this.stateStack = [];
  35742. }
  35743. StateManager.prototype = {
  35744. save: function () {
  35745. var old = this.state;
  35746. this.stateStack.push(this.state);
  35747. this.state = old.clone();
  35748. },
  35749. restore: function () {
  35750. var prev = this.stateStack.pop();
  35751. if (prev) {
  35752. this.state = prev;
  35753. }
  35754. },
  35755. transform: function (args) {
  35756. this.state.ctm = Util.transform(this.state.ctm, args);
  35757. }
  35758. };
  35759. return StateManager;
  35760. })();
  35761. var TextState = (function TextStateClosure() {
  35762. function TextState() {
  35763. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35764. this.fontSize = 0;
  35765. this.font = null;
  35766. this.fontMatrix = FONT_IDENTITY_MATRIX;
  35767. this.textMatrix = IDENTITY_MATRIX.slice();
  35768. this.textLineMatrix = IDENTITY_MATRIX.slice();
  35769. this.charSpacing = 0;
  35770. this.wordSpacing = 0;
  35771. this.leading = 0;
  35772. this.textHScale = 1;
  35773. this.textRise = 0;
  35774. }
  35775. TextState.prototype = {
  35776. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35777. var m = this.textMatrix;
  35778. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35779. },
  35780. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35781. var m = this.textLineMatrix;
  35782. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35783. },
  35784. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  35785. var m = this.textMatrix;
  35786. m[4] = m[0] * x + m[2] * y + m[4];
  35787. m[5] = m[1] * x + m[3] * y + m[5];
  35788. },
  35789. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  35790. var m = this.textLineMatrix;
  35791. m[4] = m[0] * x + m[2] * y + m[4];
  35792. m[5] = m[1] * x + m[3] * y + m[5];
  35793. },
  35794. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  35795. // 9.4.4 Text Space Details
  35796. var tsm = [this.fontSize * this.textHScale, 0,
  35797. 0, this.fontSize,
  35798. 0, this.textRise];
  35799. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  35800. },
  35801. carriageReturn: function TextState_carriageReturn() {
  35802. this.translateTextLineMatrix(0, -this.leading);
  35803. this.textMatrix = this.textLineMatrix.slice();
  35804. },
  35805. clone: function TextState_clone() {
  35806. var clone = Object.create(this);
  35807. clone.textMatrix = this.textMatrix.slice();
  35808. clone.textLineMatrix = this.textLineMatrix.slice();
  35809. clone.fontMatrix = this.fontMatrix.slice();
  35810. return clone;
  35811. }
  35812. };
  35813. return TextState;
  35814. })();
  35815. var EvalState = (function EvalStateClosure() {
  35816. function EvalState() {
  35817. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35818. this.font = null;
  35819. this.textRenderingMode = TextRenderingMode.FILL;
  35820. this.fillColorSpace = ColorSpace.singletons.gray;
  35821. this.strokeColorSpace = ColorSpace.singletons.gray;
  35822. }
  35823. EvalState.prototype = {
  35824. clone: function CanvasExtraState_clone() {
  35825. return Object.create(this);
  35826. },
  35827. };
  35828. return EvalState;
  35829. })();
  35830. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  35831. // Specifies properties for each command
  35832. //
  35833. // If variableArgs === true: [0, `numArgs`] expected
  35834. // If variableArgs === false: exactly `numArgs` expected
  35835. var OP_MAP = {
  35836. // Graphic state
  35837. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  35838. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  35839. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  35840. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  35841. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  35842. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  35843. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  35844. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  35845. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  35846. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  35847. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  35848. // Path
  35849. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  35850. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  35851. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  35852. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  35853. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  35854. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  35855. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  35856. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  35857. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  35858. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35859. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35860. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  35861. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  35862. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  35863. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  35864. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  35865. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  35866. // Clipping
  35867. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  35868. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  35869. // Text
  35870. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  35871. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  35872. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  35873. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  35874. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  35875. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  35876. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  35877. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  35878. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  35879. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  35880. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  35881. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  35882. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  35883. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  35884. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  35885. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  35886. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  35887. variableArgs: false },
  35888. // Type3 fonts
  35889. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  35890. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  35891. // Color
  35892. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  35893. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  35894. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  35895. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  35896. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  35897. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  35898. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  35899. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  35900. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  35901. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  35902. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  35903. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  35904. // Shading
  35905. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  35906. // Images
  35907. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  35908. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  35909. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  35910. // XObjects
  35911. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  35912. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  35913. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  35914. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  35915. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  35916. variableArgs: false },
  35917. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  35918. // Compatibility
  35919. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  35920. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  35921. // (reserved partial commands for the lexer)
  35922. BM: null,
  35923. BD: null,
  35924. 'true': null,
  35925. fa: null,
  35926. fal: null,
  35927. fals: null,
  35928. 'false': null,
  35929. nu: null,
  35930. nul: null,
  35931. 'null': null
  35932. };
  35933. function EvaluatorPreprocessor(stream, xref, stateManager) {
  35934. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  35935. // dictionary
  35936. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  35937. this.stateManager = stateManager;
  35938. this.nonProcessedArgs = [];
  35939. }
  35940. EvaluatorPreprocessor.prototype = {
  35941. get savedStatesDepth() {
  35942. return this.stateManager.stateStack.length;
  35943. },
  35944. // |operation| is an object with two fields:
  35945. //
  35946. // - |fn| is an out param.
  35947. //
  35948. // - |args| is an inout param. On entry, it should have one of two values.
  35949. //
  35950. // - An empty array. This indicates that the caller is providing the
  35951. // array in which the args will be stored in. The caller should use
  35952. // this value if it can reuse a single array for each call to read().
  35953. //
  35954. // - |null|. This indicates that the caller needs this function to create
  35955. // the array in which any args are stored in. If there are zero args,
  35956. // this function will leave |operation.args| as |null| (thus avoiding
  35957. // allocations that would occur if we used an empty array to represent
  35958. // zero arguments). Otherwise, it will replace |null| with a new array
  35959. // containing the arguments. The caller should use this value if it
  35960. // cannot reuse an array for each call to read().
  35961. //
  35962. // These two modes are present because this function is very hot and so
  35963. // avoiding allocations where possible is worthwhile.
  35964. //
  35965. read: function EvaluatorPreprocessor_read(operation) {
  35966. var args = operation.args;
  35967. while (true) {
  35968. var obj = this.parser.getObj();
  35969. if (isCmd(obj)) {
  35970. var cmd = obj.cmd;
  35971. // Check that the command is valid
  35972. var opSpec = OP_MAP[cmd];
  35973. if (!opSpec) {
  35974. warn('Unknown command "' + cmd + '"');
  35975. continue;
  35976. }
  35977. var fn = opSpec.id;
  35978. var numArgs = opSpec.numArgs;
  35979. var argsLength = args !== null ? args.length : 0;
  35980. if (!opSpec.variableArgs) {
  35981. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  35982. if (argsLength !== numArgs) {
  35983. var nonProcessedArgs = this.nonProcessedArgs;
  35984. while (argsLength > numArgs) {
  35985. nonProcessedArgs.push(args.shift());
  35986. argsLength--;
  35987. }
  35988. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  35989. if (!args) {
  35990. args = [];
  35991. }
  35992. args.unshift(nonProcessedArgs.pop());
  35993. argsLength++;
  35994. }
  35995. }
  35996. if (argsLength < numArgs) {
  35997. // If we receive too few args, it's not possible to possible
  35998. // to execute the command, so skip the command
  35999. info('Command ' + fn + ': because expected ' +
  36000. numArgs + ' args, but received ' + argsLength +
  36001. ' args; skipping');
  36002. args = null;
  36003. continue;
  36004. }
  36005. } else if (argsLength > numArgs) {
  36006. info('Command ' + fn + ': expected [0,' + numArgs +
  36007. '] args, but received ' + argsLength + ' args');
  36008. }
  36009. // TODO figure out how to type-check vararg functions
  36010. this.preprocessCommand(fn, args);
  36011. operation.fn = fn;
  36012. operation.args = args;
  36013. return true;
  36014. } else {
  36015. if (isEOF(obj)) {
  36016. return false; // no more commands
  36017. }
  36018. // argument
  36019. if (obj !== null) {
  36020. if (!args) {
  36021. args = [];
  36022. }
  36023. args.push((obj instanceof Dict ? obj.getAll() : obj));
  36024. assert(args.length <= 33, 'Too many arguments');
  36025. }
  36026. }
  36027. }
  36028. },
  36029. preprocessCommand:
  36030. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36031. switch (fn | 0) {
  36032. case OPS.save:
  36033. this.stateManager.save();
  36034. break;
  36035. case OPS.restore:
  36036. this.stateManager.restore();
  36037. break;
  36038. case OPS.transform:
  36039. this.stateManager.transform(args);
  36040. break;
  36041. }
  36042. }
  36043. };
  36044. return EvaluatorPreprocessor;
  36045. })();
  36046. var QueueOptimizer = (function QueueOptimizerClosure() {
  36047. function addState(parentState, pattern, fn) {
  36048. var state = parentState;
  36049. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  36050. var item = pattern[i];
  36051. state = (state[item] || (state[item] = []));
  36052. }
  36053. state[pattern[pattern.length - 1]] = fn;
  36054. }
  36055. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36056. argsArray) {
  36057. // Handles special case of mainly LaTeX documents which use image masks to
  36058. // draw lines with the current fill style.
  36059. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  36060. // have been found at iFirstSave.
  36061. var iFirstPIMXO = iFirstSave + 2;
  36062. for (var i = 0; i < count; i++) {
  36063. var arg = argsArray[iFirstPIMXO + 4 * i];
  36064. var imageMask = arg.length === 1 && arg[0];
  36065. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  36066. (!imageMask.data.length ||
  36067. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  36068. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  36069. continue;
  36070. }
  36071. break;
  36072. }
  36073. return count - i;
  36074. }
  36075. var InitialState = [];
  36076. // This replaces (save, transform, paintInlineImageXObject, restore)+
  36077. // sequences with one |paintInlineImageXObjectGroup| operation.
  36078. addState(InitialState,
  36079. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  36080. function foundInlineImageGroup(context) {
  36081. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  36082. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  36083. var MAX_WIDTH = 1000;
  36084. var IMAGE_PADDING = 1;
  36085. var fnArray = context.fnArray, argsArray = context.argsArray;
  36086. var curr = context.iCurr;
  36087. var iFirstSave = curr - 3;
  36088. var iFirstTransform = curr - 2;
  36089. var iFirstPIIXO = curr - 1;
  36090. // Look for the quartets.
  36091. var i = iFirstSave + 4;
  36092. var ii = fnArray.length;
  36093. while (i + 3 < ii) {
  36094. if (fnArray[i] !== OPS.save ||
  36095. fnArray[i + 1] !== OPS.transform ||
  36096. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  36097. fnArray[i + 3] !== OPS.restore) {
  36098. break; // ops don't match
  36099. }
  36100. i += 4;
  36101. }
  36102. // At this point, i is the index of the first op past the last valid
  36103. // quartet.
  36104. var count = Math.min((i - iFirstSave) / 4,
  36105. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  36106. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  36107. return i;
  36108. }
  36109. // assuming that heights of those image is too small (~1 pixel)
  36110. // packing as much as possible by lines
  36111. var maxX = 0;
  36112. var map = [], maxLineHeight = 0;
  36113. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  36114. var q;
  36115. for (q = 0; q < count; q++) {
  36116. var transform = argsArray[iFirstTransform + (q << 2)];
  36117. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  36118. if (currentX + img.width > MAX_WIDTH) {
  36119. // starting new line
  36120. maxX = Math.max(maxX, currentX);
  36121. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  36122. currentX = 0;
  36123. maxLineHeight = 0;
  36124. }
  36125. map.push({
  36126. transform: transform,
  36127. x: currentX, y: currentY,
  36128. w: img.width, h: img.height
  36129. });
  36130. currentX += img.width + 2 * IMAGE_PADDING;
  36131. maxLineHeight = Math.max(maxLineHeight, img.height);
  36132. }
  36133. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  36134. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  36135. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  36136. var imgRowSize = imgWidth << 2;
  36137. for (q = 0; q < count; q++) {
  36138. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  36139. // Copy image by lines and extends pixels into padding.
  36140. var rowSize = map[q].w << 2;
  36141. var dataOffset = 0;
  36142. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  36143. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  36144. for (var k = 0, kk = map[q].h; k < kk; k++) {
  36145. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  36146. dataOffset += rowSize;
  36147. offset += imgRowSize;
  36148. }
  36149. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  36150. while (offset >= 0) {
  36151. data[offset - 4] = data[offset];
  36152. data[offset - 3] = data[offset + 1];
  36153. data[offset - 2] = data[offset + 2];
  36154. data[offset - 1] = data[offset + 3];
  36155. data[offset + rowSize] = data[offset + rowSize - 4];
  36156. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  36157. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  36158. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  36159. offset -= imgRowSize;
  36160. }
  36161. }
  36162. // Replace queue items.
  36163. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  36164. argsArray.splice(iFirstSave, count * 4,
  36165. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  36166. data: imgData }, map]);
  36167. return iFirstSave + 1;
  36168. });
  36169. // This replaces (save, transform, paintImageMaskXObject, restore)+
  36170. // sequences with one |paintImageMaskXObjectGroup| or one
  36171. // |paintImageMaskXObjectRepeat| operation.
  36172. addState(InitialState,
  36173. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  36174. function foundImageMaskGroup(context) {
  36175. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  36176. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  36177. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  36178. var fnArray = context.fnArray, argsArray = context.argsArray;
  36179. var curr = context.iCurr;
  36180. var iFirstSave = curr - 3;
  36181. var iFirstTransform = curr - 2;
  36182. var iFirstPIMXO = curr - 1;
  36183. // Look for the quartets.
  36184. var i = iFirstSave + 4;
  36185. var ii = fnArray.length;
  36186. while (i + 3 < ii) {
  36187. if (fnArray[i] !== OPS.save ||
  36188. fnArray[i + 1] !== OPS.transform ||
  36189. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  36190. fnArray[i + 3] !== OPS.restore) {
  36191. break; // ops don't match
  36192. }
  36193. i += 4;
  36194. }
  36195. // At this point, i is the index of the first op past the last valid
  36196. // quartet.
  36197. var count = (i - iFirstSave) / 4;
  36198. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36199. argsArray);
  36200. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  36201. return i;
  36202. }
  36203. var q;
  36204. var isSameImage = false;
  36205. var iTransform, transformArgs;
  36206. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  36207. if (argsArray[iFirstTransform][1] === 0 &&
  36208. argsArray[iFirstTransform][2] === 0) {
  36209. isSameImage = true;
  36210. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36211. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36212. iTransform = iFirstTransform + 4;
  36213. var iPIMXO = iFirstPIMXO + 4;
  36214. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  36215. transformArgs = argsArray[iTransform];
  36216. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  36217. transformArgs[0] !== firstTransformArg0 ||
  36218. transformArgs[1] !== 0 ||
  36219. transformArgs[2] !== 0 ||
  36220. transformArgs[3] !== firstTransformArg3) {
  36221. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  36222. isSameImage = false;
  36223. } else {
  36224. count = q;
  36225. }
  36226. break; // different image or transform
  36227. }
  36228. }
  36229. }
  36230. if (isSameImage) {
  36231. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  36232. var positions = new Float32Array(count * 2);
  36233. iTransform = iFirstTransform;
  36234. for (q = 0; q < count; q++, iTransform += 4) {
  36235. transformArgs = argsArray[iTransform];
  36236. positions[(q << 1)] = transformArgs[4];
  36237. positions[(q << 1) + 1] = transformArgs[5];
  36238. }
  36239. // Replace queue items.
  36240. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  36241. argsArray.splice(iFirstSave, count * 4,
  36242. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  36243. } else {
  36244. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  36245. var images = [];
  36246. for (q = 0; q < count; q++) {
  36247. transformArgs = argsArray[iFirstTransform + (q << 2)];
  36248. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  36249. images.push({ data: maskParams.data, width: maskParams.width,
  36250. height: maskParams.height,
  36251. transform: transformArgs });
  36252. }
  36253. // Replace queue items.
  36254. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  36255. argsArray.splice(iFirstSave, count * 4, [images]);
  36256. }
  36257. return iFirstSave + 1;
  36258. });
  36259. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  36260. // with one paintImageXObjectRepeat operation, if the |transform| and
  36261. // |paintImageXObjectRepeat| ops are appropriate.
  36262. addState(InitialState,
  36263. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  36264. function (context) {
  36265. var MIN_IMAGES_IN_BLOCK = 3;
  36266. var MAX_IMAGES_IN_BLOCK = 1000;
  36267. var fnArray = context.fnArray, argsArray = context.argsArray;
  36268. var curr = context.iCurr;
  36269. var iFirstSave = curr - 3;
  36270. var iFirstTransform = curr - 2;
  36271. var iFirstPIXO = curr - 1;
  36272. var iFirstRestore = curr;
  36273. if (argsArray[iFirstTransform][1] !== 0 ||
  36274. argsArray[iFirstTransform][2] !== 0) {
  36275. return iFirstRestore + 1; // transform has the wrong form
  36276. }
  36277. // Look for the quartets.
  36278. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  36279. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36280. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36281. var i = iFirstSave + 4;
  36282. var ii = fnArray.length;
  36283. while (i + 3 < ii) {
  36284. if (fnArray[i] !== OPS.save ||
  36285. fnArray[i + 1] !== OPS.transform ||
  36286. fnArray[i + 2] !== OPS.paintImageXObject ||
  36287. fnArray[i + 3] !== OPS.restore) {
  36288. break; // ops don't match
  36289. }
  36290. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  36291. argsArray[i + 1][1] !== 0 ||
  36292. argsArray[i + 1][2] !== 0 ||
  36293. argsArray[i + 1][3] !== firstTransformArg3) {
  36294. break; // transforms don't match
  36295. }
  36296. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  36297. break; // images don't match
  36298. }
  36299. i += 4;
  36300. }
  36301. // At this point, i is the index of the first op past the last valid
  36302. // quartet.
  36303. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  36304. if (count < MIN_IMAGES_IN_BLOCK) {
  36305. return i;
  36306. }
  36307. // Extract the (x,y) positions from all of the matching transforms.
  36308. var positions = new Float32Array(count * 2);
  36309. var iTransform = iFirstTransform;
  36310. for (var q = 0; q < count; q++, iTransform += 4) {
  36311. var transformArgs = argsArray[iTransform];
  36312. positions[(q << 1)] = transformArgs[4];
  36313. positions[(q << 1) + 1] = transformArgs[5];
  36314. }
  36315. // Replace queue items.
  36316. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  36317. positions];
  36318. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  36319. argsArray.splice(iFirstSave, count * 4, args);
  36320. return iFirstSave + 1;
  36321. });
  36322. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  36323. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  36324. // sequences, if the font for each one is the same.
  36325. addState(InitialState,
  36326. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  36327. function (context) {
  36328. var MIN_CHARS_IN_BLOCK = 3;
  36329. var MAX_CHARS_IN_BLOCK = 1000;
  36330. var fnArray = context.fnArray, argsArray = context.argsArray;
  36331. var curr = context.iCurr;
  36332. var iFirstBeginText = curr - 4;
  36333. var iFirstSetFont = curr - 3;
  36334. var iFirstSetTextMatrix = curr - 2;
  36335. var iFirstShowText = curr - 1;
  36336. var iFirstEndText = curr;
  36337. // Look for the quintets.
  36338. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  36339. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  36340. var i = iFirstBeginText + 5;
  36341. var ii = fnArray.length;
  36342. while (i + 4 < ii) {
  36343. if (fnArray[i] !== OPS.beginText ||
  36344. fnArray[i + 1] !== OPS.setFont ||
  36345. fnArray[i + 2] !== OPS.setTextMatrix ||
  36346. fnArray[i + 3] !== OPS.showText ||
  36347. fnArray[i + 4] !== OPS.endText) {
  36348. break; // ops don't match
  36349. }
  36350. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  36351. argsArray[i + 1][1] !== firstSetFontArg1) {
  36352. break; // fonts don't match
  36353. }
  36354. i += 5;
  36355. }
  36356. // At this point, i is the index of the first op past the last valid
  36357. // quintet.
  36358. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  36359. if (count < MIN_CHARS_IN_BLOCK) {
  36360. return i;
  36361. }
  36362. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  36363. // showText, endText), include that as well. (E.g. <something> might be
  36364. // |dependency|.)
  36365. var iFirst = iFirstBeginText;
  36366. if (iFirstBeginText >= 4 &&
  36367. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  36368. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  36369. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  36370. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  36371. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  36372. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  36373. count++;
  36374. iFirst -= 5;
  36375. }
  36376. // Remove (endText, beginText, setFont) trios.
  36377. var iEndText = iFirst + 4;
  36378. for (var q = 1; q < count; q++) {
  36379. fnArray.splice(iEndText, 3);
  36380. argsArray.splice(iEndText, 3);
  36381. iEndText += 2;
  36382. }
  36383. return iEndText + 1;
  36384. });
  36385. function QueueOptimizer() {}
  36386. QueueOptimizer.prototype = {
  36387. optimize: function QueueOptimizer_optimize(queue) {
  36388. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36389. var context = {
  36390. iCurr: 0,
  36391. fnArray: fnArray,
  36392. argsArray: argsArray
  36393. };
  36394. var state;
  36395. var i = 0, ii = fnArray.length;
  36396. while (i < ii) {
  36397. state = (state || InitialState)[fnArray[i]];
  36398. if (typeof state === 'function') { // we found some handler
  36399. context.iCurr = i;
  36400. // state() returns the index of the first non-matching op (if we
  36401. // didn't match) or the first op past the modified ops (if we did
  36402. // match and replace).
  36403. i = state(context);
  36404. state = undefined; // reset the state machine
  36405. ii = context.fnArray.length;
  36406. } else {
  36407. i++;
  36408. }
  36409. }
  36410. }
  36411. };
  36412. return QueueOptimizer;
  36413. })();
  36414. exports.OperatorList = OperatorList;
  36415. exports.PartialEvaluator = PartialEvaluator;
  36416. }));
  36417. (function (root, factory) {
  36418. {
  36419. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  36420. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  36421. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  36422. }
  36423. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  36424. coreColorSpace, coreObj, coreEvaluator) {
  36425. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  36426. var AnnotationFlag = sharedUtil.AnnotationFlag;
  36427. var AnnotationType = sharedUtil.AnnotationType;
  36428. var OPS = sharedUtil.OPS;
  36429. var Util = sharedUtil.Util;
  36430. var isArray = sharedUtil.isArray;
  36431. var isInt = sharedUtil.isInt;
  36432. var isValidUrl = sharedUtil.isValidUrl;
  36433. var stringToBytes = sharedUtil.stringToBytes;
  36434. var stringToPDFString = sharedUtil.stringToPDFString;
  36435. var stringToUTF8String = sharedUtil.stringToUTF8String;
  36436. var warn = sharedUtil.warn;
  36437. var Dict = corePrimitives.Dict;
  36438. var isDict = corePrimitives.isDict;
  36439. var isName = corePrimitives.isName;
  36440. var Stream = coreStream.Stream;
  36441. var ColorSpace = coreColorSpace.ColorSpace;
  36442. var ObjectLoader = coreObj.ObjectLoader;
  36443. var OperatorList = coreEvaluator.OperatorList;
  36444. var DEFAULT_ICON_SIZE = 22; // px
  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. default:
  36481. warn('Unimplemented annotation type "' + subtype + '", ' +
  36482. 'falling back to base annotation');
  36483. return new Annotation(parameters);
  36484. }
  36485. }
  36486. };
  36487. var Annotation = (function AnnotationClosure() {
  36488. // 12.5.5: Algorithm: Appearance streams
  36489. function getTransformMatrix(rect, bbox, matrix) {
  36490. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  36491. var minX = bounds[0];
  36492. var minY = bounds[1];
  36493. var maxX = bounds[2];
  36494. var maxY = bounds[3];
  36495. if (minX === maxX || minY === maxY) {
  36496. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  36497. // just apply the transform for rect
  36498. return [1, 0, 0, 1, rect[0], rect[1]];
  36499. }
  36500. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  36501. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  36502. return [
  36503. xRatio,
  36504. 0,
  36505. 0,
  36506. yRatio,
  36507. rect[0] - minX * xRatio,
  36508. rect[1] - minY * yRatio
  36509. ];
  36510. }
  36511. function getDefaultAppearance(dict) {
  36512. var appearanceState = dict.get('AP');
  36513. if (!isDict(appearanceState)) {
  36514. return;
  36515. }
  36516. var appearance;
  36517. var appearances = appearanceState.get('N');
  36518. if (isDict(appearances)) {
  36519. var as = dict.get('AS');
  36520. if (as && appearances.has(as.name)) {
  36521. appearance = appearances.get(as.name);
  36522. }
  36523. } else {
  36524. appearance = appearances;
  36525. }
  36526. return appearance;
  36527. }
  36528. function Annotation(params) {
  36529. var dict = params.dict;
  36530. this.setFlags(dict.get('F'));
  36531. this.setRectangle(dict.get('Rect'));
  36532. this.setColor(dict.get('C'));
  36533. this.setBorderStyle(dict);
  36534. this.appearance = getDefaultAppearance(dict);
  36535. // Expose public properties using a data object.
  36536. this.data = {};
  36537. this.data.id = params.ref.num;
  36538. this.data.subtype = dict.get('Subtype').name;
  36539. this.data.annotationFlags = this.flags;
  36540. this.data.rect = this.rectangle;
  36541. this.data.color = this.color;
  36542. this.data.borderStyle = this.borderStyle;
  36543. this.data.hasAppearance = !!this.appearance;
  36544. }
  36545. Annotation.prototype = {
  36546. /**
  36547. * @return {boolean}
  36548. */
  36549. get viewable() {
  36550. if (this.flags) {
  36551. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36552. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  36553. !this.hasFlag(AnnotationFlag.NOVIEW);
  36554. }
  36555. return true;
  36556. },
  36557. /**
  36558. * @return {boolean}
  36559. */
  36560. get printable() {
  36561. if (this.flags) {
  36562. return this.hasFlag(AnnotationFlag.PRINT) &&
  36563. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36564. !this.hasFlag(AnnotationFlag.HIDDEN);
  36565. }
  36566. return false;
  36567. },
  36568. /**
  36569. * Set the flags.
  36570. *
  36571. * @public
  36572. * @memberof Annotation
  36573. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  36574. * characteristics
  36575. * @see {@link shared/util.js}
  36576. */
  36577. setFlags: function Annotation_setFlags(flags) {
  36578. if (isInt(flags)) {
  36579. this.flags = flags;
  36580. } else {
  36581. this.flags = 0;
  36582. }
  36583. },
  36584. /**
  36585. * Check if a provided flag is set.
  36586. *
  36587. * @public
  36588. * @memberof Annotation
  36589. * @param {number} flag - Hexadecimal representation for an annotation
  36590. * characteristic
  36591. * @return {boolean}
  36592. * @see {@link shared/util.js}
  36593. */
  36594. hasFlag: function Annotation_hasFlag(flag) {
  36595. if (this.flags) {
  36596. return (this.flags & flag) > 0;
  36597. }
  36598. return false;
  36599. },
  36600. /**
  36601. * Set the rectangle.
  36602. *
  36603. * @public
  36604. * @memberof Annotation
  36605. * @param {Array} rectangle - The rectangle array with exactly four entries
  36606. */
  36607. setRectangle: function Annotation_setRectangle(rectangle) {
  36608. if (isArray(rectangle) && rectangle.length === 4) {
  36609. this.rectangle = Util.normalizeRect(rectangle);
  36610. } else {
  36611. this.rectangle = [0, 0, 0, 0];
  36612. }
  36613. },
  36614. /**
  36615. * Set the color and take care of color space conversion.
  36616. *
  36617. * @public
  36618. * @memberof Annotation
  36619. * @param {Array} color - The color array containing either 0
  36620. * (transparent), 1 (grayscale), 3 (RGB) or
  36621. * 4 (CMYK) elements
  36622. */
  36623. setColor: function Annotation_setColor(color) {
  36624. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  36625. if (!isArray(color)) {
  36626. this.color = rgbColor;
  36627. return;
  36628. }
  36629. switch (color.length) {
  36630. case 0: // Transparent, which we indicate with a null value
  36631. this.color = null;
  36632. break;
  36633. case 1: // Convert grayscale to RGB
  36634. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  36635. this.color = rgbColor;
  36636. break;
  36637. case 3: // Convert RGB percentages to RGB
  36638. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  36639. this.color = rgbColor;
  36640. break;
  36641. case 4: // Convert CMYK to RGB
  36642. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  36643. this.color = rgbColor;
  36644. break;
  36645. default:
  36646. this.color = rgbColor;
  36647. break;
  36648. }
  36649. },
  36650. /**
  36651. * Set the border style (as AnnotationBorderStyle object).
  36652. *
  36653. * @public
  36654. * @memberof Annotation
  36655. * @param {Dict} borderStyle - The border style dictionary
  36656. */
  36657. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  36658. this.borderStyle = new AnnotationBorderStyle();
  36659. if (!isDict(borderStyle)) {
  36660. return;
  36661. }
  36662. if (borderStyle.has('BS')) {
  36663. var dict = borderStyle.get('BS');
  36664. var dictType;
  36665. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  36666. dictType.name === 'Border')) {
  36667. this.borderStyle.setWidth(dict.get('W'));
  36668. this.borderStyle.setStyle(dict.get('S'));
  36669. this.borderStyle.setDashArray(dict.get('D'));
  36670. }
  36671. } else if (borderStyle.has('Border')) {
  36672. var array = borderStyle.get('Border');
  36673. if (isArray(array) && array.length >= 3) {
  36674. this.borderStyle.setHorizontalCornerRadius(array[0]);
  36675. this.borderStyle.setVerticalCornerRadius(array[1]);
  36676. this.borderStyle.setWidth(array[2]);
  36677. if (array.length === 4) { // Dash array available
  36678. this.borderStyle.setDashArray(array[3]);
  36679. }
  36680. }
  36681. } else {
  36682. // There are no border entries in the dictionary. According to the
  36683. // specification, we should draw a solid border of width 1 in that
  36684. // case, but Adobe Reader did not implement that part of the
  36685. // specification and instead draws no border at all, so we do the same.
  36686. // See also https://github.com/mozilla/pdf.js/issues/6179.
  36687. this.borderStyle.setWidth(0);
  36688. }
  36689. },
  36690. loadResources: function Annotation_loadResources(keys) {
  36691. return new Promise(function (resolve, reject) {
  36692. this.appearance.dict.getAsync('Resources').then(function (resources) {
  36693. if (!resources) {
  36694. resolve();
  36695. return;
  36696. }
  36697. var objectLoader = new ObjectLoader(resources.map,
  36698. keys,
  36699. resources.xref);
  36700. objectLoader.load().then(function() {
  36701. resolve(resources);
  36702. }, reject);
  36703. }, reject);
  36704. }.bind(this));
  36705. },
  36706. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  36707. if (!this.appearance) {
  36708. return Promise.resolve(new OperatorList());
  36709. }
  36710. var data = this.data;
  36711. var appearanceDict = this.appearance.dict;
  36712. var resourcesPromise = this.loadResources([
  36713. 'ExtGState',
  36714. 'ColorSpace',
  36715. 'Pattern',
  36716. 'Shading',
  36717. 'XObject',
  36718. 'Font'
  36719. // ProcSet
  36720. // Properties
  36721. ]);
  36722. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  36723. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  36724. var transform = getTransformMatrix(data.rect, bbox, matrix);
  36725. var self = this;
  36726. return resourcesPromise.then(function(resources) {
  36727. var opList = new OperatorList();
  36728. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  36729. return evaluator.getOperatorList(self.appearance, task,
  36730. resources, opList).
  36731. then(function () {
  36732. opList.addOp(OPS.endAnnotation, []);
  36733. self.appearance.reset();
  36734. return opList;
  36735. });
  36736. });
  36737. }
  36738. };
  36739. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  36740. annotations, opList, partialEvaluator, task, intent) {
  36741. var annotationPromises = [];
  36742. for (var i = 0, n = annotations.length; i < n; ++i) {
  36743. if ((intent === 'display' && annotations[i].viewable) ||
  36744. (intent === 'print' && annotations[i].printable)) {
  36745. annotationPromises.push(
  36746. annotations[i].getOperatorList(partialEvaluator, task));
  36747. }
  36748. }
  36749. return Promise.all(annotationPromises).then(function(operatorLists) {
  36750. opList.addOp(OPS.beginAnnotations, []);
  36751. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  36752. opList.addOpList(operatorLists[i]);
  36753. }
  36754. opList.addOp(OPS.endAnnotations, []);
  36755. });
  36756. };
  36757. return Annotation;
  36758. })();
  36759. /**
  36760. * Contains all data regarding an annotation's border style.
  36761. *
  36762. * @class
  36763. */
  36764. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  36765. /**
  36766. * @constructor
  36767. * @private
  36768. */
  36769. function AnnotationBorderStyle() {
  36770. this.width = 1;
  36771. this.style = AnnotationBorderStyleType.SOLID;
  36772. this.dashArray = [3];
  36773. this.horizontalCornerRadius = 0;
  36774. this.verticalCornerRadius = 0;
  36775. }
  36776. AnnotationBorderStyle.prototype = {
  36777. /**
  36778. * Set the width.
  36779. *
  36780. * @public
  36781. * @memberof AnnotationBorderStyle
  36782. * @param {integer} width - The width
  36783. */
  36784. setWidth: function AnnotationBorderStyle_setWidth(width) {
  36785. if (width === (width | 0)) {
  36786. this.width = width;
  36787. }
  36788. },
  36789. /**
  36790. * Set the style.
  36791. *
  36792. * @public
  36793. * @memberof AnnotationBorderStyle
  36794. * @param {Object} style - The style object
  36795. * @see {@link shared/util.js}
  36796. */
  36797. setStyle: function AnnotationBorderStyle_setStyle(style) {
  36798. if (!style) {
  36799. return;
  36800. }
  36801. switch (style.name) {
  36802. case 'S':
  36803. this.style = AnnotationBorderStyleType.SOLID;
  36804. break;
  36805. case 'D':
  36806. this.style = AnnotationBorderStyleType.DASHED;
  36807. break;
  36808. case 'B':
  36809. this.style = AnnotationBorderStyleType.BEVELED;
  36810. break;
  36811. case 'I':
  36812. this.style = AnnotationBorderStyleType.INSET;
  36813. break;
  36814. case 'U':
  36815. this.style = AnnotationBorderStyleType.UNDERLINE;
  36816. break;
  36817. default:
  36818. break;
  36819. }
  36820. },
  36821. /**
  36822. * Set the dash array.
  36823. *
  36824. * @public
  36825. * @memberof AnnotationBorderStyle
  36826. * @param {Array} dashArray - The dash array with at least one element
  36827. */
  36828. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  36829. // We validate the dash array, but we do not use it because CSS does not
  36830. // allow us to change spacing of dashes. For more information, visit
  36831. // http://www.w3.org/TR/css3-background/#the-border-style.
  36832. if (isArray(dashArray) && dashArray.length > 0) {
  36833. // According to the PDF specification: the elements in a dashArray
  36834. // shall be numbers that are nonnegative and not all equal to zero.
  36835. var isValid = true;
  36836. var allZeros = true;
  36837. for (var i = 0, len = dashArray.length; i < len; i++) {
  36838. var element = dashArray[i];
  36839. var validNumber = (+element >= 0);
  36840. if (!validNumber) {
  36841. isValid = false;
  36842. break;
  36843. } else if (element > 0) {
  36844. allZeros = false;
  36845. }
  36846. }
  36847. if (isValid && !allZeros) {
  36848. this.dashArray = dashArray;
  36849. } else {
  36850. this.width = 0; // Adobe behavior when the array is invalid.
  36851. }
  36852. } else if (dashArray) {
  36853. this.width = 0; // Adobe behavior when the array is invalid.
  36854. }
  36855. },
  36856. /**
  36857. * Set the horizontal corner radius (from a Border dictionary).
  36858. *
  36859. * @public
  36860. * @memberof AnnotationBorderStyle
  36861. * @param {integer} radius - The horizontal corner radius
  36862. */
  36863. setHorizontalCornerRadius:
  36864. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  36865. if (radius === (radius | 0)) {
  36866. this.horizontalCornerRadius = radius;
  36867. }
  36868. },
  36869. /**
  36870. * Set the vertical corner radius (from a Border dictionary).
  36871. *
  36872. * @public
  36873. * @memberof AnnotationBorderStyle
  36874. * @param {integer} radius - The vertical corner radius
  36875. */
  36876. setVerticalCornerRadius:
  36877. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  36878. if (radius === (radius | 0)) {
  36879. this.verticalCornerRadius = radius;
  36880. }
  36881. }
  36882. };
  36883. return AnnotationBorderStyle;
  36884. })();
  36885. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  36886. function WidgetAnnotation(params) {
  36887. Annotation.call(this, params);
  36888. var dict = params.dict;
  36889. var data = this.data;
  36890. data.annotationType = AnnotationType.WIDGET;
  36891. data.fieldValue = stringToPDFString(
  36892. Util.getInheritableProperty(dict, 'V') || '');
  36893. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  36894. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  36895. var fieldType = Util.getInheritableProperty(dict, 'FT');
  36896. data.fieldType = isName(fieldType) ? fieldType.name : '';
  36897. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  36898. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  36899. // Hide unsupported Widget signatures.
  36900. if (data.fieldType === 'Sig') {
  36901. warn('unimplemented annotation type: Widget signature');
  36902. this.setFlags(AnnotationFlag.HIDDEN);
  36903. }
  36904. // Building the full field name by collecting the field and
  36905. // its ancestors 'T' data and joining them using '.'.
  36906. var fieldName = [];
  36907. var namedItem = dict;
  36908. var ref = params.ref;
  36909. while (namedItem) {
  36910. var parent = namedItem.get('Parent');
  36911. var parentRef = namedItem.getRaw('Parent');
  36912. var name = namedItem.get('T');
  36913. if (name) {
  36914. fieldName.unshift(stringToPDFString(name));
  36915. } else if (parent && ref) {
  36916. // The field name is absent, that means more than one field
  36917. // with the same name may exist. Replacing the empty name
  36918. // with the '`' plus index in the parent's 'Kids' array.
  36919. // This is not in the PDF spec but necessary to id the
  36920. // the input controls.
  36921. var kids = parent.get('Kids');
  36922. var j, jj;
  36923. for (j = 0, jj = kids.length; j < jj; j++) {
  36924. var kidRef = kids[j];
  36925. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  36926. break;
  36927. }
  36928. }
  36929. fieldName.unshift('`' + j);
  36930. }
  36931. namedItem = parent;
  36932. ref = parentRef;
  36933. }
  36934. data.fullName = fieldName.join('.');
  36935. }
  36936. Util.inherit(WidgetAnnotation, Annotation, {});
  36937. return WidgetAnnotation;
  36938. })();
  36939. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  36940. function TextWidgetAnnotation(params) {
  36941. WidgetAnnotation.call(this, params);
  36942. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  36943. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  36944. }
  36945. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  36946. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  36947. task) {
  36948. if (this.appearance) {
  36949. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  36950. }
  36951. var opList = new OperatorList();
  36952. var data = this.data;
  36953. // Even if there is an appearance stream, ignore it. This is the
  36954. // behaviour used by Adobe Reader.
  36955. if (!data.defaultAppearance) {
  36956. return Promise.resolve(opList);
  36957. }
  36958. var stream = new Stream(stringToBytes(data.defaultAppearance));
  36959. return evaluator.getOperatorList(stream, task,
  36960. this.fieldResources, opList).
  36961. then(function () {
  36962. return opList;
  36963. });
  36964. }
  36965. });
  36966. return TextWidgetAnnotation;
  36967. })();
  36968. var TextAnnotation = (function TextAnnotationClosure() {
  36969. function TextAnnotation(params) {
  36970. Annotation.call(this, params);
  36971. var dict = params.dict;
  36972. var data = this.data;
  36973. var content = dict.get('Contents');
  36974. var title = dict.get('T');
  36975. data.annotationType = AnnotationType.TEXT;
  36976. data.content = stringToPDFString(content || '');
  36977. data.title = stringToPDFString(title || '');
  36978. data.hasHtml = true;
  36979. if (data.hasAppearance) {
  36980. data.name = 'NoIcon';
  36981. } else {
  36982. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  36983. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  36984. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  36985. }
  36986. if (dict.has('C')) {
  36987. data.hasBgColor = true;
  36988. }
  36989. }
  36990. Util.inherit(TextAnnotation, Annotation, {});
  36991. return TextAnnotation;
  36992. })();
  36993. var LinkAnnotation = (function LinkAnnotationClosure() {
  36994. function LinkAnnotation(params) {
  36995. Annotation.call(this, params);
  36996. var dict = params.dict;
  36997. var data = this.data;
  36998. data.annotationType = AnnotationType.LINK;
  36999. data.hasHtml = true;
  37000. var action = dict.get('A');
  37001. if (action && isDict(action)) {
  37002. var linkType = action.get('S').name;
  37003. if (linkType === 'URI') {
  37004. var url = action.get('URI');
  37005. if (isName(url)) {
  37006. // Some bad PDFs do not put parentheses around relative URLs.
  37007. url = '/' + url.name;
  37008. } else if (url) {
  37009. url = addDefaultProtocolToUrl(url);
  37010. }
  37011. // TODO: pdf spec mentions urls can be relative to a Base
  37012. // entry in the dictionary.
  37013. if (!isValidUrl(url, false)) {
  37014. url = '';
  37015. }
  37016. // According to ISO 32000-1:2008, section 12.6.4.7,
  37017. // URI should to be encoded in 7-bit ASCII.
  37018. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37019. try {
  37020. data.url = stringToUTF8String(url);
  37021. } catch (e) {
  37022. // Fall back to a simple copy.
  37023. data.url = url;
  37024. }
  37025. } else if (linkType === 'GoTo') {
  37026. data.dest = action.get('D');
  37027. } else if (linkType === 'GoToR') {
  37028. var urlDict = action.get('F');
  37029. if (isDict(urlDict)) {
  37030. // We assume that the 'url' is a Filspec dictionary
  37031. // and fetch the url without checking any further
  37032. url = urlDict.get('F') || '';
  37033. }
  37034. // TODO: pdf reference says that GoToR
  37035. // can also have 'NewWindow' attribute
  37036. if (!isValidUrl(url, false)) {
  37037. url = '';
  37038. }
  37039. data.url = url;
  37040. data.dest = action.get('D');
  37041. } else if (linkType === 'Named') {
  37042. data.action = action.get('N').name;
  37043. } else {
  37044. warn('unrecognized link type: ' + linkType);
  37045. }
  37046. } else if (dict.has('Dest')) {
  37047. // simple destination link
  37048. var dest = dict.get('Dest');
  37049. data.dest = isName(dest) ? dest.name : dest;
  37050. }
  37051. }
  37052. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  37053. function addDefaultProtocolToUrl(url) {
  37054. if (url && url.indexOf('www.') === 0) {
  37055. return ('http://' + url);
  37056. }
  37057. return url;
  37058. }
  37059. Util.inherit(LinkAnnotation, Annotation, {});
  37060. return LinkAnnotation;
  37061. })();
  37062. exports.Annotation = Annotation;
  37063. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  37064. exports.AnnotationFactory = AnnotationFactory;
  37065. }));
  37066. (function (root, factory) {
  37067. {
  37068. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  37069. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  37070. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  37071. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  37072. }
  37073. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  37074. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  37075. var MissingDataException = sharedUtil.MissingDataException;
  37076. var Util = sharedUtil.Util;
  37077. var assert = sharedUtil.assert;
  37078. var error = sharedUtil.error;
  37079. var info = sharedUtil.info;
  37080. var isArray = sharedUtil.isArray;
  37081. var isArrayBuffer = sharedUtil.isArrayBuffer;
  37082. var isString = sharedUtil.isString;
  37083. var shadow = sharedUtil.shadow;
  37084. var stringToBytes = sharedUtil.stringToBytes;
  37085. var stringToPDFString = sharedUtil.stringToPDFString;
  37086. var warn = sharedUtil.warn;
  37087. var Dict = corePrimitives.Dict;
  37088. var isDict = corePrimitives.isDict;
  37089. var isName = corePrimitives.isName;
  37090. var isStream = corePrimitives.isStream;
  37091. var NullStream = coreStream.NullStream;
  37092. var Stream = coreStream.Stream;
  37093. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  37094. var Catalog = coreObj.Catalog;
  37095. var ObjectLoader = coreObj.ObjectLoader;
  37096. var XRef = coreObj.XRef;
  37097. var Lexer = coreParser.Lexer;
  37098. var Linearization = coreParser.Linearization;
  37099. var calculateMD5 = coreCrypto.calculateMD5;
  37100. var OperatorList = coreEvaluator.OperatorList;
  37101. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  37102. var Annotation = coreAnnotation.Annotation;
  37103. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  37104. var Page = (function PageClosure() {
  37105. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  37106. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  37107. this.pdfManager = pdfManager;
  37108. this.pageIndex = pageIndex;
  37109. this.pageDict = pageDict;
  37110. this.xref = xref;
  37111. this.ref = ref;
  37112. this.fontCache = fontCache;
  37113. this.idCounters = {
  37114. obj: 0
  37115. };
  37116. this.resourcesPromise = null;
  37117. }
  37118. Page.prototype = {
  37119. getPageProp: function Page_getPageProp(key) {
  37120. return this.pageDict.get(key);
  37121. },
  37122. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  37123. var dict = this.pageDict, valueArray = null, loopCount = 0;
  37124. var MAX_LOOP_COUNT = 100;
  37125. // Always walk up the entire parent chain, to be able to find
  37126. // e.g. \Resources placed on multiple levels of the tree.
  37127. while (dict) {
  37128. var value = dict.get(key);
  37129. if (value) {
  37130. if (!valueArray) {
  37131. valueArray = [];
  37132. }
  37133. valueArray.push(value);
  37134. }
  37135. if (++loopCount > MAX_LOOP_COUNT) {
  37136. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  37137. break;
  37138. }
  37139. dict = dict.get('Parent');
  37140. }
  37141. if (!valueArray) {
  37142. return Dict.empty;
  37143. }
  37144. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  37145. loopCount > MAX_LOOP_COUNT) {
  37146. return valueArray[0];
  37147. }
  37148. return Dict.merge(this.xref, valueArray);
  37149. },
  37150. get content() {
  37151. return this.getPageProp('Contents');
  37152. },
  37153. get resources() {
  37154. // For robustness: The spec states that a \Resources entry has to be
  37155. // present, but can be empty. Some document omit it still, in this case
  37156. // we return an empty dictionary.
  37157. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  37158. },
  37159. get mediaBox() {
  37160. var obj = this.getInheritedPageProp('MediaBox');
  37161. // Reset invalid media box to letter size.
  37162. if (!isArray(obj) || obj.length !== 4) {
  37163. obj = LETTER_SIZE_MEDIABOX;
  37164. }
  37165. return shadow(this, 'mediaBox', obj);
  37166. },
  37167. get view() {
  37168. var mediaBox = this.mediaBox;
  37169. var cropBox = this.getInheritedPageProp('CropBox');
  37170. if (!isArray(cropBox) || cropBox.length !== 4) {
  37171. return shadow(this, 'view', mediaBox);
  37172. }
  37173. // From the spec, 6th ed., p.963:
  37174. // "The crop, bleed, trim, and art boxes should not ordinarily
  37175. // extend beyond the boundaries of the media box. If they do, they are
  37176. // effectively reduced to their intersection with the media box."
  37177. cropBox = Util.intersect(cropBox, mediaBox);
  37178. if (!cropBox) {
  37179. return shadow(this, 'view', mediaBox);
  37180. }
  37181. return shadow(this, 'view', cropBox);
  37182. },
  37183. get rotate() {
  37184. var rotate = this.getInheritedPageProp('Rotate') || 0;
  37185. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  37186. if (rotate % 90 !== 0) {
  37187. rotate = 0;
  37188. } else if (rotate >= 360) {
  37189. rotate = rotate % 360;
  37190. } else if (rotate < 0) {
  37191. // The spec doesn't cover negatives, assume its counterclockwise
  37192. // rotation. The following is the other implementation of modulo.
  37193. rotate = ((rotate % 360) + 360) % 360;
  37194. }
  37195. return shadow(this, 'rotate', rotate);
  37196. },
  37197. getContentStream: function Page_getContentStream() {
  37198. var content = this.content;
  37199. var stream;
  37200. if (isArray(content)) {
  37201. // fetching items
  37202. var xref = this.xref;
  37203. var i, n = content.length;
  37204. var streams = [];
  37205. for (i = 0; i < n; ++i) {
  37206. streams.push(xref.fetchIfRef(content[i]));
  37207. }
  37208. stream = new StreamsSequenceStream(streams);
  37209. } else if (isStream(content)) {
  37210. stream = content;
  37211. } else {
  37212. // replacing non-existent page content with empty one
  37213. stream = new NullStream();
  37214. }
  37215. return stream;
  37216. },
  37217. loadResources: function Page_loadResources(keys) {
  37218. if (!this.resourcesPromise) {
  37219. // TODO: add async getInheritedPageProp and remove this.
  37220. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  37221. }
  37222. return this.resourcesPromise.then(function resourceSuccess() {
  37223. var objectLoader = new ObjectLoader(this.resources.map,
  37224. keys,
  37225. this.xref);
  37226. return objectLoader.load();
  37227. }.bind(this));
  37228. },
  37229. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  37230. var self = this;
  37231. var pdfManager = this.pdfManager;
  37232. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37233. []);
  37234. var resourcesPromise = this.loadResources([
  37235. 'ExtGState',
  37236. 'ColorSpace',
  37237. 'Pattern',
  37238. 'Shading',
  37239. 'XObject',
  37240. 'Font'
  37241. // ProcSet
  37242. // Properties
  37243. ]);
  37244. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  37245. handler, this.pageIndex,
  37246. 'p' + this.pageIndex + '_',
  37247. this.idCounters,
  37248. this.fontCache);
  37249. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  37250. var pageListPromise = dataPromises.then(function(data) {
  37251. var contentStream = data[0];
  37252. var opList = new OperatorList(intent, handler, self.pageIndex);
  37253. handler.send('StartRenderPage', {
  37254. transparency: partialEvaluator.hasBlendModes(self.resources),
  37255. pageIndex: self.pageIndex,
  37256. intent: intent
  37257. });
  37258. return partialEvaluator.getOperatorList(contentStream, task,
  37259. self.resources, opList).then(function () {
  37260. return opList;
  37261. });
  37262. });
  37263. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  37264. return Promise.all([pageListPromise, annotationsPromise]).then(
  37265. function(datas) {
  37266. var pageOpList = datas[0];
  37267. var annotations = datas[1];
  37268. if (annotations.length === 0) {
  37269. pageOpList.flush(true);
  37270. return pageOpList;
  37271. }
  37272. var annotationsReadyPromise = Annotation.appendToOperatorList(
  37273. annotations, pageOpList, partialEvaluator, task, intent);
  37274. return annotationsReadyPromise.then(function () {
  37275. pageOpList.flush(true);
  37276. return pageOpList;
  37277. });
  37278. });
  37279. },
  37280. extractTextContent: function Page_extractTextContent(task,
  37281. normalizeWhitespace) {
  37282. var handler = {
  37283. on: function nullHandlerOn() {},
  37284. send: function nullHandlerSend() {}
  37285. };
  37286. var self = this;
  37287. var pdfManager = this.pdfManager;
  37288. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37289. []);
  37290. var resourcesPromise = this.loadResources([
  37291. 'ExtGState',
  37292. 'XObject',
  37293. 'Font'
  37294. ]);
  37295. var dataPromises = Promise.all([contentStreamPromise,
  37296. resourcesPromise]);
  37297. return dataPromises.then(function(data) {
  37298. var contentStream = data[0];
  37299. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  37300. handler, self.pageIndex,
  37301. 'p' + self.pageIndex + '_',
  37302. self.idCounters,
  37303. self.fontCache);
  37304. return partialEvaluator.getTextContent(contentStream,
  37305. task,
  37306. self.resources,
  37307. /* stateManager = */ null,
  37308. normalizeWhitespace);
  37309. });
  37310. },
  37311. getAnnotationsData: function Page_getAnnotationsData(intent) {
  37312. var annotations = this.annotations;
  37313. var annotationsData = [];
  37314. for (var i = 0, n = annotations.length; i < n; ++i) {
  37315. if (intent) {
  37316. if (!(intent === 'display' && annotations[i].viewable) &&
  37317. !(intent === 'print' && annotations[i].printable)) {
  37318. continue;
  37319. }
  37320. }
  37321. annotationsData.push(annotations[i].data);
  37322. }
  37323. return annotationsData;
  37324. },
  37325. get annotations() {
  37326. var annotations = [];
  37327. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  37328. var annotationFactory = new AnnotationFactory();
  37329. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  37330. var annotationRef = annotationRefs[i];
  37331. var annotation = annotationFactory.create(this.xref, annotationRef);
  37332. if (annotation) {
  37333. annotations.push(annotation);
  37334. }
  37335. }
  37336. return shadow(this, 'annotations', annotations);
  37337. }
  37338. };
  37339. return Page;
  37340. })();
  37341. /**
  37342. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  37343. * `PDFDoc`, this one doesn't have any job management code.
  37344. * Right now there exists one PDFDocument on the main thread + one object
  37345. * for each worker. If there is no worker support enabled, there are two
  37346. * `PDFDocument` objects on the main thread created.
  37347. */
  37348. var PDFDocument = (function PDFDocumentClosure() {
  37349. var FINGERPRINT_FIRST_BYTES = 1024;
  37350. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  37351. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  37352. function PDFDocument(pdfManager, arg, password) {
  37353. if (isStream(arg)) {
  37354. init.call(this, pdfManager, arg, password);
  37355. } else if (isArrayBuffer(arg)) {
  37356. init.call(this, pdfManager, new Stream(arg), password);
  37357. } else {
  37358. error('PDFDocument: Unknown argument type');
  37359. }
  37360. }
  37361. function init(pdfManager, stream, password) {
  37362. assert(stream.length > 0, 'stream must have data');
  37363. this.pdfManager = pdfManager;
  37364. this.stream = stream;
  37365. var xref = new XRef(this.stream, password, pdfManager);
  37366. this.xref = xref;
  37367. }
  37368. function find(stream, needle, limit, backwards) {
  37369. var pos = stream.pos;
  37370. var end = stream.end;
  37371. var strBuf = [];
  37372. if (pos + limit > end) {
  37373. limit = end - pos;
  37374. }
  37375. for (var n = 0; n < limit; ++n) {
  37376. strBuf.push(String.fromCharCode(stream.getByte()));
  37377. }
  37378. var str = strBuf.join('');
  37379. stream.pos = pos;
  37380. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  37381. if (index === -1) {
  37382. return false; /* not found */
  37383. }
  37384. stream.pos += index;
  37385. return true; /* found */
  37386. }
  37387. var DocumentInfoValidators = {
  37388. get entries() {
  37389. // Lazily build this since all the validation functions below are not
  37390. // defined until after this file loads.
  37391. return shadow(this, 'entries', {
  37392. Title: isString,
  37393. Author: isString,
  37394. Subject: isString,
  37395. Keywords: isString,
  37396. Creator: isString,
  37397. Producer: isString,
  37398. CreationDate: isString,
  37399. ModDate: isString,
  37400. Trapped: isName
  37401. });
  37402. }
  37403. };
  37404. PDFDocument.prototype = {
  37405. parse: function PDFDocument_parse(recoveryMode) {
  37406. this.setup(recoveryMode);
  37407. var version = this.catalog.catDict.get('Version');
  37408. if (isName(version)) {
  37409. this.pdfFormatVersion = version.name;
  37410. }
  37411. try {
  37412. // checking if AcroForm is present
  37413. this.acroForm = this.catalog.catDict.get('AcroForm');
  37414. if (this.acroForm) {
  37415. this.xfa = this.acroForm.get('XFA');
  37416. var fields = this.acroForm.get('Fields');
  37417. if ((!fields || !isArray(fields) || fields.length === 0) &&
  37418. !this.xfa) {
  37419. // no fields and no XFA -- not a form (?)
  37420. this.acroForm = null;
  37421. }
  37422. }
  37423. } catch (ex) {
  37424. info('Something wrong with AcroForm entry');
  37425. this.acroForm = null;
  37426. }
  37427. },
  37428. get linearization() {
  37429. var linearization = null;
  37430. if (this.stream.length) {
  37431. try {
  37432. linearization = Linearization.create(this.stream);
  37433. } catch (err) {
  37434. if (err instanceof MissingDataException) {
  37435. throw err;
  37436. }
  37437. info(err);
  37438. }
  37439. }
  37440. // shadow the prototype getter with a data property
  37441. return shadow(this, 'linearization', linearization);
  37442. },
  37443. get startXRef() {
  37444. var stream = this.stream;
  37445. var startXRef = 0;
  37446. var linearization = this.linearization;
  37447. if (linearization) {
  37448. // Find end of first obj.
  37449. stream.reset();
  37450. if (find(stream, 'endobj', 1024)) {
  37451. startXRef = stream.pos + 6;
  37452. }
  37453. } else {
  37454. // Find startxref by jumping backward from the end of the file.
  37455. var step = 1024;
  37456. var found = false, pos = stream.end;
  37457. while (!found && pos > 0) {
  37458. pos -= step - 'startxref'.length;
  37459. if (pos < 0) {
  37460. pos = 0;
  37461. }
  37462. stream.pos = pos;
  37463. found = find(stream, 'startxref', step, true);
  37464. }
  37465. if (found) {
  37466. stream.skip(9);
  37467. var ch;
  37468. do {
  37469. ch = stream.getByte();
  37470. } while (Lexer.isSpace(ch));
  37471. var str = '';
  37472. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  37473. str += String.fromCharCode(ch);
  37474. ch = stream.getByte();
  37475. }
  37476. startXRef = parseInt(str, 10);
  37477. if (isNaN(startXRef)) {
  37478. startXRef = 0;
  37479. }
  37480. }
  37481. }
  37482. // shadow the prototype getter with a data property
  37483. return shadow(this, 'startXRef', startXRef);
  37484. },
  37485. get mainXRefEntriesOffset() {
  37486. var mainXRefEntriesOffset = 0;
  37487. var linearization = this.linearization;
  37488. if (linearization) {
  37489. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  37490. }
  37491. // shadow the prototype getter with a data property
  37492. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  37493. },
  37494. // Find the header, remove leading garbage and setup the stream
  37495. // starting from the header.
  37496. checkHeader: function PDFDocument_checkHeader() {
  37497. var stream = this.stream;
  37498. stream.reset();
  37499. if (find(stream, '%PDF-', 1024)) {
  37500. // Found the header, trim off any garbage before it.
  37501. stream.moveStart();
  37502. // Reading file format version
  37503. var MAX_VERSION_LENGTH = 12;
  37504. var version = '', ch;
  37505. while ((ch = stream.getByte()) > 0x20) { // SPACE
  37506. if (version.length >= MAX_VERSION_LENGTH) {
  37507. break;
  37508. }
  37509. version += String.fromCharCode(ch);
  37510. }
  37511. if (!this.pdfFormatVersion) {
  37512. // removing "%PDF-"-prefix
  37513. this.pdfFormatVersion = version.substring(5);
  37514. }
  37515. return;
  37516. }
  37517. // May not be a PDF file, continue anyway.
  37518. },
  37519. parseStartXRef: function PDFDocument_parseStartXRef() {
  37520. var startXRef = this.startXRef;
  37521. this.xref.setStartXRef(startXRef);
  37522. },
  37523. setup: function PDFDocument_setup(recoveryMode) {
  37524. this.xref.parse(recoveryMode);
  37525. var self = this;
  37526. var pageFactory = {
  37527. createPage: function (pageIndex, dict, ref, fontCache) {
  37528. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  37529. fontCache);
  37530. }
  37531. };
  37532. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  37533. },
  37534. get numPages() {
  37535. var linearization = this.linearization;
  37536. var num = linearization ? linearization.numPages : this.catalog.numPages;
  37537. // shadow the prototype getter
  37538. return shadow(this, 'numPages', num);
  37539. },
  37540. get documentInfo() {
  37541. var docInfo = {
  37542. PDFFormatVersion: this.pdfFormatVersion,
  37543. IsAcroFormPresent: !!this.acroForm,
  37544. IsXFAPresent: !!this.xfa
  37545. };
  37546. var infoDict;
  37547. try {
  37548. infoDict = this.xref.trailer.get('Info');
  37549. } catch (err) {
  37550. info('The document information dictionary is invalid.');
  37551. }
  37552. if (infoDict) {
  37553. var validEntries = DocumentInfoValidators.entries;
  37554. // Only fill the document info with valid entries from the spec.
  37555. for (var key in validEntries) {
  37556. if (infoDict.has(key)) {
  37557. var value = infoDict.get(key);
  37558. // Make sure the value conforms to the spec.
  37559. if (validEntries[key](value)) {
  37560. docInfo[key] = (typeof value !== 'string' ?
  37561. value : stringToPDFString(value));
  37562. } else {
  37563. info('Bad value in document info for "' + key + '"');
  37564. }
  37565. }
  37566. }
  37567. }
  37568. return shadow(this, 'documentInfo', docInfo);
  37569. },
  37570. get fingerprint() {
  37571. var xref = this.xref, hash, fileID = '';
  37572. var idArray = xref.trailer.get('ID');
  37573. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  37574. idArray[0] !== EMPTY_FINGERPRINT) {
  37575. hash = stringToBytes(idArray[0]);
  37576. } else {
  37577. if (this.stream.ensureRange) {
  37578. this.stream.ensureRange(0,
  37579. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  37580. }
  37581. hash = calculateMD5(this.stream.bytes.subarray(0,
  37582. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  37583. }
  37584. for (var i = 0, n = hash.length; i < n; i++) {
  37585. var hex = hash[i].toString(16);
  37586. fileID += hex.length === 1 ? '0' + hex : hex;
  37587. }
  37588. return shadow(this, 'fingerprint', fileID);
  37589. },
  37590. getPage: function PDFDocument_getPage(pageIndex) {
  37591. return this.catalog.getPage(pageIndex);
  37592. },
  37593. cleanup: function PDFDocument_cleanup() {
  37594. return this.catalog.cleanup();
  37595. }
  37596. };
  37597. return PDFDocument;
  37598. })();
  37599. exports.Page = Page;
  37600. exports.PDFDocument = PDFDocument;
  37601. }));
  37602. (function (root, factory) {
  37603. {
  37604. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  37605. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  37606. root.pdfjsCoreDocument);
  37607. }
  37608. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  37609. coreDocument) {
  37610. var NotImplementedException = sharedUtil.NotImplementedException;
  37611. var MissingDataException = sharedUtil.MissingDataException;
  37612. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37613. var Util = sharedUtil.Util;
  37614. var Stream = coreStream.Stream;
  37615. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  37616. var PDFDocument = coreDocument.PDFDocument;
  37617. var BasePdfManager = (function BasePdfManagerClosure() {
  37618. function BasePdfManager() {
  37619. throw new Error('Cannot initialize BaseManagerManager');
  37620. }
  37621. BasePdfManager.prototype = {
  37622. get docId() {
  37623. return this._docId;
  37624. },
  37625. onLoadedStream: function BasePdfManager_onLoadedStream() {
  37626. throw new NotImplementedException();
  37627. },
  37628. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  37629. return this.ensure(this.pdfDocument, prop, args);
  37630. },
  37631. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  37632. return this.ensure(this.pdfDocument.xref, prop, args);
  37633. },
  37634. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  37635. return this.ensure(this.pdfDocument.catalog, prop, args);
  37636. },
  37637. getPage: function BasePdfManager_getPage(pageIndex) {
  37638. return this.pdfDocument.getPage(pageIndex);
  37639. },
  37640. cleanup: function BasePdfManager_cleanup() {
  37641. return this.pdfDocument.cleanup();
  37642. },
  37643. ensure: function BasePdfManager_ensure(obj, prop, args) {
  37644. return new NotImplementedException();
  37645. },
  37646. requestRange: function BasePdfManager_requestRange(begin, end) {
  37647. return new NotImplementedException();
  37648. },
  37649. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  37650. return new NotImplementedException();
  37651. },
  37652. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  37653. return new NotImplementedException();
  37654. },
  37655. updatePassword: function BasePdfManager_updatePassword(password) {
  37656. this.pdfDocument.xref.password = this.password = password;
  37657. if (this._passwordChangedCapability) {
  37658. this._passwordChangedCapability.resolve();
  37659. }
  37660. },
  37661. passwordChanged: function BasePdfManager_passwordChanged() {
  37662. this._passwordChangedCapability = createPromiseCapability();
  37663. return this._passwordChangedCapability.promise;
  37664. },
  37665. terminate: function BasePdfManager_terminate() {
  37666. return new NotImplementedException();
  37667. }
  37668. };
  37669. return BasePdfManager;
  37670. })();
  37671. var LocalPdfManager = (function LocalPdfManagerClosure() {
  37672. function LocalPdfManager(docId, data, password) {
  37673. this._docId = docId;
  37674. var stream = new Stream(data);
  37675. this.pdfDocument = new PDFDocument(this, stream, password);
  37676. this._loadedStreamCapability = createPromiseCapability();
  37677. this._loadedStreamCapability.resolve(stream);
  37678. }
  37679. Util.inherit(LocalPdfManager, BasePdfManager, {
  37680. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  37681. return new Promise(function (resolve, reject) {
  37682. try {
  37683. var value = obj[prop];
  37684. var result;
  37685. if (typeof value === 'function') {
  37686. result = value.apply(obj, args);
  37687. } else {
  37688. result = value;
  37689. }
  37690. resolve(result);
  37691. } catch (e) {
  37692. reject(e);
  37693. }
  37694. });
  37695. },
  37696. requestRange: function LocalPdfManager_requestRange(begin, end) {
  37697. return Promise.resolve();
  37698. },
  37699. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  37700. return;
  37701. },
  37702. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  37703. return this._loadedStreamCapability.promise;
  37704. },
  37705. terminate: function LocalPdfManager_terminate() {
  37706. return;
  37707. }
  37708. });
  37709. return LocalPdfManager;
  37710. })();
  37711. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  37712. function NetworkPdfManager(docId, args, msgHandler) {
  37713. this._docId = docId;
  37714. this.msgHandler = msgHandler;
  37715. var params = {
  37716. msgHandler: msgHandler,
  37717. httpHeaders: args.httpHeaders,
  37718. withCredentials: args.withCredentials,
  37719. chunkedViewerLoading: args.chunkedViewerLoading,
  37720. disableAutoFetch: args.disableAutoFetch,
  37721. initialData: args.initialData
  37722. };
  37723. this.streamManager = new ChunkedStreamManager(args.length,
  37724. args.rangeChunkSize,
  37725. args.url, params);
  37726. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  37727. args.password);
  37728. }
  37729. Util.inherit(NetworkPdfManager, BasePdfManager, {
  37730. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  37731. var pdfManager = this;
  37732. return new Promise(function (resolve, reject) {
  37733. function ensureHelper() {
  37734. try {
  37735. var result;
  37736. var value = obj[prop];
  37737. if (typeof value === 'function') {
  37738. result = value.apply(obj, args);
  37739. } else {
  37740. result = value;
  37741. }
  37742. resolve(result);
  37743. } catch(e) {
  37744. if (!(e instanceof MissingDataException)) {
  37745. reject(e);
  37746. return;
  37747. }
  37748. pdfManager.streamManager.requestRange(e.begin, e.end).
  37749. then(ensureHelper, reject);
  37750. }
  37751. }
  37752. ensureHelper();
  37753. });
  37754. },
  37755. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  37756. return this.streamManager.requestRange(begin, end);
  37757. },
  37758. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  37759. this.streamManager.requestAllChunks();
  37760. },
  37761. sendProgressiveData:
  37762. function NetworkPdfManager_sendProgressiveData(chunk) {
  37763. this.streamManager.onReceiveData({ chunk: chunk });
  37764. },
  37765. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  37766. return this.streamManager.onLoadedStream();
  37767. },
  37768. terminate: function NetworkPdfManager_terminate() {
  37769. this.streamManager.abort();
  37770. }
  37771. });
  37772. return NetworkPdfManager;
  37773. })();
  37774. exports.LocalPdfManager = LocalPdfManager;
  37775. exports.NetworkPdfManager = NetworkPdfManager;
  37776. }));
  37777. (function (root, factory) {
  37778. {
  37779. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  37780. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  37781. root.pdfjsSharedGlobal);
  37782. }
  37783. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  37784. sharedGlobal) {
  37785. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  37786. var InvalidPDFException = sharedUtil.InvalidPDFException;
  37787. var MessageHandler = sharedUtil.MessageHandler;
  37788. var MissingPDFException = sharedUtil.MissingPDFException;
  37789. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  37790. var PasswordException = sharedUtil.PasswordException;
  37791. var PasswordResponses = sharedUtil.PasswordResponses;
  37792. var UnknownErrorException = sharedUtil.UnknownErrorException;
  37793. var XRefParseException = sharedUtil.XRefParseException;
  37794. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37795. var error = sharedUtil.error;
  37796. var info = sharedUtil.info;
  37797. var isInt = sharedUtil.isInt;
  37798. var warn = sharedUtil.warn;
  37799. var Ref = corePrimitives.Ref;
  37800. var LocalPdfManager = corePdfManager.LocalPdfManager;
  37801. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  37802. var globalScope = sharedGlobal.globalScope;
  37803. var PDFJS = sharedGlobal.PDFJS;
  37804. var WorkerTask = (function WorkerTaskClosure() {
  37805. function WorkerTask(name) {
  37806. this.name = name;
  37807. this.terminated = false;
  37808. this._capability = createPromiseCapability();
  37809. }
  37810. WorkerTask.prototype = {
  37811. get finished() {
  37812. return this._capability.promise;
  37813. },
  37814. finish: function () {
  37815. this._capability.resolve();
  37816. },
  37817. terminate: function () {
  37818. this.terminated = true;
  37819. },
  37820. ensureNotTerminated: function () {
  37821. if (this.terminated) {
  37822. throw new Error('Worker task was terminated');
  37823. }
  37824. }
  37825. };
  37826. return WorkerTask;
  37827. })();
  37828. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37829. setup: function wphSetup(handler, port) {
  37830. handler.on('test', function wphSetupTest(data) {
  37831. // check if Uint8Array can be sent to worker
  37832. if (!(data instanceof Uint8Array)) {
  37833. handler.send('test', 'main', false);
  37834. return;
  37835. }
  37836. // making sure postMessage transfers are working
  37837. var supportTransfers = data[0] === 255;
  37838. handler.postMessageTransfers = supportTransfers;
  37839. // check if the response property is supported by xhr
  37840. var xhr = new XMLHttpRequest();
  37841. var responseExists = 'response' in xhr;
  37842. // check if the property is actually implemented
  37843. try {
  37844. var dummy = xhr.responseType;
  37845. } catch (e) {
  37846. responseExists = false;
  37847. }
  37848. if (!responseExists) {
  37849. handler.send('test', false);
  37850. return;
  37851. }
  37852. handler.send('test', {
  37853. supportTypedArray: true,
  37854. supportTransfers: supportTransfers
  37855. });
  37856. });
  37857. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37858. return WorkerMessageHandler.createDocumentHandler(data, port);
  37859. });
  37860. },
  37861. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  37862. // This context is actually holds references on pdfManager and handler,
  37863. // until the latter is destroyed.
  37864. var pdfManager;
  37865. var terminated = false;
  37866. var cancelXHRs = null;
  37867. var WorkerTasks = [];
  37868. var docId = docParams.docId;
  37869. var workerHandlerName = docParams.docId + '_worker';
  37870. var handler = new MessageHandler(workerHandlerName, docId, port);
  37871. function ensureNotTerminated() {
  37872. if (terminated) {
  37873. throw new Error('Worker was terminated');
  37874. }
  37875. }
  37876. function startWorkerTask(task) {
  37877. WorkerTasks.push(task);
  37878. }
  37879. function finishWorkerTask(task) {
  37880. task.finish();
  37881. var i = WorkerTasks.indexOf(task);
  37882. WorkerTasks.splice(i, 1);
  37883. }
  37884. function loadDocument(recoveryMode) {
  37885. var loadDocumentCapability = createPromiseCapability();
  37886. var parseSuccess = function parseSuccess() {
  37887. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37888. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37889. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37890. Promise.all([numPagesPromise, fingerprintPromise,
  37891. encryptedPromise]).then(function onDocReady(results) {
  37892. var doc = {
  37893. numPages: results[0],
  37894. fingerprint: results[1],
  37895. encrypted: !!results[2],
  37896. };
  37897. loadDocumentCapability.resolve(doc);
  37898. },
  37899. parseFailure);
  37900. };
  37901. var parseFailure = function parseFailure(e) {
  37902. loadDocumentCapability.reject(e);
  37903. };
  37904. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37905. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37906. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37907. parseSuccess, parseFailure);
  37908. }, parseFailure);
  37909. }, parseFailure);
  37910. return loadDocumentCapability.promise;
  37911. }
  37912. function getPdfManager(data) {
  37913. var pdfManagerCapability = createPromiseCapability();
  37914. var pdfManager;
  37915. var source = data.source;
  37916. var disableRange = data.disableRange;
  37917. if (source.data) {
  37918. try {
  37919. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  37920. pdfManagerCapability.resolve(pdfManager);
  37921. } catch (ex) {
  37922. pdfManagerCapability.reject(ex);
  37923. }
  37924. return pdfManagerCapability.promise;
  37925. } else if (source.chunkedViewerLoading) {
  37926. try {
  37927. pdfManager = new NetworkPdfManager(docId, source, handler);
  37928. pdfManagerCapability.resolve(pdfManager);
  37929. } catch (ex) {
  37930. pdfManagerCapability.reject(ex);
  37931. }
  37932. return pdfManagerCapability.promise;
  37933. }
  37934. var networkManager = new NetworkManager(source.url, {
  37935. httpHeaders: source.httpHeaders,
  37936. withCredentials: source.withCredentials
  37937. });
  37938. var cachedChunks = [];
  37939. var fullRequestXhrId = networkManager.requestFull({
  37940. onHeadersReceived: function onHeadersReceived() {
  37941. if (disableRange) {
  37942. return;
  37943. }
  37944. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37945. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37946. return;
  37947. }
  37948. var contentEncoding =
  37949. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37950. if (contentEncoding !== 'identity') {
  37951. return;
  37952. }
  37953. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37954. length = parseInt(length, 10);
  37955. if (!isInt(length)) {
  37956. return;
  37957. }
  37958. source.length = length;
  37959. if (length <= 2 * source.rangeChunkSize) {
  37960. // The file size is smaller than the size of two chunks, so it does
  37961. // not make any sense to abort the request and retry with a range
  37962. // request.
  37963. return;
  37964. }
  37965. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37966. // We can continue fetching when progressive loading is enabled,
  37967. // and we don't need the autoFetch feature.
  37968. source.disableAutoFetch = true;
  37969. } else {
  37970. // NOTE: by cancelling the full request, and then issuing range
  37971. // requests, there will be an issue for sites where you can only
  37972. // request the pdf once. However, if this is the case, then the
  37973. // server should not be returning that it can support range
  37974. // requests.
  37975. networkManager.abortRequest(fullRequestXhrId);
  37976. }
  37977. try {
  37978. pdfManager = new NetworkPdfManager(docId, source, handler);
  37979. pdfManagerCapability.resolve(pdfManager);
  37980. } catch (ex) {
  37981. pdfManagerCapability.reject(ex);
  37982. }
  37983. cancelXHRs = null;
  37984. },
  37985. onProgressiveData: source.disableStream ? null :
  37986. function onProgressiveData(chunk) {
  37987. if (!pdfManager) {
  37988. cachedChunks.push(chunk);
  37989. return;
  37990. }
  37991. pdfManager.sendProgressiveData(chunk);
  37992. },
  37993. onDone: function onDone(args) {
  37994. if (pdfManager) {
  37995. return; // already processed
  37996. }
  37997. var pdfFile;
  37998. if (args === null) {
  37999. // TODO add some streaming manager, e.g. for unknown length files.
  38000. // The data was returned in the onProgressiveData, combining...
  38001. var pdfFileLength = 0, pos = 0;
  38002. cachedChunks.forEach(function (chunk) {
  38003. pdfFileLength += chunk.byteLength;
  38004. });
  38005. if (source.length && pdfFileLength !== source.length) {
  38006. warn('reported HTTP length is different from actual');
  38007. }
  38008. var pdfFileArray = new Uint8Array(pdfFileLength);
  38009. cachedChunks.forEach(function (chunk) {
  38010. pdfFileArray.set(new Uint8Array(chunk), pos);
  38011. pos += chunk.byteLength;
  38012. });
  38013. pdfFile = pdfFileArray.buffer;
  38014. } else {
  38015. pdfFile = args.chunk;
  38016. }
  38017. // the data is array, instantiating directly from it
  38018. try {
  38019. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  38020. pdfManagerCapability.resolve(pdfManager);
  38021. } catch (ex) {
  38022. pdfManagerCapability.reject(ex);
  38023. }
  38024. cancelXHRs = null;
  38025. },
  38026. onError: function onError(status) {
  38027. var exception;
  38028. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38029. exception = new MissingPDFException('Missing PDF "' +
  38030. source.url + '".');
  38031. handler.send('MissingPDF', exception);
  38032. } else {
  38033. exception = new UnexpectedResponseException(
  38034. 'Unexpected server response (' + status +
  38035. ') while retrieving PDF "' + source.url + '".', status);
  38036. handler.send('UnexpectedResponse', exception);
  38037. }
  38038. cancelXHRs = null;
  38039. },
  38040. onProgress: function onProgress(evt) {
  38041. handler.send('DocProgress', {
  38042. loaded: evt.loaded,
  38043. total: evt.lengthComputable ? evt.total : source.length
  38044. });
  38045. }
  38046. });
  38047. cancelXHRs = function () {
  38048. networkManager.abortRequest(fullRequestXhrId);
  38049. };
  38050. return pdfManagerCapability.promise;
  38051. }
  38052. var setupDoc = function(data) {
  38053. var onSuccess = function(doc) {
  38054. ensureNotTerminated();
  38055. handler.send('GetDoc', { pdfInfo: doc });
  38056. };
  38057. var onFailure = function(e) {
  38058. if (e instanceof PasswordException) {
  38059. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38060. handler.send('NeedPassword', e);
  38061. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38062. handler.send('IncorrectPassword', e);
  38063. }
  38064. } else if (e instanceof InvalidPDFException) {
  38065. handler.send('InvalidPDF', e);
  38066. } else if (e instanceof MissingPDFException) {
  38067. handler.send('MissingPDF', e);
  38068. } else if (e instanceof UnexpectedResponseException) {
  38069. handler.send('UnexpectedResponse', e);
  38070. } else {
  38071. handler.send('UnknownError',
  38072. new UnknownErrorException(e.message, e.toString()));
  38073. }
  38074. };
  38075. ensureNotTerminated();
  38076. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38077. -1 : data.maxImageSize;
  38078. PDFJS.disableFontFace = data.disableFontFace;
  38079. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38080. PDFJS.verbosity = data.verbosity;
  38081. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38082. null : data.cMapUrl;
  38083. PDFJS.cMapPacked = data.cMapPacked === true;
  38084. getPdfManager(data).then(function (newPdfManager) {
  38085. if (terminated) {
  38086. // We were in a process of setting up the manager, but it got
  38087. // terminated in the middle.
  38088. newPdfManager.terminate();
  38089. throw new Error('Worker was terminated');
  38090. }
  38091. pdfManager = newPdfManager;
  38092. handler.send('PDFManagerReady', null);
  38093. pdfManager.onLoadedStream().then(function(stream) {
  38094. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38095. });
  38096. }).then(function pdfManagerReady() {
  38097. ensureNotTerminated();
  38098. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38099. ensureNotTerminated();
  38100. // Try again with recoveryMode == true
  38101. if (!(ex instanceof XRefParseException)) {
  38102. if (ex instanceof PasswordException) {
  38103. // after password exception prepare to receive a new password
  38104. // to repeat loading
  38105. pdfManager.passwordChanged().then(pdfManagerReady);
  38106. }
  38107. onFailure(ex);
  38108. return;
  38109. }
  38110. pdfManager.requestLoadedStream();
  38111. pdfManager.onLoadedStream().then(function() {
  38112. ensureNotTerminated();
  38113. loadDocument(true).then(onSuccess, onFailure);
  38114. });
  38115. }, onFailure);
  38116. }, onFailure);
  38117. };
  38118. handler.on('GetPage', function wphSetupGetPage(data) {
  38119. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38120. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38121. var refPromise = pdfManager.ensure(page, 'ref');
  38122. var viewPromise = pdfManager.ensure(page, 'view');
  38123. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38124. function(results) {
  38125. return {
  38126. rotate: results[0],
  38127. ref: results[1],
  38128. view: results[2]
  38129. };
  38130. });
  38131. });
  38132. });
  38133. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38134. var ref = new Ref(data.ref.num, data.ref.gen);
  38135. var catalog = pdfManager.pdfDocument.catalog;
  38136. return catalog.getPageIndex(ref);
  38137. });
  38138. handler.on('GetDestinations',
  38139. function wphSetupGetDestinations(data) {
  38140. return pdfManager.ensureCatalog('destinations');
  38141. }
  38142. );
  38143. handler.on('GetDestination',
  38144. function wphSetupGetDestination(data) {
  38145. return pdfManager.ensureCatalog('getDestination', [data.id]);
  38146. }
  38147. );
  38148. handler.on('GetAttachments',
  38149. function wphSetupGetAttachments(data) {
  38150. return pdfManager.ensureCatalog('attachments');
  38151. }
  38152. );
  38153. handler.on('GetJavaScript',
  38154. function wphSetupGetJavaScript(data) {
  38155. return pdfManager.ensureCatalog('javaScript');
  38156. }
  38157. );
  38158. handler.on('GetOutline',
  38159. function wphSetupGetOutline(data) {
  38160. return pdfManager.ensureCatalog('documentOutline');
  38161. }
  38162. );
  38163. handler.on('GetMetadata',
  38164. function wphSetupGetMetadata(data) {
  38165. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38166. pdfManager.ensureCatalog('metadata')]);
  38167. }
  38168. );
  38169. handler.on('GetData', function wphSetupGetData(data) {
  38170. pdfManager.requestLoadedStream();
  38171. return pdfManager.onLoadedStream().then(function(stream) {
  38172. return stream.bytes;
  38173. });
  38174. });
  38175. handler.on('GetStats',
  38176. function wphSetupGetStats(data) {
  38177. return pdfManager.pdfDocument.xref.stats;
  38178. }
  38179. );
  38180. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38181. pdfManager.updatePassword(data);
  38182. });
  38183. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38184. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38185. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  38186. });
  38187. });
  38188. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38189. var pageIndex = data.pageIndex;
  38190. pdfManager.getPage(pageIndex).then(function(page) {
  38191. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  38192. startWorkerTask(task);
  38193. var pageNum = pageIndex + 1;
  38194. var start = Date.now();
  38195. // Pre compile the pdf page and fetch the fonts/images.
  38196. page.getOperatorList(handler, task, data.intent).then(
  38197. function(operatorList) {
  38198. finishWorkerTask(task);
  38199. info('page=' + pageNum + ' - getOperatorList: time=' +
  38200. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  38201. }, function(e) {
  38202. finishWorkerTask(task);
  38203. if (task.terminated) {
  38204. return; // ignoring errors from the terminated thread
  38205. }
  38206. // For compatibility with older behavior, generating unknown
  38207. // unsupported feature notification on errors.
  38208. handler.send('UnsupportedFeature',
  38209. {featureId: UNSUPPORTED_FEATURES.unknown});
  38210. var minimumStackMessage =
  38211. 'worker.js: while trying to getPage() and getOperatorList()';
  38212. var wrappedException;
  38213. // Turn the error into an obj that can be serialized
  38214. if (typeof e === 'string') {
  38215. wrappedException = {
  38216. message: e,
  38217. stack: minimumStackMessage
  38218. };
  38219. } else if (typeof e === 'object') {
  38220. wrappedException = {
  38221. message: e.message || e.toString(),
  38222. stack: e.stack || minimumStackMessage
  38223. };
  38224. } else {
  38225. wrappedException = {
  38226. message: 'Unknown exception type: ' + (typeof e),
  38227. stack: minimumStackMessage
  38228. };
  38229. }
  38230. handler.send('PageError', {
  38231. pageNum: pageNum,
  38232. error: wrappedException,
  38233. intent: data.intent
  38234. });
  38235. });
  38236. });
  38237. }, this);
  38238. handler.on('GetTextContent', function wphExtractText(data) {
  38239. var pageIndex = data.pageIndex;
  38240. var normalizeWhitespace = data.normalizeWhitespace;
  38241. return pdfManager.getPage(pageIndex).then(function(page) {
  38242. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  38243. startWorkerTask(task);
  38244. var pageNum = pageIndex + 1;
  38245. var start = Date.now();
  38246. return page.extractTextContent(task, normalizeWhitespace).then(
  38247. function(textContent) {
  38248. finishWorkerTask(task);
  38249. info('text indexing: page=' + pageNum + ' - time=' +
  38250. (Date.now() - start) + 'ms');
  38251. return textContent;
  38252. }, function (reason) {
  38253. finishWorkerTask(task);
  38254. if (task.terminated) {
  38255. return; // ignoring errors from the terminated thread
  38256. }
  38257. throw reason;
  38258. });
  38259. });
  38260. });
  38261. handler.on('Cleanup', function wphCleanup(data) {
  38262. return pdfManager.cleanup();
  38263. });
  38264. handler.on('Terminate', function wphTerminate(data) {
  38265. terminated = true;
  38266. if (pdfManager) {
  38267. pdfManager.terminate();
  38268. pdfManager = null;
  38269. }
  38270. if (cancelXHRs) {
  38271. cancelXHRs();
  38272. }
  38273. var waitOn = [];
  38274. WorkerTasks.forEach(function (task) {
  38275. waitOn.push(task.finished);
  38276. task.terminate();
  38277. });
  38278. return Promise.all(waitOn).then(function () {
  38279. // Notice that even if we destroying handler, resolved response promise
  38280. // must be sent back.
  38281. handler.destroy();
  38282. handler = null;
  38283. });
  38284. });
  38285. handler.on('Ready', function wphReady(data) {
  38286. setupDoc(docParams);
  38287. docParams = null; // we don't need docParams anymore -- saving memory.
  38288. });
  38289. return workerHandlerName;
  38290. }
  38291. };
  38292. var consoleTimer = {};
  38293. var workerConsole = {
  38294. log: function log() {
  38295. var args = Array.prototype.slice.call(arguments);
  38296. globalScope.postMessage({
  38297. targetName: 'main',
  38298. action: 'console_log',
  38299. data: args
  38300. });
  38301. },
  38302. error: function error() {
  38303. var args = Array.prototype.slice.call(arguments);
  38304. globalScope.postMessage({
  38305. targetName: 'main',
  38306. action: 'console_error',
  38307. data: args
  38308. });
  38309. throw 'pdf.js execution error';
  38310. },
  38311. time: function time(name) {
  38312. consoleTimer[name] = Date.now();
  38313. },
  38314. timeEnd: function timeEnd(name) {
  38315. var time = consoleTimer[name];
  38316. if (!time) {
  38317. error('Unknown timer name ' + name);
  38318. }
  38319. this.log('Timer:', name, Date.now() - time);
  38320. }
  38321. };
  38322. // Worker thread?
  38323. if (typeof window === 'undefined' && typeof require === 'undefined') {
  38324. if (!('console' in globalScope)) {
  38325. globalScope.console = workerConsole;
  38326. }
  38327. var handler = new MessageHandler('worker', 'main', self);
  38328. WorkerMessageHandler.setup(handler, self);
  38329. }
  38330. exports.WorkerTask = WorkerTask;
  38331. exports.WorkerMessageHandler = WorkerMessageHandler;
  38332. }));
  38333. }).call((typeof window === 'undefined') ? this : window);
  38334. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  38335. // workerSrc is not set -- using last script url to define default location
  38336. PDFJS.workerSrc = (function () {
  38337. 'use strict';
  38338. var pdfJsSrc = document.currentScript.src;
  38339. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  38340. })();
  38341. }