pdf.worker.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.worker', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfWorker = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.6.217';
  30. var pdfjsBuild = '9b3a91f';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreBidi = {}));
  203. }
  204. }(this, function (exports) {
  205. // Character types for symbols from 0000 to 00FF.
  206. var baseTypes = [
  207. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  208. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  209. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  210. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  211. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  212. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  213. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  214. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  215. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  216. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  217. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  218. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  219. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  220. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  221. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  222. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  223. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  224. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  225. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  226. ];
  227. // Character types for symbols from 0600 to 06FF
  228. var arabicTypes = [
  229. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  230. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  231. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  232. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  233. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  234. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  235. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  236. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  237. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  238. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  240. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  241. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  242. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  243. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  244. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  245. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  247. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  248. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  249. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  250. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  251. ];
  252. function isOdd(i) {
  253. return (i & 1) !== 0;
  254. }
  255. function isEven(i) {
  256. return (i & 1) === 0;
  257. }
  258. function findUnequal(arr, start, value) {
  259. for (var j = start, jj = arr.length; j < jj; ++j) {
  260. if (arr[j] !== value) {
  261. return j;
  262. }
  263. }
  264. return j;
  265. }
  266. function setValues(arr, start, end, value) {
  267. for (var j = start; j < end; ++j) {
  268. arr[j] = value;
  269. }
  270. }
  271. function reverseValues(arr, start, end) {
  272. for (var i = start, j = end - 1; i < j; ++i, --j) {
  273. var temp = arr[i];
  274. arr[i] = arr[j];
  275. arr[j] = temp;
  276. }
  277. }
  278. function createBidiText(str, isLTR, vertical) {
  279. return {
  280. str: str,
  281. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  282. };
  283. }
  284. // These are used in bidi(), which is called frequently. We re-use them on
  285. // each call to avoid unnecessary allocations.
  286. var chars = [];
  287. var types = [];
  288. function bidi(str, startLevel, vertical) {
  289. var isLTR = true;
  290. var strLength = str.length;
  291. if (strLength === 0 || vertical) {
  292. return createBidiText(str, isLTR, vertical);
  293. }
  294. // Get types and fill arrays
  295. chars.length = strLength;
  296. types.length = strLength;
  297. var numBidi = 0;
  298. var i, ii;
  299. for (i = 0; i < strLength; ++i) {
  300. chars[i] = str.charAt(i);
  301. var charCode = str.charCodeAt(i);
  302. var charType = 'L';
  303. if (charCode <= 0x00ff) {
  304. charType = baseTypes[charCode];
  305. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  306. charType = 'R';
  307. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  308. charType = arabicTypes[charCode & 0xff];
  309. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  310. charType = 'AL';
  311. }
  312. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  313. numBidi++;
  314. }
  315. types[i] = charType;
  316. }
  317. // Detect the bidi method
  318. // - If there are no rtl characters then no bidi needed
  319. // - If less than 30% chars are rtl then string is primarily ltr
  320. // - If more than 30% chars are rtl then string is primarily rtl
  321. if (numBidi === 0) {
  322. isLTR = true;
  323. return createBidiText(str, isLTR);
  324. }
  325. if (startLevel === -1) {
  326. if ((strLength / numBidi) < 0.3) {
  327. isLTR = true;
  328. startLevel = 0;
  329. } else {
  330. isLTR = false;
  331. startLevel = 1;
  332. }
  333. }
  334. var levels = [];
  335. for (i = 0; i < strLength; ++i) {
  336. levels[i] = startLevel;
  337. }
  338. /*
  339. X1-X10: skip most of this, since we are NOT doing the embeddings.
  340. */
  341. var e = (isOdd(startLevel) ? 'R' : 'L');
  342. var sor = e;
  343. var eor = sor;
  344. /*
  345. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  346. type of the NSM to the type of the previous character. If the NSM is at the
  347. start of the level run, it will get the type of sor.
  348. */
  349. var lastType = sor;
  350. for (i = 0; i < strLength; ++i) {
  351. if (types[i] === 'NSM') {
  352. types[i] = lastType;
  353. } else {
  354. lastType = types[i];
  355. }
  356. }
  357. /*
  358. W2. Search backwards from each instance of a European number until the
  359. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  360. the type of the European number to Arabic number.
  361. */
  362. lastType = sor;
  363. var t;
  364. for (i = 0; i < strLength; ++i) {
  365. t = types[i];
  366. if (t === 'EN') {
  367. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  368. } else if (t === 'R' || t === 'L' || t === 'AL') {
  369. lastType = t;
  370. }
  371. }
  372. /*
  373. W3. Change all ALs to R.
  374. */
  375. for (i = 0; i < strLength; ++i) {
  376. t = types[i];
  377. if (t === 'AL') {
  378. types[i] = 'R';
  379. }
  380. }
  381. /*
  382. W4. A single European separator between two European numbers changes to a
  383. European number. A single common separator between two numbers of the same
  384. type changes to that type:
  385. */
  386. for (i = 1; i < strLength - 1; ++i) {
  387. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  388. types[i] = 'EN';
  389. }
  390. if (types[i] === 'CS' &&
  391. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  392. types[i + 1] === types[i - 1]) {
  393. types[i] = types[i - 1];
  394. }
  395. }
  396. /*
  397. W5. A sequence of European terminators adjacent to European numbers changes
  398. to all European numbers:
  399. */
  400. for (i = 0; i < strLength; ++i) {
  401. if (types[i] === 'EN') {
  402. // do before
  403. var j;
  404. for (j = i - 1; j >= 0; --j) {
  405. if (types[j] !== 'ET') {
  406. break;
  407. }
  408. types[j] = 'EN';
  409. }
  410. // do after
  411. for (j = i + 1; j < strLength; ++j) {
  412. if (types[j] !== 'ET') {
  413. break;
  414. }
  415. types[j] = 'EN';
  416. }
  417. }
  418. }
  419. /*
  420. W6. Otherwise, separators and terminators change to Other Neutral:
  421. */
  422. for (i = 0; i < strLength; ++i) {
  423. t = types[i];
  424. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  425. types[i] = 'ON';
  426. }
  427. }
  428. /*
  429. W7. Search backwards from each instance of a European number until the
  430. first strong type (R, L, or sor) is found. If an L is found, then change
  431. the type of the European number to L.
  432. */
  433. lastType = sor;
  434. for (i = 0; i < strLength; ++i) {
  435. t = types[i];
  436. if (t === 'EN') {
  437. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  438. } else if (t === 'R' || t === 'L') {
  439. lastType = t;
  440. }
  441. }
  442. /*
  443. N1. A sequence of neutrals takes the direction of the surrounding strong
  444. text if the text on both sides has the same direction. European and Arabic
  445. numbers are treated as though they were R. Start-of-level-run (sor) and
  446. end-of-level-run (eor) are used at level run boundaries.
  447. */
  448. for (i = 0; i < strLength; ++i) {
  449. if (types[i] === 'ON') {
  450. var end = findUnequal(types, i + 1, 'ON');
  451. var before = sor;
  452. if (i > 0) {
  453. before = types[i - 1];
  454. }
  455. var after = eor;
  456. if (end + 1 < strLength) {
  457. after = types[end + 1];
  458. }
  459. if (before !== 'L') {
  460. before = 'R';
  461. }
  462. if (after !== 'L') {
  463. after = 'R';
  464. }
  465. if (before === after) {
  466. setValues(types, i, end, before);
  467. }
  468. i = end - 1; // reset to end (-1 so next iteration is ok)
  469. }
  470. }
  471. /*
  472. N2. Any remaining neutrals take the embedding direction.
  473. */
  474. for (i = 0; i < strLength; ++i) {
  475. if (types[i] === 'ON') {
  476. types[i] = e;
  477. }
  478. }
  479. /*
  480. I1. For all characters with an even (left-to-right) embedding direction,
  481. those of type R go up one level and those of type AN or EN go up two
  482. levels.
  483. I2. For all characters with an odd (right-to-left) embedding direction,
  484. those of type L, EN or AN go up one level.
  485. */
  486. for (i = 0; i < strLength; ++i) {
  487. t = types[i];
  488. if (isEven(levels[i])) {
  489. if (t === 'R') {
  490. levels[i] += 1;
  491. } else if (t === 'AN' || t === 'EN') {
  492. levels[i] += 2;
  493. }
  494. } else { // isOdd
  495. if (t === 'L' || t === 'AN' || t === 'EN') {
  496. levels[i] += 1;
  497. }
  498. }
  499. }
  500. /*
  501. L1. On each line, reset the embedding level of the following characters to
  502. the paragraph embedding level:
  503. segment separators,
  504. paragraph separators,
  505. any sequence of whitespace characters preceding a segment separator or
  506. paragraph separator, and any sequence of white space characters at the end
  507. of the line.
  508. */
  509. // don't bother as text is only single line
  510. /*
  511. L2. From the highest level found in the text to the lowest odd level on
  512. each line, reverse any contiguous sequence of characters that are at that
  513. level or higher.
  514. */
  515. // find highest level & lowest odd level
  516. var highestLevel = -1;
  517. var lowestOddLevel = 99;
  518. var level;
  519. for (i = 0, ii = levels.length; i < ii; ++i) {
  520. level = levels[i];
  521. if (highestLevel < level) {
  522. highestLevel = level;
  523. }
  524. if (lowestOddLevel > level && isOdd(level)) {
  525. lowestOddLevel = level;
  526. }
  527. }
  528. // now reverse between those limits
  529. for (level = highestLevel; level >= lowestOddLevel; --level) {
  530. // find segments to reverse
  531. var start = -1;
  532. for (i = 0, ii = levels.length; i < ii; ++i) {
  533. if (levels[i] < level) {
  534. if (start >= 0) {
  535. reverseValues(chars, start, i);
  536. start = -1;
  537. }
  538. } else if (start < 0) {
  539. start = i;
  540. }
  541. }
  542. if (start >= 0) {
  543. reverseValues(chars, start, levels.length);
  544. }
  545. }
  546. /*
  547. L3. Combining marks applied to a right-to-left base character will at this
  548. point precede their base character. If the rendering engine expects them to
  549. follow the base characters in the final display process, then the ordering
  550. of the marks and the base character must be reversed.
  551. */
  552. // don't bother for now
  553. /*
  554. L4. A character that possesses the mirrored property as specified by
  555. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  556. directionality of that character is R.
  557. */
  558. // don't mirror as characters are already mirrored in the pdf
  559. // Finally, return string
  560. for (i = 0, ii = chars.length; i < ii; ++i) {
  561. var ch = chars[i];
  562. if (ch === '<' || ch === '>') {
  563. chars[i] = '';
  564. }
  565. }
  566. return createBidiText(chars.join(''), isLTR);
  567. }
  568. exports.bidi = bidi;
  569. }));
  570. (function (root, factory) {
  571. {
  572. factory((root.pdfjsCoreCharsets = {}));
  573. }
  574. }(this, function (exports) {
  575. var ISOAdobeCharset = [
  576. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  577. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  578. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  579. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  580. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  581. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  582. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  583. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  584. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  585. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  586. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  587. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  588. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  589. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  590. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  591. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  592. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  593. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  594. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  595. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  596. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  597. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  598. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  599. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  600. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  601. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  602. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  603. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  604. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  605. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  606. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  607. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  608. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  609. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  610. ];
  611. var ExpertCharset = [
  612. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  613. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  614. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  615. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  616. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  617. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  618. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  619. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  620. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  621. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  622. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  623. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  624. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  625. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  626. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  627. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  628. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  629. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  630. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  631. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  632. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  633. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  634. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  635. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  636. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  637. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  638. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  639. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  640. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  641. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  642. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  643. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  644. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  645. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  646. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  647. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  648. 'Ydieresissmall'
  649. ];
  650. var ExpertSubsetCharset = [
  651. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  652. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  653. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  654. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  655. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  656. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  657. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  658. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  659. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  660. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  661. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  662. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  663. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  664. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  665. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  666. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  667. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  668. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  669. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  670. 'periodinferior', 'commainferior'
  671. ];
  672. exports.ISOAdobeCharset = ISOAdobeCharset;
  673. exports.ExpertCharset = ExpertCharset;
  674. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  675. }));
  676. (function (root, factory) {
  677. {
  678. factory((root.pdfjsCoreEncodings = {}));
  679. }
  680. }(this, function (exports) {
  681. var ExpertEncoding = [
  682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  683. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  684. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  685. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  686. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  687. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  688. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  689. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  690. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  691. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  692. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  693. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  694. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  695. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  696. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  697. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  698. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  699. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  700. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  701. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  702. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  703. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  704. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  705. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  706. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  707. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  708. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  709. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  710. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  711. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  712. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  713. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  714. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  715. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  716. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  717. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  718. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  719. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  720. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  721. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  722. 'Ydieresissmall'];
  723. var MacExpertEncoding = [
  724. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  725. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  726. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  727. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  728. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  729. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  730. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  731. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  732. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  733. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  734. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  735. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  736. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  737. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  738. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  739. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  740. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  741. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  742. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  743. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  744. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  745. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  746. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  747. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  748. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  749. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  750. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  751. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  752. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  753. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  754. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  755. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  756. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  757. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  758. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  759. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  760. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  761. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  762. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  763. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  764. var MacRomanEncoding = [
  765. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  766. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  767. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  768. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  769. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  770. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  771. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  772. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  773. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  774. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  775. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  776. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  777. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  778. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  779. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  780. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  781. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  782. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  783. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  784. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  785. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  786. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  787. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  788. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  789. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  790. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  791. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  792. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  793. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  794. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  795. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  796. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  797. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  798. 'ogonek', 'caron'];
  799. var StandardEncoding = [
  800. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  801. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  802. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  803. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  804. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  805. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  806. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  807. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  808. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  809. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  810. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  811. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  812. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  813. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  814. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  815. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  816. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  817. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  818. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  819. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  820. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  821. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  822. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  823. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  824. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  825. var WinAnsiEncoding = [
  826. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  827. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  828. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  829. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  830. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  831. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  832. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  833. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  834. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  835. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  836. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  837. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  838. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  839. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  840. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  841. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  842. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  843. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  844. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  845. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  846. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  847. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  848. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  849. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  850. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  851. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  852. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  853. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  854. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  855. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  856. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  857. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  858. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  859. 'ydieresis'];
  860. var SymbolSetEncoding = [
  861. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  862. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  863. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  864. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  865. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  866. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  867. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  868. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  869. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  870. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  871. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  872. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  873. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  874. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  875. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  877. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  878. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  879. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  880. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  881. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  882. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  883. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  884. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  885. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  886. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  887. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  888. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  889. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  890. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  891. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  892. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  893. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  894. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  895. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  896. 'bracerightbt'];
  897. var ZapfDingbatsEncoding = [
  898. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  899. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  900. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  901. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  902. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  903. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  904. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  905. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  906. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  907. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  908. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  909. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  910. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  911. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  912. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  913. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  914. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  915. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  916. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  917. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  918. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  919. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  920. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  921. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  922. function getEncoding(encodingName) {
  923. switch (encodingName) {
  924. case 'WinAnsiEncoding':
  925. return WinAnsiEncoding;
  926. case 'StandardEncoding':
  927. return StandardEncoding;
  928. case 'MacRomanEncoding':
  929. return MacRomanEncoding;
  930. case 'SymbolSetEncoding':
  931. return SymbolSetEncoding;
  932. case 'ZapfDingbatsEncoding':
  933. return ZapfDingbatsEncoding;
  934. case 'ExpertEncoding':
  935. return ExpertEncoding;
  936. case 'MacExpertEncoding':
  937. return MacExpertEncoding;
  938. default:
  939. return null;
  940. }
  941. }
  942. exports.WinAnsiEncoding = WinAnsiEncoding;
  943. exports.StandardEncoding = StandardEncoding;
  944. exports.MacRomanEncoding = MacRomanEncoding;
  945. exports.SymbolSetEncoding = SymbolSetEncoding;
  946. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  947. exports.ExpertEncoding = ExpertEncoding;
  948. exports.getEncoding = getEncoding;
  949. }));
  950. (function (root, factory) {
  951. {
  952. factory((root.pdfjsSharedUtil = {}));
  953. }
  954. }(this, function (exports) {
  955. var globalScope = (typeof window !== 'undefined') ? window :
  956. (typeof global !== 'undefined') ? global :
  957. (typeof self !== 'undefined') ? self : this;
  958. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  959. var TextRenderingMode = {
  960. FILL: 0,
  961. STROKE: 1,
  962. FILL_STROKE: 2,
  963. INVISIBLE: 3,
  964. FILL_ADD_TO_PATH: 4,
  965. STROKE_ADD_TO_PATH: 5,
  966. FILL_STROKE_ADD_TO_PATH: 6,
  967. ADD_TO_PATH: 7,
  968. FILL_STROKE_MASK: 3,
  969. ADD_TO_PATH_FLAG: 4
  970. };
  971. var ImageKind = {
  972. GRAYSCALE_1BPP: 1,
  973. RGB_24BPP: 2,
  974. RGBA_32BPP: 3
  975. };
  976. var AnnotationType = {
  977. TEXT: 1,
  978. LINK: 2,
  979. FREETEXT: 3,
  980. LINE: 4,
  981. SQUARE: 5,
  982. CIRCLE: 6,
  983. POLYGON: 7,
  984. POLYLINE: 8,
  985. HIGHLIGHT: 9,
  986. UNDERLINE: 10,
  987. SQUIGGLY: 11,
  988. STRIKEOUT: 12,
  989. STAMP: 13,
  990. CARET: 14,
  991. INK: 15,
  992. POPUP: 16,
  993. FILEATTACHMENT: 17,
  994. SOUND: 18,
  995. MOVIE: 19,
  996. WIDGET: 20,
  997. SCREEN: 21,
  998. PRINTERMARK: 22,
  999. TRAPNET: 23,
  1000. WATERMARK: 24,
  1001. THREED: 25,
  1002. REDACT: 26
  1003. };
  1004. var AnnotationFlag = {
  1005. INVISIBLE: 0x01,
  1006. HIDDEN: 0x02,
  1007. PRINT: 0x04,
  1008. NOZOOM: 0x08,
  1009. NOROTATE: 0x10,
  1010. NOVIEW: 0x20,
  1011. READONLY: 0x40,
  1012. LOCKED: 0x80,
  1013. TOGGLENOVIEW: 0x100,
  1014. LOCKEDCONTENTS: 0x200
  1015. };
  1016. var AnnotationFieldFlag = {
  1017. READONLY: 0x0000001,
  1018. REQUIRED: 0x0000002,
  1019. NOEXPORT: 0x0000004,
  1020. MULTILINE: 0x0001000,
  1021. PASSWORD: 0x0002000,
  1022. NOTOGGLETOOFF: 0x0004000,
  1023. RADIO: 0x0008000,
  1024. PUSHBUTTON: 0x0010000,
  1025. COMBO: 0x0020000,
  1026. EDIT: 0x0040000,
  1027. SORT: 0x0080000,
  1028. FILESELECT: 0x0100000,
  1029. MULTISELECT: 0x0200000,
  1030. DONOTSPELLCHECK: 0x0400000,
  1031. DONOTSCROLL: 0x0800000,
  1032. COMB: 0x1000000,
  1033. RICHTEXT: 0x2000000,
  1034. RADIOSINUNISON: 0x2000000,
  1035. COMMITONSELCHANGE: 0x4000000,
  1036. };
  1037. var AnnotationBorderStyleType = {
  1038. SOLID: 1,
  1039. DASHED: 2,
  1040. BEVELED: 3,
  1041. INSET: 4,
  1042. UNDERLINE: 5
  1043. };
  1044. var StreamType = {
  1045. UNKNOWN: 0,
  1046. FLATE: 1,
  1047. LZW: 2,
  1048. DCT: 3,
  1049. JPX: 4,
  1050. JBIG: 5,
  1051. A85: 6,
  1052. AHX: 7,
  1053. CCF: 8,
  1054. RL: 9
  1055. };
  1056. var FontType = {
  1057. UNKNOWN: 0,
  1058. TYPE1: 1,
  1059. TYPE1C: 2,
  1060. CIDFONTTYPE0: 3,
  1061. CIDFONTTYPE0C: 4,
  1062. TRUETYPE: 5,
  1063. CIDFONTTYPE2: 6,
  1064. TYPE3: 7,
  1065. OPENTYPE: 8,
  1066. TYPE0: 9,
  1067. MMTYPE1: 10
  1068. };
  1069. var VERBOSITY_LEVELS = {
  1070. errors: 0,
  1071. warnings: 1,
  1072. infos: 5
  1073. };
  1074. // All the possible operations for an operator list.
  1075. var OPS = {
  1076. // Intentionally start from 1 so it is easy to spot bad operators that will be
  1077. // 0's.
  1078. dependency: 1,
  1079. setLineWidth: 2,
  1080. setLineCap: 3,
  1081. setLineJoin: 4,
  1082. setMiterLimit: 5,
  1083. setDash: 6,
  1084. setRenderingIntent: 7,
  1085. setFlatness: 8,
  1086. setGState: 9,
  1087. save: 10,
  1088. restore: 11,
  1089. transform: 12,
  1090. moveTo: 13,
  1091. lineTo: 14,
  1092. curveTo: 15,
  1093. curveTo2: 16,
  1094. curveTo3: 17,
  1095. closePath: 18,
  1096. rectangle: 19,
  1097. stroke: 20,
  1098. closeStroke: 21,
  1099. fill: 22,
  1100. eoFill: 23,
  1101. fillStroke: 24,
  1102. eoFillStroke: 25,
  1103. closeFillStroke: 26,
  1104. closeEOFillStroke: 27,
  1105. endPath: 28,
  1106. clip: 29,
  1107. eoClip: 30,
  1108. beginText: 31,
  1109. endText: 32,
  1110. setCharSpacing: 33,
  1111. setWordSpacing: 34,
  1112. setHScale: 35,
  1113. setLeading: 36,
  1114. setFont: 37,
  1115. setTextRenderingMode: 38,
  1116. setTextRise: 39,
  1117. moveText: 40,
  1118. setLeadingMoveText: 41,
  1119. setTextMatrix: 42,
  1120. nextLine: 43,
  1121. showText: 44,
  1122. showSpacedText: 45,
  1123. nextLineShowText: 46,
  1124. nextLineSetSpacingShowText: 47,
  1125. setCharWidth: 48,
  1126. setCharWidthAndBounds: 49,
  1127. setStrokeColorSpace: 50,
  1128. setFillColorSpace: 51,
  1129. setStrokeColor: 52,
  1130. setStrokeColorN: 53,
  1131. setFillColor: 54,
  1132. setFillColorN: 55,
  1133. setStrokeGray: 56,
  1134. setFillGray: 57,
  1135. setStrokeRGBColor: 58,
  1136. setFillRGBColor: 59,
  1137. setStrokeCMYKColor: 60,
  1138. setFillCMYKColor: 61,
  1139. shadingFill: 62,
  1140. beginInlineImage: 63,
  1141. beginImageData: 64,
  1142. endInlineImage: 65,
  1143. paintXObject: 66,
  1144. markPoint: 67,
  1145. markPointProps: 68,
  1146. beginMarkedContent: 69,
  1147. beginMarkedContentProps: 70,
  1148. endMarkedContent: 71,
  1149. beginCompat: 72,
  1150. endCompat: 73,
  1151. paintFormXObjectBegin: 74,
  1152. paintFormXObjectEnd: 75,
  1153. beginGroup: 76,
  1154. endGroup: 77,
  1155. beginAnnotations: 78,
  1156. endAnnotations: 79,
  1157. beginAnnotation: 80,
  1158. endAnnotation: 81,
  1159. paintJpegXObject: 82,
  1160. paintImageMaskXObject: 83,
  1161. paintImageMaskXObjectGroup: 84,
  1162. paintImageXObject: 85,
  1163. paintInlineImageXObject: 86,
  1164. paintInlineImageXObjectGroup: 87,
  1165. paintImageXObjectRepeat: 88,
  1166. paintImageMaskXObjectRepeat: 89,
  1167. paintSolidColorImageMask: 90,
  1168. constructPath: 91
  1169. };
  1170. var verbosity = VERBOSITY_LEVELS.warnings;
  1171. function setVerbosityLevel(level) {
  1172. verbosity = level;
  1173. }
  1174. function getVerbosityLevel() {
  1175. return verbosity;
  1176. }
  1177. // A notice for devs. These are good for things that are helpful to devs, such
  1178. // as warning that Workers were disabled, which is important to devs but not
  1179. // end users.
  1180. function info(msg) {
  1181. if (verbosity >= VERBOSITY_LEVELS.infos) {
  1182. console.log('Info: ' + msg);
  1183. }
  1184. }
  1185. // Non-fatal warnings.
  1186. function warn(msg) {
  1187. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  1188. console.log('Warning: ' + msg);
  1189. }
  1190. }
  1191. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  1192. function deprecated(details) {
  1193. console.log('Deprecated API usage: ' + details);
  1194. }
  1195. // Fatal errors that should trigger the fallback UI and halt execution by
  1196. // throwing an exception.
  1197. function error(msg) {
  1198. if (verbosity >= VERBOSITY_LEVELS.errors) {
  1199. console.log('Error: ' + msg);
  1200. console.log(backtrace());
  1201. }
  1202. throw new Error(msg);
  1203. }
  1204. function backtrace() {
  1205. try {
  1206. throw new Error();
  1207. } catch (e) {
  1208. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  1209. }
  1210. }
  1211. function assert(cond, msg) {
  1212. if (!cond) {
  1213. error(msg);
  1214. }
  1215. }
  1216. var UNSUPPORTED_FEATURES = {
  1217. unknown: 'unknown',
  1218. forms: 'forms',
  1219. javaScript: 'javaScript',
  1220. smask: 'smask',
  1221. shadingPattern: 'shadingPattern',
  1222. font: 'font'
  1223. };
  1224. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  1225. function isSameOrigin(baseUrl, otherUrl) {
  1226. try {
  1227. var base = new URL(baseUrl);
  1228. if (!base.origin || base.origin === 'null') {
  1229. return false; // non-HTTP url
  1230. }
  1231. } catch (e) {
  1232. return false;
  1233. }
  1234. var other = new URL(otherUrl, base);
  1235. return base.origin === other.origin;
  1236. }
  1237. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  1238. function isValidUrl(url, allowRelative) {
  1239. if (!url || typeof url !== 'string') {
  1240. return false;
  1241. }
  1242. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  1243. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  1244. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  1245. if (!protocol) {
  1246. return allowRelative;
  1247. }
  1248. protocol = protocol[0].toLowerCase();
  1249. switch (protocol) {
  1250. case 'http':
  1251. case 'https':
  1252. case 'ftp':
  1253. case 'mailto':
  1254. case 'tel':
  1255. return true;
  1256. default:
  1257. return false;
  1258. }
  1259. }
  1260. function shadow(obj, prop, value) {
  1261. Object.defineProperty(obj, prop, { value: value,
  1262. enumerable: true,
  1263. configurable: true,
  1264. writable: false });
  1265. return value;
  1266. }
  1267. function getLookupTableFactory(initializer) {
  1268. var lookup;
  1269. return function () {
  1270. if (initializer) {
  1271. lookup = Object.create(null);
  1272. initializer(lookup);
  1273. initializer = null;
  1274. }
  1275. return lookup;
  1276. };
  1277. }
  1278. var PasswordResponses = {
  1279. NEED_PASSWORD: 1,
  1280. INCORRECT_PASSWORD: 2
  1281. };
  1282. var PasswordException = (function PasswordExceptionClosure() {
  1283. function PasswordException(msg, code) {
  1284. this.name = 'PasswordException';
  1285. this.message = msg;
  1286. this.code = code;
  1287. }
  1288. PasswordException.prototype = new Error();
  1289. PasswordException.constructor = PasswordException;
  1290. return PasswordException;
  1291. })();
  1292. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  1293. function UnknownErrorException(msg, details) {
  1294. this.name = 'UnknownErrorException';
  1295. this.message = msg;
  1296. this.details = details;
  1297. }
  1298. UnknownErrorException.prototype = new Error();
  1299. UnknownErrorException.constructor = UnknownErrorException;
  1300. return UnknownErrorException;
  1301. })();
  1302. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  1303. function InvalidPDFException(msg) {
  1304. this.name = 'InvalidPDFException';
  1305. this.message = msg;
  1306. }
  1307. InvalidPDFException.prototype = new Error();
  1308. InvalidPDFException.constructor = InvalidPDFException;
  1309. return InvalidPDFException;
  1310. })();
  1311. var MissingPDFException = (function MissingPDFExceptionClosure() {
  1312. function MissingPDFException(msg) {
  1313. this.name = 'MissingPDFException';
  1314. this.message = msg;
  1315. }
  1316. MissingPDFException.prototype = new Error();
  1317. MissingPDFException.constructor = MissingPDFException;
  1318. return MissingPDFException;
  1319. })();
  1320. var UnexpectedResponseException =
  1321. (function UnexpectedResponseExceptionClosure() {
  1322. function UnexpectedResponseException(msg, status) {
  1323. this.name = 'UnexpectedResponseException';
  1324. this.message = msg;
  1325. this.status = status;
  1326. }
  1327. UnexpectedResponseException.prototype = new Error();
  1328. UnexpectedResponseException.constructor = UnexpectedResponseException;
  1329. return UnexpectedResponseException;
  1330. })();
  1331. var NotImplementedException = (function NotImplementedExceptionClosure() {
  1332. function NotImplementedException(msg) {
  1333. this.message = msg;
  1334. }
  1335. NotImplementedException.prototype = new Error();
  1336. NotImplementedException.prototype.name = 'NotImplementedException';
  1337. NotImplementedException.constructor = NotImplementedException;
  1338. return NotImplementedException;
  1339. })();
  1340. var MissingDataException = (function MissingDataExceptionClosure() {
  1341. function MissingDataException(begin, end) {
  1342. this.begin = begin;
  1343. this.end = end;
  1344. this.message = 'Missing data [' + begin + ', ' + end + ')';
  1345. }
  1346. MissingDataException.prototype = new Error();
  1347. MissingDataException.prototype.name = 'MissingDataException';
  1348. MissingDataException.constructor = MissingDataException;
  1349. return MissingDataException;
  1350. })();
  1351. var XRefParseException = (function XRefParseExceptionClosure() {
  1352. function XRefParseException(msg) {
  1353. this.message = msg;
  1354. }
  1355. XRefParseException.prototype = new Error();
  1356. XRefParseException.prototype.name = 'XRefParseException';
  1357. XRefParseException.constructor = XRefParseException;
  1358. return XRefParseException;
  1359. })();
  1360. var NullCharactersRegExp = /\x00/g;
  1361. function removeNullCharacters(str) {
  1362. if (typeof str !== 'string') {
  1363. warn('The argument for removeNullCharacters must be a string.');
  1364. return str;
  1365. }
  1366. return str.replace(NullCharactersRegExp, '');
  1367. }
  1368. function bytesToString(bytes) {
  1369. assert(bytes !== null && typeof bytes === 'object' &&
  1370. bytes.length !== undefined, 'Invalid argument for bytesToString');
  1371. var length = bytes.length;
  1372. var MAX_ARGUMENT_COUNT = 8192;
  1373. if (length < MAX_ARGUMENT_COUNT) {
  1374. return String.fromCharCode.apply(null, bytes);
  1375. }
  1376. var strBuf = [];
  1377. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1378. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1379. var chunk = bytes.subarray(i, chunkEnd);
  1380. strBuf.push(String.fromCharCode.apply(null, chunk));
  1381. }
  1382. return strBuf.join('');
  1383. }
  1384. function stringToBytes(str) {
  1385. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  1386. var length = str.length;
  1387. var bytes = new Uint8Array(length);
  1388. for (var i = 0; i < length; ++i) {
  1389. bytes[i] = str.charCodeAt(i) & 0xFF;
  1390. }
  1391. return bytes;
  1392. }
  1393. /**
  1394. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  1395. * @param {Array|Uint8Array|string} arr
  1396. * @returns {number}
  1397. */
  1398. function arrayByteLength(arr) {
  1399. if (arr.length !== undefined) {
  1400. return arr.length;
  1401. }
  1402. assert(arr.byteLength !== undefined);
  1403. return arr.byteLength;
  1404. }
  1405. /**
  1406. * Combines array items (arrays) into single Uint8Array object.
  1407. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  1408. * @returns {Uint8Array}
  1409. */
  1410. function arraysToBytes(arr) {
  1411. // Shortcut: if first and only item is Uint8Array, return it.
  1412. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  1413. return arr[0];
  1414. }
  1415. var resultLength = 0;
  1416. var i, ii = arr.length;
  1417. var item, itemLength ;
  1418. for (i = 0; i < ii; i++) {
  1419. item = arr[i];
  1420. itemLength = arrayByteLength(item);
  1421. resultLength += itemLength;
  1422. }
  1423. var pos = 0;
  1424. var data = new Uint8Array(resultLength);
  1425. for (i = 0; i < ii; i++) {
  1426. item = arr[i];
  1427. if (!(item instanceof Uint8Array)) {
  1428. if (typeof item === 'string') {
  1429. item = stringToBytes(item);
  1430. } else {
  1431. item = new Uint8Array(item);
  1432. }
  1433. }
  1434. itemLength = item.byteLength;
  1435. data.set(item, pos);
  1436. pos += itemLength;
  1437. }
  1438. return data;
  1439. }
  1440. function string32(value) {
  1441. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  1442. (value >> 8) & 0xff, value & 0xff);
  1443. }
  1444. function log2(x) {
  1445. var n = 1, i = 0;
  1446. while (x > n) {
  1447. n <<= 1;
  1448. i++;
  1449. }
  1450. return i;
  1451. }
  1452. function readInt8(data, start) {
  1453. return (data[start] << 24) >> 24;
  1454. }
  1455. function readUint16(data, offset) {
  1456. return (data[offset] << 8) | data[offset + 1];
  1457. }
  1458. function readUint32(data, offset) {
  1459. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  1460. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  1461. }
  1462. // Lazy test the endianness of the platform
  1463. // NOTE: This will be 'true' for simulated TypedArrays
  1464. function isLittleEndian() {
  1465. var buffer8 = new Uint8Array(2);
  1466. buffer8[0] = 1;
  1467. var buffer16 = new Uint16Array(buffer8.buffer);
  1468. return (buffer16[0] === 1);
  1469. }
  1470. // Checks if it's possible to eval JS expressions.
  1471. function isEvalSupported() {
  1472. try {
  1473. /* jshint evil: true */
  1474. new Function('');
  1475. return true;
  1476. } catch (e) {
  1477. return false;
  1478. }
  1479. }
  1480. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  1481. function Uint32ArrayView(buffer, length) {
  1482. this.buffer = buffer;
  1483. this.byteLength = buffer.length;
  1484. this.length = length === undefined ? (this.byteLength >> 2) : length;
  1485. ensureUint32ArrayViewProps(this.length);
  1486. }
  1487. Uint32ArrayView.prototype = Object.create(null);
  1488. var uint32ArrayViewSetters = 0;
  1489. function createUint32ArrayProp(index) {
  1490. return {
  1491. get: function () {
  1492. var buffer = this.buffer, offset = index << 2;
  1493. return (buffer[offset] | (buffer[offset + 1] << 8) |
  1494. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  1495. },
  1496. set: function (value) {
  1497. var buffer = this.buffer, offset = index << 2;
  1498. buffer[offset] = value & 255;
  1499. buffer[offset + 1] = (value >> 8) & 255;
  1500. buffer[offset + 2] = (value >> 16) & 255;
  1501. buffer[offset + 3] = (value >>> 24) & 255;
  1502. }
  1503. };
  1504. }
  1505. function ensureUint32ArrayViewProps(length) {
  1506. while (uint32ArrayViewSetters < length) {
  1507. Object.defineProperty(Uint32ArrayView.prototype,
  1508. uint32ArrayViewSetters,
  1509. createUint32ArrayProp(uint32ArrayViewSetters));
  1510. uint32ArrayViewSetters++;
  1511. }
  1512. }
  1513. return Uint32ArrayView;
  1514. })();
  1515. exports.Uint32ArrayView = Uint32ArrayView;
  1516. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  1517. var Util = (function UtilClosure() {
  1518. function Util() {}
  1519. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  1520. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  1521. // creating many intermediate strings.
  1522. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  1523. rgbBuf[1] = r;
  1524. rgbBuf[3] = g;
  1525. rgbBuf[5] = b;
  1526. return rgbBuf.join('');
  1527. };
  1528. // Concatenates two transformation matrices together and returns the result.
  1529. Util.transform = function Util_transform(m1, m2) {
  1530. return [
  1531. m1[0] * m2[0] + m1[2] * m2[1],
  1532. m1[1] * m2[0] + m1[3] * m2[1],
  1533. m1[0] * m2[2] + m1[2] * m2[3],
  1534. m1[1] * m2[2] + m1[3] * m2[3],
  1535. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  1536. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  1537. ];
  1538. };
  1539. // For 2d affine transforms
  1540. Util.applyTransform = function Util_applyTransform(p, m) {
  1541. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1542. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1543. return [xt, yt];
  1544. };
  1545. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  1546. var d = m[0] * m[3] - m[1] * m[2];
  1547. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1548. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1549. return [xt, yt];
  1550. };
  1551. // Applies the transform to the rectangle and finds the minimum axially
  1552. // aligned bounding box.
  1553. Util.getAxialAlignedBoundingBox =
  1554. function Util_getAxialAlignedBoundingBox(r, m) {
  1555. var p1 = Util.applyTransform(r, m);
  1556. var p2 = Util.applyTransform(r.slice(2, 4), m);
  1557. var p3 = Util.applyTransform([r[0], r[3]], m);
  1558. var p4 = Util.applyTransform([r[2], r[1]], m);
  1559. return [
  1560. Math.min(p1[0], p2[0], p3[0], p4[0]),
  1561. Math.min(p1[1], p2[1], p3[1], p4[1]),
  1562. Math.max(p1[0], p2[0], p3[0], p4[0]),
  1563. Math.max(p1[1], p2[1], p3[1], p4[1])
  1564. ];
  1565. };
  1566. Util.inverseTransform = function Util_inverseTransform(m) {
  1567. var d = m[0] * m[3] - m[1] * m[2];
  1568. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  1569. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  1570. };
  1571. // Apply a generic 3d matrix M on a 3-vector v:
  1572. // | a b c | | X |
  1573. // | d e f | x | Y |
  1574. // | g h i | | Z |
  1575. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  1576. // with v as [X,Y,Z]
  1577. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  1578. return [
  1579. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  1580. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  1581. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  1582. ];
  1583. };
  1584. // This calculation uses Singular Value Decomposition.
  1585. // The SVD can be represented with formula A = USV. We are interested in the
  1586. // matrix S here because it represents the scale values.
  1587. Util.singularValueDecompose2dScale =
  1588. function Util_singularValueDecompose2dScale(m) {
  1589. var transpose = [m[0], m[2], m[1], m[3]];
  1590. // Multiply matrix m with its transpose.
  1591. var a = m[0] * transpose[0] + m[1] * transpose[2];
  1592. var b = m[0] * transpose[1] + m[1] * transpose[3];
  1593. var c = m[2] * transpose[0] + m[3] * transpose[2];
  1594. var d = m[2] * transpose[1] + m[3] * transpose[3];
  1595. // Solve the second degree polynomial to get roots.
  1596. var first = (a + d) / 2;
  1597. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  1598. var sx = first + second || 1;
  1599. var sy = first - second || 1;
  1600. // Scale values are the square roots of the eigenvalues.
  1601. return [Math.sqrt(sx), Math.sqrt(sy)];
  1602. };
  1603. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  1604. // For coordinate systems whose origin lies in the bottom-left, this
  1605. // means normalization to (BL,TR) ordering. For systems with origin in the
  1606. // top-left, this means (TL,BR) ordering.
  1607. Util.normalizeRect = function Util_normalizeRect(rect) {
  1608. var r = rect.slice(0); // clone rect
  1609. if (rect[0] > rect[2]) {
  1610. r[0] = rect[2];
  1611. r[2] = rect[0];
  1612. }
  1613. if (rect[1] > rect[3]) {
  1614. r[1] = rect[3];
  1615. r[3] = rect[1];
  1616. }
  1617. return r;
  1618. };
  1619. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  1620. // intersection of rect1 and rect2. If no intersection, returns 'false'
  1621. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  1622. Util.intersect = function Util_intersect(rect1, rect2) {
  1623. function compare(a, b) {
  1624. return a - b;
  1625. }
  1626. // Order points along the axes
  1627. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  1628. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  1629. result = [];
  1630. rect1 = Util.normalizeRect(rect1);
  1631. rect2 = Util.normalizeRect(rect2);
  1632. // X: first and second points belong to different rectangles?
  1633. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  1634. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  1635. // Intersection must be between second and third points
  1636. result[0] = orderedX[1];
  1637. result[2] = orderedX[2];
  1638. } else {
  1639. return false;
  1640. }
  1641. // Y: first and second points belong to different rectangles?
  1642. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  1643. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  1644. // Intersection must be between second and third points
  1645. result[1] = orderedY[1];
  1646. result[3] = orderedY[2];
  1647. } else {
  1648. return false;
  1649. }
  1650. return result;
  1651. };
  1652. Util.sign = function Util_sign(num) {
  1653. return num < 0 ? -1 : 1;
  1654. };
  1655. var ROMAN_NUMBER_MAP = [
  1656. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  1657. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  1658. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  1659. ];
  1660. /**
  1661. * Converts positive integers to (upper case) Roman numerals.
  1662. * @param {integer} number - The number that should be converted.
  1663. * @param {boolean} lowerCase - Indicates if the result should be converted
  1664. * to lower case letters. The default is false.
  1665. * @return {string} The resulting Roman number.
  1666. */
  1667. Util.toRoman = function Util_toRoman(number, lowerCase) {
  1668. assert(isInt(number) && number > 0,
  1669. 'The number should be a positive integer.');
  1670. var pos, romanBuf = [];
  1671. // Thousands
  1672. while (number >= 1000) {
  1673. number -= 1000;
  1674. romanBuf.push('M');
  1675. }
  1676. // Hundreds
  1677. pos = (number / 100) | 0;
  1678. number %= 100;
  1679. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  1680. // Tens
  1681. pos = (number / 10) | 0;
  1682. number %= 10;
  1683. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  1684. // Ones
  1685. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  1686. var romanStr = romanBuf.join('');
  1687. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  1688. };
  1689. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  1690. Array.prototype.push.apply(arr1, arr2);
  1691. };
  1692. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  1693. Array.prototype.unshift.apply(arr1, arr2);
  1694. };
  1695. Util.extendObj = function extendObj(obj1, obj2) {
  1696. for (var key in obj2) {
  1697. obj1[key] = obj2[key];
  1698. }
  1699. };
  1700. Util.getInheritableProperty =
  1701. function Util_getInheritableProperty(dict, name, getArray) {
  1702. while (dict && !dict.has(name)) {
  1703. dict = dict.get('Parent');
  1704. }
  1705. if (!dict) {
  1706. return null;
  1707. }
  1708. return getArray ? dict.getArray(name) : dict.get(name);
  1709. };
  1710. Util.inherit = function Util_inherit(sub, base, prototype) {
  1711. sub.prototype = Object.create(base.prototype);
  1712. sub.prototype.constructor = sub;
  1713. for (var prop in prototype) {
  1714. sub.prototype[prop] = prototype[prop];
  1715. }
  1716. };
  1717. Util.loadScript = function Util_loadScript(src, callback) {
  1718. var script = document.createElement('script');
  1719. var loaded = false;
  1720. script.setAttribute('src', src);
  1721. if (callback) {
  1722. script.onload = function() {
  1723. if (!loaded) {
  1724. callback();
  1725. }
  1726. loaded = true;
  1727. };
  1728. }
  1729. document.getElementsByTagName('head')[0].appendChild(script);
  1730. };
  1731. return Util;
  1732. })();
  1733. /**
  1734. * PDF page viewport created based on scale, rotation and offset.
  1735. * @class
  1736. * @alias PageViewport
  1737. */
  1738. var PageViewport = (function PageViewportClosure() {
  1739. /**
  1740. * @constructor
  1741. * @private
  1742. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  1743. * @param scale {number} scale of the viewport.
  1744. * @param rotation {number} rotations of the viewport in degrees.
  1745. * @param offsetX {number} offset X
  1746. * @param offsetY {number} offset Y
  1747. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  1748. */
  1749. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  1750. this.viewBox = viewBox;
  1751. this.scale = scale;
  1752. this.rotation = rotation;
  1753. this.offsetX = offsetX;
  1754. this.offsetY = offsetY;
  1755. // creating transform to convert pdf coordinate system to the normal
  1756. // canvas like coordinates taking in account scale and rotation
  1757. var centerX = (viewBox[2] + viewBox[0]) / 2;
  1758. var centerY = (viewBox[3] + viewBox[1]) / 2;
  1759. var rotateA, rotateB, rotateC, rotateD;
  1760. rotation = rotation % 360;
  1761. rotation = rotation < 0 ? rotation + 360 : rotation;
  1762. switch (rotation) {
  1763. case 180:
  1764. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  1765. break;
  1766. case 90:
  1767. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  1768. break;
  1769. case 270:
  1770. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  1771. break;
  1772. //case 0:
  1773. default:
  1774. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  1775. break;
  1776. }
  1777. if (dontFlip) {
  1778. rotateC = -rotateC; rotateD = -rotateD;
  1779. }
  1780. var offsetCanvasX, offsetCanvasY;
  1781. var width, height;
  1782. if (rotateA === 0) {
  1783. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  1784. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  1785. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1786. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1787. } else {
  1788. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  1789. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  1790. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  1791. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  1792. }
  1793. // creating transform for the following operations:
  1794. // translate(-centerX, -centerY), rotate and flip vertically,
  1795. // scale, and translate(offsetCanvasX, offsetCanvasY)
  1796. this.transform = [
  1797. rotateA * scale,
  1798. rotateB * scale,
  1799. rotateC * scale,
  1800. rotateD * scale,
  1801. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  1802. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  1803. ];
  1804. this.width = width;
  1805. this.height = height;
  1806. this.fontScale = scale;
  1807. }
  1808. PageViewport.prototype = /** @lends PageViewport.prototype */ {
  1809. /**
  1810. * Clones viewport with additional properties.
  1811. * @param args {Object} (optional) If specified, may contain the 'scale' or
  1812. * 'rotation' properties to override the corresponding properties in
  1813. * the cloned viewport.
  1814. * @returns {PageViewport} Cloned viewport.
  1815. */
  1816. clone: function PageViewPort_clone(args) {
  1817. args = args || {};
  1818. var scale = 'scale' in args ? args.scale : this.scale;
  1819. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  1820. return new PageViewport(this.viewBox.slice(), scale, rotation,
  1821. this.offsetX, this.offsetY, args.dontFlip);
  1822. },
  1823. /**
  1824. * Converts PDF point to the viewport coordinates. For examples, useful for
  1825. * converting PDF location into canvas pixel coordinates.
  1826. * @param x {number} X coordinate.
  1827. * @param y {number} Y coordinate.
  1828. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1829. * point in the viewport coordinate space.
  1830. * @see {@link convertToPdfPoint}
  1831. * @see {@link convertToViewportRectangle}
  1832. */
  1833. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  1834. return Util.applyTransform([x, y], this.transform);
  1835. },
  1836. /**
  1837. * Converts PDF rectangle to the viewport coordinates.
  1838. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  1839. * @returns {Array} Contains corresponding coordinates of the rectangle
  1840. * in the viewport coordinate space.
  1841. * @see {@link convertToViewportPoint}
  1842. */
  1843. convertToViewportRectangle:
  1844. function PageViewport_convertToViewportRectangle(rect) {
  1845. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  1846. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  1847. return [tl[0], tl[1], br[0], br[1]];
  1848. },
  1849. /**
  1850. * Converts viewport coordinates to the PDF location. For examples, useful
  1851. * for converting canvas pixel location into PDF one.
  1852. * @param x {number} X coordinate.
  1853. * @param y {number} Y coordinate.
  1854. * @returns {Object} Object that contains 'x' and 'y' properties of the
  1855. * point in the PDF coordinate space.
  1856. * @see {@link convertToViewportPoint}
  1857. */
  1858. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  1859. return Util.applyInverseTransform([x, y], this.transform);
  1860. }
  1861. };
  1862. return PageViewport;
  1863. })();
  1864. var PDFStringTranslateTable = [
  1865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1866. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  1867. 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,
  1868. 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,
  1869. 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,
  1870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  1871. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  1872. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  1873. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  1874. ];
  1875. function stringToPDFString(str) {
  1876. var i, n = str.length, strBuf = [];
  1877. if (str[0] === '\xFE' && str[1] === '\xFF') {
  1878. // UTF16BE BOM
  1879. for (i = 2; i < n; i += 2) {
  1880. strBuf.push(String.fromCharCode(
  1881. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  1882. }
  1883. } else {
  1884. for (i = 0; i < n; ++i) {
  1885. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  1886. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1887. }
  1888. }
  1889. return strBuf.join('');
  1890. }
  1891. function stringToUTF8String(str) {
  1892. return decodeURIComponent(escape(str));
  1893. }
  1894. function utf8StringToString(str) {
  1895. return unescape(encodeURIComponent(str));
  1896. }
  1897. function isEmptyObj(obj) {
  1898. for (var key in obj) {
  1899. return false;
  1900. }
  1901. return true;
  1902. }
  1903. function isBool(v) {
  1904. return typeof v === 'boolean';
  1905. }
  1906. function isInt(v) {
  1907. return typeof v === 'number' && ((v | 0) === v);
  1908. }
  1909. function isNum(v) {
  1910. return typeof v === 'number';
  1911. }
  1912. function isString(v) {
  1913. return typeof v === 'string';
  1914. }
  1915. function isArray(v) {
  1916. return v instanceof Array;
  1917. }
  1918. function isArrayBuffer(v) {
  1919. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  1920. }
  1921. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  1922. function isSpace(ch) {
  1923. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  1924. }
  1925. /**
  1926. * Promise Capability object.
  1927. *
  1928. * @typedef {Object} PromiseCapability
  1929. * @property {Promise} promise - A promise object.
  1930. * @property {function} resolve - Fulfills the promise.
  1931. * @property {function} reject - Rejects the promise.
  1932. */
  1933. /**
  1934. * Creates a promise capability object.
  1935. * @alias createPromiseCapability
  1936. *
  1937. * @return {PromiseCapability} A capability object contains:
  1938. * - a Promise, resolve and reject methods.
  1939. */
  1940. function createPromiseCapability() {
  1941. var capability = {};
  1942. capability.promise = new Promise(function (resolve, reject) {
  1943. capability.resolve = resolve;
  1944. capability.reject = reject;
  1945. });
  1946. return capability;
  1947. }
  1948. /**
  1949. * Polyfill for Promises:
  1950. * The following promise implementation tries to generally implement the
  1951. * Promise/A+ spec. Some notable differences from other promise libraries are:
  1952. * - There currently isn't a separate deferred and promise object.
  1953. * - Unhandled rejections eventually show an error if they aren't handled.
  1954. *
  1955. * Based off of the work in:
  1956. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  1957. */
  1958. (function PromiseClosure() {
  1959. if (globalScope.Promise) {
  1960. // Promises existing in the DOM/Worker, checking presence of all/resolve
  1961. if (typeof globalScope.Promise.all !== 'function') {
  1962. globalScope.Promise.all = function (iterable) {
  1963. var count = 0, results = [], resolve, reject;
  1964. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1965. resolve = resolve_;
  1966. reject = reject_;
  1967. });
  1968. iterable.forEach(function (p, i) {
  1969. count++;
  1970. p.then(function (result) {
  1971. results[i] = result;
  1972. count--;
  1973. if (count === 0) {
  1974. resolve(results);
  1975. }
  1976. }, reject);
  1977. });
  1978. if (count === 0) {
  1979. resolve(results);
  1980. }
  1981. return promise;
  1982. };
  1983. }
  1984. if (typeof globalScope.Promise.resolve !== 'function') {
  1985. globalScope.Promise.resolve = function (value) {
  1986. return new globalScope.Promise(function (resolve) { resolve(value); });
  1987. };
  1988. }
  1989. if (typeof globalScope.Promise.reject !== 'function') {
  1990. globalScope.Promise.reject = function (reason) {
  1991. return new globalScope.Promise(function (resolve, reject) {
  1992. reject(reason);
  1993. });
  1994. };
  1995. }
  1996. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1997. globalScope.Promise.prototype.catch = function (onReject) {
  1998. return globalScope.Promise.prototype.then(undefined, onReject);
  1999. };
  2000. }
  2001. return;
  2002. }
  2003. var STATUS_PENDING = 0;
  2004. var STATUS_RESOLVED = 1;
  2005. var STATUS_REJECTED = 2;
  2006. // In an attempt to avoid silent exceptions, unhandled rejections are
  2007. // tracked and if they aren't handled in a certain amount of time an
  2008. // error is logged.
  2009. var REJECTION_TIMEOUT = 500;
  2010. var HandlerManager = {
  2011. handlers: [],
  2012. running: false,
  2013. unhandledRejections: [],
  2014. pendingRejectionCheck: false,
  2015. scheduleHandlers: function scheduleHandlers(promise) {
  2016. if (promise._status === STATUS_PENDING) {
  2017. return;
  2018. }
  2019. this.handlers = this.handlers.concat(promise._handlers);
  2020. promise._handlers = [];
  2021. if (this.running) {
  2022. return;
  2023. }
  2024. this.running = true;
  2025. setTimeout(this.runHandlers.bind(this), 0);
  2026. },
  2027. runHandlers: function runHandlers() {
  2028. var RUN_TIMEOUT = 1; // ms
  2029. var timeoutAt = Date.now() + RUN_TIMEOUT;
  2030. while (this.handlers.length > 0) {
  2031. var handler = this.handlers.shift();
  2032. var nextStatus = handler.thisPromise._status;
  2033. var nextValue = handler.thisPromise._value;
  2034. try {
  2035. if (nextStatus === STATUS_RESOLVED) {
  2036. if (typeof handler.onResolve === 'function') {
  2037. nextValue = handler.onResolve(nextValue);
  2038. }
  2039. } else if (typeof handler.onReject === 'function') {
  2040. nextValue = handler.onReject(nextValue);
  2041. nextStatus = STATUS_RESOLVED;
  2042. if (handler.thisPromise._unhandledRejection) {
  2043. this.removeUnhandeledRejection(handler.thisPromise);
  2044. }
  2045. }
  2046. } catch (ex) {
  2047. nextStatus = STATUS_REJECTED;
  2048. nextValue = ex;
  2049. }
  2050. handler.nextPromise._updateStatus(nextStatus, nextValue);
  2051. if (Date.now() >= timeoutAt) {
  2052. break;
  2053. }
  2054. }
  2055. if (this.handlers.length > 0) {
  2056. setTimeout(this.runHandlers.bind(this), 0);
  2057. return;
  2058. }
  2059. this.running = false;
  2060. },
  2061. addUnhandledRejection: function addUnhandledRejection(promise) {
  2062. this.unhandledRejections.push({
  2063. promise: promise,
  2064. time: Date.now()
  2065. });
  2066. this.scheduleRejectionCheck();
  2067. },
  2068. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  2069. promise._unhandledRejection = false;
  2070. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2071. if (this.unhandledRejections[i].promise === promise) {
  2072. this.unhandledRejections.splice(i);
  2073. i--;
  2074. }
  2075. }
  2076. },
  2077. scheduleRejectionCheck: function scheduleRejectionCheck() {
  2078. if (this.pendingRejectionCheck) {
  2079. return;
  2080. }
  2081. this.pendingRejectionCheck = true;
  2082. setTimeout(function rejectionCheck() {
  2083. this.pendingRejectionCheck = false;
  2084. var now = Date.now();
  2085. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2086. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  2087. var unhandled = this.unhandledRejections[i].promise._value;
  2088. var msg = 'Unhandled rejection: ' + unhandled;
  2089. if (unhandled.stack) {
  2090. msg += '\n' + unhandled.stack;
  2091. }
  2092. warn(msg);
  2093. this.unhandledRejections.splice(i);
  2094. i--;
  2095. }
  2096. }
  2097. if (this.unhandledRejections.length) {
  2098. this.scheduleRejectionCheck();
  2099. }
  2100. }.bind(this), REJECTION_TIMEOUT);
  2101. }
  2102. };
  2103. function Promise(resolver) {
  2104. this._status = STATUS_PENDING;
  2105. this._handlers = [];
  2106. try {
  2107. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  2108. } catch (e) {
  2109. this._reject(e);
  2110. }
  2111. }
  2112. /**
  2113. * Builds a promise that is resolved when all the passed in promises are
  2114. * resolved.
  2115. * @param {array} promises array of data and/or promises to wait for.
  2116. * @return {Promise} New dependent promise.
  2117. */
  2118. Promise.all = function Promise_all(promises) {
  2119. var resolveAll, rejectAll;
  2120. var deferred = new Promise(function (resolve, reject) {
  2121. resolveAll = resolve;
  2122. rejectAll = reject;
  2123. });
  2124. var unresolved = promises.length;
  2125. var results = [];
  2126. if (unresolved === 0) {
  2127. resolveAll(results);
  2128. return deferred;
  2129. }
  2130. function reject(reason) {
  2131. if (deferred._status === STATUS_REJECTED) {
  2132. return;
  2133. }
  2134. results = [];
  2135. rejectAll(reason);
  2136. }
  2137. for (var i = 0, ii = promises.length; i < ii; ++i) {
  2138. var promise = promises[i];
  2139. var resolve = (function(i) {
  2140. return function(value) {
  2141. if (deferred._status === STATUS_REJECTED) {
  2142. return;
  2143. }
  2144. results[i] = value;
  2145. unresolved--;
  2146. if (unresolved === 0) {
  2147. resolveAll(results);
  2148. }
  2149. };
  2150. })(i);
  2151. if (Promise.isPromise(promise)) {
  2152. promise.then(resolve, reject);
  2153. } else {
  2154. resolve(promise);
  2155. }
  2156. }
  2157. return deferred;
  2158. };
  2159. /**
  2160. * Checks if the value is likely a promise (has a 'then' function).
  2161. * @return {boolean} true if value is thenable
  2162. */
  2163. Promise.isPromise = function Promise_isPromise(value) {
  2164. return value && typeof value.then === 'function';
  2165. };
  2166. /**
  2167. * Creates resolved promise
  2168. * @param value resolve value
  2169. * @returns {Promise}
  2170. */
  2171. Promise.resolve = function Promise_resolve(value) {
  2172. return new Promise(function (resolve) { resolve(value); });
  2173. };
  2174. /**
  2175. * Creates rejected promise
  2176. * @param reason rejection value
  2177. * @returns {Promise}
  2178. */
  2179. Promise.reject = function Promise_reject(reason) {
  2180. return new Promise(function (resolve, reject) { reject(reason); });
  2181. };
  2182. Promise.prototype = {
  2183. _status: null,
  2184. _value: null,
  2185. _handlers: null,
  2186. _unhandledRejection: null,
  2187. _updateStatus: function Promise__updateStatus(status, value) {
  2188. if (this._status === STATUS_RESOLVED ||
  2189. this._status === STATUS_REJECTED) {
  2190. return;
  2191. }
  2192. if (status === STATUS_RESOLVED &&
  2193. Promise.isPromise(value)) {
  2194. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  2195. this._updateStatus.bind(this, STATUS_REJECTED));
  2196. return;
  2197. }
  2198. this._status = status;
  2199. this._value = value;
  2200. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  2201. this._unhandledRejection = true;
  2202. HandlerManager.addUnhandledRejection(this);
  2203. }
  2204. HandlerManager.scheduleHandlers(this);
  2205. },
  2206. _resolve: function Promise_resolve(value) {
  2207. this._updateStatus(STATUS_RESOLVED, value);
  2208. },
  2209. _reject: function Promise_reject(reason) {
  2210. this._updateStatus(STATUS_REJECTED, reason);
  2211. },
  2212. then: function Promise_then(onResolve, onReject) {
  2213. var nextPromise = new Promise(function (resolve, reject) {
  2214. this.resolve = resolve;
  2215. this.reject = reject;
  2216. });
  2217. this._handlers.push({
  2218. thisPromise: this,
  2219. onResolve: onResolve,
  2220. onReject: onReject,
  2221. nextPromise: nextPromise
  2222. });
  2223. HandlerManager.scheduleHandlers(this);
  2224. return nextPromise;
  2225. },
  2226. catch: function Promise_catch(onReject) {
  2227. return this.then(undefined, onReject);
  2228. }
  2229. };
  2230. globalScope.Promise = Promise;
  2231. })();
  2232. (function WeakMapClosure() {
  2233. if (globalScope.WeakMap) {
  2234. return;
  2235. }
  2236. var id = 0;
  2237. function WeakMap() {
  2238. this.id = '$weakmap' + (id++);
  2239. }
  2240. WeakMap.prototype = {
  2241. has: function(obj) {
  2242. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  2243. },
  2244. get: function(obj, defaultValue) {
  2245. return this.has(obj) ? obj[this.id] : defaultValue;
  2246. },
  2247. set: function(obj, value) {
  2248. Object.defineProperty(obj, this.id, {
  2249. value: value,
  2250. enumerable: false,
  2251. configurable: true
  2252. });
  2253. },
  2254. delete: function(obj) {
  2255. delete obj[this.id];
  2256. }
  2257. };
  2258. globalScope.WeakMap = WeakMap;
  2259. })();
  2260. var StatTimer = (function StatTimerClosure() {
  2261. function rpad(str, pad, length) {
  2262. while (str.length < length) {
  2263. str += pad;
  2264. }
  2265. return str;
  2266. }
  2267. function StatTimer() {
  2268. this.started = Object.create(null);
  2269. this.times = [];
  2270. this.enabled = true;
  2271. }
  2272. StatTimer.prototype = {
  2273. time: function StatTimer_time(name) {
  2274. if (!this.enabled) {
  2275. return;
  2276. }
  2277. if (name in this.started) {
  2278. warn('Timer is already running for ' + name);
  2279. }
  2280. this.started[name] = Date.now();
  2281. },
  2282. timeEnd: function StatTimer_timeEnd(name) {
  2283. if (!this.enabled) {
  2284. return;
  2285. }
  2286. if (!(name in this.started)) {
  2287. warn('Timer has not been started for ' + name);
  2288. }
  2289. this.times.push({
  2290. 'name': name,
  2291. 'start': this.started[name],
  2292. 'end': Date.now()
  2293. });
  2294. // Remove timer from started so it can be called again.
  2295. delete this.started[name];
  2296. },
  2297. toString: function StatTimer_toString() {
  2298. var i, ii;
  2299. var times = this.times;
  2300. var out = '';
  2301. // Find the longest name for padding purposes.
  2302. var longest = 0;
  2303. for (i = 0, ii = times.length; i < ii; ++i) {
  2304. var name = times[i]['name'];
  2305. if (name.length > longest) {
  2306. longest = name.length;
  2307. }
  2308. }
  2309. for (i = 0, ii = times.length; i < ii; ++i) {
  2310. var span = times[i];
  2311. var duration = span.end - span.start;
  2312. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  2313. }
  2314. return out;
  2315. }
  2316. };
  2317. return StatTimer;
  2318. })();
  2319. var createBlob = function createBlob(data, contentType) {
  2320. if (typeof Blob !== 'undefined') {
  2321. return new Blob([data], { type: contentType });
  2322. }
  2323. warn('The "Blob" constructor is not supported.');
  2324. };
  2325. var createObjectURL = (function createObjectURLClosure() {
  2326. // Blob/createObjectURL is not available, falling back to data schema.
  2327. var digits =
  2328. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  2329. return function createObjectURL(data, contentType, forceDataSchema) {
  2330. if (!forceDataSchema &&
  2331. typeof URL !== 'undefined' && URL.createObjectURL) {
  2332. var blob = createBlob(data, contentType);
  2333. return URL.createObjectURL(blob);
  2334. }
  2335. var buffer = 'data:' + contentType + ';base64,';
  2336. for (var i = 0, ii = data.length; i < ii; i += 3) {
  2337. var b1 = data[i] & 0xFF;
  2338. var b2 = data[i + 1] & 0xFF;
  2339. var b3 = data[i + 2] & 0xFF;
  2340. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  2341. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  2342. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  2343. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  2344. }
  2345. return buffer;
  2346. };
  2347. })();
  2348. function MessageHandler(sourceName, targetName, comObj) {
  2349. this.sourceName = sourceName;
  2350. this.targetName = targetName;
  2351. this.comObj = comObj;
  2352. this.callbackIndex = 1;
  2353. this.postMessageTransfers = true;
  2354. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  2355. var ah = this.actionHandler = Object.create(null);
  2356. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  2357. var data = event.data;
  2358. if (data.targetName !== this.sourceName) {
  2359. return;
  2360. }
  2361. if (data.isReply) {
  2362. var callbackId = data.callbackId;
  2363. if (data.callbackId in callbacksCapabilities) {
  2364. var callback = callbacksCapabilities[callbackId];
  2365. delete callbacksCapabilities[callbackId];
  2366. if ('error' in data) {
  2367. callback.reject(data.error);
  2368. } else {
  2369. callback.resolve(data.data);
  2370. }
  2371. } else {
  2372. error('Cannot resolve callback ' + callbackId);
  2373. }
  2374. } else if (data.action in ah) {
  2375. var action = ah[data.action];
  2376. if (data.callbackId) {
  2377. var sourceName = this.sourceName;
  2378. var targetName = data.sourceName;
  2379. Promise.resolve().then(function () {
  2380. return action[0].call(action[1], data.data);
  2381. }).then(function (result) {
  2382. comObj.postMessage({
  2383. sourceName: sourceName,
  2384. targetName: targetName,
  2385. isReply: true,
  2386. callbackId: data.callbackId,
  2387. data: result
  2388. });
  2389. }, function (reason) {
  2390. if (reason instanceof Error) {
  2391. // Serialize error to avoid "DataCloneError"
  2392. reason = reason + '';
  2393. }
  2394. comObj.postMessage({
  2395. sourceName: sourceName,
  2396. targetName: targetName,
  2397. isReply: true,
  2398. callbackId: data.callbackId,
  2399. error: reason
  2400. });
  2401. });
  2402. } else {
  2403. action[0].call(action[1], data.data);
  2404. }
  2405. } else {
  2406. error('Unknown action from worker: ' + data.action);
  2407. }
  2408. }.bind(this);
  2409. comObj.addEventListener('message', this._onComObjOnMessage);
  2410. }
  2411. MessageHandler.prototype = {
  2412. on: function messageHandlerOn(actionName, handler, scope) {
  2413. var ah = this.actionHandler;
  2414. if (ah[actionName]) {
  2415. error('There is already an actionName called "' + actionName + '"');
  2416. }
  2417. ah[actionName] = [handler, scope];
  2418. },
  2419. /**
  2420. * Sends a message to the comObj to invoke the action with the supplied data.
  2421. * @param {String} actionName Action to call.
  2422. * @param {JSON} data JSON data to send.
  2423. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  2424. */
  2425. send: function messageHandlerSend(actionName, data, transfers) {
  2426. var message = {
  2427. sourceName: this.sourceName,
  2428. targetName: this.targetName,
  2429. action: actionName,
  2430. data: data
  2431. };
  2432. this.postMessage(message, transfers);
  2433. },
  2434. /**
  2435. * Sends a message to the comObj to invoke the action with the supplied data.
  2436. * Expects that other side will callback with the response.
  2437. * @param {String} actionName Action to call.
  2438. * @param {JSON} data JSON data to send.
  2439. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  2440. * @returns {Promise} Promise to be resolved with response data.
  2441. */
  2442. sendWithPromise:
  2443. function messageHandlerSendWithPromise(actionName, data, transfers) {
  2444. var callbackId = this.callbackIndex++;
  2445. var message = {
  2446. sourceName: this.sourceName,
  2447. targetName: this.targetName,
  2448. action: actionName,
  2449. data: data,
  2450. callbackId: callbackId
  2451. };
  2452. var capability = createPromiseCapability();
  2453. this.callbacksCapabilities[callbackId] = capability;
  2454. try {
  2455. this.postMessage(message, transfers);
  2456. } catch (e) {
  2457. capability.reject(e);
  2458. }
  2459. return capability.promise;
  2460. },
  2461. /**
  2462. * Sends raw message to the comObj.
  2463. * @private
  2464. * @param message {Object} Raw message.
  2465. * @param transfers List of transfers/ArrayBuffers, or undefined.
  2466. */
  2467. postMessage: function (message, transfers) {
  2468. if (transfers && this.postMessageTransfers) {
  2469. this.comObj.postMessage(message, transfers);
  2470. } else {
  2471. this.comObj.postMessage(message);
  2472. }
  2473. },
  2474. destroy: function () {
  2475. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  2476. }
  2477. };
  2478. function loadJpegStream(id, imageUrl, objs) {
  2479. var img = new Image();
  2480. img.onload = (function loadJpegStream_onloadClosure() {
  2481. objs.resolve(id, img);
  2482. });
  2483. img.onerror = (function loadJpegStream_onerrorClosure() {
  2484. objs.resolve(id, null);
  2485. warn('Error during JPEG image loading');
  2486. });
  2487. img.src = imageUrl;
  2488. }
  2489. // Polyfill from https://github.com/Polymer/URL
  2490. /* Any copyright is dedicated to the Public Domain.
  2491. * http://creativecommons.org/publicdomain/zero/1.0/ */
  2492. (function checkURLConstructor(scope) {
  2493. // feature detect for URL constructor
  2494. var hasWorkingUrl = false;
  2495. try {
  2496. if (typeof URL === 'function' &&
  2497. typeof URL.prototype === 'object' &&
  2498. ('origin' in URL.prototype)) {
  2499. var u = new URL('b', 'http://a');
  2500. u.pathname = 'c%20d';
  2501. hasWorkingUrl = u.href === 'http://a/c%20d';
  2502. }
  2503. } catch(e) { }
  2504. if (hasWorkingUrl) {
  2505. return;
  2506. }
  2507. var relative = Object.create(null);
  2508. relative['ftp'] = 21;
  2509. relative['file'] = 0;
  2510. relative['gopher'] = 70;
  2511. relative['http'] = 80;
  2512. relative['https'] = 443;
  2513. relative['ws'] = 80;
  2514. relative['wss'] = 443;
  2515. var relativePathDotMapping = Object.create(null);
  2516. relativePathDotMapping['%2e'] = '.';
  2517. relativePathDotMapping['.%2e'] = '..';
  2518. relativePathDotMapping['%2e.'] = '..';
  2519. relativePathDotMapping['%2e%2e'] = '..';
  2520. function isRelativeScheme(scheme) {
  2521. return relative[scheme] !== undefined;
  2522. }
  2523. function invalid() {
  2524. clear.call(this);
  2525. this._isInvalid = true;
  2526. }
  2527. function IDNAToASCII(h) {
  2528. if ('' === h) {
  2529. invalid.call(this);
  2530. }
  2531. // XXX
  2532. return h.toLowerCase();
  2533. }
  2534. function percentEscape(c) {
  2535. var unicode = c.charCodeAt(0);
  2536. if (unicode > 0x20 &&
  2537. unicode < 0x7F &&
  2538. // " # < > ? `
  2539. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1
  2540. ) {
  2541. return c;
  2542. }
  2543. return encodeURIComponent(c);
  2544. }
  2545. function percentEscapeQuery(c) {
  2546. // XXX This actually needs to encode c using encoding and then
  2547. // convert the bytes one-by-one.
  2548. var unicode = c.charCodeAt(0);
  2549. if (unicode > 0x20 &&
  2550. unicode < 0x7F &&
  2551. // " # < > ` (do not escape '?')
  2552. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1
  2553. ) {
  2554. return c;
  2555. }
  2556. return encodeURIComponent(c);
  2557. }
  2558. var EOF, ALPHA = /[a-zA-Z]/,
  2559. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  2560. function parse(input, stateOverride, base) {
  2561. function err(message) {
  2562. errors.push(message);
  2563. }
  2564. var state = stateOverride || 'scheme start',
  2565. cursor = 0,
  2566. buffer = '',
  2567. seenAt = false,
  2568. seenBracket = false,
  2569. errors = [];
  2570. loop: while ((input[cursor - 1] !== EOF || cursor === 0) &&
  2571. !this._isInvalid) {
  2572. var c = input[cursor];
  2573. switch (state) {
  2574. case 'scheme start':
  2575. if (c && ALPHA.test(c)) {
  2576. buffer += c.toLowerCase(); // ASCII-safe
  2577. state = 'scheme';
  2578. } else if (!stateOverride) {
  2579. buffer = '';
  2580. state = 'no scheme';
  2581. continue;
  2582. } else {
  2583. err('Invalid scheme.');
  2584. break loop;
  2585. }
  2586. break;
  2587. case 'scheme':
  2588. if (c && ALPHANUMERIC.test(c)) {
  2589. buffer += c.toLowerCase(); // ASCII-safe
  2590. } else if (':' === c) {
  2591. this._scheme = buffer;
  2592. buffer = '';
  2593. if (stateOverride) {
  2594. break loop;
  2595. }
  2596. if (isRelativeScheme(this._scheme)) {
  2597. this._isRelative = true;
  2598. }
  2599. if ('file' === this._scheme) {
  2600. state = 'relative';
  2601. } else if (this._isRelative && base &&
  2602. base._scheme === this._scheme) {
  2603. state = 'relative or authority';
  2604. } else if (this._isRelative) {
  2605. state = 'authority first slash';
  2606. } else {
  2607. state = 'scheme data';
  2608. }
  2609. } else if (!stateOverride) {
  2610. buffer = '';
  2611. cursor = 0;
  2612. state = 'no scheme';
  2613. continue;
  2614. } else if (EOF === c) {
  2615. break loop;
  2616. } else {
  2617. err('Code point not allowed in scheme: ' + c);
  2618. break loop;
  2619. }
  2620. break;
  2621. case 'scheme data':
  2622. if ('?' === c) {
  2623. this._query = '?';
  2624. state = 'query';
  2625. } else if ('#' === c) {
  2626. this._fragment = '#';
  2627. state = 'fragment';
  2628. } else {
  2629. // XXX error handling
  2630. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2631. this._schemeData += percentEscape(c);
  2632. }
  2633. }
  2634. break;
  2635. case 'no scheme':
  2636. if (!base || !(isRelativeScheme(base._scheme))) {
  2637. err('Missing scheme.');
  2638. invalid.call(this);
  2639. } else {
  2640. state = 'relative';
  2641. continue;
  2642. }
  2643. break;
  2644. case 'relative or authority':
  2645. if ('/' === c && '/' === input[cursor+1]) {
  2646. state = 'authority ignore slashes';
  2647. } else {
  2648. err('Expected /, got: ' + c);
  2649. state = 'relative';
  2650. continue;
  2651. }
  2652. break;
  2653. case 'relative':
  2654. this._isRelative = true;
  2655. if ('file' !== this._scheme) {
  2656. this._scheme = base._scheme;
  2657. }
  2658. if (EOF === c) {
  2659. this._host = base._host;
  2660. this._port = base._port;
  2661. this._path = base._path.slice();
  2662. this._query = base._query;
  2663. this._username = base._username;
  2664. this._password = base._password;
  2665. break loop;
  2666. } else if ('/' === c || '\\' === c) {
  2667. if ('\\' === c) {
  2668. err('\\ is an invalid code point.');
  2669. }
  2670. state = 'relative slash';
  2671. } else if ('?' === c) {
  2672. this._host = base._host;
  2673. this._port = base._port;
  2674. this._path = base._path.slice();
  2675. this._query = '?';
  2676. this._username = base._username;
  2677. this._password = base._password;
  2678. state = 'query';
  2679. } else if ('#' === c) {
  2680. this._host = base._host;
  2681. this._port = base._port;
  2682. this._path = base._path.slice();
  2683. this._query = base._query;
  2684. this._fragment = '#';
  2685. this._username = base._username;
  2686. this._password = base._password;
  2687. state = 'fragment';
  2688. } else {
  2689. var nextC = input[cursor+1];
  2690. var nextNextC = input[cursor+2];
  2691. if ('file' !== this._scheme || !ALPHA.test(c) ||
  2692. (nextC !== ':' && nextC !== '|') ||
  2693. (EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC &&
  2694. '?' !== nextNextC && '#' !== nextNextC)) {
  2695. this._host = base._host;
  2696. this._port = base._port;
  2697. this._username = base._username;
  2698. this._password = base._password;
  2699. this._path = base._path.slice();
  2700. this._path.pop();
  2701. }
  2702. state = 'relative path';
  2703. continue;
  2704. }
  2705. break;
  2706. case 'relative slash':
  2707. if ('/' === c || '\\' === c) {
  2708. if ('\\' === c) {
  2709. err('\\ is an invalid code point.');
  2710. }
  2711. if ('file' === this._scheme) {
  2712. state = 'file host';
  2713. } else {
  2714. state = 'authority ignore slashes';
  2715. }
  2716. } else {
  2717. if ('file' !== this._scheme) {
  2718. this._host = base._host;
  2719. this._port = base._port;
  2720. this._username = base._username;
  2721. this._password = base._password;
  2722. }
  2723. state = 'relative path';
  2724. continue;
  2725. }
  2726. break;
  2727. case 'authority first slash':
  2728. if ('/' === c) {
  2729. state = 'authority second slash';
  2730. } else {
  2731. err('Expected \'/\', got: ' + c);
  2732. state = 'authority ignore slashes';
  2733. continue;
  2734. }
  2735. break;
  2736. case 'authority second slash':
  2737. state = 'authority ignore slashes';
  2738. if ('/' !== c) {
  2739. err('Expected \'/\', got: ' + c);
  2740. continue;
  2741. }
  2742. break;
  2743. case 'authority ignore slashes':
  2744. if ('/' !== c && '\\' !== c) {
  2745. state = 'authority';
  2746. continue;
  2747. } else {
  2748. err('Expected authority, got: ' + c);
  2749. }
  2750. break;
  2751. case 'authority':
  2752. if ('@' === c) {
  2753. if (seenAt) {
  2754. err('@ already seen.');
  2755. buffer += '%40';
  2756. }
  2757. seenAt = true;
  2758. for (var i = 0; i < buffer.length; i++) {
  2759. var cp = buffer[i];
  2760. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  2761. err('Invalid whitespace in authority.');
  2762. continue;
  2763. }
  2764. // XXX check URL code points
  2765. if (':' === cp && null === this._password) {
  2766. this._password = '';
  2767. continue;
  2768. }
  2769. var tempC = percentEscape(cp);
  2770. if (null !== this._password) {
  2771. this._password += tempC;
  2772. } else {
  2773. this._username += tempC;
  2774. }
  2775. }
  2776. buffer = '';
  2777. } else if (EOF === c || '/' === c || '\\' === c ||
  2778. '?' === c || '#' === c) {
  2779. cursor -= buffer.length;
  2780. buffer = '';
  2781. state = 'host';
  2782. continue;
  2783. } else {
  2784. buffer += c;
  2785. }
  2786. break;
  2787. case 'file host':
  2788. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  2789. if (buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2790. (buffer[1] === ':' || buffer[1] === '|')) {
  2791. state = 'relative path';
  2792. } else if (buffer.length === 0) {
  2793. state = 'relative path start';
  2794. } else {
  2795. this._host = IDNAToASCII.call(this, buffer);
  2796. buffer = '';
  2797. state = 'relative path start';
  2798. }
  2799. continue;
  2800. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2801. err('Invalid whitespace in file host.');
  2802. } else {
  2803. buffer += c;
  2804. }
  2805. break;
  2806. case 'host':
  2807. case 'hostname':
  2808. if (':' === c && !seenBracket) {
  2809. // XXX host parsing
  2810. this._host = IDNAToASCII.call(this, buffer);
  2811. buffer = '';
  2812. state = 'port';
  2813. if ('hostname' === stateOverride) {
  2814. break loop;
  2815. }
  2816. } else if (EOF === c || '/' === c ||
  2817. '\\' === c || '?' === c || '#' === c) {
  2818. this._host = IDNAToASCII.call(this, buffer);
  2819. buffer = '';
  2820. state = 'relative path start';
  2821. if (stateOverride) {
  2822. break loop;
  2823. }
  2824. continue;
  2825. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2826. if ('[' === c) {
  2827. seenBracket = true;
  2828. } else if (']' === c) {
  2829. seenBracket = false;
  2830. }
  2831. buffer += c;
  2832. } else {
  2833. err('Invalid code point in host/hostname: ' + c);
  2834. }
  2835. break;
  2836. case 'port':
  2837. if (/[0-9]/.test(c)) {
  2838. buffer += c;
  2839. } else if (EOF === c || '/' === c || '\\' === c ||
  2840. '?' === c || '#' === c || stateOverride) {
  2841. if ('' !== buffer) {
  2842. var temp = parseInt(buffer, 10);
  2843. if (temp !== relative[this._scheme]) {
  2844. this._port = temp + '';
  2845. }
  2846. buffer = '';
  2847. }
  2848. if (stateOverride) {
  2849. break loop;
  2850. }
  2851. state = 'relative path start';
  2852. continue;
  2853. } else if ('\t' === c || '\n' === c || '\r' === c) {
  2854. err('Invalid code point in port: ' + c);
  2855. } else {
  2856. invalid.call(this);
  2857. }
  2858. break;
  2859. case 'relative path start':
  2860. if ('\\' === c) {
  2861. err('\'\\\' not allowed in path.');
  2862. }
  2863. state = 'relative path';
  2864. if ('/' !== c && '\\' !== c) {
  2865. continue;
  2866. }
  2867. break;
  2868. case 'relative path':
  2869. if (EOF === c || '/' === c || '\\' === c ||
  2870. (!stateOverride && ('?' === c || '#' === c))) {
  2871. if ('\\' === c) {
  2872. err('\\ not allowed in relative path.');
  2873. }
  2874. var tmp;
  2875. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  2876. buffer = tmp;
  2877. }
  2878. if ('..' === buffer) {
  2879. this._path.pop();
  2880. if ('/' !== c && '\\' !== c) {
  2881. this._path.push('');
  2882. }
  2883. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  2884. this._path.push('');
  2885. } else if ('.' !== buffer) {
  2886. if ('file' === this._scheme && this._path.length === 0 &&
  2887. buffer.length === 2 && ALPHA.test(buffer[0]) &&
  2888. buffer[1] === '|') {
  2889. buffer = buffer[0] + ':';
  2890. }
  2891. this._path.push(buffer);
  2892. }
  2893. buffer = '';
  2894. if ('?' === c) {
  2895. this._query = '?';
  2896. state = 'query';
  2897. } else if ('#' === c) {
  2898. this._fragment = '#';
  2899. state = 'fragment';
  2900. }
  2901. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  2902. buffer += percentEscape(c);
  2903. }
  2904. break;
  2905. case 'query':
  2906. if (!stateOverride && '#' === c) {
  2907. this._fragment = '#';
  2908. state = 'fragment';
  2909. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2910. this._query += percentEscapeQuery(c);
  2911. }
  2912. break;
  2913. case 'fragment':
  2914. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  2915. this._fragment += c;
  2916. }
  2917. break;
  2918. }
  2919. cursor++;
  2920. }
  2921. }
  2922. function clear() {
  2923. this._scheme = '';
  2924. this._schemeData = '';
  2925. this._username = '';
  2926. this._password = null;
  2927. this._host = '';
  2928. this._port = '';
  2929. this._path = [];
  2930. this._query = '';
  2931. this._fragment = '';
  2932. this._isInvalid = false;
  2933. this._isRelative = false;
  2934. }
  2935. // Does not process domain names or IP addresses.
  2936. // Does not handle encoding for the query parameter.
  2937. function JURL(url, base /* , encoding */) {
  2938. if (base !== undefined && !(base instanceof JURL)) {
  2939. base = new JURL(String(base));
  2940. }
  2941. this._url = url;
  2942. clear.call(this);
  2943. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  2944. // encoding = encoding || 'utf-8'
  2945. parse.call(this, input, null, base);
  2946. }
  2947. JURL.prototype = {
  2948. toString: function() {
  2949. return this.href;
  2950. },
  2951. get href() {
  2952. if (this._isInvalid) {
  2953. return this._url;
  2954. }
  2955. var authority = '';
  2956. if ('' !== this._username || null !== this._password) {
  2957. authority = this._username +
  2958. (null !== this._password ? ':' + this._password : '') + '@';
  2959. }
  2960. return this.protocol +
  2961. (this._isRelative ? '//' + authority + this.host : '') +
  2962. this.pathname + this._query + this._fragment;
  2963. },
  2964. set href(href) {
  2965. clear.call(this);
  2966. parse.call(this, href);
  2967. },
  2968. get protocol() {
  2969. return this._scheme + ':';
  2970. },
  2971. set protocol(protocol) {
  2972. if (this._isInvalid) {
  2973. return;
  2974. }
  2975. parse.call(this, protocol + ':', 'scheme start');
  2976. },
  2977. get host() {
  2978. return this._isInvalid ? '' : this._port ?
  2979. this._host + ':' + this._port : this._host;
  2980. },
  2981. set host(host) {
  2982. if (this._isInvalid || !this._isRelative) {
  2983. return;
  2984. }
  2985. parse.call(this, host, 'host');
  2986. },
  2987. get hostname() {
  2988. return this._host;
  2989. },
  2990. set hostname(hostname) {
  2991. if (this._isInvalid || !this._isRelative) {
  2992. return;
  2993. }
  2994. parse.call(this, hostname, 'hostname');
  2995. },
  2996. get port() {
  2997. return this._port;
  2998. },
  2999. set port(port) {
  3000. if (this._isInvalid || !this._isRelative) {
  3001. return;
  3002. }
  3003. parse.call(this, port, 'port');
  3004. },
  3005. get pathname() {
  3006. return this._isInvalid ? '' : this._isRelative ?
  3007. '/' + this._path.join('/') : this._schemeData;
  3008. },
  3009. set pathname(pathname) {
  3010. if (this._isInvalid || !this._isRelative) {
  3011. return;
  3012. }
  3013. this._path = [];
  3014. parse.call(this, pathname, 'relative path start');
  3015. },
  3016. get search() {
  3017. return this._isInvalid || !this._query || '?' === this._query ?
  3018. '' : this._query;
  3019. },
  3020. set search(search) {
  3021. if (this._isInvalid || !this._isRelative) {
  3022. return;
  3023. }
  3024. this._query = '?';
  3025. if ('?' === search[0]) {
  3026. search = search.slice(1);
  3027. }
  3028. parse.call(this, search, 'query');
  3029. },
  3030. get hash() {
  3031. return this._isInvalid || !this._fragment || '#' === this._fragment ?
  3032. '' : this._fragment;
  3033. },
  3034. set hash(hash) {
  3035. if (this._isInvalid) {
  3036. return;
  3037. }
  3038. this._fragment = '#';
  3039. if ('#' === hash[0]) {
  3040. hash = hash.slice(1);
  3041. }
  3042. parse.call(this, hash, 'fragment');
  3043. },
  3044. get origin() {
  3045. var host;
  3046. if (this._isInvalid || !this._scheme) {
  3047. return '';
  3048. }
  3049. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  3050. // Gecko throws error for "data://"
  3051. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  3052. // Gecko returns String("") for file: mailto:
  3053. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  3054. switch (this._scheme) {
  3055. case 'data':
  3056. case 'file':
  3057. case 'javascript':
  3058. case 'mailto':
  3059. return 'null';
  3060. }
  3061. host = this.host;
  3062. if (!host) {
  3063. return '';
  3064. }
  3065. return this._scheme + '://' + host;
  3066. }
  3067. };
  3068. // Copy over the static methods
  3069. var OriginalURL = scope.URL;
  3070. if (OriginalURL) {
  3071. JURL.createObjectURL = function(blob) {
  3072. // IE extension allows a second optional options argument.
  3073. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  3074. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  3075. };
  3076. JURL.revokeObjectURL = function(url) {
  3077. OriginalURL.revokeObjectURL(url);
  3078. };
  3079. }
  3080. scope.URL = JURL;
  3081. })(globalScope);
  3082. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  3083. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  3084. exports.OPS = OPS;
  3085. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  3086. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  3087. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  3088. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  3089. exports.AnnotationFlag = AnnotationFlag;
  3090. exports.AnnotationType = AnnotationType;
  3091. exports.FontType = FontType;
  3092. exports.ImageKind = ImageKind;
  3093. exports.InvalidPDFException = InvalidPDFException;
  3094. exports.MessageHandler = MessageHandler;
  3095. exports.MissingDataException = MissingDataException;
  3096. exports.MissingPDFException = MissingPDFException;
  3097. exports.NotImplementedException = NotImplementedException;
  3098. exports.PageViewport = PageViewport;
  3099. exports.PasswordException = PasswordException;
  3100. exports.PasswordResponses = PasswordResponses;
  3101. exports.StatTimer = StatTimer;
  3102. exports.StreamType = StreamType;
  3103. exports.TextRenderingMode = TextRenderingMode;
  3104. exports.UnexpectedResponseException = UnexpectedResponseException;
  3105. exports.UnknownErrorException = UnknownErrorException;
  3106. exports.Util = Util;
  3107. exports.XRefParseException = XRefParseException;
  3108. exports.arrayByteLength = arrayByteLength;
  3109. exports.arraysToBytes = arraysToBytes;
  3110. exports.assert = assert;
  3111. exports.bytesToString = bytesToString;
  3112. exports.createBlob = createBlob;
  3113. exports.createPromiseCapability = createPromiseCapability;
  3114. exports.createObjectURL = createObjectURL;
  3115. exports.deprecated = deprecated;
  3116. exports.error = error;
  3117. exports.getLookupTableFactory = getLookupTableFactory;
  3118. exports.getVerbosityLevel = getVerbosityLevel;
  3119. exports.globalScope = globalScope;
  3120. exports.info = info;
  3121. exports.isArray = isArray;
  3122. exports.isArrayBuffer = isArrayBuffer;
  3123. exports.isBool = isBool;
  3124. exports.isEmptyObj = isEmptyObj;
  3125. exports.isInt = isInt;
  3126. exports.isNum = isNum;
  3127. exports.isString = isString;
  3128. exports.isSpace = isSpace;
  3129. exports.isSameOrigin = isSameOrigin;
  3130. exports.isValidUrl = isValidUrl;
  3131. exports.isLittleEndian = isLittleEndian;
  3132. exports.isEvalSupported = isEvalSupported;
  3133. exports.loadJpegStream = loadJpegStream;
  3134. exports.log2 = log2;
  3135. exports.readInt8 = readInt8;
  3136. exports.readUint16 = readUint16;
  3137. exports.readUint32 = readUint32;
  3138. exports.removeNullCharacters = removeNullCharacters;
  3139. exports.setVerbosityLevel = setVerbosityLevel;
  3140. exports.shadow = shadow;
  3141. exports.string32 = string32;
  3142. exports.stringToBytes = stringToBytes;
  3143. exports.stringToPDFString = stringToPDFString;
  3144. exports.stringToUTF8String = stringToUTF8String;
  3145. exports.utf8StringToString = utf8StringToString;
  3146. exports.warn = warn;
  3147. }));
  3148. (function (root, factory) {
  3149. {
  3150. factory((root.pdfjsCoreCFFParser = {}), root.pdfjsSharedUtil,
  3151. root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  3152. }
  3153. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  3154. var error = sharedUtil.error;
  3155. var info = sharedUtil.info;
  3156. var bytesToString = sharedUtil.bytesToString;
  3157. var warn = sharedUtil.warn;
  3158. var isArray = sharedUtil.isArray;
  3159. var Util = sharedUtil.Util;
  3160. var stringToBytes = sharedUtil.stringToBytes;
  3161. var assert = sharedUtil.assert;
  3162. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  3163. var ExpertCharset = coreCharsets.ExpertCharset;
  3164. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  3165. var StandardEncoding = coreEncodings.StandardEncoding;
  3166. var ExpertEncoding = coreEncodings.ExpertEncoding;
  3167. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  3168. var MAX_SUBR_NESTING = 10;
  3169. /**
  3170. * The CFF class takes a Type1 file and wrap it into a
  3171. * 'Compact Font Format' which itself embed Type2 charstrings.
  3172. */
  3173. var CFFStandardStrings = [
  3174. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  3175. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  3176. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  3177. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  3178. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  3179. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  3180. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  3181. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  3182. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  3183. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  3184. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  3185. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  3186. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  3187. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  3188. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  3189. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  3190. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  3191. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  3192. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  3193. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  3194. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  3195. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  3196. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  3197. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  3198. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  3199. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  3200. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  3201. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  3202. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  3203. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  3204. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  3205. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  3206. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  3207. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  3208. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  3209. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  3210. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  3211. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  3212. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  3213. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  3214. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  3215. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  3216. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  3217. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  3218. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  3219. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  3220. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  3221. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  3222. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  3223. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  3224. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  3225. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  3226. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  3227. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  3228. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  3229. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  3230. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  3231. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  3232. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  3233. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  3234. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  3235. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  3236. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  3237. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  3238. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  3239. ];
  3240. var CFFParser = (function CFFParserClosure() {
  3241. var CharstringValidationData = [
  3242. null,
  3243. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  3244. null,
  3245. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  3246. { id: 'vmoveto', min: 1, stackClearing: true },
  3247. { id: 'rlineto', min: 2, resetStack: true },
  3248. { id: 'hlineto', min: 1, resetStack: true },
  3249. { id: 'vlineto', min: 1, resetStack: true },
  3250. { id: 'rrcurveto', min: 6, resetStack: true },
  3251. null,
  3252. { id: 'callsubr', min: 1, undefStack: true },
  3253. { id: 'return', min: 0, undefStack: true },
  3254. null, // 12
  3255. null,
  3256. { id: 'endchar', min: 0, stackClearing: true },
  3257. null,
  3258. null,
  3259. null,
  3260. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  3261. { id: 'hintmask', min: 0, stackClearing: true },
  3262. { id: 'cntrmask', min: 0, stackClearing: true },
  3263. { id: 'rmoveto', min: 2, stackClearing: true },
  3264. { id: 'hmoveto', min: 1, stackClearing: true },
  3265. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  3266. { id: 'rcurveline', min: 8, resetStack: true },
  3267. { id: 'rlinecurve', min: 8, resetStack: true },
  3268. { id: 'vvcurveto', min: 4, resetStack: true },
  3269. { id: 'hhcurveto', min: 4, resetStack: true },
  3270. null, // shortint
  3271. { id: 'callgsubr', min: 1, undefStack: true },
  3272. { id: 'vhcurveto', min: 4, resetStack: true },
  3273. { id: 'hvcurveto', min: 4, resetStack: true }
  3274. ];
  3275. var CharstringValidationData12 = [
  3276. null,
  3277. null,
  3278. null,
  3279. { id: 'and', min: 2, stackDelta: -1 },
  3280. { id: 'or', min: 2, stackDelta: -1 },
  3281. { id: 'not', min: 1, stackDelta: 0 },
  3282. null,
  3283. null,
  3284. null,
  3285. { id: 'abs', min: 1, stackDelta: 0 },
  3286. { id: 'add', min: 2, stackDelta: -1,
  3287. stackFn: function stack_div(stack, index) {
  3288. stack[index - 2] = stack[index - 2] + stack[index - 1];
  3289. }
  3290. },
  3291. { id: 'sub', min: 2, stackDelta: -1,
  3292. stackFn: function stack_div(stack, index) {
  3293. stack[index - 2] = stack[index - 2] - stack[index - 1];
  3294. }
  3295. },
  3296. { id: 'div', min: 2, stackDelta: -1,
  3297. stackFn: function stack_div(stack, index) {
  3298. stack[index - 2] = stack[index - 2] / stack[index - 1];
  3299. }
  3300. },
  3301. null,
  3302. { id: 'neg', min: 1, stackDelta: 0,
  3303. stackFn: function stack_div(stack, index) {
  3304. stack[index - 1] = -stack[index - 1];
  3305. }
  3306. },
  3307. { id: 'eq', min: 2, stackDelta: -1 },
  3308. null,
  3309. null,
  3310. { id: 'drop', min: 1, stackDelta: -1 },
  3311. null,
  3312. { id: 'put', min: 2, stackDelta: -2 },
  3313. { id: 'get', min: 1, stackDelta: 0 },
  3314. { id: 'ifelse', min: 4, stackDelta: -3 },
  3315. { id: 'random', min: 0, stackDelta: 1 },
  3316. { id: 'mul', min: 2, stackDelta: -1,
  3317. stackFn: function stack_div(stack, index) {
  3318. stack[index - 2] = stack[index - 2] * stack[index - 1];
  3319. }
  3320. },
  3321. null,
  3322. { id: 'sqrt', min: 1, stackDelta: 0 },
  3323. { id: 'dup', min: 1, stackDelta: 1 },
  3324. { id: 'exch', min: 2, stackDelta: 0 },
  3325. { id: 'index', min: 2, stackDelta: 0 },
  3326. { id: 'roll', min: 3, stackDelta: -2 },
  3327. null,
  3328. null,
  3329. null,
  3330. { id: 'hflex', min: 7, resetStack: true },
  3331. { id: 'flex', min: 13, resetStack: true },
  3332. { id: 'hflex1', min: 9, resetStack: true },
  3333. { id: 'flex1', min: 11, resetStack: true }
  3334. ];
  3335. function CFFParser(file, properties, seacAnalysisEnabled) {
  3336. this.bytes = file.getBytes();
  3337. this.properties = properties;
  3338. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  3339. }
  3340. CFFParser.prototype = {
  3341. parse: function CFFParser_parse() {
  3342. var properties = this.properties;
  3343. var cff = new CFF();
  3344. this.cff = cff;
  3345. // The first five sections must be in order, all the others are reached
  3346. // via offsets contained in one of the below.
  3347. var header = this.parseHeader();
  3348. var nameIndex = this.parseIndex(header.endPos);
  3349. var topDictIndex = this.parseIndex(nameIndex.endPos);
  3350. var stringIndex = this.parseIndex(topDictIndex.endPos);
  3351. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  3352. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  3353. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  3354. cff.header = header.obj;
  3355. cff.names = this.parseNameIndex(nameIndex.obj);
  3356. cff.strings = this.parseStringIndex(stringIndex.obj);
  3357. cff.topDict = topDict;
  3358. cff.globalSubrIndex = globalSubrIndex.obj;
  3359. this.parsePrivateDict(cff.topDict);
  3360. cff.isCIDFont = topDict.hasName('ROS');
  3361. var charStringOffset = topDict.getByName('CharStrings');
  3362. var charStringIndex = this.parseIndex(charStringOffset).obj;
  3363. var fontMatrix = topDict.getByName('FontMatrix');
  3364. if (fontMatrix) {
  3365. properties.fontMatrix = fontMatrix;
  3366. }
  3367. var fontBBox = topDict.getByName('FontBBox');
  3368. if (fontBBox) {
  3369. // adjusting ascent/descent
  3370. properties.ascent = fontBBox[3];
  3371. properties.descent = fontBBox[1];
  3372. properties.ascentScaled = true;
  3373. }
  3374. var charset, encoding;
  3375. if (cff.isCIDFont) {
  3376. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  3377. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  3378. var dictRaw = fdArrayIndex.get(i);
  3379. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  3380. cff.strings);
  3381. this.parsePrivateDict(fontDict);
  3382. cff.fdArray.push(fontDict);
  3383. }
  3384. // cid fonts don't have an encoding
  3385. encoding = null;
  3386. charset = this.parseCharsets(topDict.getByName('charset'),
  3387. charStringIndex.count, cff.strings, true);
  3388. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  3389. charStringIndex.count);
  3390. } else {
  3391. charset = this.parseCharsets(topDict.getByName('charset'),
  3392. charStringIndex.count, cff.strings, false);
  3393. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  3394. properties,
  3395. cff.strings, charset.charset);
  3396. }
  3397. cff.charset = charset;
  3398. cff.encoding = encoding;
  3399. var charStringsAndSeacs = this.parseCharStrings(
  3400. charStringIndex,
  3401. topDict.privateDict.subrsIndex,
  3402. globalSubrIndex.obj,
  3403. cff.fdSelect,
  3404. cff.fdArray);
  3405. cff.charStrings = charStringsAndSeacs.charStrings;
  3406. cff.seacs = charStringsAndSeacs.seacs;
  3407. cff.widths = charStringsAndSeacs.widths;
  3408. return cff;
  3409. },
  3410. parseHeader: function CFFParser_parseHeader() {
  3411. var bytes = this.bytes;
  3412. var bytesLength = bytes.length;
  3413. var offset = 0;
  3414. // Prevent an infinite loop, by checking that the offset is within the
  3415. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  3416. while (offset < bytesLength && bytes[offset] !== 1) {
  3417. ++offset;
  3418. }
  3419. if (offset >= bytesLength) {
  3420. error('Invalid CFF header');
  3421. } else if (offset !== 0) {
  3422. info('cff data is shifted');
  3423. bytes = bytes.subarray(offset);
  3424. this.bytes = bytes;
  3425. }
  3426. var major = bytes[0];
  3427. var minor = bytes[1];
  3428. var hdrSize = bytes[2];
  3429. var offSize = bytes[3];
  3430. var header = new CFFHeader(major, minor, hdrSize, offSize);
  3431. return { obj: header, endPos: hdrSize };
  3432. },
  3433. parseDict: function CFFParser_parseDict(dict) {
  3434. var pos = 0;
  3435. function parseOperand() {
  3436. var value = dict[pos++];
  3437. if (value === 30) {
  3438. return parseFloatOperand();
  3439. } else if (value === 28) {
  3440. value = dict[pos++];
  3441. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  3442. return value;
  3443. } else if (value === 29) {
  3444. value = dict[pos++];
  3445. value = (value << 8) | dict[pos++];
  3446. value = (value << 8) | dict[pos++];
  3447. value = (value << 8) | dict[pos++];
  3448. return value;
  3449. } else if (value >= 32 && value <= 246) {
  3450. return value - 139;
  3451. } else if (value >= 247 && value <= 250) {
  3452. return ((value - 247) * 256) + dict[pos++] + 108;
  3453. } else if (value >= 251 && value <= 254) {
  3454. return -((value - 251) * 256) - dict[pos++] - 108;
  3455. } else {
  3456. error('255 is not a valid DICT command');
  3457. }
  3458. return -1;
  3459. }
  3460. function parseFloatOperand() {
  3461. var str = '';
  3462. var eof = 15;
  3463. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  3464. '9', '.', 'E', 'E-', null, '-'];
  3465. var length = dict.length;
  3466. while (pos < length) {
  3467. var b = dict[pos++];
  3468. var b1 = b >> 4;
  3469. var b2 = b & 15;
  3470. if (b1 === eof) {
  3471. break;
  3472. }
  3473. str += lookup[b1];
  3474. if (b2 === eof) {
  3475. break;
  3476. }
  3477. str += lookup[b2];
  3478. }
  3479. return parseFloat(str);
  3480. }
  3481. var operands = [];
  3482. var entries = [];
  3483. pos = 0;
  3484. var end = dict.length;
  3485. while (pos < end) {
  3486. var b = dict[pos];
  3487. if (b <= 21) {
  3488. if (b === 12) {
  3489. b = (b << 8) | dict[++pos];
  3490. }
  3491. entries.push([b, operands]);
  3492. operands = [];
  3493. ++pos;
  3494. } else {
  3495. operands.push(parseOperand());
  3496. }
  3497. }
  3498. return entries;
  3499. },
  3500. parseIndex: function CFFParser_parseIndex(pos) {
  3501. var cffIndex = new CFFIndex();
  3502. var bytes = this.bytes;
  3503. var count = (bytes[pos++] << 8) | bytes[pos++];
  3504. var offsets = [];
  3505. var end = pos;
  3506. var i, ii;
  3507. if (count !== 0) {
  3508. var offsetSize = bytes[pos++];
  3509. // add 1 for offset to determine size of last object
  3510. var startPos = pos + ((count + 1) * offsetSize) - 1;
  3511. for (i = 0, ii = count + 1; i < ii; ++i) {
  3512. var offset = 0;
  3513. for (var j = 0; j < offsetSize; ++j) {
  3514. offset <<= 8;
  3515. offset += bytes[pos++];
  3516. }
  3517. offsets.push(startPos + offset);
  3518. }
  3519. end = offsets[count];
  3520. }
  3521. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  3522. var offsetStart = offsets[i];
  3523. var offsetEnd = offsets[i + 1];
  3524. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  3525. }
  3526. return {obj: cffIndex, endPos: end};
  3527. },
  3528. parseNameIndex: function CFFParser_parseNameIndex(index) {
  3529. var names = [];
  3530. for (var i = 0, ii = index.count; i < ii; ++i) {
  3531. var name = index.get(i);
  3532. // OTS doesn't allow names to be over 127 characters.
  3533. var length = Math.min(name.length, 127);
  3534. var data = [];
  3535. // OTS also only permits certain characters in the name.
  3536. for (var j = 0; j < length; ++j) {
  3537. var c = name[j];
  3538. if (j === 0 && c === 0) {
  3539. data[j] = c;
  3540. continue;
  3541. }
  3542. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  3543. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  3544. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  3545. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  3546. data[j] = 95;
  3547. continue;
  3548. }
  3549. data[j] = c;
  3550. }
  3551. names.push(bytesToString(data));
  3552. }
  3553. return names;
  3554. },
  3555. parseStringIndex: function CFFParser_parseStringIndex(index) {
  3556. var strings = new CFFStrings();
  3557. for (var i = 0, ii = index.count; i < ii; ++i) {
  3558. var data = index.get(i);
  3559. strings.add(bytesToString(data));
  3560. }
  3561. return strings;
  3562. },
  3563. createDict: function CFFParser_createDict(Type, dict, strings) {
  3564. var cffDict = new Type(strings);
  3565. for (var i = 0, ii = dict.length; i < ii; ++i) {
  3566. var pair = dict[i];
  3567. var key = pair[0];
  3568. var value = pair[1];
  3569. cffDict.setByKey(key, value);
  3570. }
  3571. return cffDict;
  3572. },
  3573. parseCharString: function CFFParser_parseCharString(state, data,
  3574. localSubrIndex,
  3575. globalSubrIndex) {
  3576. if (state.callDepth > MAX_SUBR_NESTING) {
  3577. return false;
  3578. }
  3579. var stackSize = state.stackSize;
  3580. var stack = state.stack;
  3581. var length = data.length;
  3582. for (var j = 0; j < length;) {
  3583. var value = data[j++];
  3584. var validationCommand = null;
  3585. if (value === 12) {
  3586. var q = data[j++];
  3587. if (q === 0) {
  3588. // The CFF specification state that the 'dotsection' command
  3589. // (12, 0) is deprecated and treated as a no-op, but all Type2
  3590. // charstrings processors should support them. Unfortunately
  3591. // the font sanitizer don't. As a workaround the sequence (12, 0)
  3592. // is replaced by a useless (0, hmoveto).
  3593. data[j - 2] = 139;
  3594. data[j - 1] = 22;
  3595. stackSize = 0;
  3596. } else {
  3597. validationCommand = CharstringValidationData12[q];
  3598. }
  3599. } else if (value === 28) { // number (16 bit)
  3600. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  3601. j += 2;
  3602. stackSize++;
  3603. } else if (value === 14) {
  3604. if (stackSize >= 4) {
  3605. stackSize -= 4;
  3606. if (this.seacAnalysisEnabled) {
  3607. state.seac = stack.slice(stackSize, stackSize + 4);
  3608. return false;
  3609. }
  3610. }
  3611. validationCommand = CharstringValidationData[value];
  3612. } else if (value >= 32 && value <= 246) { // number
  3613. stack[stackSize] = value - 139;
  3614. stackSize++;
  3615. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  3616. stack[stackSize] = (value < 251 ?
  3617. ((value - 247) << 8) + data[j] + 108 :
  3618. -((value - 251) << 8) - data[j] - 108);
  3619. j++;
  3620. stackSize++;
  3621. } else if (value === 255) { // number (32 bit)
  3622. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  3623. (data[j + 2] << 8) | data[j + 3]) / 65536;
  3624. j += 4;
  3625. stackSize++;
  3626. } else if (value === 19 || value === 20) {
  3627. state.hints += stackSize >> 1;
  3628. // skipping right amount of hints flag data
  3629. j += (state.hints + 7) >> 3;
  3630. stackSize %= 2;
  3631. validationCommand = CharstringValidationData[value];
  3632. } else if (value === 10 || value === 29) {
  3633. var subrsIndex;
  3634. if (value === 10) {
  3635. subrsIndex = localSubrIndex;
  3636. } else {
  3637. subrsIndex = globalSubrIndex;
  3638. }
  3639. if (!subrsIndex) {
  3640. validationCommand = CharstringValidationData[value];
  3641. warn('Missing subrsIndex for ' + validationCommand.id);
  3642. return false;
  3643. }
  3644. var bias = 32768;
  3645. if (subrsIndex.count < 1240) {
  3646. bias = 107;
  3647. } else if (subrsIndex.count < 33900) {
  3648. bias = 1131;
  3649. }
  3650. var subrNumber = stack[--stackSize] + bias;
  3651. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  3652. validationCommand = CharstringValidationData[value];
  3653. warn('Out of bounds subrIndex for ' + validationCommand.id);
  3654. return false;
  3655. }
  3656. state.stackSize = stackSize;
  3657. state.callDepth++;
  3658. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  3659. localSubrIndex, globalSubrIndex);
  3660. if (!valid) {
  3661. return false;
  3662. }
  3663. state.callDepth--;
  3664. stackSize = state.stackSize;
  3665. continue;
  3666. } else if (value === 11) {
  3667. state.stackSize = stackSize;
  3668. return true;
  3669. } else {
  3670. validationCommand = CharstringValidationData[value];
  3671. }
  3672. if (validationCommand) {
  3673. if (validationCommand.stem) {
  3674. state.hints += stackSize >> 1;
  3675. }
  3676. if ('min' in validationCommand) {
  3677. if (!state.undefStack && stackSize < validationCommand.min) {
  3678. warn('Not enough parameters for ' + validationCommand.id +
  3679. '; actual: ' + stackSize +
  3680. ', expected: ' + validationCommand.min);
  3681. return false;
  3682. }
  3683. }
  3684. if (state.firstStackClearing && validationCommand.stackClearing) {
  3685. state.firstStackClearing = false;
  3686. // the optional character width can be found before the first
  3687. // stack-clearing command arguments
  3688. stackSize -= validationCommand.min;
  3689. if (stackSize >= 2 && validationCommand.stem) {
  3690. // there are even amount of arguments for stem commands
  3691. stackSize %= 2;
  3692. } else if (stackSize > 1) {
  3693. warn('Found too many parameters for stack-clearing command');
  3694. }
  3695. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  3696. state.width = stack[stackSize - 1];
  3697. }
  3698. }
  3699. if ('stackDelta' in validationCommand) {
  3700. if ('stackFn' in validationCommand) {
  3701. validationCommand.stackFn(stack, stackSize);
  3702. }
  3703. stackSize += validationCommand.stackDelta;
  3704. } else if (validationCommand.stackClearing) {
  3705. stackSize = 0;
  3706. } else if (validationCommand.resetStack) {
  3707. stackSize = 0;
  3708. state.undefStack = false;
  3709. } else if (validationCommand.undefStack) {
  3710. stackSize = 0;
  3711. state.undefStack = true;
  3712. state.firstStackClearing = false;
  3713. }
  3714. }
  3715. }
  3716. state.stackSize = stackSize;
  3717. return true;
  3718. },
  3719. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  3720. localSubrIndex,
  3721. globalSubrIndex,
  3722. fdSelect,
  3723. fdArray) {
  3724. var seacs = [];
  3725. var widths = [];
  3726. var count = charStrings.count;
  3727. for (var i = 0; i < count; i++) {
  3728. var charstring = charStrings.get(i);
  3729. var state = {
  3730. callDepth: 0,
  3731. stackSize: 0,
  3732. stack: [],
  3733. undefStack: true,
  3734. hints: 0,
  3735. firstStackClearing: true,
  3736. seac: null,
  3737. width: null
  3738. };
  3739. var valid = true;
  3740. var localSubrToUse = null;
  3741. if (fdSelect && fdArray.length) {
  3742. var fdIndex = fdSelect.getFDIndex(i);
  3743. if (fdIndex === -1) {
  3744. warn('Glyph index is not in fd select.');
  3745. valid = false;
  3746. }
  3747. if (fdIndex >= fdArray.length) {
  3748. warn('Invalid fd index for glyph index.');
  3749. valid = false;
  3750. }
  3751. if (valid) {
  3752. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  3753. }
  3754. } else if (localSubrIndex) {
  3755. localSubrToUse = localSubrIndex;
  3756. }
  3757. if (valid) {
  3758. valid = this.parseCharString(state, charstring, localSubrToUse,
  3759. globalSubrIndex);
  3760. }
  3761. if (state.width !== null) {
  3762. widths[i] = state.width;
  3763. }
  3764. if (state.seac !== null) {
  3765. seacs[i] = state.seac;
  3766. }
  3767. if (!valid) {
  3768. // resetting invalid charstring to single 'endchar'
  3769. charStrings.set(i, new Uint8Array([14]));
  3770. }
  3771. }
  3772. return { charStrings: charStrings, seacs: seacs, widths: widths };
  3773. },
  3774. emptyPrivateDictionary:
  3775. function CFFParser_emptyPrivateDictionary(parentDict) {
  3776. var privateDict = this.createDict(CFFPrivateDict, [],
  3777. parentDict.strings);
  3778. parentDict.setByKey(18, [0, 0]);
  3779. parentDict.privateDict = privateDict;
  3780. },
  3781. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  3782. // no private dict, do nothing
  3783. if (!parentDict.hasName('Private')) {
  3784. this.emptyPrivateDictionary(parentDict);
  3785. return;
  3786. }
  3787. var privateOffset = parentDict.getByName('Private');
  3788. // make sure the params are formatted correctly
  3789. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  3790. parentDict.removeByName('Private');
  3791. return;
  3792. }
  3793. var size = privateOffset[0];
  3794. var offset = privateOffset[1];
  3795. // remove empty dicts or ones that refer to invalid location
  3796. if (size === 0 || offset >= this.bytes.length) {
  3797. this.emptyPrivateDictionary(parentDict);
  3798. return;
  3799. }
  3800. var privateDictEnd = offset + size;
  3801. var dictData = this.bytes.subarray(offset, privateDictEnd);
  3802. var dict = this.parseDict(dictData);
  3803. var privateDict = this.createDict(CFFPrivateDict, dict,
  3804. parentDict.strings);
  3805. parentDict.privateDict = privateDict;
  3806. // Parse the Subrs index also since it's relative to the private dict.
  3807. if (!privateDict.getByName('Subrs')) {
  3808. return;
  3809. }
  3810. var subrsOffset = privateDict.getByName('Subrs');
  3811. var relativeOffset = offset + subrsOffset;
  3812. // Validate the offset.
  3813. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  3814. this.emptyPrivateDictionary(parentDict);
  3815. return;
  3816. }
  3817. var subrsIndex = this.parseIndex(relativeOffset);
  3818. privateDict.subrsIndex = subrsIndex.obj;
  3819. },
  3820. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  3821. if (pos === 0) {
  3822. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  3823. ISOAdobeCharset);
  3824. } else if (pos === 1) {
  3825. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  3826. ExpertCharset);
  3827. } else if (pos === 2) {
  3828. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  3829. ExpertSubsetCharset);
  3830. }
  3831. var bytes = this.bytes;
  3832. var start = pos;
  3833. var format = bytes[pos++];
  3834. var charset = ['.notdef'];
  3835. var id, count, i;
  3836. // subtract 1 for the .notdef glyph
  3837. length -= 1;
  3838. switch (format) {
  3839. case 0:
  3840. for (i = 0; i < length; i++) {
  3841. id = (bytes[pos++] << 8) | bytes[pos++];
  3842. charset.push(cid ? id : strings.get(id));
  3843. }
  3844. break;
  3845. case 1:
  3846. while (charset.length <= length) {
  3847. id = (bytes[pos++] << 8) | bytes[pos++];
  3848. count = bytes[pos++];
  3849. for (i = 0; i <= count; i++) {
  3850. charset.push(cid ? id++ : strings.get(id++));
  3851. }
  3852. }
  3853. break;
  3854. case 2:
  3855. while (charset.length <= length) {
  3856. id = (bytes[pos++] << 8) | bytes[pos++];
  3857. count = (bytes[pos++] << 8) | bytes[pos++];
  3858. for (i = 0; i <= count; i++) {
  3859. charset.push(cid ? id++ : strings.get(id++));
  3860. }
  3861. }
  3862. break;
  3863. default:
  3864. error('Unknown charset format');
  3865. }
  3866. // Raw won't be needed if we actually compile the charset.
  3867. var end = pos;
  3868. var raw = bytes.subarray(start, end);
  3869. return new CFFCharset(false, format, charset, raw);
  3870. },
  3871. parseEncoding: function CFFParser_parseEncoding(pos,
  3872. properties,
  3873. strings,
  3874. charset) {
  3875. var encoding = Object.create(null);
  3876. var bytes = this.bytes;
  3877. var predefined = false;
  3878. var hasSupplement = false;
  3879. var format, i, ii;
  3880. var raw = null;
  3881. function readSupplement() {
  3882. var supplementsCount = bytes[pos++];
  3883. for (i = 0; i < supplementsCount; i++) {
  3884. var code = bytes[pos++];
  3885. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  3886. encoding[code] = charset.indexOf(strings.get(sid));
  3887. }
  3888. }
  3889. if (pos === 0 || pos === 1) {
  3890. predefined = true;
  3891. format = pos;
  3892. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  3893. for (i = 0, ii = charset.length; i < ii; i++) {
  3894. var index = baseEncoding.indexOf(charset[i]);
  3895. if (index !== -1) {
  3896. encoding[index] = i;
  3897. }
  3898. }
  3899. } else {
  3900. var dataStart = pos;
  3901. format = bytes[pos++];
  3902. switch (format & 0x7f) {
  3903. case 0:
  3904. var glyphsCount = bytes[pos++];
  3905. for (i = 1; i <= glyphsCount; i++) {
  3906. encoding[bytes[pos++]] = i;
  3907. }
  3908. break;
  3909. case 1:
  3910. var rangesCount = bytes[pos++];
  3911. var gid = 1;
  3912. for (i = 0; i < rangesCount; i++) {
  3913. var start = bytes[pos++];
  3914. var left = bytes[pos++];
  3915. for (var j = start; j <= start + left; j++) {
  3916. encoding[j] = gid++;
  3917. }
  3918. }
  3919. break;
  3920. default:
  3921. error('Unknown encoding format: ' + format + ' in CFF');
  3922. break;
  3923. }
  3924. var dataEnd = pos;
  3925. if (format & 0x80) {
  3926. // The font sanitizer does not support CFF encoding with a
  3927. // supplement, since the encoding is not really used to map
  3928. // between gid to glyph, let's overwrite what is declared in
  3929. // the top dictionary to let the sanitizer think the font use
  3930. // StandardEncoding, that's a lie but that's ok.
  3931. bytes[dataStart] &= 0x7f;
  3932. readSupplement();
  3933. hasSupplement = true;
  3934. }
  3935. raw = bytes.subarray(dataStart, dataEnd);
  3936. }
  3937. format = format & 0x7f;
  3938. return new CFFEncoding(predefined, format, encoding, raw);
  3939. },
  3940. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  3941. var start = pos;
  3942. var bytes = this.bytes;
  3943. var format = bytes[pos++];
  3944. var fdSelect = [], rawBytes;
  3945. var i, invalidFirstGID = false;
  3946. switch (format) {
  3947. case 0:
  3948. for (i = 0; i < length; ++i) {
  3949. var id = bytes[pos++];
  3950. fdSelect.push(id);
  3951. }
  3952. rawBytes = bytes.subarray(start, pos);
  3953. break;
  3954. case 3:
  3955. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  3956. for (i = 0; i < rangesCount; ++i) {
  3957. var first = (bytes[pos++] << 8) | bytes[pos++];
  3958. if (i === 0 && first !== 0) {
  3959. warn('parseFDSelect: The first range must have a first GID of 0' +
  3960. ' -- trying to recover.');
  3961. invalidFirstGID = true;
  3962. first = 0;
  3963. }
  3964. var fdIndex = bytes[pos++];
  3965. var next = (bytes[pos] << 8) | bytes[pos + 1];
  3966. for (var j = first; j < next; ++j) {
  3967. fdSelect.push(fdIndex);
  3968. }
  3969. }
  3970. // Advance past the sentinel(next).
  3971. pos += 2;
  3972. rawBytes = bytes.subarray(start, pos);
  3973. if (invalidFirstGID) {
  3974. rawBytes[3] = rawBytes[4] = 0; // Adjust the first range, first GID.
  3975. }
  3976. break;
  3977. default:
  3978. error('parseFDSelect: Unknown format "' + format + '".');
  3979. break;
  3980. }
  3981. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  3982. return new CFFFDSelect(fdSelect, rawBytes);
  3983. }
  3984. };
  3985. return CFFParser;
  3986. })();
  3987. // Compact Font Format
  3988. var CFF = (function CFFClosure() {
  3989. function CFF() {
  3990. this.header = null;
  3991. this.names = [];
  3992. this.topDict = null;
  3993. this.strings = new CFFStrings();
  3994. this.globalSubrIndex = null;
  3995. // The following could really be per font, but since we only have one font
  3996. // store them here.
  3997. this.encoding = null;
  3998. this.charset = null;
  3999. this.charStrings = null;
  4000. this.fdArray = [];
  4001. this.fdSelect = null;
  4002. this.isCIDFont = false;
  4003. }
  4004. return CFF;
  4005. })();
  4006. var CFFHeader = (function CFFHeaderClosure() {
  4007. function CFFHeader(major, minor, hdrSize, offSize) {
  4008. this.major = major;
  4009. this.minor = minor;
  4010. this.hdrSize = hdrSize;
  4011. this.offSize = offSize;
  4012. }
  4013. return CFFHeader;
  4014. })();
  4015. var CFFStrings = (function CFFStringsClosure() {
  4016. function CFFStrings() {
  4017. this.strings = [];
  4018. }
  4019. CFFStrings.prototype = {
  4020. get: function CFFStrings_get(index) {
  4021. if (index >= 0 && index <= 390) {
  4022. return CFFStandardStrings[index];
  4023. }
  4024. if (index - 391 <= this.strings.length) {
  4025. return this.strings[index - 391];
  4026. }
  4027. return CFFStandardStrings[0];
  4028. },
  4029. add: function CFFStrings_add(value) {
  4030. this.strings.push(value);
  4031. },
  4032. get count() {
  4033. return this.strings.length;
  4034. }
  4035. };
  4036. return CFFStrings;
  4037. })();
  4038. var CFFIndex = (function CFFIndexClosure() {
  4039. function CFFIndex() {
  4040. this.objects = [];
  4041. this.length = 0;
  4042. }
  4043. CFFIndex.prototype = {
  4044. add: function CFFIndex_add(data) {
  4045. this.length += data.length;
  4046. this.objects.push(data);
  4047. },
  4048. set: function CFFIndex_set(index, data) {
  4049. this.length += data.length - this.objects[index].length;
  4050. this.objects[index] = data;
  4051. },
  4052. get: function CFFIndex_get(index) {
  4053. return this.objects[index];
  4054. },
  4055. get count() {
  4056. return this.objects.length;
  4057. }
  4058. };
  4059. return CFFIndex;
  4060. })();
  4061. var CFFDict = (function CFFDictClosure() {
  4062. function CFFDict(tables, strings) {
  4063. this.keyToNameMap = tables.keyToNameMap;
  4064. this.nameToKeyMap = tables.nameToKeyMap;
  4065. this.defaults = tables.defaults;
  4066. this.types = tables.types;
  4067. this.opcodes = tables.opcodes;
  4068. this.order = tables.order;
  4069. this.strings = strings;
  4070. this.values = Object.create(null);
  4071. }
  4072. CFFDict.prototype = {
  4073. // value should always be an array
  4074. setByKey: function CFFDict_setByKey(key, value) {
  4075. if (!(key in this.keyToNameMap)) {
  4076. return false;
  4077. }
  4078. // ignore empty values
  4079. if (value.length === 0) {
  4080. return true;
  4081. }
  4082. var type = this.types[key];
  4083. // remove the array wrapping these types of values
  4084. if (type === 'num' || type === 'sid' || type === 'offset') {
  4085. value = value[0];
  4086. // Ignore invalid values (fixes bug 1068432).
  4087. if (isNaN(value)) {
  4088. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  4089. return true;
  4090. }
  4091. }
  4092. this.values[key] = value;
  4093. return true;
  4094. },
  4095. setByName: function CFFDict_setByName(name, value) {
  4096. if (!(name in this.nameToKeyMap)) {
  4097. error('Invalid dictionary name "' + name + '"');
  4098. }
  4099. this.values[this.nameToKeyMap[name]] = value;
  4100. },
  4101. hasName: function CFFDict_hasName(name) {
  4102. return this.nameToKeyMap[name] in this.values;
  4103. },
  4104. getByName: function CFFDict_getByName(name) {
  4105. if (!(name in this.nameToKeyMap)) {
  4106. error('Invalid dictionary name "' + name + '"');
  4107. }
  4108. var key = this.nameToKeyMap[name];
  4109. if (!(key in this.values)) {
  4110. return this.defaults[key];
  4111. }
  4112. return this.values[key];
  4113. },
  4114. removeByName: function CFFDict_removeByName(name) {
  4115. delete this.values[this.nameToKeyMap[name]];
  4116. }
  4117. };
  4118. CFFDict.createTables = function CFFDict_createTables(layout) {
  4119. var tables = {
  4120. keyToNameMap: {},
  4121. nameToKeyMap: {},
  4122. defaults: {},
  4123. types: {},
  4124. opcodes: {},
  4125. order: []
  4126. };
  4127. for (var i = 0, ii = layout.length; i < ii; ++i) {
  4128. var entry = layout[i];
  4129. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  4130. tables.keyToNameMap[key] = entry[1];
  4131. tables.nameToKeyMap[entry[1]] = key;
  4132. tables.types[key] = entry[2];
  4133. tables.defaults[key] = entry[3];
  4134. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  4135. tables.order.push(key);
  4136. }
  4137. return tables;
  4138. };
  4139. return CFFDict;
  4140. })();
  4141. var CFFTopDict = (function CFFTopDictClosure() {
  4142. var layout = [
  4143. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  4144. [[12, 20], 'SyntheticBase', 'num', null],
  4145. [0, 'version', 'sid', null],
  4146. [1, 'Notice', 'sid', null],
  4147. [[12, 0], 'Copyright', 'sid', null],
  4148. [2, 'FullName', 'sid', null],
  4149. [3, 'FamilyName', 'sid', null],
  4150. [4, 'Weight', 'sid', null],
  4151. [[12, 1], 'isFixedPitch', 'num', 0],
  4152. [[12, 2], 'ItalicAngle', 'num', 0],
  4153. [[12, 3], 'UnderlinePosition', 'num', -100],
  4154. [[12, 4], 'UnderlineThickness', 'num', 50],
  4155. [[12, 5], 'PaintType', 'num', 0],
  4156. [[12, 6], 'CharstringType', 'num', 2],
  4157. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  4158. [0.001, 0, 0, 0.001, 0, 0]],
  4159. [13, 'UniqueID', 'num', null],
  4160. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  4161. [[12, 8], 'StrokeWidth', 'num', 0],
  4162. [14, 'XUID', 'array', null],
  4163. [15, 'charset', 'offset', 0],
  4164. [16, 'Encoding', 'offset', 0],
  4165. [17, 'CharStrings', 'offset', 0],
  4166. [18, 'Private', ['offset', 'offset'], null],
  4167. [[12, 21], 'PostScript', 'sid', null],
  4168. [[12, 22], 'BaseFontName', 'sid', null],
  4169. [[12, 23], 'BaseFontBlend', 'delta', null],
  4170. [[12, 31], 'CIDFontVersion', 'num', 0],
  4171. [[12, 32], 'CIDFontRevision', 'num', 0],
  4172. [[12, 33], 'CIDFontType', 'num', 0],
  4173. [[12, 34], 'CIDCount', 'num', 8720],
  4174. [[12, 35], 'UIDBase', 'num', null],
  4175. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  4176. // before FDArray.
  4177. [[12, 37], 'FDSelect', 'offset', null],
  4178. [[12, 36], 'FDArray', 'offset', null],
  4179. [[12, 38], 'FontName', 'sid', null]
  4180. ];
  4181. var tables = null;
  4182. function CFFTopDict(strings) {
  4183. if (tables === null) {
  4184. tables = CFFDict.createTables(layout);
  4185. }
  4186. CFFDict.call(this, tables, strings);
  4187. this.privateDict = null;
  4188. }
  4189. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  4190. return CFFTopDict;
  4191. })();
  4192. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  4193. var layout = [
  4194. [6, 'BlueValues', 'delta', null],
  4195. [7, 'OtherBlues', 'delta', null],
  4196. [8, 'FamilyBlues', 'delta', null],
  4197. [9, 'FamilyOtherBlues', 'delta', null],
  4198. [[12, 9], 'BlueScale', 'num', 0.039625],
  4199. [[12, 10], 'BlueShift', 'num', 7],
  4200. [[12, 11], 'BlueFuzz', 'num', 1],
  4201. [10, 'StdHW', 'num', null],
  4202. [11, 'StdVW', 'num', null],
  4203. [[12, 12], 'StemSnapH', 'delta', null],
  4204. [[12, 13], 'StemSnapV', 'delta', null],
  4205. [[12, 14], 'ForceBold', 'num', 0],
  4206. [[12, 17], 'LanguageGroup', 'num', 0],
  4207. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  4208. [[12, 19], 'initialRandomSeed', 'num', 0],
  4209. [20, 'defaultWidthX', 'num', 0],
  4210. [21, 'nominalWidthX', 'num', 0],
  4211. [19, 'Subrs', 'offset', null]
  4212. ];
  4213. var tables = null;
  4214. function CFFPrivateDict(strings) {
  4215. if (tables === null) {
  4216. tables = CFFDict.createTables(layout);
  4217. }
  4218. CFFDict.call(this, tables, strings);
  4219. this.subrsIndex = null;
  4220. }
  4221. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  4222. return CFFPrivateDict;
  4223. })();
  4224. var CFFCharsetPredefinedTypes = {
  4225. ISO_ADOBE: 0,
  4226. EXPERT: 1,
  4227. EXPERT_SUBSET: 2
  4228. };
  4229. var CFFCharset = (function CFFCharsetClosure() {
  4230. function CFFCharset(predefined, format, charset, raw) {
  4231. this.predefined = predefined;
  4232. this.format = format;
  4233. this.charset = charset;
  4234. this.raw = raw;
  4235. }
  4236. return CFFCharset;
  4237. })();
  4238. var CFFEncoding = (function CFFEncodingClosure() {
  4239. function CFFEncoding(predefined, format, encoding, raw) {
  4240. this.predefined = predefined;
  4241. this.format = format;
  4242. this.encoding = encoding;
  4243. this.raw = raw;
  4244. }
  4245. return CFFEncoding;
  4246. })();
  4247. var CFFFDSelect = (function CFFFDSelectClosure() {
  4248. function CFFFDSelect(fdSelect, raw) {
  4249. this.fdSelect = fdSelect;
  4250. this.raw = raw;
  4251. }
  4252. CFFFDSelect.prototype = {
  4253. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  4254. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  4255. return -1;
  4256. }
  4257. return this.fdSelect[glyphIndex];
  4258. }
  4259. };
  4260. return CFFFDSelect;
  4261. })();
  4262. // Helper class to keep track of where an offset is within the data and helps
  4263. // filling in that offset once it's known.
  4264. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  4265. function CFFOffsetTracker() {
  4266. this.offsets = Object.create(null);
  4267. }
  4268. CFFOffsetTracker.prototype = {
  4269. isTracking: function CFFOffsetTracker_isTracking(key) {
  4270. return key in this.offsets;
  4271. },
  4272. track: function CFFOffsetTracker_track(key, location) {
  4273. if (key in this.offsets) {
  4274. error('Already tracking location of ' + key);
  4275. }
  4276. this.offsets[key] = location;
  4277. },
  4278. offset: function CFFOffsetTracker_offset(value) {
  4279. for (var key in this.offsets) {
  4280. this.offsets[key] += value;
  4281. }
  4282. },
  4283. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  4284. values,
  4285. output) {
  4286. if (!(key in this.offsets)) {
  4287. error('Not tracking location of ' + key);
  4288. }
  4289. var data = output.data;
  4290. var dataOffset = this.offsets[key];
  4291. var size = 5;
  4292. for (var i = 0, ii = values.length; i < ii; ++i) {
  4293. var offset0 = i * size + dataOffset;
  4294. var offset1 = offset0 + 1;
  4295. var offset2 = offset0 + 2;
  4296. var offset3 = offset0 + 3;
  4297. var offset4 = offset0 + 4;
  4298. // It's easy to screw up offsets so perform this sanity check.
  4299. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  4300. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  4301. error('writing to an offset that is not empty');
  4302. }
  4303. var value = values[i];
  4304. data[offset0] = 0x1d;
  4305. data[offset1] = (value >> 24) & 0xFF;
  4306. data[offset2] = (value >> 16) & 0xFF;
  4307. data[offset3] = (value >> 8) & 0xFF;
  4308. data[offset4] = value & 0xFF;
  4309. }
  4310. }
  4311. };
  4312. return CFFOffsetTracker;
  4313. })();
  4314. // Takes a CFF and converts it to the binary representation.
  4315. var CFFCompiler = (function CFFCompilerClosure() {
  4316. function CFFCompiler(cff) {
  4317. this.cff = cff;
  4318. }
  4319. CFFCompiler.prototype = {
  4320. compile: function CFFCompiler_compile() {
  4321. var cff = this.cff;
  4322. var output = {
  4323. data: [],
  4324. length: 0,
  4325. add: function CFFCompiler_add(data) {
  4326. this.data = this.data.concat(data);
  4327. this.length = this.data.length;
  4328. }
  4329. };
  4330. // Compile the five entries that must be in order.
  4331. var header = this.compileHeader(cff.header);
  4332. output.add(header);
  4333. var nameIndex = this.compileNameIndex(cff.names);
  4334. output.add(nameIndex);
  4335. if (cff.isCIDFont) {
  4336. // The spec is unclear on how font matrices should relate to each other
  4337. // when there is one in the main top dict and the sub top dicts.
  4338. // Windows handles this differently than linux and osx so we have to
  4339. // normalize to work on all.
  4340. // Rules based off of some mailing list discussions:
  4341. // - If main font has a matrix and subfont doesn't, use the main matrix.
  4342. // - If no main font matrix and there is a subfont matrix, use the
  4343. // subfont matrix.
  4344. // - If both have matrices, concat together.
  4345. // - If neither have matrices, use default.
  4346. // To make this work on all platforms we move the top matrix into each
  4347. // sub top dict and concat if necessary.
  4348. if (cff.topDict.hasName('FontMatrix')) {
  4349. var base = cff.topDict.getByName('FontMatrix');
  4350. cff.topDict.removeByName('FontMatrix');
  4351. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  4352. var subDict = cff.fdArray[i];
  4353. var matrix = base.slice(0);
  4354. if (subDict.hasName('FontMatrix')) {
  4355. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  4356. }
  4357. subDict.setByName('FontMatrix', matrix);
  4358. }
  4359. }
  4360. }
  4361. var compiled = this.compileTopDicts([cff.topDict],
  4362. output.length,
  4363. cff.isCIDFont);
  4364. output.add(compiled.output);
  4365. var topDictTracker = compiled.trackers[0];
  4366. var stringIndex = this.compileStringIndex(cff.strings.strings);
  4367. output.add(stringIndex);
  4368. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  4369. output.add(globalSubrIndex);
  4370. // Now start on the other entries that have no specific order.
  4371. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  4372. if (cff.encoding.predefined) {
  4373. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  4374. output);
  4375. } else {
  4376. var encoding = this.compileEncoding(cff.encoding);
  4377. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  4378. output.add(encoding);
  4379. }
  4380. }
  4381. if (cff.charset && cff.topDict.hasName('charset')) {
  4382. if (cff.charset.predefined) {
  4383. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  4384. output);
  4385. } else {
  4386. var charset = this.compileCharset(cff.charset);
  4387. topDictTracker.setEntryLocation('charset', [output.length], output);
  4388. output.add(charset);
  4389. }
  4390. }
  4391. var charStrings = this.compileCharStrings(cff.charStrings);
  4392. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  4393. output.add(charStrings);
  4394. if (cff.isCIDFont) {
  4395. // For some reason FDSelect must be in front of FDArray on windows. OSX
  4396. // and linux don't seem to care.
  4397. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  4398. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  4399. output.add(fdSelect);
  4400. // It is unclear if the sub font dictionary can have CID related
  4401. // dictionary keys, but the sanitizer doesn't like them so remove them.
  4402. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  4403. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  4404. output.add(compiled.output);
  4405. var fontDictTrackers = compiled.trackers;
  4406. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  4407. }
  4408. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  4409. // If the font data ends with INDEX whose object data is zero-length,
  4410. // the sanitizer will bail out. Add a dummy byte to avoid that.
  4411. output.add([0]);
  4412. return output.data;
  4413. },
  4414. encodeNumber: function CFFCompiler_encodeNumber(value) {
  4415. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  4416. return this.encodeInteger(value);
  4417. } else {
  4418. return this.encodeFloat(value);
  4419. }
  4420. },
  4421. encodeFloat: function CFFCompiler_encodeFloat(num) {
  4422. var value = num.toString();
  4423. // rounding inaccurate doubles
  4424. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  4425. if (m) {
  4426. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  4427. value = (Math.round(num * epsilon) / epsilon).toString();
  4428. }
  4429. var nibbles = '';
  4430. var i, ii;
  4431. for (i = 0, ii = value.length; i < ii; ++i) {
  4432. var a = value[i];
  4433. if (a === 'e') {
  4434. nibbles += value[++i] === '-' ? 'c' : 'b';
  4435. } else if (a === '.') {
  4436. nibbles += 'a';
  4437. } else if (a === '-') {
  4438. nibbles += 'e';
  4439. } else {
  4440. nibbles += a;
  4441. }
  4442. }
  4443. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  4444. var out = [30];
  4445. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  4446. out.push(parseInt(nibbles.substr(i, 2), 16));
  4447. }
  4448. return out;
  4449. },
  4450. encodeInteger: function CFFCompiler_encodeInteger(value) {
  4451. var code;
  4452. if (value >= -107 && value <= 107) {
  4453. code = [value + 139];
  4454. } else if (value >= 108 && value <= 1131) {
  4455. value = value - 108;
  4456. code = [(value >> 8) + 247, value & 0xFF];
  4457. } else if (value >= -1131 && value <= -108) {
  4458. value = -value - 108;
  4459. code = [(value >> 8) + 251, value & 0xFF];
  4460. } else if (value >= -32768 && value <= 32767) {
  4461. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  4462. } else {
  4463. code = [0x1d,
  4464. (value >> 24) & 0xFF,
  4465. (value >> 16) & 0xFF,
  4466. (value >> 8) & 0xFF,
  4467. value & 0xFF];
  4468. }
  4469. return code;
  4470. },
  4471. compileHeader: function CFFCompiler_compileHeader(header) {
  4472. return [
  4473. header.major,
  4474. header.minor,
  4475. header.hdrSize,
  4476. header.offSize
  4477. ];
  4478. },
  4479. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  4480. var nameIndex = new CFFIndex();
  4481. for (var i = 0, ii = names.length; i < ii; ++i) {
  4482. nameIndex.add(stringToBytes(names[i]));
  4483. }
  4484. return this.compileIndex(nameIndex);
  4485. },
  4486. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  4487. length,
  4488. removeCidKeys) {
  4489. var fontDictTrackers = [];
  4490. var fdArrayIndex = new CFFIndex();
  4491. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4492. var fontDict = dicts[i];
  4493. if (removeCidKeys) {
  4494. fontDict.removeByName('CIDFontVersion');
  4495. fontDict.removeByName('CIDFontRevision');
  4496. fontDict.removeByName('CIDFontType');
  4497. fontDict.removeByName('CIDCount');
  4498. fontDict.removeByName('UIDBase');
  4499. }
  4500. var fontDictTracker = new CFFOffsetTracker();
  4501. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  4502. fontDictTrackers.push(fontDictTracker);
  4503. fdArrayIndex.add(fontDictData);
  4504. fontDictTracker.offset(length);
  4505. }
  4506. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  4507. return {
  4508. trackers: fontDictTrackers,
  4509. output: fdArrayIndex
  4510. };
  4511. },
  4512. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  4513. trackers,
  4514. output) {
  4515. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  4516. var fontDict = dicts[i];
  4517. assert(fontDict.privateDict && fontDict.hasName('Private'),
  4518. 'There must be an private dictionary.');
  4519. var privateDict = fontDict.privateDict;
  4520. var privateDictTracker = new CFFOffsetTracker();
  4521. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  4522. var outputLength = output.length;
  4523. privateDictTracker.offset(outputLength);
  4524. if (!privateDictData.length) {
  4525. // The private dictionary was empty, set the output length to zero to
  4526. // ensure the offset length isn't out of bounds in the eyes of the
  4527. // sanitizer.
  4528. outputLength = 0;
  4529. }
  4530. trackers[i].setEntryLocation('Private',
  4531. [privateDictData.length, outputLength],
  4532. output);
  4533. output.add(privateDictData);
  4534. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  4535. var subrs = this.compileIndex(privateDict.subrsIndex);
  4536. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  4537. output);
  4538. output.add(subrs);
  4539. }
  4540. }
  4541. },
  4542. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  4543. var out = [];
  4544. // The dictionary keys must be in a certain order.
  4545. var order = dict.order;
  4546. for (var i = 0; i < order.length; ++i) {
  4547. var key = order[i];
  4548. if (!(key in dict.values)) {
  4549. continue;
  4550. }
  4551. var values = dict.values[key];
  4552. var types = dict.types[key];
  4553. if (!isArray(types)) {
  4554. types = [types];
  4555. }
  4556. if (!isArray(values)) {
  4557. values = [values];
  4558. }
  4559. // Remove any empty dict values.
  4560. if (values.length === 0) {
  4561. continue;
  4562. }
  4563. for (var j = 0, jj = types.length; j < jj; ++j) {
  4564. var type = types[j];
  4565. var value = values[j];
  4566. switch (type) {
  4567. case 'num':
  4568. case 'sid':
  4569. out = out.concat(this.encodeNumber(value));
  4570. break;
  4571. case 'offset':
  4572. // For offsets we just insert a 32bit integer so we don't have to
  4573. // deal with figuring out the length of the offset when it gets
  4574. // replaced later on by the compiler.
  4575. var name = dict.keyToNameMap[key];
  4576. // Some offsets have the offset and the length, so just record the
  4577. // position of the first one.
  4578. if (!offsetTracker.isTracking(name)) {
  4579. offsetTracker.track(name, out.length);
  4580. }
  4581. out = out.concat([0x1d, 0, 0, 0, 0]);
  4582. break;
  4583. case 'array':
  4584. case 'delta':
  4585. out = out.concat(this.encodeNumber(value));
  4586. for (var k = 1, kk = values.length; k < kk; ++k) {
  4587. out = out.concat(this.encodeNumber(values[k]));
  4588. }
  4589. break;
  4590. default:
  4591. error('Unknown data type of ' + type);
  4592. break;
  4593. }
  4594. }
  4595. out = out.concat(dict.opcodes[key]);
  4596. }
  4597. return out;
  4598. },
  4599. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  4600. var stringIndex = new CFFIndex();
  4601. for (var i = 0, ii = strings.length; i < ii; ++i) {
  4602. stringIndex.add(stringToBytes(strings[i]));
  4603. }
  4604. return this.compileIndex(stringIndex);
  4605. },
  4606. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  4607. var globalSubrIndex = this.cff.globalSubrIndex;
  4608. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  4609. },
  4610. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  4611. return this.compileIndex(charStrings);
  4612. },
  4613. compileCharset: function CFFCompiler_compileCharset(charset) {
  4614. return this.compileTypedArray(charset.raw);
  4615. },
  4616. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  4617. return this.compileTypedArray(encoding.raw);
  4618. },
  4619. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  4620. return this.compileTypedArray(fdSelect);
  4621. },
  4622. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  4623. var out = [];
  4624. for (var i = 0, ii = data.length; i < ii; ++i) {
  4625. out[i] = data[i];
  4626. }
  4627. return out;
  4628. },
  4629. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  4630. trackers = trackers || [];
  4631. var objects = index.objects;
  4632. // First 2 bytes contains the number of objects contained into this index
  4633. var count = objects.length;
  4634. // If there is no object, just create an index. This technically
  4635. // should just be [0, 0] but OTS has an issue with that.
  4636. if (count === 0) {
  4637. return [0, 0, 0];
  4638. }
  4639. var data = [(count >> 8) & 0xFF, count & 0xff];
  4640. var lastOffset = 1, i;
  4641. for (i = 0; i < count; ++i) {
  4642. lastOffset += objects[i].length;
  4643. }
  4644. var offsetSize;
  4645. if (lastOffset < 0x100) {
  4646. offsetSize = 1;
  4647. } else if (lastOffset < 0x10000) {
  4648. offsetSize = 2;
  4649. } else if (lastOffset < 0x1000000) {
  4650. offsetSize = 3;
  4651. } else {
  4652. offsetSize = 4;
  4653. }
  4654. // Next byte contains the offset size use to reference object in the file
  4655. data.push(offsetSize);
  4656. // Add another offset after this one because we need a new offset
  4657. var relativeOffset = 1;
  4658. for (i = 0; i < count + 1; i++) {
  4659. if (offsetSize === 1) {
  4660. data.push(relativeOffset & 0xFF);
  4661. } else if (offsetSize === 2) {
  4662. data.push((relativeOffset >> 8) & 0xFF,
  4663. relativeOffset & 0xFF);
  4664. } else if (offsetSize === 3) {
  4665. data.push((relativeOffset >> 16) & 0xFF,
  4666. (relativeOffset >> 8) & 0xFF,
  4667. relativeOffset & 0xFF);
  4668. } else {
  4669. data.push((relativeOffset >>> 24) & 0xFF,
  4670. (relativeOffset >> 16) & 0xFF,
  4671. (relativeOffset >> 8) & 0xFF,
  4672. relativeOffset & 0xFF);
  4673. }
  4674. if (objects[i]) {
  4675. relativeOffset += objects[i].length;
  4676. }
  4677. }
  4678. for (i = 0; i < count; i++) {
  4679. // Notify the tracker where the object will be offset in the data.
  4680. if (trackers[i]) {
  4681. trackers[i].offset(data.length);
  4682. }
  4683. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  4684. data.push(objects[i][j]);
  4685. }
  4686. }
  4687. return data;
  4688. }
  4689. };
  4690. return CFFCompiler;
  4691. })();
  4692. exports.CFFStandardStrings = CFFStandardStrings;
  4693. exports.CFFParser = CFFParser;
  4694. exports.CFF = CFF;
  4695. exports.CFFHeader = CFFHeader;
  4696. exports.CFFStrings = CFFStrings;
  4697. exports.CFFIndex = CFFIndex;
  4698. exports.CFFCharset = CFFCharset;
  4699. exports.CFFTopDict = CFFTopDict;
  4700. exports.CFFPrivateDict = CFFPrivateDict;
  4701. exports.CFFCompiler = CFFCompiler;
  4702. }));
  4703. (function (root, factory) {
  4704. {
  4705. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4706. }
  4707. }(this, function (exports, sharedUtil) {
  4708. var MissingDataException = sharedUtil.MissingDataException;
  4709. var arrayByteLength = sharedUtil.arrayByteLength;
  4710. var arraysToBytes = sharedUtil.arraysToBytes;
  4711. var assert = sharedUtil.assert;
  4712. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4713. var isInt = sharedUtil.isInt;
  4714. var isEmptyObj = sharedUtil.isEmptyObj;
  4715. var ChunkedStream = (function ChunkedStreamClosure() {
  4716. function ChunkedStream(length, chunkSize, manager) {
  4717. this.bytes = new Uint8Array(length);
  4718. this.start = 0;
  4719. this.pos = 0;
  4720. this.end = length;
  4721. this.chunkSize = chunkSize;
  4722. this.loadedChunks = [];
  4723. this.numChunksLoaded = 0;
  4724. this.numChunks = Math.ceil(length / chunkSize);
  4725. this.manager = manager;
  4726. this.progressiveDataLength = 0;
  4727. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4728. }
  4729. // required methods for a stream. if a particular stream does not
  4730. // implement these, an error should be thrown
  4731. ChunkedStream.prototype = {
  4732. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4733. var chunks = [];
  4734. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4735. if (!this.loadedChunks[chunk]) {
  4736. chunks.push(chunk);
  4737. }
  4738. }
  4739. return chunks;
  4740. },
  4741. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4742. return [this];
  4743. },
  4744. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4745. return this.numChunksLoaded === this.numChunks;
  4746. },
  4747. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4748. var end = begin + chunk.byteLength;
  4749. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4750. // Using this.length is inaccurate here since this.start can be moved
  4751. // See ChunkedStream.moveStart()
  4752. var length = this.bytes.length;
  4753. assert(end % this.chunkSize === 0 || end === length,
  4754. 'Bad end offset: ' + end);
  4755. this.bytes.set(new Uint8Array(chunk), begin);
  4756. var chunkSize = this.chunkSize;
  4757. var beginChunk = Math.floor(begin / chunkSize);
  4758. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4759. var curChunk;
  4760. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4761. if (!this.loadedChunks[curChunk]) {
  4762. this.loadedChunks[curChunk] = true;
  4763. ++this.numChunksLoaded;
  4764. }
  4765. }
  4766. },
  4767. onReceiveProgressiveData:
  4768. function ChunkedStream_onReceiveProgressiveData(data) {
  4769. var position = this.progressiveDataLength;
  4770. var beginChunk = Math.floor(position / this.chunkSize);
  4771. this.bytes.set(new Uint8Array(data), position);
  4772. position += data.byteLength;
  4773. this.progressiveDataLength = position;
  4774. var endChunk = position >= this.end ? this.numChunks :
  4775. Math.floor(position / this.chunkSize);
  4776. var curChunk;
  4777. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4778. if (!this.loadedChunks[curChunk]) {
  4779. this.loadedChunks[curChunk] = true;
  4780. ++this.numChunksLoaded;
  4781. }
  4782. }
  4783. },
  4784. ensureByte: function ChunkedStream_ensureByte(pos) {
  4785. var chunk = Math.floor(pos / this.chunkSize);
  4786. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4787. return;
  4788. }
  4789. if (!this.loadedChunks[chunk]) {
  4790. throw new MissingDataException(pos, pos + 1);
  4791. }
  4792. this.lastSuccessfulEnsureByteChunk = chunk;
  4793. },
  4794. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4795. if (begin >= end) {
  4796. return;
  4797. }
  4798. if (end <= this.progressiveDataLength) {
  4799. return;
  4800. }
  4801. var chunkSize = this.chunkSize;
  4802. var beginChunk = Math.floor(begin / chunkSize);
  4803. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4804. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4805. if (!this.loadedChunks[chunk]) {
  4806. throw new MissingDataException(begin, end);
  4807. }
  4808. }
  4809. },
  4810. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4811. var chunk, numChunks = this.numChunks;
  4812. for (var i = 0; i < numChunks; ++i) {
  4813. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4814. if (!this.loadedChunks[chunk]) {
  4815. return chunk;
  4816. }
  4817. }
  4818. return null;
  4819. },
  4820. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4821. return !!this.loadedChunks[chunk];
  4822. },
  4823. get length() {
  4824. return this.end - this.start;
  4825. },
  4826. get isEmpty() {
  4827. return this.length === 0;
  4828. },
  4829. getByte: function ChunkedStream_getByte() {
  4830. var pos = this.pos;
  4831. if (pos >= this.end) {
  4832. return -1;
  4833. }
  4834. this.ensureByte(pos);
  4835. return this.bytes[this.pos++];
  4836. },
  4837. getUint16: function ChunkedStream_getUint16() {
  4838. var b0 = this.getByte();
  4839. var b1 = this.getByte();
  4840. if (b0 === -1 || b1 === -1) {
  4841. return -1;
  4842. }
  4843. return (b0 << 8) + b1;
  4844. },
  4845. getInt32: function ChunkedStream_getInt32() {
  4846. var b0 = this.getByte();
  4847. var b1 = this.getByte();
  4848. var b2 = this.getByte();
  4849. var b3 = this.getByte();
  4850. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4851. },
  4852. // returns subarray of original buffer
  4853. // should only be read
  4854. getBytes: function ChunkedStream_getBytes(length) {
  4855. var bytes = this.bytes;
  4856. var pos = this.pos;
  4857. var strEnd = this.end;
  4858. if (!length) {
  4859. this.ensureRange(pos, strEnd);
  4860. return bytes.subarray(pos, strEnd);
  4861. }
  4862. var end = pos + length;
  4863. if (end > strEnd) {
  4864. end = strEnd;
  4865. }
  4866. this.ensureRange(pos, end);
  4867. this.pos = end;
  4868. return bytes.subarray(pos, end);
  4869. },
  4870. peekByte: function ChunkedStream_peekByte() {
  4871. var peekedByte = this.getByte();
  4872. this.pos--;
  4873. return peekedByte;
  4874. },
  4875. peekBytes: function ChunkedStream_peekBytes(length) {
  4876. var bytes = this.getBytes(length);
  4877. this.pos -= bytes.length;
  4878. return bytes;
  4879. },
  4880. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4881. this.ensureRange(begin, end);
  4882. return this.bytes.subarray(begin, end);
  4883. },
  4884. skip: function ChunkedStream_skip(n) {
  4885. if (!n) {
  4886. n = 1;
  4887. }
  4888. this.pos += n;
  4889. },
  4890. reset: function ChunkedStream_reset() {
  4891. this.pos = this.start;
  4892. },
  4893. moveStart: function ChunkedStream_moveStart() {
  4894. this.start = this.pos;
  4895. },
  4896. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4897. this.ensureRange(start, start + length);
  4898. function ChunkedStreamSubstream() {}
  4899. ChunkedStreamSubstream.prototype = Object.create(this);
  4900. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4901. var chunkSize = this.chunkSize;
  4902. var beginChunk = Math.floor(this.start / chunkSize);
  4903. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4904. var missingChunks = [];
  4905. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4906. if (!this.loadedChunks[chunk]) {
  4907. missingChunks.push(chunk);
  4908. }
  4909. }
  4910. return missingChunks;
  4911. };
  4912. var subStream = new ChunkedStreamSubstream();
  4913. subStream.pos = subStream.start = start;
  4914. subStream.end = start + length || this.end;
  4915. subStream.dict = dict;
  4916. return subStream;
  4917. },
  4918. isStream: true
  4919. };
  4920. return ChunkedStream;
  4921. })();
  4922. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4923. function ChunkedStreamManager(pdfNetworkStream, args) {
  4924. var chunkSize = args.rangeChunkSize;
  4925. var length = args.length;
  4926. this.stream = new ChunkedStream(length, chunkSize, this);
  4927. this.length = length;
  4928. this.chunkSize = chunkSize;
  4929. this.pdfNetworkStream = pdfNetworkStream;
  4930. this.url = args.url;
  4931. this.disableAutoFetch = args.disableAutoFetch;
  4932. this.msgHandler = args.msgHandler;
  4933. this.currRequestId = 0;
  4934. this.chunksNeededByRequest = Object.create(null);
  4935. this.requestsByChunk = Object.create(null);
  4936. this.promisesByRequest = Object.create(null);
  4937. this.progressiveDataLength = 0;
  4938. this.aborted = false;
  4939. this._loadedStreamCapability = createPromiseCapability();
  4940. }
  4941. ChunkedStreamManager.prototype = {
  4942. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4943. return this._loadedStreamCapability.promise;
  4944. },
  4945. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  4946. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  4947. if (!rangeReader.isStreamingSupported) {
  4948. rangeReader.onProgress = this.onProgress.bind(this);
  4949. }
  4950. var chunks = [], loaded = 0;
  4951. var manager = this;
  4952. var promise = new Promise(function (resolve, reject) {
  4953. var readChunk = function (chunk) {
  4954. try {
  4955. if (!chunk.done) {
  4956. var data = chunk.value;
  4957. chunks.push(data);
  4958. loaded += arrayByteLength(data);
  4959. if (rangeReader.isStreamingSupported) {
  4960. manager.onProgress({loaded: loaded});
  4961. }
  4962. rangeReader.read().then(readChunk, reject);
  4963. return;
  4964. }
  4965. var chunkData = arraysToBytes(chunks);
  4966. chunks = null;
  4967. resolve(chunkData);
  4968. } catch (e) {
  4969. reject(e);
  4970. }
  4971. };
  4972. rangeReader.read().then(readChunk, reject);
  4973. });
  4974. promise.then(function (data) {
  4975. if (this.aborted) {
  4976. return; // ignoring any data after abort
  4977. }
  4978. this.onReceiveData({chunk: data, begin: begin});
  4979. }.bind(this));
  4980. // TODO check errors
  4981. },
  4982. // Get all the chunks that are not yet loaded and groups them into
  4983. // contiguous ranges to load in as few requests as possible
  4984. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4985. var missingChunks = this.stream.getMissingChunks();
  4986. this._requestChunks(missingChunks);
  4987. return this._loadedStreamCapability.promise;
  4988. },
  4989. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4990. var requestId = this.currRequestId++;
  4991. var i, ii;
  4992. var chunksNeeded = Object.create(null);
  4993. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4994. for (i = 0, ii = chunks.length; i < ii; i++) {
  4995. if (!this.stream.hasChunk(chunks[i])) {
  4996. chunksNeeded[chunks[i]] = true;
  4997. }
  4998. }
  4999. if (isEmptyObj(chunksNeeded)) {
  5000. return Promise.resolve();
  5001. }
  5002. var capability = createPromiseCapability();
  5003. this.promisesByRequest[requestId] = capability;
  5004. var chunksToRequest = [];
  5005. for (var chunk in chunksNeeded) {
  5006. chunk = chunk | 0;
  5007. if (!(chunk in this.requestsByChunk)) {
  5008. this.requestsByChunk[chunk] = [];
  5009. chunksToRequest.push(chunk);
  5010. }
  5011. this.requestsByChunk[chunk].push(requestId);
  5012. }
  5013. if (!chunksToRequest.length) {
  5014. return capability.promise;
  5015. }
  5016. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  5017. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  5018. var groupedChunk = groupedChunksToRequest[i];
  5019. var begin = groupedChunk.beginChunk * this.chunkSize;
  5020. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  5021. this.sendRequest(begin, end);
  5022. }
  5023. return capability.promise;
  5024. },
  5025. getStream: function ChunkedStreamManager_getStream() {
  5026. return this.stream;
  5027. },
  5028. // Loads any chunks in the requested range that are not yet loaded
  5029. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  5030. end = Math.min(end, this.length);
  5031. var beginChunk = this.getBeginChunk(begin);
  5032. var endChunk = this.getEndChunk(end);
  5033. var chunks = [];
  5034. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5035. chunks.push(chunk);
  5036. }
  5037. return this._requestChunks(chunks);
  5038. },
  5039. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  5040. ranges = ranges || [];
  5041. var chunksToRequest = [];
  5042. for (var i = 0; i < ranges.length; i++) {
  5043. var beginChunk = this.getBeginChunk(ranges[i].begin);
  5044. var endChunk = this.getEndChunk(ranges[i].end);
  5045. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5046. if (chunksToRequest.indexOf(chunk) < 0) {
  5047. chunksToRequest.push(chunk);
  5048. }
  5049. }
  5050. }
  5051. chunksToRequest.sort(function(a, b) { return a - b; });
  5052. return this._requestChunks(chunksToRequest);
  5053. },
  5054. // Groups a sorted array of chunks into as few contiguous larger
  5055. // chunks as possible
  5056. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  5057. var groupedChunks = [];
  5058. var beginChunk = -1;
  5059. var prevChunk = -1;
  5060. for (var i = 0; i < chunks.length; ++i) {
  5061. var chunk = chunks[i];
  5062. if (beginChunk < 0) {
  5063. beginChunk = chunk;
  5064. }
  5065. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  5066. groupedChunks.push({ beginChunk: beginChunk,
  5067. endChunk: prevChunk + 1 });
  5068. beginChunk = chunk;
  5069. }
  5070. if (i + 1 === chunks.length) {
  5071. groupedChunks.push({ beginChunk: beginChunk,
  5072. endChunk: chunk + 1 });
  5073. }
  5074. prevChunk = chunk;
  5075. }
  5076. return groupedChunks;
  5077. },
  5078. onProgress: function ChunkedStreamManager_onProgress(args) {
  5079. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  5080. args.loaded);
  5081. this.msgHandler.send('DocProgress', {
  5082. loaded: bytesLoaded,
  5083. total: this.length
  5084. });
  5085. },
  5086. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  5087. var chunk = args.chunk;
  5088. var isProgressive = args.begin === undefined;
  5089. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  5090. var end = begin + chunk.byteLength;
  5091. var beginChunk = Math.floor(begin / this.chunkSize);
  5092. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  5093. Math.ceil(end / this.chunkSize);
  5094. if (isProgressive) {
  5095. this.stream.onReceiveProgressiveData(chunk);
  5096. this.progressiveDataLength = end;
  5097. } else {
  5098. this.stream.onReceiveData(begin, chunk);
  5099. }
  5100. if (this.stream.allChunksLoaded()) {
  5101. this._loadedStreamCapability.resolve(this.stream);
  5102. }
  5103. var loadedRequests = [];
  5104. var i, requestId;
  5105. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  5106. // The server might return more chunks than requested
  5107. var requestIds = this.requestsByChunk[chunk] || [];
  5108. delete this.requestsByChunk[chunk];
  5109. for (i = 0; i < requestIds.length; ++i) {
  5110. requestId = requestIds[i];
  5111. var chunksNeeded = this.chunksNeededByRequest[requestId];
  5112. if (chunk in chunksNeeded) {
  5113. delete chunksNeeded[chunk];
  5114. }
  5115. if (!isEmptyObj(chunksNeeded)) {
  5116. continue;
  5117. }
  5118. loadedRequests.push(requestId);
  5119. }
  5120. }
  5121. // If there are no pending requests, automatically fetch the next
  5122. // unfetched chunk of the PDF
  5123. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  5124. var nextEmptyChunk;
  5125. if (this.stream.numChunksLoaded === 1) {
  5126. // This is a special optimization so that after fetching the first
  5127. // chunk, rather than fetching the second chunk, we fetch the last
  5128. // chunk.
  5129. var lastChunk = this.stream.numChunks - 1;
  5130. if (!this.stream.hasChunk(lastChunk)) {
  5131. nextEmptyChunk = lastChunk;
  5132. }
  5133. } else {
  5134. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  5135. }
  5136. if (isInt(nextEmptyChunk)) {
  5137. this._requestChunks([nextEmptyChunk]);
  5138. }
  5139. }
  5140. for (i = 0; i < loadedRequests.length; ++i) {
  5141. requestId = loadedRequests[i];
  5142. var capability = this.promisesByRequest[requestId];
  5143. delete this.promisesByRequest[requestId];
  5144. capability.resolve();
  5145. }
  5146. this.msgHandler.send('DocProgress', {
  5147. loaded: this.stream.numChunksLoaded * this.chunkSize,
  5148. total: this.length
  5149. });
  5150. },
  5151. onError: function ChunkedStreamManager_onError(err) {
  5152. this._loadedStreamCapability.reject(err);
  5153. },
  5154. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  5155. var chunk = Math.floor(begin / this.chunkSize);
  5156. return chunk;
  5157. },
  5158. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  5159. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  5160. return chunk;
  5161. },
  5162. abort: function ChunkedStreamManager_abort() {
  5163. this.aborted = true;
  5164. if (this.pdfNetworkStream) {
  5165. this.pdfNetworkStream.cancelAllRequests('abort');
  5166. }
  5167. for(var requestId in this.promisesByRequest) {
  5168. var capability = this.promisesByRequest[requestId];
  5169. capability.reject(new Error('Request was aborted'));
  5170. }
  5171. }
  5172. };
  5173. return ChunkedStreamManager;
  5174. })();
  5175. exports.ChunkedStream = ChunkedStream;
  5176. exports.ChunkedStreamManager = ChunkedStreamManager;
  5177. }));
  5178. (function (root, factory) {
  5179. {
  5180. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  5181. }
  5182. }(this, function (exports, sharedUtil) {
  5183. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  5184. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  5185. t['A'] = 0x0041;
  5186. t['AE'] = 0x00C6;
  5187. t['AEacute'] = 0x01FC;
  5188. t['AEmacron'] = 0x01E2;
  5189. t['AEsmall'] = 0xF7E6;
  5190. t['Aacute'] = 0x00C1;
  5191. t['Aacutesmall'] = 0xF7E1;
  5192. t['Abreve'] = 0x0102;
  5193. t['Abreveacute'] = 0x1EAE;
  5194. t['Abrevecyrillic'] = 0x04D0;
  5195. t['Abrevedotbelow'] = 0x1EB6;
  5196. t['Abrevegrave'] = 0x1EB0;
  5197. t['Abrevehookabove'] = 0x1EB2;
  5198. t['Abrevetilde'] = 0x1EB4;
  5199. t['Acaron'] = 0x01CD;
  5200. t['Acircle'] = 0x24B6;
  5201. t['Acircumflex'] = 0x00C2;
  5202. t['Acircumflexacute'] = 0x1EA4;
  5203. t['Acircumflexdotbelow'] = 0x1EAC;
  5204. t['Acircumflexgrave'] = 0x1EA6;
  5205. t['Acircumflexhookabove'] = 0x1EA8;
  5206. t['Acircumflexsmall'] = 0xF7E2;
  5207. t['Acircumflextilde'] = 0x1EAA;
  5208. t['Acute'] = 0xF6C9;
  5209. t['Acutesmall'] = 0xF7B4;
  5210. t['Acyrillic'] = 0x0410;
  5211. t['Adblgrave'] = 0x0200;
  5212. t['Adieresis'] = 0x00C4;
  5213. t['Adieresiscyrillic'] = 0x04D2;
  5214. t['Adieresismacron'] = 0x01DE;
  5215. t['Adieresissmall'] = 0xF7E4;
  5216. t['Adotbelow'] = 0x1EA0;
  5217. t['Adotmacron'] = 0x01E0;
  5218. t['Agrave'] = 0x00C0;
  5219. t['Agravesmall'] = 0xF7E0;
  5220. t['Ahookabove'] = 0x1EA2;
  5221. t['Aiecyrillic'] = 0x04D4;
  5222. t['Ainvertedbreve'] = 0x0202;
  5223. t['Alpha'] = 0x0391;
  5224. t['Alphatonos'] = 0x0386;
  5225. t['Amacron'] = 0x0100;
  5226. t['Amonospace'] = 0xFF21;
  5227. t['Aogonek'] = 0x0104;
  5228. t['Aring'] = 0x00C5;
  5229. t['Aringacute'] = 0x01FA;
  5230. t['Aringbelow'] = 0x1E00;
  5231. t['Aringsmall'] = 0xF7E5;
  5232. t['Asmall'] = 0xF761;
  5233. t['Atilde'] = 0x00C3;
  5234. t['Atildesmall'] = 0xF7E3;
  5235. t['Aybarmenian'] = 0x0531;
  5236. t['B'] = 0x0042;
  5237. t['Bcircle'] = 0x24B7;
  5238. t['Bdotaccent'] = 0x1E02;
  5239. t['Bdotbelow'] = 0x1E04;
  5240. t['Becyrillic'] = 0x0411;
  5241. t['Benarmenian'] = 0x0532;
  5242. t['Beta'] = 0x0392;
  5243. t['Bhook'] = 0x0181;
  5244. t['Blinebelow'] = 0x1E06;
  5245. t['Bmonospace'] = 0xFF22;
  5246. t['Brevesmall'] = 0xF6F4;
  5247. t['Bsmall'] = 0xF762;
  5248. t['Btopbar'] = 0x0182;
  5249. t['C'] = 0x0043;
  5250. t['Caarmenian'] = 0x053E;
  5251. t['Cacute'] = 0x0106;
  5252. t['Caron'] = 0xF6CA;
  5253. t['Caronsmall'] = 0xF6F5;
  5254. t['Ccaron'] = 0x010C;
  5255. t['Ccedilla'] = 0x00C7;
  5256. t['Ccedillaacute'] = 0x1E08;
  5257. t['Ccedillasmall'] = 0xF7E7;
  5258. t['Ccircle'] = 0x24B8;
  5259. t['Ccircumflex'] = 0x0108;
  5260. t['Cdot'] = 0x010A;
  5261. t['Cdotaccent'] = 0x010A;
  5262. t['Cedillasmall'] = 0xF7B8;
  5263. t['Chaarmenian'] = 0x0549;
  5264. t['Cheabkhasiancyrillic'] = 0x04BC;
  5265. t['Checyrillic'] = 0x0427;
  5266. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  5267. t['Chedescendercyrillic'] = 0x04B6;
  5268. t['Chedieresiscyrillic'] = 0x04F4;
  5269. t['Cheharmenian'] = 0x0543;
  5270. t['Chekhakassiancyrillic'] = 0x04CB;
  5271. t['Cheverticalstrokecyrillic'] = 0x04B8;
  5272. t['Chi'] = 0x03A7;
  5273. t['Chook'] = 0x0187;
  5274. t['Circumflexsmall'] = 0xF6F6;
  5275. t['Cmonospace'] = 0xFF23;
  5276. t['Coarmenian'] = 0x0551;
  5277. t['Csmall'] = 0xF763;
  5278. t['D'] = 0x0044;
  5279. t['DZ'] = 0x01F1;
  5280. t['DZcaron'] = 0x01C4;
  5281. t['Daarmenian'] = 0x0534;
  5282. t['Dafrican'] = 0x0189;
  5283. t['Dcaron'] = 0x010E;
  5284. t['Dcedilla'] = 0x1E10;
  5285. t['Dcircle'] = 0x24B9;
  5286. t['Dcircumflexbelow'] = 0x1E12;
  5287. t['Dcroat'] = 0x0110;
  5288. t['Ddotaccent'] = 0x1E0A;
  5289. t['Ddotbelow'] = 0x1E0C;
  5290. t['Decyrillic'] = 0x0414;
  5291. t['Deicoptic'] = 0x03EE;
  5292. t['Delta'] = 0x2206;
  5293. t['Deltagreek'] = 0x0394;
  5294. t['Dhook'] = 0x018A;
  5295. t['Dieresis'] = 0xF6CB;
  5296. t['DieresisAcute'] = 0xF6CC;
  5297. t['DieresisGrave'] = 0xF6CD;
  5298. t['Dieresissmall'] = 0xF7A8;
  5299. t['Digammagreek'] = 0x03DC;
  5300. t['Djecyrillic'] = 0x0402;
  5301. t['Dlinebelow'] = 0x1E0E;
  5302. t['Dmonospace'] = 0xFF24;
  5303. t['Dotaccentsmall'] = 0xF6F7;
  5304. t['Dslash'] = 0x0110;
  5305. t['Dsmall'] = 0xF764;
  5306. t['Dtopbar'] = 0x018B;
  5307. t['Dz'] = 0x01F2;
  5308. t['Dzcaron'] = 0x01C5;
  5309. t['Dzeabkhasiancyrillic'] = 0x04E0;
  5310. t['Dzecyrillic'] = 0x0405;
  5311. t['Dzhecyrillic'] = 0x040F;
  5312. t['E'] = 0x0045;
  5313. t['Eacute'] = 0x00C9;
  5314. t['Eacutesmall'] = 0xF7E9;
  5315. t['Ebreve'] = 0x0114;
  5316. t['Ecaron'] = 0x011A;
  5317. t['Ecedillabreve'] = 0x1E1C;
  5318. t['Echarmenian'] = 0x0535;
  5319. t['Ecircle'] = 0x24BA;
  5320. t['Ecircumflex'] = 0x00CA;
  5321. t['Ecircumflexacute'] = 0x1EBE;
  5322. t['Ecircumflexbelow'] = 0x1E18;
  5323. t['Ecircumflexdotbelow'] = 0x1EC6;
  5324. t['Ecircumflexgrave'] = 0x1EC0;
  5325. t['Ecircumflexhookabove'] = 0x1EC2;
  5326. t['Ecircumflexsmall'] = 0xF7EA;
  5327. t['Ecircumflextilde'] = 0x1EC4;
  5328. t['Ecyrillic'] = 0x0404;
  5329. t['Edblgrave'] = 0x0204;
  5330. t['Edieresis'] = 0x00CB;
  5331. t['Edieresissmall'] = 0xF7EB;
  5332. t['Edot'] = 0x0116;
  5333. t['Edotaccent'] = 0x0116;
  5334. t['Edotbelow'] = 0x1EB8;
  5335. t['Efcyrillic'] = 0x0424;
  5336. t['Egrave'] = 0x00C8;
  5337. t['Egravesmall'] = 0xF7E8;
  5338. t['Eharmenian'] = 0x0537;
  5339. t['Ehookabove'] = 0x1EBA;
  5340. t['Eightroman'] = 0x2167;
  5341. t['Einvertedbreve'] = 0x0206;
  5342. t['Eiotifiedcyrillic'] = 0x0464;
  5343. t['Elcyrillic'] = 0x041B;
  5344. t['Elevenroman'] = 0x216A;
  5345. t['Emacron'] = 0x0112;
  5346. t['Emacronacute'] = 0x1E16;
  5347. t['Emacrongrave'] = 0x1E14;
  5348. t['Emcyrillic'] = 0x041C;
  5349. t['Emonospace'] = 0xFF25;
  5350. t['Encyrillic'] = 0x041D;
  5351. t['Endescendercyrillic'] = 0x04A2;
  5352. t['Eng'] = 0x014A;
  5353. t['Enghecyrillic'] = 0x04A4;
  5354. t['Enhookcyrillic'] = 0x04C7;
  5355. t['Eogonek'] = 0x0118;
  5356. t['Eopen'] = 0x0190;
  5357. t['Epsilon'] = 0x0395;
  5358. t['Epsilontonos'] = 0x0388;
  5359. t['Ercyrillic'] = 0x0420;
  5360. t['Ereversed'] = 0x018E;
  5361. t['Ereversedcyrillic'] = 0x042D;
  5362. t['Escyrillic'] = 0x0421;
  5363. t['Esdescendercyrillic'] = 0x04AA;
  5364. t['Esh'] = 0x01A9;
  5365. t['Esmall'] = 0xF765;
  5366. t['Eta'] = 0x0397;
  5367. t['Etarmenian'] = 0x0538;
  5368. t['Etatonos'] = 0x0389;
  5369. t['Eth'] = 0x00D0;
  5370. t['Ethsmall'] = 0xF7F0;
  5371. t['Etilde'] = 0x1EBC;
  5372. t['Etildebelow'] = 0x1E1A;
  5373. t['Euro'] = 0x20AC;
  5374. t['Ezh'] = 0x01B7;
  5375. t['Ezhcaron'] = 0x01EE;
  5376. t['Ezhreversed'] = 0x01B8;
  5377. t['F'] = 0x0046;
  5378. t['Fcircle'] = 0x24BB;
  5379. t['Fdotaccent'] = 0x1E1E;
  5380. t['Feharmenian'] = 0x0556;
  5381. t['Feicoptic'] = 0x03E4;
  5382. t['Fhook'] = 0x0191;
  5383. t['Fitacyrillic'] = 0x0472;
  5384. t['Fiveroman'] = 0x2164;
  5385. t['Fmonospace'] = 0xFF26;
  5386. t['Fourroman'] = 0x2163;
  5387. t['Fsmall'] = 0xF766;
  5388. t['G'] = 0x0047;
  5389. t['GBsquare'] = 0x3387;
  5390. t['Gacute'] = 0x01F4;
  5391. t['Gamma'] = 0x0393;
  5392. t['Gammaafrican'] = 0x0194;
  5393. t['Gangiacoptic'] = 0x03EA;
  5394. t['Gbreve'] = 0x011E;
  5395. t['Gcaron'] = 0x01E6;
  5396. t['Gcedilla'] = 0x0122;
  5397. t['Gcircle'] = 0x24BC;
  5398. t['Gcircumflex'] = 0x011C;
  5399. t['Gcommaaccent'] = 0x0122;
  5400. t['Gdot'] = 0x0120;
  5401. t['Gdotaccent'] = 0x0120;
  5402. t['Gecyrillic'] = 0x0413;
  5403. t['Ghadarmenian'] = 0x0542;
  5404. t['Ghemiddlehookcyrillic'] = 0x0494;
  5405. t['Ghestrokecyrillic'] = 0x0492;
  5406. t['Gheupturncyrillic'] = 0x0490;
  5407. t['Ghook'] = 0x0193;
  5408. t['Gimarmenian'] = 0x0533;
  5409. t['Gjecyrillic'] = 0x0403;
  5410. t['Gmacron'] = 0x1E20;
  5411. t['Gmonospace'] = 0xFF27;
  5412. t['Grave'] = 0xF6CE;
  5413. t['Gravesmall'] = 0xF760;
  5414. t['Gsmall'] = 0xF767;
  5415. t['Gsmallhook'] = 0x029B;
  5416. t['Gstroke'] = 0x01E4;
  5417. t['H'] = 0x0048;
  5418. t['H18533'] = 0x25CF;
  5419. t['H18543'] = 0x25AA;
  5420. t['H18551'] = 0x25AB;
  5421. t['H22073'] = 0x25A1;
  5422. t['HPsquare'] = 0x33CB;
  5423. t['Haabkhasiancyrillic'] = 0x04A8;
  5424. t['Hadescendercyrillic'] = 0x04B2;
  5425. t['Hardsigncyrillic'] = 0x042A;
  5426. t['Hbar'] = 0x0126;
  5427. t['Hbrevebelow'] = 0x1E2A;
  5428. t['Hcedilla'] = 0x1E28;
  5429. t['Hcircle'] = 0x24BD;
  5430. t['Hcircumflex'] = 0x0124;
  5431. t['Hdieresis'] = 0x1E26;
  5432. t['Hdotaccent'] = 0x1E22;
  5433. t['Hdotbelow'] = 0x1E24;
  5434. t['Hmonospace'] = 0xFF28;
  5435. t['Hoarmenian'] = 0x0540;
  5436. t['Horicoptic'] = 0x03E8;
  5437. t['Hsmall'] = 0xF768;
  5438. t['Hungarumlaut'] = 0xF6CF;
  5439. t['Hungarumlautsmall'] = 0xF6F8;
  5440. t['Hzsquare'] = 0x3390;
  5441. t['I'] = 0x0049;
  5442. t['IAcyrillic'] = 0x042F;
  5443. t['IJ'] = 0x0132;
  5444. t['IUcyrillic'] = 0x042E;
  5445. t['Iacute'] = 0x00CD;
  5446. t['Iacutesmall'] = 0xF7ED;
  5447. t['Ibreve'] = 0x012C;
  5448. t['Icaron'] = 0x01CF;
  5449. t['Icircle'] = 0x24BE;
  5450. t['Icircumflex'] = 0x00CE;
  5451. t['Icircumflexsmall'] = 0xF7EE;
  5452. t['Icyrillic'] = 0x0406;
  5453. t['Idblgrave'] = 0x0208;
  5454. t['Idieresis'] = 0x00CF;
  5455. t['Idieresisacute'] = 0x1E2E;
  5456. t['Idieresiscyrillic'] = 0x04E4;
  5457. t['Idieresissmall'] = 0xF7EF;
  5458. t['Idot'] = 0x0130;
  5459. t['Idotaccent'] = 0x0130;
  5460. t['Idotbelow'] = 0x1ECA;
  5461. t['Iebrevecyrillic'] = 0x04D6;
  5462. t['Iecyrillic'] = 0x0415;
  5463. t['Ifraktur'] = 0x2111;
  5464. t['Igrave'] = 0x00CC;
  5465. t['Igravesmall'] = 0xF7EC;
  5466. t['Ihookabove'] = 0x1EC8;
  5467. t['Iicyrillic'] = 0x0418;
  5468. t['Iinvertedbreve'] = 0x020A;
  5469. t['Iishortcyrillic'] = 0x0419;
  5470. t['Imacron'] = 0x012A;
  5471. t['Imacroncyrillic'] = 0x04E2;
  5472. t['Imonospace'] = 0xFF29;
  5473. t['Iniarmenian'] = 0x053B;
  5474. t['Iocyrillic'] = 0x0401;
  5475. t['Iogonek'] = 0x012E;
  5476. t['Iota'] = 0x0399;
  5477. t['Iotaafrican'] = 0x0196;
  5478. t['Iotadieresis'] = 0x03AA;
  5479. t['Iotatonos'] = 0x038A;
  5480. t['Ismall'] = 0xF769;
  5481. t['Istroke'] = 0x0197;
  5482. t['Itilde'] = 0x0128;
  5483. t['Itildebelow'] = 0x1E2C;
  5484. t['Izhitsacyrillic'] = 0x0474;
  5485. t['Izhitsadblgravecyrillic'] = 0x0476;
  5486. t['J'] = 0x004A;
  5487. t['Jaarmenian'] = 0x0541;
  5488. t['Jcircle'] = 0x24BF;
  5489. t['Jcircumflex'] = 0x0134;
  5490. t['Jecyrillic'] = 0x0408;
  5491. t['Jheharmenian'] = 0x054B;
  5492. t['Jmonospace'] = 0xFF2A;
  5493. t['Jsmall'] = 0xF76A;
  5494. t['K'] = 0x004B;
  5495. t['KBsquare'] = 0x3385;
  5496. t['KKsquare'] = 0x33CD;
  5497. t['Kabashkircyrillic'] = 0x04A0;
  5498. t['Kacute'] = 0x1E30;
  5499. t['Kacyrillic'] = 0x041A;
  5500. t['Kadescendercyrillic'] = 0x049A;
  5501. t['Kahookcyrillic'] = 0x04C3;
  5502. t['Kappa'] = 0x039A;
  5503. t['Kastrokecyrillic'] = 0x049E;
  5504. t['Kaverticalstrokecyrillic'] = 0x049C;
  5505. t['Kcaron'] = 0x01E8;
  5506. t['Kcedilla'] = 0x0136;
  5507. t['Kcircle'] = 0x24C0;
  5508. t['Kcommaaccent'] = 0x0136;
  5509. t['Kdotbelow'] = 0x1E32;
  5510. t['Keharmenian'] = 0x0554;
  5511. t['Kenarmenian'] = 0x053F;
  5512. t['Khacyrillic'] = 0x0425;
  5513. t['Kheicoptic'] = 0x03E6;
  5514. t['Khook'] = 0x0198;
  5515. t['Kjecyrillic'] = 0x040C;
  5516. t['Klinebelow'] = 0x1E34;
  5517. t['Kmonospace'] = 0xFF2B;
  5518. t['Koppacyrillic'] = 0x0480;
  5519. t['Koppagreek'] = 0x03DE;
  5520. t['Ksicyrillic'] = 0x046E;
  5521. t['Ksmall'] = 0xF76B;
  5522. t['L'] = 0x004C;
  5523. t['LJ'] = 0x01C7;
  5524. t['LL'] = 0xF6BF;
  5525. t['Lacute'] = 0x0139;
  5526. t['Lambda'] = 0x039B;
  5527. t['Lcaron'] = 0x013D;
  5528. t['Lcedilla'] = 0x013B;
  5529. t['Lcircle'] = 0x24C1;
  5530. t['Lcircumflexbelow'] = 0x1E3C;
  5531. t['Lcommaaccent'] = 0x013B;
  5532. t['Ldot'] = 0x013F;
  5533. t['Ldotaccent'] = 0x013F;
  5534. t['Ldotbelow'] = 0x1E36;
  5535. t['Ldotbelowmacron'] = 0x1E38;
  5536. t['Liwnarmenian'] = 0x053C;
  5537. t['Lj'] = 0x01C8;
  5538. t['Ljecyrillic'] = 0x0409;
  5539. t['Llinebelow'] = 0x1E3A;
  5540. t['Lmonospace'] = 0xFF2C;
  5541. t['Lslash'] = 0x0141;
  5542. t['Lslashsmall'] = 0xF6F9;
  5543. t['Lsmall'] = 0xF76C;
  5544. t['M'] = 0x004D;
  5545. t['MBsquare'] = 0x3386;
  5546. t['Macron'] = 0xF6D0;
  5547. t['Macronsmall'] = 0xF7AF;
  5548. t['Macute'] = 0x1E3E;
  5549. t['Mcircle'] = 0x24C2;
  5550. t['Mdotaccent'] = 0x1E40;
  5551. t['Mdotbelow'] = 0x1E42;
  5552. t['Menarmenian'] = 0x0544;
  5553. t['Mmonospace'] = 0xFF2D;
  5554. t['Msmall'] = 0xF76D;
  5555. t['Mturned'] = 0x019C;
  5556. t['Mu'] = 0x039C;
  5557. t['N'] = 0x004E;
  5558. t['NJ'] = 0x01CA;
  5559. t['Nacute'] = 0x0143;
  5560. t['Ncaron'] = 0x0147;
  5561. t['Ncedilla'] = 0x0145;
  5562. t['Ncircle'] = 0x24C3;
  5563. t['Ncircumflexbelow'] = 0x1E4A;
  5564. t['Ncommaaccent'] = 0x0145;
  5565. t['Ndotaccent'] = 0x1E44;
  5566. t['Ndotbelow'] = 0x1E46;
  5567. t['Nhookleft'] = 0x019D;
  5568. t['Nineroman'] = 0x2168;
  5569. t['Nj'] = 0x01CB;
  5570. t['Njecyrillic'] = 0x040A;
  5571. t['Nlinebelow'] = 0x1E48;
  5572. t['Nmonospace'] = 0xFF2E;
  5573. t['Nowarmenian'] = 0x0546;
  5574. t['Nsmall'] = 0xF76E;
  5575. t['Ntilde'] = 0x00D1;
  5576. t['Ntildesmall'] = 0xF7F1;
  5577. t['Nu'] = 0x039D;
  5578. t['O'] = 0x004F;
  5579. t['OE'] = 0x0152;
  5580. t['OEsmall'] = 0xF6FA;
  5581. t['Oacute'] = 0x00D3;
  5582. t['Oacutesmall'] = 0xF7F3;
  5583. t['Obarredcyrillic'] = 0x04E8;
  5584. t['Obarreddieresiscyrillic'] = 0x04EA;
  5585. t['Obreve'] = 0x014E;
  5586. t['Ocaron'] = 0x01D1;
  5587. t['Ocenteredtilde'] = 0x019F;
  5588. t['Ocircle'] = 0x24C4;
  5589. t['Ocircumflex'] = 0x00D4;
  5590. t['Ocircumflexacute'] = 0x1ED0;
  5591. t['Ocircumflexdotbelow'] = 0x1ED8;
  5592. t['Ocircumflexgrave'] = 0x1ED2;
  5593. t['Ocircumflexhookabove'] = 0x1ED4;
  5594. t['Ocircumflexsmall'] = 0xF7F4;
  5595. t['Ocircumflextilde'] = 0x1ED6;
  5596. t['Ocyrillic'] = 0x041E;
  5597. t['Odblacute'] = 0x0150;
  5598. t['Odblgrave'] = 0x020C;
  5599. t['Odieresis'] = 0x00D6;
  5600. t['Odieresiscyrillic'] = 0x04E6;
  5601. t['Odieresissmall'] = 0xF7F6;
  5602. t['Odotbelow'] = 0x1ECC;
  5603. t['Ogoneksmall'] = 0xF6FB;
  5604. t['Ograve'] = 0x00D2;
  5605. t['Ogravesmall'] = 0xF7F2;
  5606. t['Oharmenian'] = 0x0555;
  5607. t['Ohm'] = 0x2126;
  5608. t['Ohookabove'] = 0x1ECE;
  5609. t['Ohorn'] = 0x01A0;
  5610. t['Ohornacute'] = 0x1EDA;
  5611. t['Ohorndotbelow'] = 0x1EE2;
  5612. t['Ohorngrave'] = 0x1EDC;
  5613. t['Ohornhookabove'] = 0x1EDE;
  5614. t['Ohorntilde'] = 0x1EE0;
  5615. t['Ohungarumlaut'] = 0x0150;
  5616. t['Oi'] = 0x01A2;
  5617. t['Oinvertedbreve'] = 0x020E;
  5618. t['Omacron'] = 0x014C;
  5619. t['Omacronacute'] = 0x1E52;
  5620. t['Omacrongrave'] = 0x1E50;
  5621. t['Omega'] = 0x2126;
  5622. t['Omegacyrillic'] = 0x0460;
  5623. t['Omegagreek'] = 0x03A9;
  5624. t['Omegaroundcyrillic'] = 0x047A;
  5625. t['Omegatitlocyrillic'] = 0x047C;
  5626. t['Omegatonos'] = 0x038F;
  5627. t['Omicron'] = 0x039F;
  5628. t['Omicrontonos'] = 0x038C;
  5629. t['Omonospace'] = 0xFF2F;
  5630. t['Oneroman'] = 0x2160;
  5631. t['Oogonek'] = 0x01EA;
  5632. t['Oogonekmacron'] = 0x01EC;
  5633. t['Oopen'] = 0x0186;
  5634. t['Oslash'] = 0x00D8;
  5635. t['Oslashacute'] = 0x01FE;
  5636. t['Oslashsmall'] = 0xF7F8;
  5637. t['Osmall'] = 0xF76F;
  5638. t['Ostrokeacute'] = 0x01FE;
  5639. t['Otcyrillic'] = 0x047E;
  5640. t['Otilde'] = 0x00D5;
  5641. t['Otildeacute'] = 0x1E4C;
  5642. t['Otildedieresis'] = 0x1E4E;
  5643. t['Otildesmall'] = 0xF7F5;
  5644. t['P'] = 0x0050;
  5645. t['Pacute'] = 0x1E54;
  5646. t['Pcircle'] = 0x24C5;
  5647. t['Pdotaccent'] = 0x1E56;
  5648. t['Pecyrillic'] = 0x041F;
  5649. t['Peharmenian'] = 0x054A;
  5650. t['Pemiddlehookcyrillic'] = 0x04A6;
  5651. t['Phi'] = 0x03A6;
  5652. t['Phook'] = 0x01A4;
  5653. t['Pi'] = 0x03A0;
  5654. t['Piwrarmenian'] = 0x0553;
  5655. t['Pmonospace'] = 0xFF30;
  5656. t['Psi'] = 0x03A8;
  5657. t['Psicyrillic'] = 0x0470;
  5658. t['Psmall'] = 0xF770;
  5659. t['Q'] = 0x0051;
  5660. t['Qcircle'] = 0x24C6;
  5661. t['Qmonospace'] = 0xFF31;
  5662. t['Qsmall'] = 0xF771;
  5663. t['R'] = 0x0052;
  5664. t['Raarmenian'] = 0x054C;
  5665. t['Racute'] = 0x0154;
  5666. t['Rcaron'] = 0x0158;
  5667. t['Rcedilla'] = 0x0156;
  5668. t['Rcircle'] = 0x24C7;
  5669. t['Rcommaaccent'] = 0x0156;
  5670. t['Rdblgrave'] = 0x0210;
  5671. t['Rdotaccent'] = 0x1E58;
  5672. t['Rdotbelow'] = 0x1E5A;
  5673. t['Rdotbelowmacron'] = 0x1E5C;
  5674. t['Reharmenian'] = 0x0550;
  5675. t['Rfraktur'] = 0x211C;
  5676. t['Rho'] = 0x03A1;
  5677. t['Ringsmall'] = 0xF6FC;
  5678. t['Rinvertedbreve'] = 0x0212;
  5679. t['Rlinebelow'] = 0x1E5E;
  5680. t['Rmonospace'] = 0xFF32;
  5681. t['Rsmall'] = 0xF772;
  5682. t['Rsmallinverted'] = 0x0281;
  5683. t['Rsmallinvertedsuperior'] = 0x02B6;
  5684. t['S'] = 0x0053;
  5685. t['SF010000'] = 0x250C;
  5686. t['SF020000'] = 0x2514;
  5687. t['SF030000'] = 0x2510;
  5688. t['SF040000'] = 0x2518;
  5689. t['SF050000'] = 0x253C;
  5690. t['SF060000'] = 0x252C;
  5691. t['SF070000'] = 0x2534;
  5692. t['SF080000'] = 0x251C;
  5693. t['SF090000'] = 0x2524;
  5694. t['SF100000'] = 0x2500;
  5695. t['SF110000'] = 0x2502;
  5696. t['SF190000'] = 0x2561;
  5697. t['SF200000'] = 0x2562;
  5698. t['SF210000'] = 0x2556;
  5699. t['SF220000'] = 0x2555;
  5700. t['SF230000'] = 0x2563;
  5701. t['SF240000'] = 0x2551;
  5702. t['SF250000'] = 0x2557;
  5703. t['SF260000'] = 0x255D;
  5704. t['SF270000'] = 0x255C;
  5705. t['SF280000'] = 0x255B;
  5706. t['SF360000'] = 0x255E;
  5707. t['SF370000'] = 0x255F;
  5708. t['SF380000'] = 0x255A;
  5709. t['SF390000'] = 0x2554;
  5710. t['SF400000'] = 0x2569;
  5711. t['SF410000'] = 0x2566;
  5712. t['SF420000'] = 0x2560;
  5713. t['SF430000'] = 0x2550;
  5714. t['SF440000'] = 0x256C;
  5715. t['SF450000'] = 0x2567;
  5716. t['SF460000'] = 0x2568;
  5717. t['SF470000'] = 0x2564;
  5718. t['SF480000'] = 0x2565;
  5719. t['SF490000'] = 0x2559;
  5720. t['SF500000'] = 0x2558;
  5721. t['SF510000'] = 0x2552;
  5722. t['SF520000'] = 0x2553;
  5723. t['SF530000'] = 0x256B;
  5724. t['SF540000'] = 0x256A;
  5725. t['Sacute'] = 0x015A;
  5726. t['Sacutedotaccent'] = 0x1E64;
  5727. t['Sampigreek'] = 0x03E0;
  5728. t['Scaron'] = 0x0160;
  5729. t['Scarondotaccent'] = 0x1E66;
  5730. t['Scaronsmall'] = 0xF6FD;
  5731. t['Scedilla'] = 0x015E;
  5732. t['Schwa'] = 0x018F;
  5733. t['Schwacyrillic'] = 0x04D8;
  5734. t['Schwadieresiscyrillic'] = 0x04DA;
  5735. t['Scircle'] = 0x24C8;
  5736. t['Scircumflex'] = 0x015C;
  5737. t['Scommaaccent'] = 0x0218;
  5738. t['Sdotaccent'] = 0x1E60;
  5739. t['Sdotbelow'] = 0x1E62;
  5740. t['Sdotbelowdotaccent'] = 0x1E68;
  5741. t['Seharmenian'] = 0x054D;
  5742. t['Sevenroman'] = 0x2166;
  5743. t['Shaarmenian'] = 0x0547;
  5744. t['Shacyrillic'] = 0x0428;
  5745. t['Shchacyrillic'] = 0x0429;
  5746. t['Sheicoptic'] = 0x03E2;
  5747. t['Shhacyrillic'] = 0x04BA;
  5748. t['Shimacoptic'] = 0x03EC;
  5749. t['Sigma'] = 0x03A3;
  5750. t['Sixroman'] = 0x2165;
  5751. t['Smonospace'] = 0xFF33;
  5752. t['Softsigncyrillic'] = 0x042C;
  5753. t['Ssmall'] = 0xF773;
  5754. t['Stigmagreek'] = 0x03DA;
  5755. t['T'] = 0x0054;
  5756. t['Tau'] = 0x03A4;
  5757. t['Tbar'] = 0x0166;
  5758. t['Tcaron'] = 0x0164;
  5759. t['Tcedilla'] = 0x0162;
  5760. t['Tcircle'] = 0x24C9;
  5761. t['Tcircumflexbelow'] = 0x1E70;
  5762. t['Tcommaaccent'] = 0x0162;
  5763. t['Tdotaccent'] = 0x1E6A;
  5764. t['Tdotbelow'] = 0x1E6C;
  5765. t['Tecyrillic'] = 0x0422;
  5766. t['Tedescendercyrillic'] = 0x04AC;
  5767. t['Tenroman'] = 0x2169;
  5768. t['Tetsecyrillic'] = 0x04B4;
  5769. t['Theta'] = 0x0398;
  5770. t['Thook'] = 0x01AC;
  5771. t['Thorn'] = 0x00DE;
  5772. t['Thornsmall'] = 0xF7FE;
  5773. t['Threeroman'] = 0x2162;
  5774. t['Tildesmall'] = 0xF6FE;
  5775. t['Tiwnarmenian'] = 0x054F;
  5776. t['Tlinebelow'] = 0x1E6E;
  5777. t['Tmonospace'] = 0xFF34;
  5778. t['Toarmenian'] = 0x0539;
  5779. t['Tonefive'] = 0x01BC;
  5780. t['Tonesix'] = 0x0184;
  5781. t['Tonetwo'] = 0x01A7;
  5782. t['Tretroflexhook'] = 0x01AE;
  5783. t['Tsecyrillic'] = 0x0426;
  5784. t['Tshecyrillic'] = 0x040B;
  5785. t['Tsmall'] = 0xF774;
  5786. t['Twelveroman'] = 0x216B;
  5787. t['Tworoman'] = 0x2161;
  5788. t['U'] = 0x0055;
  5789. t['Uacute'] = 0x00DA;
  5790. t['Uacutesmall'] = 0xF7FA;
  5791. t['Ubreve'] = 0x016C;
  5792. t['Ucaron'] = 0x01D3;
  5793. t['Ucircle'] = 0x24CA;
  5794. t['Ucircumflex'] = 0x00DB;
  5795. t['Ucircumflexbelow'] = 0x1E76;
  5796. t['Ucircumflexsmall'] = 0xF7FB;
  5797. t['Ucyrillic'] = 0x0423;
  5798. t['Udblacute'] = 0x0170;
  5799. t['Udblgrave'] = 0x0214;
  5800. t['Udieresis'] = 0x00DC;
  5801. t['Udieresisacute'] = 0x01D7;
  5802. t['Udieresisbelow'] = 0x1E72;
  5803. t['Udieresiscaron'] = 0x01D9;
  5804. t['Udieresiscyrillic'] = 0x04F0;
  5805. t['Udieresisgrave'] = 0x01DB;
  5806. t['Udieresismacron'] = 0x01D5;
  5807. t['Udieresissmall'] = 0xF7FC;
  5808. t['Udotbelow'] = 0x1EE4;
  5809. t['Ugrave'] = 0x00D9;
  5810. t['Ugravesmall'] = 0xF7F9;
  5811. t['Uhookabove'] = 0x1EE6;
  5812. t['Uhorn'] = 0x01AF;
  5813. t['Uhornacute'] = 0x1EE8;
  5814. t['Uhorndotbelow'] = 0x1EF0;
  5815. t['Uhorngrave'] = 0x1EEA;
  5816. t['Uhornhookabove'] = 0x1EEC;
  5817. t['Uhorntilde'] = 0x1EEE;
  5818. t['Uhungarumlaut'] = 0x0170;
  5819. t['Uhungarumlautcyrillic'] = 0x04F2;
  5820. t['Uinvertedbreve'] = 0x0216;
  5821. t['Ukcyrillic'] = 0x0478;
  5822. t['Umacron'] = 0x016A;
  5823. t['Umacroncyrillic'] = 0x04EE;
  5824. t['Umacrondieresis'] = 0x1E7A;
  5825. t['Umonospace'] = 0xFF35;
  5826. t['Uogonek'] = 0x0172;
  5827. t['Upsilon'] = 0x03A5;
  5828. t['Upsilon1'] = 0x03D2;
  5829. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5830. t['Upsilonafrican'] = 0x01B1;
  5831. t['Upsilondieresis'] = 0x03AB;
  5832. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5833. t['Upsilonhooksymbol'] = 0x03D2;
  5834. t['Upsilontonos'] = 0x038E;
  5835. t['Uring'] = 0x016E;
  5836. t['Ushortcyrillic'] = 0x040E;
  5837. t['Usmall'] = 0xF775;
  5838. t['Ustraightcyrillic'] = 0x04AE;
  5839. t['Ustraightstrokecyrillic'] = 0x04B0;
  5840. t['Utilde'] = 0x0168;
  5841. t['Utildeacute'] = 0x1E78;
  5842. t['Utildebelow'] = 0x1E74;
  5843. t['V'] = 0x0056;
  5844. t['Vcircle'] = 0x24CB;
  5845. t['Vdotbelow'] = 0x1E7E;
  5846. t['Vecyrillic'] = 0x0412;
  5847. t['Vewarmenian'] = 0x054E;
  5848. t['Vhook'] = 0x01B2;
  5849. t['Vmonospace'] = 0xFF36;
  5850. t['Voarmenian'] = 0x0548;
  5851. t['Vsmall'] = 0xF776;
  5852. t['Vtilde'] = 0x1E7C;
  5853. t['W'] = 0x0057;
  5854. t['Wacute'] = 0x1E82;
  5855. t['Wcircle'] = 0x24CC;
  5856. t['Wcircumflex'] = 0x0174;
  5857. t['Wdieresis'] = 0x1E84;
  5858. t['Wdotaccent'] = 0x1E86;
  5859. t['Wdotbelow'] = 0x1E88;
  5860. t['Wgrave'] = 0x1E80;
  5861. t['Wmonospace'] = 0xFF37;
  5862. t['Wsmall'] = 0xF777;
  5863. t['X'] = 0x0058;
  5864. t['Xcircle'] = 0x24CD;
  5865. t['Xdieresis'] = 0x1E8C;
  5866. t['Xdotaccent'] = 0x1E8A;
  5867. t['Xeharmenian'] = 0x053D;
  5868. t['Xi'] = 0x039E;
  5869. t['Xmonospace'] = 0xFF38;
  5870. t['Xsmall'] = 0xF778;
  5871. t['Y'] = 0x0059;
  5872. t['Yacute'] = 0x00DD;
  5873. t['Yacutesmall'] = 0xF7FD;
  5874. t['Yatcyrillic'] = 0x0462;
  5875. t['Ycircle'] = 0x24CE;
  5876. t['Ycircumflex'] = 0x0176;
  5877. t['Ydieresis'] = 0x0178;
  5878. t['Ydieresissmall'] = 0xF7FF;
  5879. t['Ydotaccent'] = 0x1E8E;
  5880. t['Ydotbelow'] = 0x1EF4;
  5881. t['Yericyrillic'] = 0x042B;
  5882. t['Yerudieresiscyrillic'] = 0x04F8;
  5883. t['Ygrave'] = 0x1EF2;
  5884. t['Yhook'] = 0x01B3;
  5885. t['Yhookabove'] = 0x1EF6;
  5886. t['Yiarmenian'] = 0x0545;
  5887. t['Yicyrillic'] = 0x0407;
  5888. t['Yiwnarmenian'] = 0x0552;
  5889. t['Ymonospace'] = 0xFF39;
  5890. t['Ysmall'] = 0xF779;
  5891. t['Ytilde'] = 0x1EF8;
  5892. t['Yusbigcyrillic'] = 0x046A;
  5893. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5894. t['Yuslittlecyrillic'] = 0x0466;
  5895. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5896. t['Z'] = 0x005A;
  5897. t['Zaarmenian'] = 0x0536;
  5898. t['Zacute'] = 0x0179;
  5899. t['Zcaron'] = 0x017D;
  5900. t['Zcaronsmall'] = 0xF6FF;
  5901. t['Zcircle'] = 0x24CF;
  5902. t['Zcircumflex'] = 0x1E90;
  5903. t['Zdot'] = 0x017B;
  5904. t['Zdotaccent'] = 0x017B;
  5905. t['Zdotbelow'] = 0x1E92;
  5906. t['Zecyrillic'] = 0x0417;
  5907. t['Zedescendercyrillic'] = 0x0498;
  5908. t['Zedieresiscyrillic'] = 0x04DE;
  5909. t['Zeta'] = 0x0396;
  5910. t['Zhearmenian'] = 0x053A;
  5911. t['Zhebrevecyrillic'] = 0x04C1;
  5912. t['Zhecyrillic'] = 0x0416;
  5913. t['Zhedescendercyrillic'] = 0x0496;
  5914. t['Zhedieresiscyrillic'] = 0x04DC;
  5915. t['Zlinebelow'] = 0x1E94;
  5916. t['Zmonospace'] = 0xFF3A;
  5917. t['Zsmall'] = 0xF77A;
  5918. t['Zstroke'] = 0x01B5;
  5919. t['a'] = 0x0061;
  5920. t['aabengali'] = 0x0986;
  5921. t['aacute'] = 0x00E1;
  5922. t['aadeva'] = 0x0906;
  5923. t['aagujarati'] = 0x0A86;
  5924. t['aagurmukhi'] = 0x0A06;
  5925. t['aamatragurmukhi'] = 0x0A3E;
  5926. t['aarusquare'] = 0x3303;
  5927. t['aavowelsignbengali'] = 0x09BE;
  5928. t['aavowelsigndeva'] = 0x093E;
  5929. t['aavowelsigngujarati'] = 0x0ABE;
  5930. t['abbreviationmarkarmenian'] = 0x055F;
  5931. t['abbreviationsigndeva'] = 0x0970;
  5932. t['abengali'] = 0x0985;
  5933. t['abopomofo'] = 0x311A;
  5934. t['abreve'] = 0x0103;
  5935. t['abreveacute'] = 0x1EAF;
  5936. t['abrevecyrillic'] = 0x04D1;
  5937. t['abrevedotbelow'] = 0x1EB7;
  5938. t['abrevegrave'] = 0x1EB1;
  5939. t['abrevehookabove'] = 0x1EB3;
  5940. t['abrevetilde'] = 0x1EB5;
  5941. t['acaron'] = 0x01CE;
  5942. t['acircle'] = 0x24D0;
  5943. t['acircumflex'] = 0x00E2;
  5944. t['acircumflexacute'] = 0x1EA5;
  5945. t['acircumflexdotbelow'] = 0x1EAD;
  5946. t['acircumflexgrave'] = 0x1EA7;
  5947. t['acircumflexhookabove'] = 0x1EA9;
  5948. t['acircumflextilde'] = 0x1EAB;
  5949. t['acute'] = 0x00B4;
  5950. t['acutebelowcmb'] = 0x0317;
  5951. t['acutecmb'] = 0x0301;
  5952. t['acutecomb'] = 0x0301;
  5953. t['acutedeva'] = 0x0954;
  5954. t['acutelowmod'] = 0x02CF;
  5955. t['acutetonecmb'] = 0x0341;
  5956. t['acyrillic'] = 0x0430;
  5957. t['adblgrave'] = 0x0201;
  5958. t['addakgurmukhi'] = 0x0A71;
  5959. t['adeva'] = 0x0905;
  5960. t['adieresis'] = 0x00E4;
  5961. t['adieresiscyrillic'] = 0x04D3;
  5962. t['adieresismacron'] = 0x01DF;
  5963. t['adotbelow'] = 0x1EA1;
  5964. t['adotmacron'] = 0x01E1;
  5965. t['ae'] = 0x00E6;
  5966. t['aeacute'] = 0x01FD;
  5967. t['aekorean'] = 0x3150;
  5968. t['aemacron'] = 0x01E3;
  5969. t['afii00208'] = 0x2015;
  5970. t['afii08941'] = 0x20A4;
  5971. t['afii10017'] = 0x0410;
  5972. t['afii10018'] = 0x0411;
  5973. t['afii10019'] = 0x0412;
  5974. t['afii10020'] = 0x0413;
  5975. t['afii10021'] = 0x0414;
  5976. t['afii10022'] = 0x0415;
  5977. t['afii10023'] = 0x0401;
  5978. t['afii10024'] = 0x0416;
  5979. t['afii10025'] = 0x0417;
  5980. t['afii10026'] = 0x0418;
  5981. t['afii10027'] = 0x0419;
  5982. t['afii10028'] = 0x041A;
  5983. t['afii10029'] = 0x041B;
  5984. t['afii10030'] = 0x041C;
  5985. t['afii10031'] = 0x041D;
  5986. t['afii10032'] = 0x041E;
  5987. t['afii10033'] = 0x041F;
  5988. t['afii10034'] = 0x0420;
  5989. t['afii10035'] = 0x0421;
  5990. t['afii10036'] = 0x0422;
  5991. t['afii10037'] = 0x0423;
  5992. t['afii10038'] = 0x0424;
  5993. t['afii10039'] = 0x0425;
  5994. t['afii10040'] = 0x0426;
  5995. t['afii10041'] = 0x0427;
  5996. t['afii10042'] = 0x0428;
  5997. t['afii10043'] = 0x0429;
  5998. t['afii10044'] = 0x042A;
  5999. t['afii10045'] = 0x042B;
  6000. t['afii10046'] = 0x042C;
  6001. t['afii10047'] = 0x042D;
  6002. t['afii10048'] = 0x042E;
  6003. t['afii10049'] = 0x042F;
  6004. t['afii10050'] = 0x0490;
  6005. t['afii10051'] = 0x0402;
  6006. t['afii10052'] = 0x0403;
  6007. t['afii10053'] = 0x0404;
  6008. t['afii10054'] = 0x0405;
  6009. t['afii10055'] = 0x0406;
  6010. t['afii10056'] = 0x0407;
  6011. t['afii10057'] = 0x0408;
  6012. t['afii10058'] = 0x0409;
  6013. t['afii10059'] = 0x040A;
  6014. t['afii10060'] = 0x040B;
  6015. t['afii10061'] = 0x040C;
  6016. t['afii10062'] = 0x040E;
  6017. t['afii10063'] = 0xF6C4;
  6018. t['afii10064'] = 0xF6C5;
  6019. t['afii10065'] = 0x0430;
  6020. t['afii10066'] = 0x0431;
  6021. t['afii10067'] = 0x0432;
  6022. t['afii10068'] = 0x0433;
  6023. t['afii10069'] = 0x0434;
  6024. t['afii10070'] = 0x0435;
  6025. t['afii10071'] = 0x0451;
  6026. t['afii10072'] = 0x0436;
  6027. t['afii10073'] = 0x0437;
  6028. t['afii10074'] = 0x0438;
  6029. t['afii10075'] = 0x0439;
  6030. t['afii10076'] = 0x043A;
  6031. t['afii10077'] = 0x043B;
  6032. t['afii10078'] = 0x043C;
  6033. t['afii10079'] = 0x043D;
  6034. t['afii10080'] = 0x043E;
  6035. t['afii10081'] = 0x043F;
  6036. t['afii10082'] = 0x0440;
  6037. t['afii10083'] = 0x0441;
  6038. t['afii10084'] = 0x0442;
  6039. t['afii10085'] = 0x0443;
  6040. t['afii10086'] = 0x0444;
  6041. t['afii10087'] = 0x0445;
  6042. t['afii10088'] = 0x0446;
  6043. t['afii10089'] = 0x0447;
  6044. t['afii10090'] = 0x0448;
  6045. t['afii10091'] = 0x0449;
  6046. t['afii10092'] = 0x044A;
  6047. t['afii10093'] = 0x044B;
  6048. t['afii10094'] = 0x044C;
  6049. t['afii10095'] = 0x044D;
  6050. t['afii10096'] = 0x044E;
  6051. t['afii10097'] = 0x044F;
  6052. t['afii10098'] = 0x0491;
  6053. t['afii10099'] = 0x0452;
  6054. t['afii10100'] = 0x0453;
  6055. t['afii10101'] = 0x0454;
  6056. t['afii10102'] = 0x0455;
  6057. t['afii10103'] = 0x0456;
  6058. t['afii10104'] = 0x0457;
  6059. t['afii10105'] = 0x0458;
  6060. t['afii10106'] = 0x0459;
  6061. t['afii10107'] = 0x045A;
  6062. t['afii10108'] = 0x045B;
  6063. t['afii10109'] = 0x045C;
  6064. t['afii10110'] = 0x045E;
  6065. t['afii10145'] = 0x040F;
  6066. t['afii10146'] = 0x0462;
  6067. t['afii10147'] = 0x0472;
  6068. t['afii10148'] = 0x0474;
  6069. t['afii10192'] = 0xF6C6;
  6070. t['afii10193'] = 0x045F;
  6071. t['afii10194'] = 0x0463;
  6072. t['afii10195'] = 0x0473;
  6073. t['afii10196'] = 0x0475;
  6074. t['afii10831'] = 0xF6C7;
  6075. t['afii10832'] = 0xF6C8;
  6076. t['afii10846'] = 0x04D9;
  6077. t['afii299'] = 0x200E;
  6078. t['afii300'] = 0x200F;
  6079. t['afii301'] = 0x200D;
  6080. t['afii57381'] = 0x066A;
  6081. t['afii57388'] = 0x060C;
  6082. t['afii57392'] = 0x0660;
  6083. t['afii57393'] = 0x0661;
  6084. t['afii57394'] = 0x0662;
  6085. t['afii57395'] = 0x0663;
  6086. t['afii57396'] = 0x0664;
  6087. t['afii57397'] = 0x0665;
  6088. t['afii57398'] = 0x0666;
  6089. t['afii57399'] = 0x0667;
  6090. t['afii57400'] = 0x0668;
  6091. t['afii57401'] = 0x0669;
  6092. t['afii57403'] = 0x061B;
  6093. t['afii57407'] = 0x061F;
  6094. t['afii57409'] = 0x0621;
  6095. t['afii57410'] = 0x0622;
  6096. t['afii57411'] = 0x0623;
  6097. t['afii57412'] = 0x0624;
  6098. t['afii57413'] = 0x0625;
  6099. t['afii57414'] = 0x0626;
  6100. t['afii57415'] = 0x0627;
  6101. t['afii57416'] = 0x0628;
  6102. t['afii57417'] = 0x0629;
  6103. t['afii57418'] = 0x062A;
  6104. t['afii57419'] = 0x062B;
  6105. t['afii57420'] = 0x062C;
  6106. t['afii57421'] = 0x062D;
  6107. t['afii57422'] = 0x062E;
  6108. t['afii57423'] = 0x062F;
  6109. t['afii57424'] = 0x0630;
  6110. t['afii57425'] = 0x0631;
  6111. t['afii57426'] = 0x0632;
  6112. t['afii57427'] = 0x0633;
  6113. t['afii57428'] = 0x0634;
  6114. t['afii57429'] = 0x0635;
  6115. t['afii57430'] = 0x0636;
  6116. t['afii57431'] = 0x0637;
  6117. t['afii57432'] = 0x0638;
  6118. t['afii57433'] = 0x0639;
  6119. t['afii57434'] = 0x063A;
  6120. t['afii57440'] = 0x0640;
  6121. t['afii57441'] = 0x0641;
  6122. t['afii57442'] = 0x0642;
  6123. t['afii57443'] = 0x0643;
  6124. t['afii57444'] = 0x0644;
  6125. t['afii57445'] = 0x0645;
  6126. t['afii57446'] = 0x0646;
  6127. t['afii57448'] = 0x0648;
  6128. t['afii57449'] = 0x0649;
  6129. t['afii57450'] = 0x064A;
  6130. t['afii57451'] = 0x064B;
  6131. t['afii57452'] = 0x064C;
  6132. t['afii57453'] = 0x064D;
  6133. t['afii57454'] = 0x064E;
  6134. t['afii57455'] = 0x064F;
  6135. t['afii57456'] = 0x0650;
  6136. t['afii57457'] = 0x0651;
  6137. t['afii57458'] = 0x0652;
  6138. t['afii57470'] = 0x0647;
  6139. t['afii57505'] = 0x06A4;
  6140. t['afii57506'] = 0x067E;
  6141. t['afii57507'] = 0x0686;
  6142. t['afii57508'] = 0x0698;
  6143. t['afii57509'] = 0x06AF;
  6144. t['afii57511'] = 0x0679;
  6145. t['afii57512'] = 0x0688;
  6146. t['afii57513'] = 0x0691;
  6147. t['afii57514'] = 0x06BA;
  6148. t['afii57519'] = 0x06D2;
  6149. t['afii57534'] = 0x06D5;
  6150. t['afii57636'] = 0x20AA;
  6151. t['afii57645'] = 0x05BE;
  6152. t['afii57658'] = 0x05C3;
  6153. t['afii57664'] = 0x05D0;
  6154. t['afii57665'] = 0x05D1;
  6155. t['afii57666'] = 0x05D2;
  6156. t['afii57667'] = 0x05D3;
  6157. t['afii57668'] = 0x05D4;
  6158. t['afii57669'] = 0x05D5;
  6159. t['afii57670'] = 0x05D6;
  6160. t['afii57671'] = 0x05D7;
  6161. t['afii57672'] = 0x05D8;
  6162. t['afii57673'] = 0x05D9;
  6163. t['afii57674'] = 0x05DA;
  6164. t['afii57675'] = 0x05DB;
  6165. t['afii57676'] = 0x05DC;
  6166. t['afii57677'] = 0x05DD;
  6167. t['afii57678'] = 0x05DE;
  6168. t['afii57679'] = 0x05DF;
  6169. t['afii57680'] = 0x05E0;
  6170. t['afii57681'] = 0x05E1;
  6171. t['afii57682'] = 0x05E2;
  6172. t['afii57683'] = 0x05E3;
  6173. t['afii57684'] = 0x05E4;
  6174. t['afii57685'] = 0x05E5;
  6175. t['afii57686'] = 0x05E6;
  6176. t['afii57687'] = 0x05E7;
  6177. t['afii57688'] = 0x05E8;
  6178. t['afii57689'] = 0x05E9;
  6179. t['afii57690'] = 0x05EA;
  6180. t['afii57694'] = 0xFB2A;
  6181. t['afii57695'] = 0xFB2B;
  6182. t['afii57700'] = 0xFB4B;
  6183. t['afii57705'] = 0xFB1F;
  6184. t['afii57716'] = 0x05F0;
  6185. t['afii57717'] = 0x05F1;
  6186. t['afii57718'] = 0x05F2;
  6187. t['afii57723'] = 0xFB35;
  6188. t['afii57793'] = 0x05B4;
  6189. t['afii57794'] = 0x05B5;
  6190. t['afii57795'] = 0x05B6;
  6191. t['afii57796'] = 0x05BB;
  6192. t['afii57797'] = 0x05B8;
  6193. t['afii57798'] = 0x05B7;
  6194. t['afii57799'] = 0x05B0;
  6195. t['afii57800'] = 0x05B2;
  6196. t['afii57801'] = 0x05B1;
  6197. t['afii57802'] = 0x05B3;
  6198. t['afii57803'] = 0x05C2;
  6199. t['afii57804'] = 0x05C1;
  6200. t['afii57806'] = 0x05B9;
  6201. t['afii57807'] = 0x05BC;
  6202. t['afii57839'] = 0x05BD;
  6203. t['afii57841'] = 0x05BF;
  6204. t['afii57842'] = 0x05C0;
  6205. t['afii57929'] = 0x02BC;
  6206. t['afii61248'] = 0x2105;
  6207. t['afii61289'] = 0x2113;
  6208. t['afii61352'] = 0x2116;
  6209. t['afii61573'] = 0x202C;
  6210. t['afii61574'] = 0x202D;
  6211. t['afii61575'] = 0x202E;
  6212. t['afii61664'] = 0x200C;
  6213. t['afii63167'] = 0x066D;
  6214. t['afii64937'] = 0x02BD;
  6215. t['agrave'] = 0x00E0;
  6216. t['agujarati'] = 0x0A85;
  6217. t['agurmukhi'] = 0x0A05;
  6218. t['ahiragana'] = 0x3042;
  6219. t['ahookabove'] = 0x1EA3;
  6220. t['aibengali'] = 0x0990;
  6221. t['aibopomofo'] = 0x311E;
  6222. t['aideva'] = 0x0910;
  6223. t['aiecyrillic'] = 0x04D5;
  6224. t['aigujarati'] = 0x0A90;
  6225. t['aigurmukhi'] = 0x0A10;
  6226. t['aimatragurmukhi'] = 0x0A48;
  6227. t['ainarabic'] = 0x0639;
  6228. t['ainfinalarabic'] = 0xFECA;
  6229. t['aininitialarabic'] = 0xFECB;
  6230. t['ainmedialarabic'] = 0xFECC;
  6231. t['ainvertedbreve'] = 0x0203;
  6232. t['aivowelsignbengali'] = 0x09C8;
  6233. t['aivowelsigndeva'] = 0x0948;
  6234. t['aivowelsigngujarati'] = 0x0AC8;
  6235. t['akatakana'] = 0x30A2;
  6236. t['akatakanahalfwidth'] = 0xFF71;
  6237. t['akorean'] = 0x314F;
  6238. t['alef'] = 0x05D0;
  6239. t['alefarabic'] = 0x0627;
  6240. t['alefdageshhebrew'] = 0xFB30;
  6241. t['aleffinalarabic'] = 0xFE8E;
  6242. t['alefhamzaabovearabic'] = 0x0623;
  6243. t['alefhamzaabovefinalarabic'] = 0xFE84;
  6244. t['alefhamzabelowarabic'] = 0x0625;
  6245. t['alefhamzabelowfinalarabic'] = 0xFE88;
  6246. t['alefhebrew'] = 0x05D0;
  6247. t['aleflamedhebrew'] = 0xFB4F;
  6248. t['alefmaddaabovearabic'] = 0x0622;
  6249. t['alefmaddaabovefinalarabic'] = 0xFE82;
  6250. t['alefmaksuraarabic'] = 0x0649;
  6251. t['alefmaksurafinalarabic'] = 0xFEF0;
  6252. t['alefmaksurainitialarabic'] = 0xFEF3;
  6253. t['alefmaksuramedialarabic'] = 0xFEF4;
  6254. t['alefpatahhebrew'] = 0xFB2E;
  6255. t['alefqamatshebrew'] = 0xFB2F;
  6256. t['aleph'] = 0x2135;
  6257. t['allequal'] = 0x224C;
  6258. t['alpha'] = 0x03B1;
  6259. t['alphatonos'] = 0x03AC;
  6260. t['amacron'] = 0x0101;
  6261. t['amonospace'] = 0xFF41;
  6262. t['ampersand'] = 0x0026;
  6263. t['ampersandmonospace'] = 0xFF06;
  6264. t['ampersandsmall'] = 0xF726;
  6265. t['amsquare'] = 0x33C2;
  6266. t['anbopomofo'] = 0x3122;
  6267. t['angbopomofo'] = 0x3124;
  6268. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  6269. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  6270. t['angkhankhuthai'] = 0x0E5A;
  6271. t['angle'] = 0x2220;
  6272. t['anglebracketleft'] = 0x3008;
  6273. t['anglebracketleftvertical'] = 0xFE3F;
  6274. t['anglebracketright'] = 0x3009;
  6275. t['anglebracketrightvertical'] = 0xFE40;
  6276. t['angleleft'] = 0x2329;
  6277. t['angleright'] = 0x232A;
  6278. t['angstrom'] = 0x212B;
  6279. t['anoteleia'] = 0x0387;
  6280. t['anudattadeva'] = 0x0952;
  6281. t['anusvarabengali'] = 0x0982;
  6282. t['anusvaradeva'] = 0x0902;
  6283. t['anusvaragujarati'] = 0x0A82;
  6284. t['aogonek'] = 0x0105;
  6285. t['apaatosquare'] = 0x3300;
  6286. t['aparen'] = 0x249C;
  6287. t['apostrophearmenian'] = 0x055A;
  6288. t['apostrophemod'] = 0x02BC;
  6289. t['apple'] = 0xF8FF;
  6290. t['approaches'] = 0x2250;
  6291. t['approxequal'] = 0x2248;
  6292. t['approxequalorimage'] = 0x2252;
  6293. t['approximatelyequal'] = 0x2245;
  6294. t['araeaekorean'] = 0x318E;
  6295. t['araeakorean'] = 0x318D;
  6296. t['arc'] = 0x2312;
  6297. t['arighthalfring'] = 0x1E9A;
  6298. t['aring'] = 0x00E5;
  6299. t['aringacute'] = 0x01FB;
  6300. t['aringbelow'] = 0x1E01;
  6301. t['arrowboth'] = 0x2194;
  6302. t['arrowdashdown'] = 0x21E3;
  6303. t['arrowdashleft'] = 0x21E0;
  6304. t['arrowdashright'] = 0x21E2;
  6305. t['arrowdashup'] = 0x21E1;
  6306. t['arrowdblboth'] = 0x21D4;
  6307. t['arrowdbldown'] = 0x21D3;
  6308. t['arrowdblleft'] = 0x21D0;
  6309. t['arrowdblright'] = 0x21D2;
  6310. t['arrowdblup'] = 0x21D1;
  6311. t['arrowdown'] = 0x2193;
  6312. t['arrowdownleft'] = 0x2199;
  6313. t['arrowdownright'] = 0x2198;
  6314. t['arrowdownwhite'] = 0x21E9;
  6315. t['arrowheaddownmod'] = 0x02C5;
  6316. t['arrowheadleftmod'] = 0x02C2;
  6317. t['arrowheadrightmod'] = 0x02C3;
  6318. t['arrowheadupmod'] = 0x02C4;
  6319. t['arrowhorizex'] = 0xF8E7;
  6320. t['arrowleft'] = 0x2190;
  6321. t['arrowleftdbl'] = 0x21D0;
  6322. t['arrowleftdblstroke'] = 0x21CD;
  6323. t['arrowleftoverright'] = 0x21C6;
  6324. t['arrowleftwhite'] = 0x21E6;
  6325. t['arrowright'] = 0x2192;
  6326. t['arrowrightdblstroke'] = 0x21CF;
  6327. t['arrowrightheavy'] = 0x279E;
  6328. t['arrowrightoverleft'] = 0x21C4;
  6329. t['arrowrightwhite'] = 0x21E8;
  6330. t['arrowtableft'] = 0x21E4;
  6331. t['arrowtabright'] = 0x21E5;
  6332. t['arrowup'] = 0x2191;
  6333. t['arrowupdn'] = 0x2195;
  6334. t['arrowupdnbse'] = 0x21A8;
  6335. t['arrowupdownbase'] = 0x21A8;
  6336. t['arrowupleft'] = 0x2196;
  6337. t['arrowupleftofdown'] = 0x21C5;
  6338. t['arrowupright'] = 0x2197;
  6339. t['arrowupwhite'] = 0x21E7;
  6340. t['arrowvertex'] = 0xF8E6;
  6341. t['asciicircum'] = 0x005E;
  6342. t['asciicircummonospace'] = 0xFF3E;
  6343. t['asciitilde'] = 0x007E;
  6344. t['asciitildemonospace'] = 0xFF5E;
  6345. t['ascript'] = 0x0251;
  6346. t['ascriptturned'] = 0x0252;
  6347. t['asmallhiragana'] = 0x3041;
  6348. t['asmallkatakana'] = 0x30A1;
  6349. t['asmallkatakanahalfwidth'] = 0xFF67;
  6350. t['asterisk'] = 0x002A;
  6351. t['asteriskaltonearabic'] = 0x066D;
  6352. t['asteriskarabic'] = 0x066D;
  6353. t['asteriskmath'] = 0x2217;
  6354. t['asteriskmonospace'] = 0xFF0A;
  6355. t['asterisksmall'] = 0xFE61;
  6356. t['asterism'] = 0x2042;
  6357. t['asuperior'] = 0xF6E9;
  6358. t['asymptoticallyequal'] = 0x2243;
  6359. t['at'] = 0x0040;
  6360. t['atilde'] = 0x00E3;
  6361. t['atmonospace'] = 0xFF20;
  6362. t['atsmall'] = 0xFE6B;
  6363. t['aturned'] = 0x0250;
  6364. t['aubengali'] = 0x0994;
  6365. t['aubopomofo'] = 0x3120;
  6366. t['audeva'] = 0x0914;
  6367. t['augujarati'] = 0x0A94;
  6368. t['augurmukhi'] = 0x0A14;
  6369. t['aulengthmarkbengali'] = 0x09D7;
  6370. t['aumatragurmukhi'] = 0x0A4C;
  6371. t['auvowelsignbengali'] = 0x09CC;
  6372. t['auvowelsigndeva'] = 0x094C;
  6373. t['auvowelsigngujarati'] = 0x0ACC;
  6374. t['avagrahadeva'] = 0x093D;
  6375. t['aybarmenian'] = 0x0561;
  6376. t['ayin'] = 0x05E2;
  6377. t['ayinaltonehebrew'] = 0xFB20;
  6378. t['ayinhebrew'] = 0x05E2;
  6379. t['b'] = 0x0062;
  6380. t['babengali'] = 0x09AC;
  6381. t['backslash'] = 0x005C;
  6382. t['backslashmonospace'] = 0xFF3C;
  6383. t['badeva'] = 0x092C;
  6384. t['bagujarati'] = 0x0AAC;
  6385. t['bagurmukhi'] = 0x0A2C;
  6386. t['bahiragana'] = 0x3070;
  6387. t['bahtthai'] = 0x0E3F;
  6388. t['bakatakana'] = 0x30D0;
  6389. t['bar'] = 0x007C;
  6390. t['barmonospace'] = 0xFF5C;
  6391. t['bbopomofo'] = 0x3105;
  6392. t['bcircle'] = 0x24D1;
  6393. t['bdotaccent'] = 0x1E03;
  6394. t['bdotbelow'] = 0x1E05;
  6395. t['beamedsixteenthnotes'] = 0x266C;
  6396. t['because'] = 0x2235;
  6397. t['becyrillic'] = 0x0431;
  6398. t['beharabic'] = 0x0628;
  6399. t['behfinalarabic'] = 0xFE90;
  6400. t['behinitialarabic'] = 0xFE91;
  6401. t['behiragana'] = 0x3079;
  6402. t['behmedialarabic'] = 0xFE92;
  6403. t['behmeeminitialarabic'] = 0xFC9F;
  6404. t['behmeemisolatedarabic'] = 0xFC08;
  6405. t['behnoonfinalarabic'] = 0xFC6D;
  6406. t['bekatakana'] = 0x30D9;
  6407. t['benarmenian'] = 0x0562;
  6408. t['bet'] = 0x05D1;
  6409. t['beta'] = 0x03B2;
  6410. t['betasymbolgreek'] = 0x03D0;
  6411. t['betdagesh'] = 0xFB31;
  6412. t['betdageshhebrew'] = 0xFB31;
  6413. t['bethebrew'] = 0x05D1;
  6414. t['betrafehebrew'] = 0xFB4C;
  6415. t['bhabengali'] = 0x09AD;
  6416. t['bhadeva'] = 0x092D;
  6417. t['bhagujarati'] = 0x0AAD;
  6418. t['bhagurmukhi'] = 0x0A2D;
  6419. t['bhook'] = 0x0253;
  6420. t['bihiragana'] = 0x3073;
  6421. t['bikatakana'] = 0x30D3;
  6422. t['bilabialclick'] = 0x0298;
  6423. t['bindigurmukhi'] = 0x0A02;
  6424. t['birusquare'] = 0x3331;
  6425. t['blackcircle'] = 0x25CF;
  6426. t['blackdiamond'] = 0x25C6;
  6427. t['blackdownpointingtriangle'] = 0x25BC;
  6428. t['blackleftpointingpointer'] = 0x25C4;
  6429. t['blackleftpointingtriangle'] = 0x25C0;
  6430. t['blacklenticularbracketleft'] = 0x3010;
  6431. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6432. t['blacklenticularbracketright'] = 0x3011;
  6433. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6434. t['blacklowerlefttriangle'] = 0x25E3;
  6435. t['blacklowerrighttriangle'] = 0x25E2;
  6436. t['blackrectangle'] = 0x25AC;
  6437. t['blackrightpointingpointer'] = 0x25BA;
  6438. t['blackrightpointingtriangle'] = 0x25B6;
  6439. t['blacksmallsquare'] = 0x25AA;
  6440. t['blacksmilingface'] = 0x263B;
  6441. t['blacksquare'] = 0x25A0;
  6442. t['blackstar'] = 0x2605;
  6443. t['blackupperlefttriangle'] = 0x25E4;
  6444. t['blackupperrighttriangle'] = 0x25E5;
  6445. t['blackuppointingsmalltriangle'] = 0x25B4;
  6446. t['blackuppointingtriangle'] = 0x25B2;
  6447. t['blank'] = 0x2423;
  6448. t['blinebelow'] = 0x1E07;
  6449. t['block'] = 0x2588;
  6450. t['bmonospace'] = 0xFF42;
  6451. t['bobaimaithai'] = 0x0E1A;
  6452. t['bohiragana'] = 0x307C;
  6453. t['bokatakana'] = 0x30DC;
  6454. t['bparen'] = 0x249D;
  6455. t['bqsquare'] = 0x33C3;
  6456. t['braceex'] = 0xF8F4;
  6457. t['braceleft'] = 0x007B;
  6458. t['braceleftbt'] = 0xF8F3;
  6459. t['braceleftmid'] = 0xF8F2;
  6460. t['braceleftmonospace'] = 0xFF5B;
  6461. t['braceleftsmall'] = 0xFE5B;
  6462. t['bracelefttp'] = 0xF8F1;
  6463. t['braceleftvertical'] = 0xFE37;
  6464. t['braceright'] = 0x007D;
  6465. t['bracerightbt'] = 0xF8FE;
  6466. t['bracerightmid'] = 0xF8FD;
  6467. t['bracerightmonospace'] = 0xFF5D;
  6468. t['bracerightsmall'] = 0xFE5C;
  6469. t['bracerighttp'] = 0xF8FC;
  6470. t['bracerightvertical'] = 0xFE38;
  6471. t['bracketleft'] = 0x005B;
  6472. t['bracketleftbt'] = 0xF8F0;
  6473. t['bracketleftex'] = 0xF8EF;
  6474. t['bracketleftmonospace'] = 0xFF3B;
  6475. t['bracketlefttp'] = 0xF8EE;
  6476. t['bracketright'] = 0x005D;
  6477. t['bracketrightbt'] = 0xF8FB;
  6478. t['bracketrightex'] = 0xF8FA;
  6479. t['bracketrightmonospace'] = 0xFF3D;
  6480. t['bracketrighttp'] = 0xF8F9;
  6481. t['breve'] = 0x02D8;
  6482. t['brevebelowcmb'] = 0x032E;
  6483. t['brevecmb'] = 0x0306;
  6484. t['breveinvertedbelowcmb'] = 0x032F;
  6485. t['breveinvertedcmb'] = 0x0311;
  6486. t['breveinverteddoublecmb'] = 0x0361;
  6487. t['bridgebelowcmb'] = 0x032A;
  6488. t['bridgeinvertedbelowcmb'] = 0x033A;
  6489. t['brokenbar'] = 0x00A6;
  6490. t['bstroke'] = 0x0180;
  6491. t['bsuperior'] = 0xF6EA;
  6492. t['btopbar'] = 0x0183;
  6493. t['buhiragana'] = 0x3076;
  6494. t['bukatakana'] = 0x30D6;
  6495. t['bullet'] = 0x2022;
  6496. t['bulletinverse'] = 0x25D8;
  6497. t['bulletoperator'] = 0x2219;
  6498. t['bullseye'] = 0x25CE;
  6499. t['c'] = 0x0063;
  6500. t['caarmenian'] = 0x056E;
  6501. t['cabengali'] = 0x099A;
  6502. t['cacute'] = 0x0107;
  6503. t['cadeva'] = 0x091A;
  6504. t['cagujarati'] = 0x0A9A;
  6505. t['cagurmukhi'] = 0x0A1A;
  6506. t['calsquare'] = 0x3388;
  6507. t['candrabindubengali'] = 0x0981;
  6508. t['candrabinducmb'] = 0x0310;
  6509. t['candrabindudeva'] = 0x0901;
  6510. t['candrabindugujarati'] = 0x0A81;
  6511. t['capslock'] = 0x21EA;
  6512. t['careof'] = 0x2105;
  6513. t['caron'] = 0x02C7;
  6514. t['caronbelowcmb'] = 0x032C;
  6515. t['caroncmb'] = 0x030C;
  6516. t['carriagereturn'] = 0x21B5;
  6517. t['cbopomofo'] = 0x3118;
  6518. t['ccaron'] = 0x010D;
  6519. t['ccedilla'] = 0x00E7;
  6520. t['ccedillaacute'] = 0x1E09;
  6521. t['ccircle'] = 0x24D2;
  6522. t['ccircumflex'] = 0x0109;
  6523. t['ccurl'] = 0x0255;
  6524. t['cdot'] = 0x010B;
  6525. t['cdotaccent'] = 0x010B;
  6526. t['cdsquare'] = 0x33C5;
  6527. t['cedilla'] = 0x00B8;
  6528. t['cedillacmb'] = 0x0327;
  6529. t['cent'] = 0x00A2;
  6530. t['centigrade'] = 0x2103;
  6531. t['centinferior'] = 0xF6DF;
  6532. t['centmonospace'] = 0xFFE0;
  6533. t['centoldstyle'] = 0xF7A2;
  6534. t['centsuperior'] = 0xF6E0;
  6535. t['chaarmenian'] = 0x0579;
  6536. t['chabengali'] = 0x099B;
  6537. t['chadeva'] = 0x091B;
  6538. t['chagujarati'] = 0x0A9B;
  6539. t['chagurmukhi'] = 0x0A1B;
  6540. t['chbopomofo'] = 0x3114;
  6541. t['cheabkhasiancyrillic'] = 0x04BD;
  6542. t['checkmark'] = 0x2713;
  6543. t['checyrillic'] = 0x0447;
  6544. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6545. t['chedescendercyrillic'] = 0x04B7;
  6546. t['chedieresiscyrillic'] = 0x04F5;
  6547. t['cheharmenian'] = 0x0573;
  6548. t['chekhakassiancyrillic'] = 0x04CC;
  6549. t['cheverticalstrokecyrillic'] = 0x04B9;
  6550. t['chi'] = 0x03C7;
  6551. t['chieuchacirclekorean'] = 0x3277;
  6552. t['chieuchaparenkorean'] = 0x3217;
  6553. t['chieuchcirclekorean'] = 0x3269;
  6554. t['chieuchkorean'] = 0x314A;
  6555. t['chieuchparenkorean'] = 0x3209;
  6556. t['chochangthai'] = 0x0E0A;
  6557. t['chochanthai'] = 0x0E08;
  6558. t['chochingthai'] = 0x0E09;
  6559. t['chochoethai'] = 0x0E0C;
  6560. t['chook'] = 0x0188;
  6561. t['cieucacirclekorean'] = 0x3276;
  6562. t['cieucaparenkorean'] = 0x3216;
  6563. t['cieuccirclekorean'] = 0x3268;
  6564. t['cieuckorean'] = 0x3148;
  6565. t['cieucparenkorean'] = 0x3208;
  6566. t['cieucuparenkorean'] = 0x321C;
  6567. t['circle'] = 0x25CB;
  6568. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6569. t['circlemultiply'] = 0x2297;
  6570. t['circleot'] = 0x2299;
  6571. t['circleplus'] = 0x2295;
  6572. t['circlepostalmark'] = 0x3036;
  6573. t['circlewithlefthalfblack'] = 0x25D0;
  6574. t['circlewithrighthalfblack'] = 0x25D1;
  6575. t['circumflex'] = 0x02C6;
  6576. t['circumflexbelowcmb'] = 0x032D;
  6577. t['circumflexcmb'] = 0x0302;
  6578. t['clear'] = 0x2327;
  6579. t['clickalveolar'] = 0x01C2;
  6580. t['clickdental'] = 0x01C0;
  6581. t['clicklateral'] = 0x01C1;
  6582. t['clickretroflex'] = 0x01C3;
  6583. t['club'] = 0x2663;
  6584. t['clubsuitblack'] = 0x2663;
  6585. t['clubsuitwhite'] = 0x2667;
  6586. t['cmcubedsquare'] = 0x33A4;
  6587. t['cmonospace'] = 0xFF43;
  6588. t['cmsquaredsquare'] = 0x33A0;
  6589. t['coarmenian'] = 0x0581;
  6590. t['colon'] = 0x003A;
  6591. t['colonmonetary'] = 0x20A1;
  6592. t['colonmonospace'] = 0xFF1A;
  6593. t['colonsign'] = 0x20A1;
  6594. t['colonsmall'] = 0xFE55;
  6595. t['colontriangularhalfmod'] = 0x02D1;
  6596. t['colontriangularmod'] = 0x02D0;
  6597. t['comma'] = 0x002C;
  6598. t['commaabovecmb'] = 0x0313;
  6599. t['commaaboverightcmb'] = 0x0315;
  6600. t['commaaccent'] = 0xF6C3;
  6601. t['commaarabic'] = 0x060C;
  6602. t['commaarmenian'] = 0x055D;
  6603. t['commainferior'] = 0xF6E1;
  6604. t['commamonospace'] = 0xFF0C;
  6605. t['commareversedabovecmb'] = 0x0314;
  6606. t['commareversedmod'] = 0x02BD;
  6607. t['commasmall'] = 0xFE50;
  6608. t['commasuperior'] = 0xF6E2;
  6609. t['commaturnedabovecmb'] = 0x0312;
  6610. t['commaturnedmod'] = 0x02BB;
  6611. t['compass'] = 0x263C;
  6612. t['congruent'] = 0x2245;
  6613. t['contourintegral'] = 0x222E;
  6614. t['control'] = 0x2303;
  6615. t['controlACK'] = 0x0006;
  6616. t['controlBEL'] = 0x0007;
  6617. t['controlBS'] = 0x0008;
  6618. t['controlCAN'] = 0x0018;
  6619. t['controlCR'] = 0x000D;
  6620. t['controlDC1'] = 0x0011;
  6621. t['controlDC2'] = 0x0012;
  6622. t['controlDC3'] = 0x0013;
  6623. t['controlDC4'] = 0x0014;
  6624. t['controlDEL'] = 0x007F;
  6625. t['controlDLE'] = 0x0010;
  6626. t['controlEM'] = 0x0019;
  6627. t['controlENQ'] = 0x0005;
  6628. t['controlEOT'] = 0x0004;
  6629. t['controlESC'] = 0x001B;
  6630. t['controlETB'] = 0x0017;
  6631. t['controlETX'] = 0x0003;
  6632. t['controlFF'] = 0x000C;
  6633. t['controlFS'] = 0x001C;
  6634. t['controlGS'] = 0x001D;
  6635. t['controlHT'] = 0x0009;
  6636. t['controlLF'] = 0x000A;
  6637. t['controlNAK'] = 0x0015;
  6638. t['controlRS'] = 0x001E;
  6639. t['controlSI'] = 0x000F;
  6640. t['controlSO'] = 0x000E;
  6641. t['controlSOT'] = 0x0002;
  6642. t['controlSTX'] = 0x0001;
  6643. t['controlSUB'] = 0x001A;
  6644. t['controlSYN'] = 0x0016;
  6645. t['controlUS'] = 0x001F;
  6646. t['controlVT'] = 0x000B;
  6647. t['copyright'] = 0x00A9;
  6648. t['copyrightsans'] = 0xF8E9;
  6649. t['copyrightserif'] = 0xF6D9;
  6650. t['cornerbracketleft'] = 0x300C;
  6651. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6652. t['cornerbracketleftvertical'] = 0xFE41;
  6653. t['cornerbracketright'] = 0x300D;
  6654. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6655. t['cornerbracketrightvertical'] = 0xFE42;
  6656. t['corporationsquare'] = 0x337F;
  6657. t['cosquare'] = 0x33C7;
  6658. t['coverkgsquare'] = 0x33C6;
  6659. t['cparen'] = 0x249E;
  6660. t['cruzeiro'] = 0x20A2;
  6661. t['cstretched'] = 0x0297;
  6662. t['curlyand'] = 0x22CF;
  6663. t['curlyor'] = 0x22CE;
  6664. t['currency'] = 0x00A4;
  6665. t['cyrBreve'] = 0xF6D1;
  6666. t['cyrFlex'] = 0xF6D2;
  6667. t['cyrbreve'] = 0xF6D4;
  6668. t['cyrflex'] = 0xF6D5;
  6669. t['d'] = 0x0064;
  6670. t['daarmenian'] = 0x0564;
  6671. t['dabengali'] = 0x09A6;
  6672. t['dadarabic'] = 0x0636;
  6673. t['dadeva'] = 0x0926;
  6674. t['dadfinalarabic'] = 0xFEBE;
  6675. t['dadinitialarabic'] = 0xFEBF;
  6676. t['dadmedialarabic'] = 0xFEC0;
  6677. t['dagesh'] = 0x05BC;
  6678. t['dageshhebrew'] = 0x05BC;
  6679. t['dagger'] = 0x2020;
  6680. t['daggerdbl'] = 0x2021;
  6681. t['dagujarati'] = 0x0AA6;
  6682. t['dagurmukhi'] = 0x0A26;
  6683. t['dahiragana'] = 0x3060;
  6684. t['dakatakana'] = 0x30C0;
  6685. t['dalarabic'] = 0x062F;
  6686. t['dalet'] = 0x05D3;
  6687. t['daletdagesh'] = 0xFB33;
  6688. t['daletdageshhebrew'] = 0xFB33;
  6689. t['dalethebrew'] = 0x05D3;
  6690. t['dalfinalarabic'] = 0xFEAA;
  6691. t['dammaarabic'] = 0x064F;
  6692. t['dammalowarabic'] = 0x064F;
  6693. t['dammatanaltonearabic'] = 0x064C;
  6694. t['dammatanarabic'] = 0x064C;
  6695. t['danda'] = 0x0964;
  6696. t['dargahebrew'] = 0x05A7;
  6697. t['dargalefthebrew'] = 0x05A7;
  6698. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6699. t['dblGrave'] = 0xF6D3;
  6700. t['dblanglebracketleft'] = 0x300A;
  6701. t['dblanglebracketleftvertical'] = 0xFE3D;
  6702. t['dblanglebracketright'] = 0x300B;
  6703. t['dblanglebracketrightvertical'] = 0xFE3E;
  6704. t['dblarchinvertedbelowcmb'] = 0x032B;
  6705. t['dblarrowleft'] = 0x21D4;
  6706. t['dblarrowright'] = 0x21D2;
  6707. t['dbldanda'] = 0x0965;
  6708. t['dblgrave'] = 0xF6D6;
  6709. t['dblgravecmb'] = 0x030F;
  6710. t['dblintegral'] = 0x222C;
  6711. t['dbllowline'] = 0x2017;
  6712. t['dbllowlinecmb'] = 0x0333;
  6713. t['dbloverlinecmb'] = 0x033F;
  6714. t['dblprimemod'] = 0x02BA;
  6715. t['dblverticalbar'] = 0x2016;
  6716. t['dblverticallineabovecmb'] = 0x030E;
  6717. t['dbopomofo'] = 0x3109;
  6718. t['dbsquare'] = 0x33C8;
  6719. t['dcaron'] = 0x010F;
  6720. t['dcedilla'] = 0x1E11;
  6721. t['dcircle'] = 0x24D3;
  6722. t['dcircumflexbelow'] = 0x1E13;
  6723. t['dcroat'] = 0x0111;
  6724. t['ddabengali'] = 0x09A1;
  6725. t['ddadeva'] = 0x0921;
  6726. t['ddagujarati'] = 0x0AA1;
  6727. t['ddagurmukhi'] = 0x0A21;
  6728. t['ddalarabic'] = 0x0688;
  6729. t['ddalfinalarabic'] = 0xFB89;
  6730. t['dddhadeva'] = 0x095C;
  6731. t['ddhabengali'] = 0x09A2;
  6732. t['ddhadeva'] = 0x0922;
  6733. t['ddhagujarati'] = 0x0AA2;
  6734. t['ddhagurmukhi'] = 0x0A22;
  6735. t['ddotaccent'] = 0x1E0B;
  6736. t['ddotbelow'] = 0x1E0D;
  6737. t['decimalseparatorarabic'] = 0x066B;
  6738. t['decimalseparatorpersian'] = 0x066B;
  6739. t['decyrillic'] = 0x0434;
  6740. t['degree'] = 0x00B0;
  6741. t['dehihebrew'] = 0x05AD;
  6742. t['dehiragana'] = 0x3067;
  6743. t['deicoptic'] = 0x03EF;
  6744. t['dekatakana'] = 0x30C7;
  6745. t['deleteleft'] = 0x232B;
  6746. t['deleteright'] = 0x2326;
  6747. t['delta'] = 0x03B4;
  6748. t['deltaturned'] = 0x018D;
  6749. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6750. t['dezh'] = 0x02A4;
  6751. t['dhabengali'] = 0x09A7;
  6752. t['dhadeva'] = 0x0927;
  6753. t['dhagujarati'] = 0x0AA7;
  6754. t['dhagurmukhi'] = 0x0A27;
  6755. t['dhook'] = 0x0257;
  6756. t['dialytikatonos'] = 0x0385;
  6757. t['dialytikatonoscmb'] = 0x0344;
  6758. t['diamond'] = 0x2666;
  6759. t['diamondsuitwhite'] = 0x2662;
  6760. t['dieresis'] = 0x00A8;
  6761. t['dieresisacute'] = 0xF6D7;
  6762. t['dieresisbelowcmb'] = 0x0324;
  6763. t['dieresiscmb'] = 0x0308;
  6764. t['dieresisgrave'] = 0xF6D8;
  6765. t['dieresistonos'] = 0x0385;
  6766. t['dihiragana'] = 0x3062;
  6767. t['dikatakana'] = 0x30C2;
  6768. t['dittomark'] = 0x3003;
  6769. t['divide'] = 0x00F7;
  6770. t['divides'] = 0x2223;
  6771. t['divisionslash'] = 0x2215;
  6772. t['djecyrillic'] = 0x0452;
  6773. t['dkshade'] = 0x2593;
  6774. t['dlinebelow'] = 0x1E0F;
  6775. t['dlsquare'] = 0x3397;
  6776. t['dmacron'] = 0x0111;
  6777. t['dmonospace'] = 0xFF44;
  6778. t['dnblock'] = 0x2584;
  6779. t['dochadathai'] = 0x0E0E;
  6780. t['dodekthai'] = 0x0E14;
  6781. t['dohiragana'] = 0x3069;
  6782. t['dokatakana'] = 0x30C9;
  6783. t['dollar'] = 0x0024;
  6784. t['dollarinferior'] = 0xF6E3;
  6785. t['dollarmonospace'] = 0xFF04;
  6786. t['dollaroldstyle'] = 0xF724;
  6787. t['dollarsmall'] = 0xFE69;
  6788. t['dollarsuperior'] = 0xF6E4;
  6789. t['dong'] = 0x20AB;
  6790. t['dorusquare'] = 0x3326;
  6791. t['dotaccent'] = 0x02D9;
  6792. t['dotaccentcmb'] = 0x0307;
  6793. t['dotbelowcmb'] = 0x0323;
  6794. t['dotbelowcomb'] = 0x0323;
  6795. t['dotkatakana'] = 0x30FB;
  6796. t['dotlessi'] = 0x0131;
  6797. t['dotlessj'] = 0xF6BE;
  6798. t['dotlessjstrokehook'] = 0x0284;
  6799. t['dotmath'] = 0x22C5;
  6800. t['dottedcircle'] = 0x25CC;
  6801. t['doubleyodpatah'] = 0xFB1F;
  6802. t['doubleyodpatahhebrew'] = 0xFB1F;
  6803. t['downtackbelowcmb'] = 0x031E;
  6804. t['downtackmod'] = 0x02D5;
  6805. t['dparen'] = 0x249F;
  6806. t['dsuperior'] = 0xF6EB;
  6807. t['dtail'] = 0x0256;
  6808. t['dtopbar'] = 0x018C;
  6809. t['duhiragana'] = 0x3065;
  6810. t['dukatakana'] = 0x30C5;
  6811. t['dz'] = 0x01F3;
  6812. t['dzaltone'] = 0x02A3;
  6813. t['dzcaron'] = 0x01C6;
  6814. t['dzcurl'] = 0x02A5;
  6815. t['dzeabkhasiancyrillic'] = 0x04E1;
  6816. t['dzecyrillic'] = 0x0455;
  6817. t['dzhecyrillic'] = 0x045F;
  6818. t['e'] = 0x0065;
  6819. t['eacute'] = 0x00E9;
  6820. t['earth'] = 0x2641;
  6821. t['ebengali'] = 0x098F;
  6822. t['ebopomofo'] = 0x311C;
  6823. t['ebreve'] = 0x0115;
  6824. t['ecandradeva'] = 0x090D;
  6825. t['ecandragujarati'] = 0x0A8D;
  6826. t['ecandravowelsigndeva'] = 0x0945;
  6827. t['ecandravowelsigngujarati'] = 0x0AC5;
  6828. t['ecaron'] = 0x011B;
  6829. t['ecedillabreve'] = 0x1E1D;
  6830. t['echarmenian'] = 0x0565;
  6831. t['echyiwnarmenian'] = 0x0587;
  6832. t['ecircle'] = 0x24D4;
  6833. t['ecircumflex'] = 0x00EA;
  6834. t['ecircumflexacute'] = 0x1EBF;
  6835. t['ecircumflexbelow'] = 0x1E19;
  6836. t['ecircumflexdotbelow'] = 0x1EC7;
  6837. t['ecircumflexgrave'] = 0x1EC1;
  6838. t['ecircumflexhookabove'] = 0x1EC3;
  6839. t['ecircumflextilde'] = 0x1EC5;
  6840. t['ecyrillic'] = 0x0454;
  6841. t['edblgrave'] = 0x0205;
  6842. t['edeva'] = 0x090F;
  6843. t['edieresis'] = 0x00EB;
  6844. t['edot'] = 0x0117;
  6845. t['edotaccent'] = 0x0117;
  6846. t['edotbelow'] = 0x1EB9;
  6847. t['eegurmukhi'] = 0x0A0F;
  6848. t['eematragurmukhi'] = 0x0A47;
  6849. t['efcyrillic'] = 0x0444;
  6850. t['egrave'] = 0x00E8;
  6851. t['egujarati'] = 0x0A8F;
  6852. t['eharmenian'] = 0x0567;
  6853. t['ehbopomofo'] = 0x311D;
  6854. t['ehiragana'] = 0x3048;
  6855. t['ehookabove'] = 0x1EBB;
  6856. t['eibopomofo'] = 0x311F;
  6857. t['eight'] = 0x0038;
  6858. t['eightarabic'] = 0x0668;
  6859. t['eightbengali'] = 0x09EE;
  6860. t['eightcircle'] = 0x2467;
  6861. t['eightcircleinversesansserif'] = 0x2791;
  6862. t['eightdeva'] = 0x096E;
  6863. t['eighteencircle'] = 0x2471;
  6864. t['eighteenparen'] = 0x2485;
  6865. t['eighteenperiod'] = 0x2499;
  6866. t['eightgujarati'] = 0x0AEE;
  6867. t['eightgurmukhi'] = 0x0A6E;
  6868. t['eighthackarabic'] = 0x0668;
  6869. t['eighthangzhou'] = 0x3028;
  6870. t['eighthnotebeamed'] = 0x266B;
  6871. t['eightideographicparen'] = 0x3227;
  6872. t['eightinferior'] = 0x2088;
  6873. t['eightmonospace'] = 0xFF18;
  6874. t['eightoldstyle'] = 0xF738;
  6875. t['eightparen'] = 0x247B;
  6876. t['eightperiod'] = 0x248F;
  6877. t['eightpersian'] = 0x06F8;
  6878. t['eightroman'] = 0x2177;
  6879. t['eightsuperior'] = 0x2078;
  6880. t['eightthai'] = 0x0E58;
  6881. t['einvertedbreve'] = 0x0207;
  6882. t['eiotifiedcyrillic'] = 0x0465;
  6883. t['ekatakana'] = 0x30A8;
  6884. t['ekatakanahalfwidth'] = 0xFF74;
  6885. t['ekonkargurmukhi'] = 0x0A74;
  6886. t['ekorean'] = 0x3154;
  6887. t['elcyrillic'] = 0x043B;
  6888. t['element'] = 0x2208;
  6889. t['elevencircle'] = 0x246A;
  6890. t['elevenparen'] = 0x247E;
  6891. t['elevenperiod'] = 0x2492;
  6892. t['elevenroman'] = 0x217A;
  6893. t['ellipsis'] = 0x2026;
  6894. t['ellipsisvertical'] = 0x22EE;
  6895. t['emacron'] = 0x0113;
  6896. t['emacronacute'] = 0x1E17;
  6897. t['emacrongrave'] = 0x1E15;
  6898. t['emcyrillic'] = 0x043C;
  6899. t['emdash'] = 0x2014;
  6900. t['emdashvertical'] = 0xFE31;
  6901. t['emonospace'] = 0xFF45;
  6902. t['emphasismarkarmenian'] = 0x055B;
  6903. t['emptyset'] = 0x2205;
  6904. t['enbopomofo'] = 0x3123;
  6905. t['encyrillic'] = 0x043D;
  6906. t['endash'] = 0x2013;
  6907. t['endashvertical'] = 0xFE32;
  6908. t['endescendercyrillic'] = 0x04A3;
  6909. t['eng'] = 0x014B;
  6910. t['engbopomofo'] = 0x3125;
  6911. t['enghecyrillic'] = 0x04A5;
  6912. t['enhookcyrillic'] = 0x04C8;
  6913. t['enspace'] = 0x2002;
  6914. t['eogonek'] = 0x0119;
  6915. t['eokorean'] = 0x3153;
  6916. t['eopen'] = 0x025B;
  6917. t['eopenclosed'] = 0x029A;
  6918. t['eopenreversed'] = 0x025C;
  6919. t['eopenreversedclosed'] = 0x025E;
  6920. t['eopenreversedhook'] = 0x025D;
  6921. t['eparen'] = 0x24A0;
  6922. t['epsilon'] = 0x03B5;
  6923. t['epsilontonos'] = 0x03AD;
  6924. t['equal'] = 0x003D;
  6925. t['equalmonospace'] = 0xFF1D;
  6926. t['equalsmall'] = 0xFE66;
  6927. t['equalsuperior'] = 0x207C;
  6928. t['equivalence'] = 0x2261;
  6929. t['erbopomofo'] = 0x3126;
  6930. t['ercyrillic'] = 0x0440;
  6931. t['ereversed'] = 0x0258;
  6932. t['ereversedcyrillic'] = 0x044D;
  6933. t['escyrillic'] = 0x0441;
  6934. t['esdescendercyrillic'] = 0x04AB;
  6935. t['esh'] = 0x0283;
  6936. t['eshcurl'] = 0x0286;
  6937. t['eshortdeva'] = 0x090E;
  6938. t['eshortvowelsigndeva'] = 0x0946;
  6939. t['eshreversedloop'] = 0x01AA;
  6940. t['eshsquatreversed'] = 0x0285;
  6941. t['esmallhiragana'] = 0x3047;
  6942. t['esmallkatakana'] = 0x30A7;
  6943. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6944. t['estimated'] = 0x212E;
  6945. t['esuperior'] = 0xF6EC;
  6946. t['eta'] = 0x03B7;
  6947. t['etarmenian'] = 0x0568;
  6948. t['etatonos'] = 0x03AE;
  6949. t['eth'] = 0x00F0;
  6950. t['etilde'] = 0x1EBD;
  6951. t['etildebelow'] = 0x1E1B;
  6952. t['etnahtafoukhhebrew'] = 0x0591;
  6953. t['etnahtafoukhlefthebrew'] = 0x0591;
  6954. t['etnahtahebrew'] = 0x0591;
  6955. t['etnahtalefthebrew'] = 0x0591;
  6956. t['eturned'] = 0x01DD;
  6957. t['eukorean'] = 0x3161;
  6958. t['euro'] = 0x20AC;
  6959. t['evowelsignbengali'] = 0x09C7;
  6960. t['evowelsigndeva'] = 0x0947;
  6961. t['evowelsigngujarati'] = 0x0AC7;
  6962. t['exclam'] = 0x0021;
  6963. t['exclamarmenian'] = 0x055C;
  6964. t['exclamdbl'] = 0x203C;
  6965. t['exclamdown'] = 0x00A1;
  6966. t['exclamdownsmall'] = 0xF7A1;
  6967. t['exclammonospace'] = 0xFF01;
  6968. t['exclamsmall'] = 0xF721;
  6969. t['existential'] = 0x2203;
  6970. t['ezh'] = 0x0292;
  6971. t['ezhcaron'] = 0x01EF;
  6972. t['ezhcurl'] = 0x0293;
  6973. t['ezhreversed'] = 0x01B9;
  6974. t['ezhtail'] = 0x01BA;
  6975. t['f'] = 0x0066;
  6976. t['fadeva'] = 0x095E;
  6977. t['fagurmukhi'] = 0x0A5E;
  6978. t['fahrenheit'] = 0x2109;
  6979. t['fathaarabic'] = 0x064E;
  6980. t['fathalowarabic'] = 0x064E;
  6981. t['fathatanarabic'] = 0x064B;
  6982. t['fbopomofo'] = 0x3108;
  6983. t['fcircle'] = 0x24D5;
  6984. t['fdotaccent'] = 0x1E1F;
  6985. t['feharabic'] = 0x0641;
  6986. t['feharmenian'] = 0x0586;
  6987. t['fehfinalarabic'] = 0xFED2;
  6988. t['fehinitialarabic'] = 0xFED3;
  6989. t['fehmedialarabic'] = 0xFED4;
  6990. t['feicoptic'] = 0x03E5;
  6991. t['female'] = 0x2640;
  6992. t['ff'] = 0xFB00;
  6993. t['ffi'] = 0xFB03;
  6994. t['ffl'] = 0xFB04;
  6995. t['fi'] = 0xFB01;
  6996. t['fifteencircle'] = 0x246E;
  6997. t['fifteenparen'] = 0x2482;
  6998. t['fifteenperiod'] = 0x2496;
  6999. t['figuredash'] = 0x2012;
  7000. t['filledbox'] = 0x25A0;
  7001. t['filledrect'] = 0x25AC;
  7002. t['finalkaf'] = 0x05DA;
  7003. t['finalkafdagesh'] = 0xFB3A;
  7004. t['finalkafdageshhebrew'] = 0xFB3A;
  7005. t['finalkafhebrew'] = 0x05DA;
  7006. t['finalmem'] = 0x05DD;
  7007. t['finalmemhebrew'] = 0x05DD;
  7008. t['finalnun'] = 0x05DF;
  7009. t['finalnunhebrew'] = 0x05DF;
  7010. t['finalpe'] = 0x05E3;
  7011. t['finalpehebrew'] = 0x05E3;
  7012. t['finaltsadi'] = 0x05E5;
  7013. t['finaltsadihebrew'] = 0x05E5;
  7014. t['firsttonechinese'] = 0x02C9;
  7015. t['fisheye'] = 0x25C9;
  7016. t['fitacyrillic'] = 0x0473;
  7017. t['five'] = 0x0035;
  7018. t['fivearabic'] = 0x0665;
  7019. t['fivebengali'] = 0x09EB;
  7020. t['fivecircle'] = 0x2464;
  7021. t['fivecircleinversesansserif'] = 0x278E;
  7022. t['fivedeva'] = 0x096B;
  7023. t['fiveeighths'] = 0x215D;
  7024. t['fivegujarati'] = 0x0AEB;
  7025. t['fivegurmukhi'] = 0x0A6B;
  7026. t['fivehackarabic'] = 0x0665;
  7027. t['fivehangzhou'] = 0x3025;
  7028. t['fiveideographicparen'] = 0x3224;
  7029. t['fiveinferior'] = 0x2085;
  7030. t['fivemonospace'] = 0xFF15;
  7031. t['fiveoldstyle'] = 0xF735;
  7032. t['fiveparen'] = 0x2478;
  7033. t['fiveperiod'] = 0x248C;
  7034. t['fivepersian'] = 0x06F5;
  7035. t['fiveroman'] = 0x2174;
  7036. t['fivesuperior'] = 0x2075;
  7037. t['fivethai'] = 0x0E55;
  7038. t['fl'] = 0xFB02;
  7039. t['florin'] = 0x0192;
  7040. t['fmonospace'] = 0xFF46;
  7041. t['fmsquare'] = 0x3399;
  7042. t['fofanthai'] = 0x0E1F;
  7043. t['fofathai'] = 0x0E1D;
  7044. t['fongmanthai'] = 0x0E4F;
  7045. t['forall'] = 0x2200;
  7046. t['four'] = 0x0034;
  7047. t['fourarabic'] = 0x0664;
  7048. t['fourbengali'] = 0x09EA;
  7049. t['fourcircle'] = 0x2463;
  7050. t['fourcircleinversesansserif'] = 0x278D;
  7051. t['fourdeva'] = 0x096A;
  7052. t['fourgujarati'] = 0x0AEA;
  7053. t['fourgurmukhi'] = 0x0A6A;
  7054. t['fourhackarabic'] = 0x0664;
  7055. t['fourhangzhou'] = 0x3024;
  7056. t['fourideographicparen'] = 0x3223;
  7057. t['fourinferior'] = 0x2084;
  7058. t['fourmonospace'] = 0xFF14;
  7059. t['fournumeratorbengali'] = 0x09F7;
  7060. t['fouroldstyle'] = 0xF734;
  7061. t['fourparen'] = 0x2477;
  7062. t['fourperiod'] = 0x248B;
  7063. t['fourpersian'] = 0x06F4;
  7064. t['fourroman'] = 0x2173;
  7065. t['foursuperior'] = 0x2074;
  7066. t['fourteencircle'] = 0x246D;
  7067. t['fourteenparen'] = 0x2481;
  7068. t['fourteenperiod'] = 0x2495;
  7069. t['fourthai'] = 0x0E54;
  7070. t['fourthtonechinese'] = 0x02CB;
  7071. t['fparen'] = 0x24A1;
  7072. t['fraction'] = 0x2044;
  7073. t['franc'] = 0x20A3;
  7074. t['g'] = 0x0067;
  7075. t['gabengali'] = 0x0997;
  7076. t['gacute'] = 0x01F5;
  7077. t['gadeva'] = 0x0917;
  7078. t['gafarabic'] = 0x06AF;
  7079. t['gaffinalarabic'] = 0xFB93;
  7080. t['gafinitialarabic'] = 0xFB94;
  7081. t['gafmedialarabic'] = 0xFB95;
  7082. t['gagujarati'] = 0x0A97;
  7083. t['gagurmukhi'] = 0x0A17;
  7084. t['gahiragana'] = 0x304C;
  7085. t['gakatakana'] = 0x30AC;
  7086. t['gamma'] = 0x03B3;
  7087. t['gammalatinsmall'] = 0x0263;
  7088. t['gammasuperior'] = 0x02E0;
  7089. t['gangiacoptic'] = 0x03EB;
  7090. t['gbopomofo'] = 0x310D;
  7091. t['gbreve'] = 0x011F;
  7092. t['gcaron'] = 0x01E7;
  7093. t['gcedilla'] = 0x0123;
  7094. t['gcircle'] = 0x24D6;
  7095. t['gcircumflex'] = 0x011D;
  7096. t['gcommaaccent'] = 0x0123;
  7097. t['gdot'] = 0x0121;
  7098. t['gdotaccent'] = 0x0121;
  7099. t['gecyrillic'] = 0x0433;
  7100. t['gehiragana'] = 0x3052;
  7101. t['gekatakana'] = 0x30B2;
  7102. t['geometricallyequal'] = 0x2251;
  7103. t['gereshaccenthebrew'] = 0x059C;
  7104. t['gereshhebrew'] = 0x05F3;
  7105. t['gereshmuqdamhebrew'] = 0x059D;
  7106. t['germandbls'] = 0x00DF;
  7107. t['gershayimaccenthebrew'] = 0x059E;
  7108. t['gershayimhebrew'] = 0x05F4;
  7109. t['getamark'] = 0x3013;
  7110. t['ghabengali'] = 0x0998;
  7111. t['ghadarmenian'] = 0x0572;
  7112. t['ghadeva'] = 0x0918;
  7113. t['ghagujarati'] = 0x0A98;
  7114. t['ghagurmukhi'] = 0x0A18;
  7115. t['ghainarabic'] = 0x063A;
  7116. t['ghainfinalarabic'] = 0xFECE;
  7117. t['ghaininitialarabic'] = 0xFECF;
  7118. t['ghainmedialarabic'] = 0xFED0;
  7119. t['ghemiddlehookcyrillic'] = 0x0495;
  7120. t['ghestrokecyrillic'] = 0x0493;
  7121. t['gheupturncyrillic'] = 0x0491;
  7122. t['ghhadeva'] = 0x095A;
  7123. t['ghhagurmukhi'] = 0x0A5A;
  7124. t['ghook'] = 0x0260;
  7125. t['ghzsquare'] = 0x3393;
  7126. t['gihiragana'] = 0x304E;
  7127. t['gikatakana'] = 0x30AE;
  7128. t['gimarmenian'] = 0x0563;
  7129. t['gimel'] = 0x05D2;
  7130. t['gimeldagesh'] = 0xFB32;
  7131. t['gimeldageshhebrew'] = 0xFB32;
  7132. t['gimelhebrew'] = 0x05D2;
  7133. t['gjecyrillic'] = 0x0453;
  7134. t['glottalinvertedstroke'] = 0x01BE;
  7135. t['glottalstop'] = 0x0294;
  7136. t['glottalstopinverted'] = 0x0296;
  7137. t['glottalstopmod'] = 0x02C0;
  7138. t['glottalstopreversed'] = 0x0295;
  7139. t['glottalstopreversedmod'] = 0x02C1;
  7140. t['glottalstopreversedsuperior'] = 0x02E4;
  7141. t['glottalstopstroke'] = 0x02A1;
  7142. t['glottalstopstrokereversed'] = 0x02A2;
  7143. t['gmacron'] = 0x1E21;
  7144. t['gmonospace'] = 0xFF47;
  7145. t['gohiragana'] = 0x3054;
  7146. t['gokatakana'] = 0x30B4;
  7147. t['gparen'] = 0x24A2;
  7148. t['gpasquare'] = 0x33AC;
  7149. t['gradient'] = 0x2207;
  7150. t['grave'] = 0x0060;
  7151. t['gravebelowcmb'] = 0x0316;
  7152. t['gravecmb'] = 0x0300;
  7153. t['gravecomb'] = 0x0300;
  7154. t['gravedeva'] = 0x0953;
  7155. t['gravelowmod'] = 0x02CE;
  7156. t['gravemonospace'] = 0xFF40;
  7157. t['gravetonecmb'] = 0x0340;
  7158. t['greater'] = 0x003E;
  7159. t['greaterequal'] = 0x2265;
  7160. t['greaterequalorless'] = 0x22DB;
  7161. t['greatermonospace'] = 0xFF1E;
  7162. t['greaterorequivalent'] = 0x2273;
  7163. t['greaterorless'] = 0x2277;
  7164. t['greateroverequal'] = 0x2267;
  7165. t['greatersmall'] = 0xFE65;
  7166. t['gscript'] = 0x0261;
  7167. t['gstroke'] = 0x01E5;
  7168. t['guhiragana'] = 0x3050;
  7169. t['guillemotleft'] = 0x00AB;
  7170. t['guillemotright'] = 0x00BB;
  7171. t['guilsinglleft'] = 0x2039;
  7172. t['guilsinglright'] = 0x203A;
  7173. t['gukatakana'] = 0x30B0;
  7174. t['guramusquare'] = 0x3318;
  7175. t['gysquare'] = 0x33C9;
  7176. t['h'] = 0x0068;
  7177. t['haabkhasiancyrillic'] = 0x04A9;
  7178. t['haaltonearabic'] = 0x06C1;
  7179. t['habengali'] = 0x09B9;
  7180. t['hadescendercyrillic'] = 0x04B3;
  7181. t['hadeva'] = 0x0939;
  7182. t['hagujarati'] = 0x0AB9;
  7183. t['hagurmukhi'] = 0x0A39;
  7184. t['haharabic'] = 0x062D;
  7185. t['hahfinalarabic'] = 0xFEA2;
  7186. t['hahinitialarabic'] = 0xFEA3;
  7187. t['hahiragana'] = 0x306F;
  7188. t['hahmedialarabic'] = 0xFEA4;
  7189. t['haitusquare'] = 0x332A;
  7190. t['hakatakana'] = 0x30CF;
  7191. t['hakatakanahalfwidth'] = 0xFF8A;
  7192. t['halantgurmukhi'] = 0x0A4D;
  7193. t['hamzaarabic'] = 0x0621;
  7194. t['hamzalowarabic'] = 0x0621;
  7195. t['hangulfiller'] = 0x3164;
  7196. t['hardsigncyrillic'] = 0x044A;
  7197. t['harpoonleftbarbup'] = 0x21BC;
  7198. t['harpoonrightbarbup'] = 0x21C0;
  7199. t['hasquare'] = 0x33CA;
  7200. t['hatafpatah'] = 0x05B2;
  7201. t['hatafpatah16'] = 0x05B2;
  7202. t['hatafpatah23'] = 0x05B2;
  7203. t['hatafpatah2f'] = 0x05B2;
  7204. t['hatafpatahhebrew'] = 0x05B2;
  7205. t['hatafpatahnarrowhebrew'] = 0x05B2;
  7206. t['hatafpatahquarterhebrew'] = 0x05B2;
  7207. t['hatafpatahwidehebrew'] = 0x05B2;
  7208. t['hatafqamats'] = 0x05B3;
  7209. t['hatafqamats1b'] = 0x05B3;
  7210. t['hatafqamats28'] = 0x05B3;
  7211. t['hatafqamats34'] = 0x05B3;
  7212. t['hatafqamatshebrew'] = 0x05B3;
  7213. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  7214. t['hatafqamatsquarterhebrew'] = 0x05B3;
  7215. t['hatafqamatswidehebrew'] = 0x05B3;
  7216. t['hatafsegol'] = 0x05B1;
  7217. t['hatafsegol17'] = 0x05B1;
  7218. t['hatafsegol24'] = 0x05B1;
  7219. t['hatafsegol30'] = 0x05B1;
  7220. t['hatafsegolhebrew'] = 0x05B1;
  7221. t['hatafsegolnarrowhebrew'] = 0x05B1;
  7222. t['hatafsegolquarterhebrew'] = 0x05B1;
  7223. t['hatafsegolwidehebrew'] = 0x05B1;
  7224. t['hbar'] = 0x0127;
  7225. t['hbopomofo'] = 0x310F;
  7226. t['hbrevebelow'] = 0x1E2B;
  7227. t['hcedilla'] = 0x1E29;
  7228. t['hcircle'] = 0x24D7;
  7229. t['hcircumflex'] = 0x0125;
  7230. t['hdieresis'] = 0x1E27;
  7231. t['hdotaccent'] = 0x1E23;
  7232. t['hdotbelow'] = 0x1E25;
  7233. t['he'] = 0x05D4;
  7234. t['heart'] = 0x2665;
  7235. t['heartsuitblack'] = 0x2665;
  7236. t['heartsuitwhite'] = 0x2661;
  7237. t['hedagesh'] = 0xFB34;
  7238. t['hedageshhebrew'] = 0xFB34;
  7239. t['hehaltonearabic'] = 0x06C1;
  7240. t['heharabic'] = 0x0647;
  7241. t['hehebrew'] = 0x05D4;
  7242. t['hehfinalaltonearabic'] = 0xFBA7;
  7243. t['hehfinalalttwoarabic'] = 0xFEEA;
  7244. t['hehfinalarabic'] = 0xFEEA;
  7245. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  7246. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  7247. t['hehinitialaltonearabic'] = 0xFBA8;
  7248. t['hehinitialarabic'] = 0xFEEB;
  7249. t['hehiragana'] = 0x3078;
  7250. t['hehmedialaltonearabic'] = 0xFBA9;
  7251. t['hehmedialarabic'] = 0xFEEC;
  7252. t['heiseierasquare'] = 0x337B;
  7253. t['hekatakana'] = 0x30D8;
  7254. t['hekatakanahalfwidth'] = 0xFF8D;
  7255. t['hekutaarusquare'] = 0x3336;
  7256. t['henghook'] = 0x0267;
  7257. t['herutusquare'] = 0x3339;
  7258. t['het'] = 0x05D7;
  7259. t['hethebrew'] = 0x05D7;
  7260. t['hhook'] = 0x0266;
  7261. t['hhooksuperior'] = 0x02B1;
  7262. t['hieuhacirclekorean'] = 0x327B;
  7263. t['hieuhaparenkorean'] = 0x321B;
  7264. t['hieuhcirclekorean'] = 0x326D;
  7265. t['hieuhkorean'] = 0x314E;
  7266. t['hieuhparenkorean'] = 0x320D;
  7267. t['hihiragana'] = 0x3072;
  7268. t['hikatakana'] = 0x30D2;
  7269. t['hikatakanahalfwidth'] = 0xFF8B;
  7270. t['hiriq'] = 0x05B4;
  7271. t['hiriq14'] = 0x05B4;
  7272. t['hiriq21'] = 0x05B4;
  7273. t['hiriq2d'] = 0x05B4;
  7274. t['hiriqhebrew'] = 0x05B4;
  7275. t['hiriqnarrowhebrew'] = 0x05B4;
  7276. t['hiriqquarterhebrew'] = 0x05B4;
  7277. t['hiriqwidehebrew'] = 0x05B4;
  7278. t['hlinebelow'] = 0x1E96;
  7279. t['hmonospace'] = 0xFF48;
  7280. t['hoarmenian'] = 0x0570;
  7281. t['hohipthai'] = 0x0E2B;
  7282. t['hohiragana'] = 0x307B;
  7283. t['hokatakana'] = 0x30DB;
  7284. t['hokatakanahalfwidth'] = 0xFF8E;
  7285. t['holam'] = 0x05B9;
  7286. t['holam19'] = 0x05B9;
  7287. t['holam26'] = 0x05B9;
  7288. t['holam32'] = 0x05B9;
  7289. t['holamhebrew'] = 0x05B9;
  7290. t['holamnarrowhebrew'] = 0x05B9;
  7291. t['holamquarterhebrew'] = 0x05B9;
  7292. t['holamwidehebrew'] = 0x05B9;
  7293. t['honokhukthai'] = 0x0E2E;
  7294. t['hookabovecomb'] = 0x0309;
  7295. t['hookcmb'] = 0x0309;
  7296. t['hookpalatalizedbelowcmb'] = 0x0321;
  7297. t['hookretroflexbelowcmb'] = 0x0322;
  7298. t['hoonsquare'] = 0x3342;
  7299. t['horicoptic'] = 0x03E9;
  7300. t['horizontalbar'] = 0x2015;
  7301. t['horncmb'] = 0x031B;
  7302. t['hotsprings'] = 0x2668;
  7303. t['house'] = 0x2302;
  7304. t['hparen'] = 0x24A3;
  7305. t['hsuperior'] = 0x02B0;
  7306. t['hturned'] = 0x0265;
  7307. t['huhiragana'] = 0x3075;
  7308. t['huiitosquare'] = 0x3333;
  7309. t['hukatakana'] = 0x30D5;
  7310. t['hukatakanahalfwidth'] = 0xFF8C;
  7311. t['hungarumlaut'] = 0x02DD;
  7312. t['hungarumlautcmb'] = 0x030B;
  7313. t['hv'] = 0x0195;
  7314. t['hyphen'] = 0x002D;
  7315. t['hypheninferior'] = 0xF6E5;
  7316. t['hyphenmonospace'] = 0xFF0D;
  7317. t['hyphensmall'] = 0xFE63;
  7318. t['hyphensuperior'] = 0xF6E6;
  7319. t['hyphentwo'] = 0x2010;
  7320. t['i'] = 0x0069;
  7321. t['iacute'] = 0x00ED;
  7322. t['iacyrillic'] = 0x044F;
  7323. t['ibengali'] = 0x0987;
  7324. t['ibopomofo'] = 0x3127;
  7325. t['ibreve'] = 0x012D;
  7326. t['icaron'] = 0x01D0;
  7327. t['icircle'] = 0x24D8;
  7328. t['icircumflex'] = 0x00EE;
  7329. t['icyrillic'] = 0x0456;
  7330. t['idblgrave'] = 0x0209;
  7331. t['ideographearthcircle'] = 0x328F;
  7332. t['ideographfirecircle'] = 0x328B;
  7333. t['ideographicallianceparen'] = 0x323F;
  7334. t['ideographiccallparen'] = 0x323A;
  7335. t['ideographiccentrecircle'] = 0x32A5;
  7336. t['ideographicclose'] = 0x3006;
  7337. t['ideographiccomma'] = 0x3001;
  7338. t['ideographiccommaleft'] = 0xFF64;
  7339. t['ideographiccongratulationparen'] = 0x3237;
  7340. t['ideographiccorrectcircle'] = 0x32A3;
  7341. t['ideographicearthparen'] = 0x322F;
  7342. t['ideographicenterpriseparen'] = 0x323D;
  7343. t['ideographicexcellentcircle'] = 0x329D;
  7344. t['ideographicfestivalparen'] = 0x3240;
  7345. t['ideographicfinancialcircle'] = 0x3296;
  7346. t['ideographicfinancialparen'] = 0x3236;
  7347. t['ideographicfireparen'] = 0x322B;
  7348. t['ideographichaveparen'] = 0x3232;
  7349. t['ideographichighcircle'] = 0x32A4;
  7350. t['ideographiciterationmark'] = 0x3005;
  7351. t['ideographiclaborcircle'] = 0x3298;
  7352. t['ideographiclaborparen'] = 0x3238;
  7353. t['ideographicleftcircle'] = 0x32A7;
  7354. t['ideographiclowcircle'] = 0x32A6;
  7355. t['ideographicmedicinecircle'] = 0x32A9;
  7356. t['ideographicmetalparen'] = 0x322E;
  7357. t['ideographicmoonparen'] = 0x322A;
  7358. t['ideographicnameparen'] = 0x3234;
  7359. t['ideographicperiod'] = 0x3002;
  7360. t['ideographicprintcircle'] = 0x329E;
  7361. t['ideographicreachparen'] = 0x3243;
  7362. t['ideographicrepresentparen'] = 0x3239;
  7363. t['ideographicresourceparen'] = 0x323E;
  7364. t['ideographicrightcircle'] = 0x32A8;
  7365. t['ideographicsecretcircle'] = 0x3299;
  7366. t['ideographicselfparen'] = 0x3242;
  7367. t['ideographicsocietyparen'] = 0x3233;
  7368. t['ideographicspace'] = 0x3000;
  7369. t['ideographicspecialparen'] = 0x3235;
  7370. t['ideographicstockparen'] = 0x3231;
  7371. t['ideographicstudyparen'] = 0x323B;
  7372. t['ideographicsunparen'] = 0x3230;
  7373. t['ideographicsuperviseparen'] = 0x323C;
  7374. t['ideographicwaterparen'] = 0x322C;
  7375. t['ideographicwoodparen'] = 0x322D;
  7376. t['ideographiczero'] = 0x3007;
  7377. t['ideographmetalcircle'] = 0x328E;
  7378. t['ideographmooncircle'] = 0x328A;
  7379. t['ideographnamecircle'] = 0x3294;
  7380. t['ideographsuncircle'] = 0x3290;
  7381. t['ideographwatercircle'] = 0x328C;
  7382. t['ideographwoodcircle'] = 0x328D;
  7383. t['ideva'] = 0x0907;
  7384. t['idieresis'] = 0x00EF;
  7385. t['idieresisacute'] = 0x1E2F;
  7386. t['idieresiscyrillic'] = 0x04E5;
  7387. t['idotbelow'] = 0x1ECB;
  7388. t['iebrevecyrillic'] = 0x04D7;
  7389. t['iecyrillic'] = 0x0435;
  7390. t['ieungacirclekorean'] = 0x3275;
  7391. t['ieungaparenkorean'] = 0x3215;
  7392. t['ieungcirclekorean'] = 0x3267;
  7393. t['ieungkorean'] = 0x3147;
  7394. t['ieungparenkorean'] = 0x3207;
  7395. t['igrave'] = 0x00EC;
  7396. t['igujarati'] = 0x0A87;
  7397. t['igurmukhi'] = 0x0A07;
  7398. t['ihiragana'] = 0x3044;
  7399. t['ihookabove'] = 0x1EC9;
  7400. t['iibengali'] = 0x0988;
  7401. t['iicyrillic'] = 0x0438;
  7402. t['iideva'] = 0x0908;
  7403. t['iigujarati'] = 0x0A88;
  7404. t['iigurmukhi'] = 0x0A08;
  7405. t['iimatragurmukhi'] = 0x0A40;
  7406. t['iinvertedbreve'] = 0x020B;
  7407. t['iishortcyrillic'] = 0x0439;
  7408. t['iivowelsignbengali'] = 0x09C0;
  7409. t['iivowelsigndeva'] = 0x0940;
  7410. t['iivowelsigngujarati'] = 0x0AC0;
  7411. t['ij'] = 0x0133;
  7412. t['ikatakana'] = 0x30A4;
  7413. t['ikatakanahalfwidth'] = 0xFF72;
  7414. t['ikorean'] = 0x3163;
  7415. t['ilde'] = 0x02DC;
  7416. t['iluyhebrew'] = 0x05AC;
  7417. t['imacron'] = 0x012B;
  7418. t['imacroncyrillic'] = 0x04E3;
  7419. t['imageorapproximatelyequal'] = 0x2253;
  7420. t['imatragurmukhi'] = 0x0A3F;
  7421. t['imonospace'] = 0xFF49;
  7422. t['increment'] = 0x2206;
  7423. t['infinity'] = 0x221E;
  7424. t['iniarmenian'] = 0x056B;
  7425. t['integral'] = 0x222B;
  7426. t['integralbottom'] = 0x2321;
  7427. t['integralbt'] = 0x2321;
  7428. t['integralex'] = 0xF8F5;
  7429. t['integraltop'] = 0x2320;
  7430. t['integraltp'] = 0x2320;
  7431. t['intersection'] = 0x2229;
  7432. t['intisquare'] = 0x3305;
  7433. t['invbullet'] = 0x25D8;
  7434. t['invcircle'] = 0x25D9;
  7435. t['invsmileface'] = 0x263B;
  7436. t['iocyrillic'] = 0x0451;
  7437. t['iogonek'] = 0x012F;
  7438. t['iota'] = 0x03B9;
  7439. t['iotadieresis'] = 0x03CA;
  7440. t['iotadieresistonos'] = 0x0390;
  7441. t['iotalatin'] = 0x0269;
  7442. t['iotatonos'] = 0x03AF;
  7443. t['iparen'] = 0x24A4;
  7444. t['irigurmukhi'] = 0x0A72;
  7445. t['ismallhiragana'] = 0x3043;
  7446. t['ismallkatakana'] = 0x30A3;
  7447. t['ismallkatakanahalfwidth'] = 0xFF68;
  7448. t['issharbengali'] = 0x09FA;
  7449. t['istroke'] = 0x0268;
  7450. t['isuperior'] = 0xF6ED;
  7451. t['iterationhiragana'] = 0x309D;
  7452. t['iterationkatakana'] = 0x30FD;
  7453. t['itilde'] = 0x0129;
  7454. t['itildebelow'] = 0x1E2D;
  7455. t['iubopomofo'] = 0x3129;
  7456. t['iucyrillic'] = 0x044E;
  7457. t['ivowelsignbengali'] = 0x09BF;
  7458. t['ivowelsigndeva'] = 0x093F;
  7459. t['ivowelsigngujarati'] = 0x0ABF;
  7460. t['izhitsacyrillic'] = 0x0475;
  7461. t['izhitsadblgravecyrillic'] = 0x0477;
  7462. t['j'] = 0x006A;
  7463. t['jaarmenian'] = 0x0571;
  7464. t['jabengali'] = 0x099C;
  7465. t['jadeva'] = 0x091C;
  7466. t['jagujarati'] = 0x0A9C;
  7467. t['jagurmukhi'] = 0x0A1C;
  7468. t['jbopomofo'] = 0x3110;
  7469. t['jcaron'] = 0x01F0;
  7470. t['jcircle'] = 0x24D9;
  7471. t['jcircumflex'] = 0x0135;
  7472. t['jcrossedtail'] = 0x029D;
  7473. t['jdotlessstroke'] = 0x025F;
  7474. t['jecyrillic'] = 0x0458;
  7475. t['jeemarabic'] = 0x062C;
  7476. t['jeemfinalarabic'] = 0xFE9E;
  7477. t['jeeminitialarabic'] = 0xFE9F;
  7478. t['jeemmedialarabic'] = 0xFEA0;
  7479. t['jeharabic'] = 0x0698;
  7480. t['jehfinalarabic'] = 0xFB8B;
  7481. t['jhabengali'] = 0x099D;
  7482. t['jhadeva'] = 0x091D;
  7483. t['jhagujarati'] = 0x0A9D;
  7484. t['jhagurmukhi'] = 0x0A1D;
  7485. t['jheharmenian'] = 0x057B;
  7486. t['jis'] = 0x3004;
  7487. t['jmonospace'] = 0xFF4A;
  7488. t['jparen'] = 0x24A5;
  7489. t['jsuperior'] = 0x02B2;
  7490. t['k'] = 0x006B;
  7491. t['kabashkircyrillic'] = 0x04A1;
  7492. t['kabengali'] = 0x0995;
  7493. t['kacute'] = 0x1E31;
  7494. t['kacyrillic'] = 0x043A;
  7495. t['kadescendercyrillic'] = 0x049B;
  7496. t['kadeva'] = 0x0915;
  7497. t['kaf'] = 0x05DB;
  7498. t['kafarabic'] = 0x0643;
  7499. t['kafdagesh'] = 0xFB3B;
  7500. t['kafdageshhebrew'] = 0xFB3B;
  7501. t['kaffinalarabic'] = 0xFEDA;
  7502. t['kafhebrew'] = 0x05DB;
  7503. t['kafinitialarabic'] = 0xFEDB;
  7504. t['kafmedialarabic'] = 0xFEDC;
  7505. t['kafrafehebrew'] = 0xFB4D;
  7506. t['kagujarati'] = 0x0A95;
  7507. t['kagurmukhi'] = 0x0A15;
  7508. t['kahiragana'] = 0x304B;
  7509. t['kahookcyrillic'] = 0x04C4;
  7510. t['kakatakana'] = 0x30AB;
  7511. t['kakatakanahalfwidth'] = 0xFF76;
  7512. t['kappa'] = 0x03BA;
  7513. t['kappasymbolgreek'] = 0x03F0;
  7514. t['kapyeounmieumkorean'] = 0x3171;
  7515. t['kapyeounphieuphkorean'] = 0x3184;
  7516. t['kapyeounpieupkorean'] = 0x3178;
  7517. t['kapyeounssangpieupkorean'] = 0x3179;
  7518. t['karoriisquare'] = 0x330D;
  7519. t['kashidaautoarabic'] = 0x0640;
  7520. t['kashidaautonosidebearingarabic'] = 0x0640;
  7521. t['kasmallkatakana'] = 0x30F5;
  7522. t['kasquare'] = 0x3384;
  7523. t['kasraarabic'] = 0x0650;
  7524. t['kasratanarabic'] = 0x064D;
  7525. t['kastrokecyrillic'] = 0x049F;
  7526. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7527. t['kaverticalstrokecyrillic'] = 0x049D;
  7528. t['kbopomofo'] = 0x310E;
  7529. t['kcalsquare'] = 0x3389;
  7530. t['kcaron'] = 0x01E9;
  7531. t['kcedilla'] = 0x0137;
  7532. t['kcircle'] = 0x24DA;
  7533. t['kcommaaccent'] = 0x0137;
  7534. t['kdotbelow'] = 0x1E33;
  7535. t['keharmenian'] = 0x0584;
  7536. t['kehiragana'] = 0x3051;
  7537. t['kekatakana'] = 0x30B1;
  7538. t['kekatakanahalfwidth'] = 0xFF79;
  7539. t['kenarmenian'] = 0x056F;
  7540. t['kesmallkatakana'] = 0x30F6;
  7541. t['kgreenlandic'] = 0x0138;
  7542. t['khabengali'] = 0x0996;
  7543. t['khacyrillic'] = 0x0445;
  7544. t['khadeva'] = 0x0916;
  7545. t['khagujarati'] = 0x0A96;
  7546. t['khagurmukhi'] = 0x0A16;
  7547. t['khaharabic'] = 0x062E;
  7548. t['khahfinalarabic'] = 0xFEA6;
  7549. t['khahinitialarabic'] = 0xFEA7;
  7550. t['khahmedialarabic'] = 0xFEA8;
  7551. t['kheicoptic'] = 0x03E7;
  7552. t['khhadeva'] = 0x0959;
  7553. t['khhagurmukhi'] = 0x0A59;
  7554. t['khieukhacirclekorean'] = 0x3278;
  7555. t['khieukhaparenkorean'] = 0x3218;
  7556. t['khieukhcirclekorean'] = 0x326A;
  7557. t['khieukhkorean'] = 0x314B;
  7558. t['khieukhparenkorean'] = 0x320A;
  7559. t['khokhaithai'] = 0x0E02;
  7560. t['khokhonthai'] = 0x0E05;
  7561. t['khokhuatthai'] = 0x0E03;
  7562. t['khokhwaithai'] = 0x0E04;
  7563. t['khomutthai'] = 0x0E5B;
  7564. t['khook'] = 0x0199;
  7565. t['khorakhangthai'] = 0x0E06;
  7566. t['khzsquare'] = 0x3391;
  7567. t['kihiragana'] = 0x304D;
  7568. t['kikatakana'] = 0x30AD;
  7569. t['kikatakanahalfwidth'] = 0xFF77;
  7570. t['kiroguramusquare'] = 0x3315;
  7571. t['kiromeetorusquare'] = 0x3316;
  7572. t['kirosquare'] = 0x3314;
  7573. t['kiyeokacirclekorean'] = 0x326E;
  7574. t['kiyeokaparenkorean'] = 0x320E;
  7575. t['kiyeokcirclekorean'] = 0x3260;
  7576. t['kiyeokkorean'] = 0x3131;
  7577. t['kiyeokparenkorean'] = 0x3200;
  7578. t['kiyeoksioskorean'] = 0x3133;
  7579. t['kjecyrillic'] = 0x045C;
  7580. t['klinebelow'] = 0x1E35;
  7581. t['klsquare'] = 0x3398;
  7582. t['kmcubedsquare'] = 0x33A6;
  7583. t['kmonospace'] = 0xFF4B;
  7584. t['kmsquaredsquare'] = 0x33A2;
  7585. t['kohiragana'] = 0x3053;
  7586. t['kohmsquare'] = 0x33C0;
  7587. t['kokaithai'] = 0x0E01;
  7588. t['kokatakana'] = 0x30B3;
  7589. t['kokatakanahalfwidth'] = 0xFF7A;
  7590. t['kooposquare'] = 0x331E;
  7591. t['koppacyrillic'] = 0x0481;
  7592. t['koreanstandardsymbol'] = 0x327F;
  7593. t['koroniscmb'] = 0x0343;
  7594. t['kparen'] = 0x24A6;
  7595. t['kpasquare'] = 0x33AA;
  7596. t['ksicyrillic'] = 0x046F;
  7597. t['ktsquare'] = 0x33CF;
  7598. t['kturned'] = 0x029E;
  7599. t['kuhiragana'] = 0x304F;
  7600. t['kukatakana'] = 0x30AF;
  7601. t['kukatakanahalfwidth'] = 0xFF78;
  7602. t['kvsquare'] = 0x33B8;
  7603. t['kwsquare'] = 0x33BE;
  7604. t['l'] = 0x006C;
  7605. t['labengali'] = 0x09B2;
  7606. t['lacute'] = 0x013A;
  7607. t['ladeva'] = 0x0932;
  7608. t['lagujarati'] = 0x0AB2;
  7609. t['lagurmukhi'] = 0x0A32;
  7610. t['lakkhangyaothai'] = 0x0E45;
  7611. t['lamaleffinalarabic'] = 0xFEFC;
  7612. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7613. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7614. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7615. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7616. t['lamalefisolatedarabic'] = 0xFEFB;
  7617. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7618. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7619. t['lamarabic'] = 0x0644;
  7620. t['lambda'] = 0x03BB;
  7621. t['lambdastroke'] = 0x019B;
  7622. t['lamed'] = 0x05DC;
  7623. t['lameddagesh'] = 0xFB3C;
  7624. t['lameddageshhebrew'] = 0xFB3C;
  7625. t['lamedhebrew'] = 0x05DC;
  7626. t['lamfinalarabic'] = 0xFEDE;
  7627. t['lamhahinitialarabic'] = 0xFCCA;
  7628. t['laminitialarabic'] = 0xFEDF;
  7629. t['lamjeeminitialarabic'] = 0xFCC9;
  7630. t['lamkhahinitialarabic'] = 0xFCCB;
  7631. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7632. t['lammedialarabic'] = 0xFEE0;
  7633. t['lammeemhahinitialarabic'] = 0xFD88;
  7634. t['lammeeminitialarabic'] = 0xFCCC;
  7635. t['largecircle'] = 0x25EF;
  7636. t['lbar'] = 0x019A;
  7637. t['lbelt'] = 0x026C;
  7638. t['lbopomofo'] = 0x310C;
  7639. t['lcaron'] = 0x013E;
  7640. t['lcedilla'] = 0x013C;
  7641. t['lcircle'] = 0x24DB;
  7642. t['lcircumflexbelow'] = 0x1E3D;
  7643. t['lcommaaccent'] = 0x013C;
  7644. t['ldot'] = 0x0140;
  7645. t['ldotaccent'] = 0x0140;
  7646. t['ldotbelow'] = 0x1E37;
  7647. t['ldotbelowmacron'] = 0x1E39;
  7648. t['leftangleabovecmb'] = 0x031A;
  7649. t['lefttackbelowcmb'] = 0x0318;
  7650. t['less'] = 0x003C;
  7651. t['lessequal'] = 0x2264;
  7652. t['lessequalorgreater'] = 0x22DA;
  7653. t['lessmonospace'] = 0xFF1C;
  7654. t['lessorequivalent'] = 0x2272;
  7655. t['lessorgreater'] = 0x2276;
  7656. t['lessoverequal'] = 0x2266;
  7657. t['lesssmall'] = 0xFE64;
  7658. t['lezh'] = 0x026E;
  7659. t['lfblock'] = 0x258C;
  7660. t['lhookretroflex'] = 0x026D;
  7661. t['lira'] = 0x20A4;
  7662. t['liwnarmenian'] = 0x056C;
  7663. t['lj'] = 0x01C9;
  7664. t['ljecyrillic'] = 0x0459;
  7665. t['ll'] = 0xF6C0;
  7666. t['lladeva'] = 0x0933;
  7667. t['llagujarati'] = 0x0AB3;
  7668. t['llinebelow'] = 0x1E3B;
  7669. t['llladeva'] = 0x0934;
  7670. t['llvocalicbengali'] = 0x09E1;
  7671. t['llvocalicdeva'] = 0x0961;
  7672. t['llvocalicvowelsignbengali'] = 0x09E3;
  7673. t['llvocalicvowelsigndeva'] = 0x0963;
  7674. t['lmiddletilde'] = 0x026B;
  7675. t['lmonospace'] = 0xFF4C;
  7676. t['lmsquare'] = 0x33D0;
  7677. t['lochulathai'] = 0x0E2C;
  7678. t['logicaland'] = 0x2227;
  7679. t['logicalnot'] = 0x00AC;
  7680. t['logicalnotreversed'] = 0x2310;
  7681. t['logicalor'] = 0x2228;
  7682. t['lolingthai'] = 0x0E25;
  7683. t['longs'] = 0x017F;
  7684. t['lowlinecenterline'] = 0xFE4E;
  7685. t['lowlinecmb'] = 0x0332;
  7686. t['lowlinedashed'] = 0xFE4D;
  7687. t['lozenge'] = 0x25CA;
  7688. t['lparen'] = 0x24A7;
  7689. t['lslash'] = 0x0142;
  7690. t['lsquare'] = 0x2113;
  7691. t['lsuperior'] = 0xF6EE;
  7692. t['ltshade'] = 0x2591;
  7693. t['luthai'] = 0x0E26;
  7694. t['lvocalicbengali'] = 0x098C;
  7695. t['lvocalicdeva'] = 0x090C;
  7696. t['lvocalicvowelsignbengali'] = 0x09E2;
  7697. t['lvocalicvowelsigndeva'] = 0x0962;
  7698. t['lxsquare'] = 0x33D3;
  7699. t['m'] = 0x006D;
  7700. t['mabengali'] = 0x09AE;
  7701. t['macron'] = 0x00AF;
  7702. t['macronbelowcmb'] = 0x0331;
  7703. t['macroncmb'] = 0x0304;
  7704. t['macronlowmod'] = 0x02CD;
  7705. t['macronmonospace'] = 0xFFE3;
  7706. t['macute'] = 0x1E3F;
  7707. t['madeva'] = 0x092E;
  7708. t['magujarati'] = 0x0AAE;
  7709. t['magurmukhi'] = 0x0A2E;
  7710. t['mahapakhhebrew'] = 0x05A4;
  7711. t['mahapakhlefthebrew'] = 0x05A4;
  7712. t['mahiragana'] = 0x307E;
  7713. t['maichattawalowleftthai'] = 0xF895;
  7714. t['maichattawalowrightthai'] = 0xF894;
  7715. t['maichattawathai'] = 0x0E4B;
  7716. t['maichattawaupperleftthai'] = 0xF893;
  7717. t['maieklowleftthai'] = 0xF88C;
  7718. t['maieklowrightthai'] = 0xF88B;
  7719. t['maiekthai'] = 0x0E48;
  7720. t['maiekupperleftthai'] = 0xF88A;
  7721. t['maihanakatleftthai'] = 0xF884;
  7722. t['maihanakatthai'] = 0x0E31;
  7723. t['maitaikhuleftthai'] = 0xF889;
  7724. t['maitaikhuthai'] = 0x0E47;
  7725. t['maitholowleftthai'] = 0xF88F;
  7726. t['maitholowrightthai'] = 0xF88E;
  7727. t['maithothai'] = 0x0E49;
  7728. t['maithoupperleftthai'] = 0xF88D;
  7729. t['maitrilowleftthai'] = 0xF892;
  7730. t['maitrilowrightthai'] = 0xF891;
  7731. t['maitrithai'] = 0x0E4A;
  7732. t['maitriupperleftthai'] = 0xF890;
  7733. t['maiyamokthai'] = 0x0E46;
  7734. t['makatakana'] = 0x30DE;
  7735. t['makatakanahalfwidth'] = 0xFF8F;
  7736. t['male'] = 0x2642;
  7737. t['mansyonsquare'] = 0x3347;
  7738. t['maqafhebrew'] = 0x05BE;
  7739. t['mars'] = 0x2642;
  7740. t['masoracirclehebrew'] = 0x05AF;
  7741. t['masquare'] = 0x3383;
  7742. t['mbopomofo'] = 0x3107;
  7743. t['mbsquare'] = 0x33D4;
  7744. t['mcircle'] = 0x24DC;
  7745. t['mcubedsquare'] = 0x33A5;
  7746. t['mdotaccent'] = 0x1E41;
  7747. t['mdotbelow'] = 0x1E43;
  7748. t['meemarabic'] = 0x0645;
  7749. t['meemfinalarabic'] = 0xFEE2;
  7750. t['meeminitialarabic'] = 0xFEE3;
  7751. t['meemmedialarabic'] = 0xFEE4;
  7752. t['meemmeeminitialarabic'] = 0xFCD1;
  7753. t['meemmeemisolatedarabic'] = 0xFC48;
  7754. t['meetorusquare'] = 0x334D;
  7755. t['mehiragana'] = 0x3081;
  7756. t['meizierasquare'] = 0x337E;
  7757. t['mekatakana'] = 0x30E1;
  7758. t['mekatakanahalfwidth'] = 0xFF92;
  7759. t['mem'] = 0x05DE;
  7760. t['memdagesh'] = 0xFB3E;
  7761. t['memdageshhebrew'] = 0xFB3E;
  7762. t['memhebrew'] = 0x05DE;
  7763. t['menarmenian'] = 0x0574;
  7764. t['merkhahebrew'] = 0x05A5;
  7765. t['merkhakefulahebrew'] = 0x05A6;
  7766. t['merkhakefulalefthebrew'] = 0x05A6;
  7767. t['merkhalefthebrew'] = 0x05A5;
  7768. t['mhook'] = 0x0271;
  7769. t['mhzsquare'] = 0x3392;
  7770. t['middledotkatakanahalfwidth'] = 0xFF65;
  7771. t['middot'] = 0x00B7;
  7772. t['mieumacirclekorean'] = 0x3272;
  7773. t['mieumaparenkorean'] = 0x3212;
  7774. t['mieumcirclekorean'] = 0x3264;
  7775. t['mieumkorean'] = 0x3141;
  7776. t['mieumpansioskorean'] = 0x3170;
  7777. t['mieumparenkorean'] = 0x3204;
  7778. t['mieumpieupkorean'] = 0x316E;
  7779. t['mieumsioskorean'] = 0x316F;
  7780. t['mihiragana'] = 0x307F;
  7781. t['mikatakana'] = 0x30DF;
  7782. t['mikatakanahalfwidth'] = 0xFF90;
  7783. t['minus'] = 0x2212;
  7784. t['minusbelowcmb'] = 0x0320;
  7785. t['minuscircle'] = 0x2296;
  7786. t['minusmod'] = 0x02D7;
  7787. t['minusplus'] = 0x2213;
  7788. t['minute'] = 0x2032;
  7789. t['miribaarusquare'] = 0x334A;
  7790. t['mirisquare'] = 0x3349;
  7791. t['mlonglegturned'] = 0x0270;
  7792. t['mlsquare'] = 0x3396;
  7793. t['mmcubedsquare'] = 0x33A3;
  7794. t['mmonospace'] = 0xFF4D;
  7795. t['mmsquaredsquare'] = 0x339F;
  7796. t['mohiragana'] = 0x3082;
  7797. t['mohmsquare'] = 0x33C1;
  7798. t['mokatakana'] = 0x30E2;
  7799. t['mokatakanahalfwidth'] = 0xFF93;
  7800. t['molsquare'] = 0x33D6;
  7801. t['momathai'] = 0x0E21;
  7802. t['moverssquare'] = 0x33A7;
  7803. t['moverssquaredsquare'] = 0x33A8;
  7804. t['mparen'] = 0x24A8;
  7805. t['mpasquare'] = 0x33AB;
  7806. t['mssquare'] = 0x33B3;
  7807. t['msuperior'] = 0xF6EF;
  7808. t['mturned'] = 0x026F;
  7809. t['mu'] = 0x00B5;
  7810. t['mu1'] = 0x00B5;
  7811. t['muasquare'] = 0x3382;
  7812. t['muchgreater'] = 0x226B;
  7813. t['muchless'] = 0x226A;
  7814. t['mufsquare'] = 0x338C;
  7815. t['mugreek'] = 0x03BC;
  7816. t['mugsquare'] = 0x338D;
  7817. t['muhiragana'] = 0x3080;
  7818. t['mukatakana'] = 0x30E0;
  7819. t['mukatakanahalfwidth'] = 0xFF91;
  7820. t['mulsquare'] = 0x3395;
  7821. t['multiply'] = 0x00D7;
  7822. t['mumsquare'] = 0x339B;
  7823. t['munahhebrew'] = 0x05A3;
  7824. t['munahlefthebrew'] = 0x05A3;
  7825. t['musicalnote'] = 0x266A;
  7826. t['musicalnotedbl'] = 0x266B;
  7827. t['musicflatsign'] = 0x266D;
  7828. t['musicsharpsign'] = 0x266F;
  7829. t['mussquare'] = 0x33B2;
  7830. t['muvsquare'] = 0x33B6;
  7831. t['muwsquare'] = 0x33BC;
  7832. t['mvmegasquare'] = 0x33B9;
  7833. t['mvsquare'] = 0x33B7;
  7834. t['mwmegasquare'] = 0x33BF;
  7835. t['mwsquare'] = 0x33BD;
  7836. t['n'] = 0x006E;
  7837. t['nabengali'] = 0x09A8;
  7838. t['nabla'] = 0x2207;
  7839. t['nacute'] = 0x0144;
  7840. t['nadeva'] = 0x0928;
  7841. t['nagujarati'] = 0x0AA8;
  7842. t['nagurmukhi'] = 0x0A28;
  7843. t['nahiragana'] = 0x306A;
  7844. t['nakatakana'] = 0x30CA;
  7845. t['nakatakanahalfwidth'] = 0xFF85;
  7846. t['napostrophe'] = 0x0149;
  7847. t['nasquare'] = 0x3381;
  7848. t['nbopomofo'] = 0x310B;
  7849. t['nbspace'] = 0x00A0;
  7850. t['ncaron'] = 0x0148;
  7851. t['ncedilla'] = 0x0146;
  7852. t['ncircle'] = 0x24DD;
  7853. t['ncircumflexbelow'] = 0x1E4B;
  7854. t['ncommaaccent'] = 0x0146;
  7855. t['ndotaccent'] = 0x1E45;
  7856. t['ndotbelow'] = 0x1E47;
  7857. t['nehiragana'] = 0x306D;
  7858. t['nekatakana'] = 0x30CD;
  7859. t['nekatakanahalfwidth'] = 0xFF88;
  7860. t['newsheqelsign'] = 0x20AA;
  7861. t['nfsquare'] = 0x338B;
  7862. t['ngabengali'] = 0x0999;
  7863. t['ngadeva'] = 0x0919;
  7864. t['ngagujarati'] = 0x0A99;
  7865. t['ngagurmukhi'] = 0x0A19;
  7866. t['ngonguthai'] = 0x0E07;
  7867. t['nhiragana'] = 0x3093;
  7868. t['nhookleft'] = 0x0272;
  7869. t['nhookretroflex'] = 0x0273;
  7870. t['nieunacirclekorean'] = 0x326F;
  7871. t['nieunaparenkorean'] = 0x320F;
  7872. t['nieuncieuckorean'] = 0x3135;
  7873. t['nieuncirclekorean'] = 0x3261;
  7874. t['nieunhieuhkorean'] = 0x3136;
  7875. t['nieunkorean'] = 0x3134;
  7876. t['nieunpansioskorean'] = 0x3168;
  7877. t['nieunparenkorean'] = 0x3201;
  7878. t['nieunsioskorean'] = 0x3167;
  7879. t['nieuntikeutkorean'] = 0x3166;
  7880. t['nihiragana'] = 0x306B;
  7881. t['nikatakana'] = 0x30CB;
  7882. t['nikatakanahalfwidth'] = 0xFF86;
  7883. t['nikhahitleftthai'] = 0xF899;
  7884. t['nikhahitthai'] = 0x0E4D;
  7885. t['nine'] = 0x0039;
  7886. t['ninearabic'] = 0x0669;
  7887. t['ninebengali'] = 0x09EF;
  7888. t['ninecircle'] = 0x2468;
  7889. t['ninecircleinversesansserif'] = 0x2792;
  7890. t['ninedeva'] = 0x096F;
  7891. t['ninegujarati'] = 0x0AEF;
  7892. t['ninegurmukhi'] = 0x0A6F;
  7893. t['ninehackarabic'] = 0x0669;
  7894. t['ninehangzhou'] = 0x3029;
  7895. t['nineideographicparen'] = 0x3228;
  7896. t['nineinferior'] = 0x2089;
  7897. t['ninemonospace'] = 0xFF19;
  7898. t['nineoldstyle'] = 0xF739;
  7899. t['nineparen'] = 0x247C;
  7900. t['nineperiod'] = 0x2490;
  7901. t['ninepersian'] = 0x06F9;
  7902. t['nineroman'] = 0x2178;
  7903. t['ninesuperior'] = 0x2079;
  7904. t['nineteencircle'] = 0x2472;
  7905. t['nineteenparen'] = 0x2486;
  7906. t['nineteenperiod'] = 0x249A;
  7907. t['ninethai'] = 0x0E59;
  7908. t['nj'] = 0x01CC;
  7909. t['njecyrillic'] = 0x045A;
  7910. t['nkatakana'] = 0x30F3;
  7911. t['nkatakanahalfwidth'] = 0xFF9D;
  7912. t['nlegrightlong'] = 0x019E;
  7913. t['nlinebelow'] = 0x1E49;
  7914. t['nmonospace'] = 0xFF4E;
  7915. t['nmsquare'] = 0x339A;
  7916. t['nnabengali'] = 0x09A3;
  7917. t['nnadeva'] = 0x0923;
  7918. t['nnagujarati'] = 0x0AA3;
  7919. t['nnagurmukhi'] = 0x0A23;
  7920. t['nnnadeva'] = 0x0929;
  7921. t['nohiragana'] = 0x306E;
  7922. t['nokatakana'] = 0x30CE;
  7923. t['nokatakanahalfwidth'] = 0xFF89;
  7924. t['nonbreakingspace'] = 0x00A0;
  7925. t['nonenthai'] = 0x0E13;
  7926. t['nonuthai'] = 0x0E19;
  7927. t['noonarabic'] = 0x0646;
  7928. t['noonfinalarabic'] = 0xFEE6;
  7929. t['noonghunnaarabic'] = 0x06BA;
  7930. t['noonghunnafinalarabic'] = 0xFB9F;
  7931. t['nooninitialarabic'] = 0xFEE7;
  7932. t['noonjeeminitialarabic'] = 0xFCD2;
  7933. t['noonjeemisolatedarabic'] = 0xFC4B;
  7934. t['noonmedialarabic'] = 0xFEE8;
  7935. t['noonmeeminitialarabic'] = 0xFCD5;
  7936. t['noonmeemisolatedarabic'] = 0xFC4E;
  7937. t['noonnoonfinalarabic'] = 0xFC8D;
  7938. t['notcontains'] = 0x220C;
  7939. t['notelement'] = 0x2209;
  7940. t['notelementof'] = 0x2209;
  7941. t['notequal'] = 0x2260;
  7942. t['notgreater'] = 0x226F;
  7943. t['notgreaternorequal'] = 0x2271;
  7944. t['notgreaternorless'] = 0x2279;
  7945. t['notidentical'] = 0x2262;
  7946. t['notless'] = 0x226E;
  7947. t['notlessnorequal'] = 0x2270;
  7948. t['notparallel'] = 0x2226;
  7949. t['notprecedes'] = 0x2280;
  7950. t['notsubset'] = 0x2284;
  7951. t['notsucceeds'] = 0x2281;
  7952. t['notsuperset'] = 0x2285;
  7953. t['nowarmenian'] = 0x0576;
  7954. t['nparen'] = 0x24A9;
  7955. t['nssquare'] = 0x33B1;
  7956. t['nsuperior'] = 0x207F;
  7957. t['ntilde'] = 0x00F1;
  7958. t['nu'] = 0x03BD;
  7959. t['nuhiragana'] = 0x306C;
  7960. t['nukatakana'] = 0x30CC;
  7961. t['nukatakanahalfwidth'] = 0xFF87;
  7962. t['nuktabengali'] = 0x09BC;
  7963. t['nuktadeva'] = 0x093C;
  7964. t['nuktagujarati'] = 0x0ABC;
  7965. t['nuktagurmukhi'] = 0x0A3C;
  7966. t['numbersign'] = 0x0023;
  7967. t['numbersignmonospace'] = 0xFF03;
  7968. t['numbersignsmall'] = 0xFE5F;
  7969. t['numeralsigngreek'] = 0x0374;
  7970. t['numeralsignlowergreek'] = 0x0375;
  7971. t['numero'] = 0x2116;
  7972. t['nun'] = 0x05E0;
  7973. t['nundagesh'] = 0xFB40;
  7974. t['nundageshhebrew'] = 0xFB40;
  7975. t['nunhebrew'] = 0x05E0;
  7976. t['nvsquare'] = 0x33B5;
  7977. t['nwsquare'] = 0x33BB;
  7978. t['nyabengali'] = 0x099E;
  7979. t['nyadeva'] = 0x091E;
  7980. t['nyagujarati'] = 0x0A9E;
  7981. t['nyagurmukhi'] = 0x0A1E;
  7982. t['o'] = 0x006F;
  7983. t['oacute'] = 0x00F3;
  7984. t['oangthai'] = 0x0E2D;
  7985. t['obarred'] = 0x0275;
  7986. t['obarredcyrillic'] = 0x04E9;
  7987. t['obarreddieresiscyrillic'] = 0x04EB;
  7988. t['obengali'] = 0x0993;
  7989. t['obopomofo'] = 0x311B;
  7990. t['obreve'] = 0x014F;
  7991. t['ocandradeva'] = 0x0911;
  7992. t['ocandragujarati'] = 0x0A91;
  7993. t['ocandravowelsigndeva'] = 0x0949;
  7994. t['ocandravowelsigngujarati'] = 0x0AC9;
  7995. t['ocaron'] = 0x01D2;
  7996. t['ocircle'] = 0x24DE;
  7997. t['ocircumflex'] = 0x00F4;
  7998. t['ocircumflexacute'] = 0x1ED1;
  7999. t['ocircumflexdotbelow'] = 0x1ED9;
  8000. t['ocircumflexgrave'] = 0x1ED3;
  8001. t['ocircumflexhookabove'] = 0x1ED5;
  8002. t['ocircumflextilde'] = 0x1ED7;
  8003. t['ocyrillic'] = 0x043E;
  8004. t['odblacute'] = 0x0151;
  8005. t['odblgrave'] = 0x020D;
  8006. t['odeva'] = 0x0913;
  8007. t['odieresis'] = 0x00F6;
  8008. t['odieresiscyrillic'] = 0x04E7;
  8009. t['odotbelow'] = 0x1ECD;
  8010. t['oe'] = 0x0153;
  8011. t['oekorean'] = 0x315A;
  8012. t['ogonek'] = 0x02DB;
  8013. t['ogonekcmb'] = 0x0328;
  8014. t['ograve'] = 0x00F2;
  8015. t['ogujarati'] = 0x0A93;
  8016. t['oharmenian'] = 0x0585;
  8017. t['ohiragana'] = 0x304A;
  8018. t['ohookabove'] = 0x1ECF;
  8019. t['ohorn'] = 0x01A1;
  8020. t['ohornacute'] = 0x1EDB;
  8021. t['ohorndotbelow'] = 0x1EE3;
  8022. t['ohorngrave'] = 0x1EDD;
  8023. t['ohornhookabove'] = 0x1EDF;
  8024. t['ohorntilde'] = 0x1EE1;
  8025. t['ohungarumlaut'] = 0x0151;
  8026. t['oi'] = 0x01A3;
  8027. t['oinvertedbreve'] = 0x020F;
  8028. t['okatakana'] = 0x30AA;
  8029. t['okatakanahalfwidth'] = 0xFF75;
  8030. t['okorean'] = 0x3157;
  8031. t['olehebrew'] = 0x05AB;
  8032. t['omacron'] = 0x014D;
  8033. t['omacronacute'] = 0x1E53;
  8034. t['omacrongrave'] = 0x1E51;
  8035. t['omdeva'] = 0x0950;
  8036. t['omega'] = 0x03C9;
  8037. t['omega1'] = 0x03D6;
  8038. t['omegacyrillic'] = 0x0461;
  8039. t['omegalatinclosed'] = 0x0277;
  8040. t['omegaroundcyrillic'] = 0x047B;
  8041. t['omegatitlocyrillic'] = 0x047D;
  8042. t['omegatonos'] = 0x03CE;
  8043. t['omgujarati'] = 0x0AD0;
  8044. t['omicron'] = 0x03BF;
  8045. t['omicrontonos'] = 0x03CC;
  8046. t['omonospace'] = 0xFF4F;
  8047. t['one'] = 0x0031;
  8048. t['onearabic'] = 0x0661;
  8049. t['onebengali'] = 0x09E7;
  8050. t['onecircle'] = 0x2460;
  8051. t['onecircleinversesansserif'] = 0x278A;
  8052. t['onedeva'] = 0x0967;
  8053. t['onedotenleader'] = 0x2024;
  8054. t['oneeighth'] = 0x215B;
  8055. t['onefitted'] = 0xF6DC;
  8056. t['onegujarati'] = 0x0AE7;
  8057. t['onegurmukhi'] = 0x0A67;
  8058. t['onehackarabic'] = 0x0661;
  8059. t['onehalf'] = 0x00BD;
  8060. t['onehangzhou'] = 0x3021;
  8061. t['oneideographicparen'] = 0x3220;
  8062. t['oneinferior'] = 0x2081;
  8063. t['onemonospace'] = 0xFF11;
  8064. t['onenumeratorbengali'] = 0x09F4;
  8065. t['oneoldstyle'] = 0xF731;
  8066. t['oneparen'] = 0x2474;
  8067. t['oneperiod'] = 0x2488;
  8068. t['onepersian'] = 0x06F1;
  8069. t['onequarter'] = 0x00BC;
  8070. t['oneroman'] = 0x2170;
  8071. t['onesuperior'] = 0x00B9;
  8072. t['onethai'] = 0x0E51;
  8073. t['onethird'] = 0x2153;
  8074. t['oogonek'] = 0x01EB;
  8075. t['oogonekmacron'] = 0x01ED;
  8076. t['oogurmukhi'] = 0x0A13;
  8077. t['oomatragurmukhi'] = 0x0A4B;
  8078. t['oopen'] = 0x0254;
  8079. t['oparen'] = 0x24AA;
  8080. t['openbullet'] = 0x25E6;
  8081. t['option'] = 0x2325;
  8082. t['ordfeminine'] = 0x00AA;
  8083. t['ordmasculine'] = 0x00BA;
  8084. t['orthogonal'] = 0x221F;
  8085. t['oshortdeva'] = 0x0912;
  8086. t['oshortvowelsigndeva'] = 0x094A;
  8087. t['oslash'] = 0x00F8;
  8088. t['oslashacute'] = 0x01FF;
  8089. t['osmallhiragana'] = 0x3049;
  8090. t['osmallkatakana'] = 0x30A9;
  8091. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8092. t['ostrokeacute'] = 0x01FF;
  8093. t['osuperior'] = 0xF6F0;
  8094. t['otcyrillic'] = 0x047F;
  8095. t['otilde'] = 0x00F5;
  8096. t['otildeacute'] = 0x1E4D;
  8097. t['otildedieresis'] = 0x1E4F;
  8098. t['oubopomofo'] = 0x3121;
  8099. t['overline'] = 0x203E;
  8100. t['overlinecenterline'] = 0xFE4A;
  8101. t['overlinecmb'] = 0x0305;
  8102. t['overlinedashed'] = 0xFE49;
  8103. t['overlinedblwavy'] = 0xFE4C;
  8104. t['overlinewavy'] = 0xFE4B;
  8105. t['overscore'] = 0x00AF;
  8106. t['ovowelsignbengali'] = 0x09CB;
  8107. t['ovowelsigndeva'] = 0x094B;
  8108. t['ovowelsigngujarati'] = 0x0ACB;
  8109. t['p'] = 0x0070;
  8110. t['paampssquare'] = 0x3380;
  8111. t['paasentosquare'] = 0x332B;
  8112. t['pabengali'] = 0x09AA;
  8113. t['pacute'] = 0x1E55;
  8114. t['padeva'] = 0x092A;
  8115. t['pagedown'] = 0x21DF;
  8116. t['pageup'] = 0x21DE;
  8117. t['pagujarati'] = 0x0AAA;
  8118. t['pagurmukhi'] = 0x0A2A;
  8119. t['pahiragana'] = 0x3071;
  8120. t['paiyannoithai'] = 0x0E2F;
  8121. t['pakatakana'] = 0x30D1;
  8122. t['palatalizationcyrilliccmb'] = 0x0484;
  8123. t['palochkacyrillic'] = 0x04C0;
  8124. t['pansioskorean'] = 0x317F;
  8125. t['paragraph'] = 0x00B6;
  8126. t['parallel'] = 0x2225;
  8127. t['parenleft'] = 0x0028;
  8128. t['parenleftaltonearabic'] = 0xFD3E;
  8129. t['parenleftbt'] = 0xF8ED;
  8130. t['parenleftex'] = 0xF8EC;
  8131. t['parenleftinferior'] = 0x208D;
  8132. t['parenleftmonospace'] = 0xFF08;
  8133. t['parenleftsmall'] = 0xFE59;
  8134. t['parenleftsuperior'] = 0x207D;
  8135. t['parenlefttp'] = 0xF8EB;
  8136. t['parenleftvertical'] = 0xFE35;
  8137. t['parenright'] = 0x0029;
  8138. t['parenrightaltonearabic'] = 0xFD3F;
  8139. t['parenrightbt'] = 0xF8F8;
  8140. t['parenrightex'] = 0xF8F7;
  8141. t['parenrightinferior'] = 0x208E;
  8142. t['parenrightmonospace'] = 0xFF09;
  8143. t['parenrightsmall'] = 0xFE5A;
  8144. t['parenrightsuperior'] = 0x207E;
  8145. t['parenrighttp'] = 0xF8F6;
  8146. t['parenrightvertical'] = 0xFE36;
  8147. t['partialdiff'] = 0x2202;
  8148. t['paseqhebrew'] = 0x05C0;
  8149. t['pashtahebrew'] = 0x0599;
  8150. t['pasquare'] = 0x33A9;
  8151. t['patah'] = 0x05B7;
  8152. t['patah11'] = 0x05B7;
  8153. t['patah1d'] = 0x05B7;
  8154. t['patah2a'] = 0x05B7;
  8155. t['patahhebrew'] = 0x05B7;
  8156. t['patahnarrowhebrew'] = 0x05B7;
  8157. t['patahquarterhebrew'] = 0x05B7;
  8158. t['patahwidehebrew'] = 0x05B7;
  8159. t['pazerhebrew'] = 0x05A1;
  8160. t['pbopomofo'] = 0x3106;
  8161. t['pcircle'] = 0x24DF;
  8162. t['pdotaccent'] = 0x1E57;
  8163. t['pe'] = 0x05E4;
  8164. t['pecyrillic'] = 0x043F;
  8165. t['pedagesh'] = 0xFB44;
  8166. t['pedageshhebrew'] = 0xFB44;
  8167. t['peezisquare'] = 0x333B;
  8168. t['pefinaldageshhebrew'] = 0xFB43;
  8169. t['peharabic'] = 0x067E;
  8170. t['peharmenian'] = 0x057A;
  8171. t['pehebrew'] = 0x05E4;
  8172. t['pehfinalarabic'] = 0xFB57;
  8173. t['pehinitialarabic'] = 0xFB58;
  8174. t['pehiragana'] = 0x307A;
  8175. t['pehmedialarabic'] = 0xFB59;
  8176. t['pekatakana'] = 0x30DA;
  8177. t['pemiddlehookcyrillic'] = 0x04A7;
  8178. t['perafehebrew'] = 0xFB4E;
  8179. t['percent'] = 0x0025;
  8180. t['percentarabic'] = 0x066A;
  8181. t['percentmonospace'] = 0xFF05;
  8182. t['percentsmall'] = 0xFE6A;
  8183. t['period'] = 0x002E;
  8184. t['periodarmenian'] = 0x0589;
  8185. t['periodcentered'] = 0x00B7;
  8186. t['periodhalfwidth'] = 0xFF61;
  8187. t['periodinferior'] = 0xF6E7;
  8188. t['periodmonospace'] = 0xFF0E;
  8189. t['periodsmall'] = 0xFE52;
  8190. t['periodsuperior'] = 0xF6E8;
  8191. t['perispomenigreekcmb'] = 0x0342;
  8192. t['perpendicular'] = 0x22A5;
  8193. t['perthousand'] = 0x2030;
  8194. t['peseta'] = 0x20A7;
  8195. t['pfsquare'] = 0x338A;
  8196. t['phabengali'] = 0x09AB;
  8197. t['phadeva'] = 0x092B;
  8198. t['phagujarati'] = 0x0AAB;
  8199. t['phagurmukhi'] = 0x0A2B;
  8200. t['phi'] = 0x03C6;
  8201. t['phi1'] = 0x03D5;
  8202. t['phieuphacirclekorean'] = 0x327A;
  8203. t['phieuphaparenkorean'] = 0x321A;
  8204. t['phieuphcirclekorean'] = 0x326C;
  8205. t['phieuphkorean'] = 0x314D;
  8206. t['phieuphparenkorean'] = 0x320C;
  8207. t['philatin'] = 0x0278;
  8208. t['phinthuthai'] = 0x0E3A;
  8209. t['phisymbolgreek'] = 0x03D5;
  8210. t['phook'] = 0x01A5;
  8211. t['phophanthai'] = 0x0E1E;
  8212. t['phophungthai'] = 0x0E1C;
  8213. t['phosamphaothai'] = 0x0E20;
  8214. t['pi'] = 0x03C0;
  8215. t['pieupacirclekorean'] = 0x3273;
  8216. t['pieupaparenkorean'] = 0x3213;
  8217. t['pieupcieuckorean'] = 0x3176;
  8218. t['pieupcirclekorean'] = 0x3265;
  8219. t['pieupkiyeokkorean'] = 0x3172;
  8220. t['pieupkorean'] = 0x3142;
  8221. t['pieupparenkorean'] = 0x3205;
  8222. t['pieupsioskiyeokkorean'] = 0x3174;
  8223. t['pieupsioskorean'] = 0x3144;
  8224. t['pieupsiostikeutkorean'] = 0x3175;
  8225. t['pieupthieuthkorean'] = 0x3177;
  8226. t['pieuptikeutkorean'] = 0x3173;
  8227. t['pihiragana'] = 0x3074;
  8228. t['pikatakana'] = 0x30D4;
  8229. t['pisymbolgreek'] = 0x03D6;
  8230. t['piwrarmenian'] = 0x0583;
  8231. t['plus'] = 0x002B;
  8232. t['plusbelowcmb'] = 0x031F;
  8233. t['pluscircle'] = 0x2295;
  8234. t['plusminus'] = 0x00B1;
  8235. t['plusmod'] = 0x02D6;
  8236. t['plusmonospace'] = 0xFF0B;
  8237. t['plussmall'] = 0xFE62;
  8238. t['plussuperior'] = 0x207A;
  8239. t['pmonospace'] = 0xFF50;
  8240. t['pmsquare'] = 0x33D8;
  8241. t['pohiragana'] = 0x307D;
  8242. t['pointingindexdownwhite'] = 0x261F;
  8243. t['pointingindexleftwhite'] = 0x261C;
  8244. t['pointingindexrightwhite'] = 0x261E;
  8245. t['pointingindexupwhite'] = 0x261D;
  8246. t['pokatakana'] = 0x30DD;
  8247. t['poplathai'] = 0x0E1B;
  8248. t['postalmark'] = 0x3012;
  8249. t['postalmarkface'] = 0x3020;
  8250. t['pparen'] = 0x24AB;
  8251. t['precedes'] = 0x227A;
  8252. t['prescription'] = 0x211E;
  8253. t['primemod'] = 0x02B9;
  8254. t['primereversed'] = 0x2035;
  8255. t['product'] = 0x220F;
  8256. t['projective'] = 0x2305;
  8257. t['prolongedkana'] = 0x30FC;
  8258. t['propellor'] = 0x2318;
  8259. t['propersubset'] = 0x2282;
  8260. t['propersuperset'] = 0x2283;
  8261. t['proportion'] = 0x2237;
  8262. t['proportional'] = 0x221D;
  8263. t['psi'] = 0x03C8;
  8264. t['psicyrillic'] = 0x0471;
  8265. t['psilipneumatacyrilliccmb'] = 0x0486;
  8266. t['pssquare'] = 0x33B0;
  8267. t['puhiragana'] = 0x3077;
  8268. t['pukatakana'] = 0x30D7;
  8269. t['pvsquare'] = 0x33B4;
  8270. t['pwsquare'] = 0x33BA;
  8271. t['q'] = 0x0071;
  8272. t['qadeva'] = 0x0958;
  8273. t['qadmahebrew'] = 0x05A8;
  8274. t['qafarabic'] = 0x0642;
  8275. t['qaffinalarabic'] = 0xFED6;
  8276. t['qafinitialarabic'] = 0xFED7;
  8277. t['qafmedialarabic'] = 0xFED8;
  8278. t['qamats'] = 0x05B8;
  8279. t['qamats10'] = 0x05B8;
  8280. t['qamats1a'] = 0x05B8;
  8281. t['qamats1c'] = 0x05B8;
  8282. t['qamats27'] = 0x05B8;
  8283. t['qamats29'] = 0x05B8;
  8284. t['qamats33'] = 0x05B8;
  8285. t['qamatsde'] = 0x05B8;
  8286. t['qamatshebrew'] = 0x05B8;
  8287. t['qamatsnarrowhebrew'] = 0x05B8;
  8288. t['qamatsqatanhebrew'] = 0x05B8;
  8289. t['qamatsqatannarrowhebrew'] = 0x05B8;
  8290. t['qamatsqatanquarterhebrew'] = 0x05B8;
  8291. t['qamatsqatanwidehebrew'] = 0x05B8;
  8292. t['qamatsquarterhebrew'] = 0x05B8;
  8293. t['qamatswidehebrew'] = 0x05B8;
  8294. t['qarneyparahebrew'] = 0x059F;
  8295. t['qbopomofo'] = 0x3111;
  8296. t['qcircle'] = 0x24E0;
  8297. t['qhook'] = 0x02A0;
  8298. t['qmonospace'] = 0xFF51;
  8299. t['qof'] = 0x05E7;
  8300. t['qofdagesh'] = 0xFB47;
  8301. t['qofdageshhebrew'] = 0xFB47;
  8302. t['qofhebrew'] = 0x05E7;
  8303. t['qparen'] = 0x24AC;
  8304. t['quarternote'] = 0x2669;
  8305. t['qubuts'] = 0x05BB;
  8306. t['qubuts18'] = 0x05BB;
  8307. t['qubuts25'] = 0x05BB;
  8308. t['qubuts31'] = 0x05BB;
  8309. t['qubutshebrew'] = 0x05BB;
  8310. t['qubutsnarrowhebrew'] = 0x05BB;
  8311. t['qubutsquarterhebrew'] = 0x05BB;
  8312. t['qubutswidehebrew'] = 0x05BB;
  8313. t['question'] = 0x003F;
  8314. t['questionarabic'] = 0x061F;
  8315. t['questionarmenian'] = 0x055E;
  8316. t['questiondown'] = 0x00BF;
  8317. t['questiondownsmall'] = 0xF7BF;
  8318. t['questiongreek'] = 0x037E;
  8319. t['questionmonospace'] = 0xFF1F;
  8320. t['questionsmall'] = 0xF73F;
  8321. t['quotedbl'] = 0x0022;
  8322. t['quotedblbase'] = 0x201E;
  8323. t['quotedblleft'] = 0x201C;
  8324. t['quotedblmonospace'] = 0xFF02;
  8325. t['quotedblprime'] = 0x301E;
  8326. t['quotedblprimereversed'] = 0x301D;
  8327. t['quotedblright'] = 0x201D;
  8328. t['quoteleft'] = 0x2018;
  8329. t['quoteleftreversed'] = 0x201B;
  8330. t['quotereversed'] = 0x201B;
  8331. t['quoteright'] = 0x2019;
  8332. t['quoterightn'] = 0x0149;
  8333. t['quotesinglbase'] = 0x201A;
  8334. t['quotesingle'] = 0x0027;
  8335. t['quotesinglemonospace'] = 0xFF07;
  8336. t['r'] = 0x0072;
  8337. t['raarmenian'] = 0x057C;
  8338. t['rabengali'] = 0x09B0;
  8339. t['racute'] = 0x0155;
  8340. t['radeva'] = 0x0930;
  8341. t['radical'] = 0x221A;
  8342. t['radicalex'] = 0xF8E5;
  8343. t['radoverssquare'] = 0x33AE;
  8344. t['radoverssquaredsquare'] = 0x33AF;
  8345. t['radsquare'] = 0x33AD;
  8346. t['rafe'] = 0x05BF;
  8347. t['rafehebrew'] = 0x05BF;
  8348. t['ragujarati'] = 0x0AB0;
  8349. t['ragurmukhi'] = 0x0A30;
  8350. t['rahiragana'] = 0x3089;
  8351. t['rakatakana'] = 0x30E9;
  8352. t['rakatakanahalfwidth'] = 0xFF97;
  8353. t['ralowerdiagonalbengali'] = 0x09F1;
  8354. t['ramiddlediagonalbengali'] = 0x09F0;
  8355. t['ramshorn'] = 0x0264;
  8356. t['ratio'] = 0x2236;
  8357. t['rbopomofo'] = 0x3116;
  8358. t['rcaron'] = 0x0159;
  8359. t['rcedilla'] = 0x0157;
  8360. t['rcircle'] = 0x24E1;
  8361. t['rcommaaccent'] = 0x0157;
  8362. t['rdblgrave'] = 0x0211;
  8363. t['rdotaccent'] = 0x1E59;
  8364. t['rdotbelow'] = 0x1E5B;
  8365. t['rdotbelowmacron'] = 0x1E5D;
  8366. t['referencemark'] = 0x203B;
  8367. t['reflexsubset'] = 0x2286;
  8368. t['reflexsuperset'] = 0x2287;
  8369. t['registered'] = 0x00AE;
  8370. t['registersans'] = 0xF8E8;
  8371. t['registerserif'] = 0xF6DA;
  8372. t['reharabic'] = 0x0631;
  8373. t['reharmenian'] = 0x0580;
  8374. t['rehfinalarabic'] = 0xFEAE;
  8375. t['rehiragana'] = 0x308C;
  8376. t['rekatakana'] = 0x30EC;
  8377. t['rekatakanahalfwidth'] = 0xFF9A;
  8378. t['resh'] = 0x05E8;
  8379. t['reshdageshhebrew'] = 0xFB48;
  8380. t['reshhebrew'] = 0x05E8;
  8381. t['reversedtilde'] = 0x223D;
  8382. t['reviahebrew'] = 0x0597;
  8383. t['reviamugrashhebrew'] = 0x0597;
  8384. t['revlogicalnot'] = 0x2310;
  8385. t['rfishhook'] = 0x027E;
  8386. t['rfishhookreversed'] = 0x027F;
  8387. t['rhabengali'] = 0x09DD;
  8388. t['rhadeva'] = 0x095D;
  8389. t['rho'] = 0x03C1;
  8390. t['rhook'] = 0x027D;
  8391. t['rhookturned'] = 0x027B;
  8392. t['rhookturnedsuperior'] = 0x02B5;
  8393. t['rhosymbolgreek'] = 0x03F1;
  8394. t['rhotichookmod'] = 0x02DE;
  8395. t['rieulacirclekorean'] = 0x3271;
  8396. t['rieulaparenkorean'] = 0x3211;
  8397. t['rieulcirclekorean'] = 0x3263;
  8398. t['rieulhieuhkorean'] = 0x3140;
  8399. t['rieulkiyeokkorean'] = 0x313A;
  8400. t['rieulkiyeoksioskorean'] = 0x3169;
  8401. t['rieulkorean'] = 0x3139;
  8402. t['rieulmieumkorean'] = 0x313B;
  8403. t['rieulpansioskorean'] = 0x316C;
  8404. t['rieulparenkorean'] = 0x3203;
  8405. t['rieulphieuphkorean'] = 0x313F;
  8406. t['rieulpieupkorean'] = 0x313C;
  8407. t['rieulpieupsioskorean'] = 0x316B;
  8408. t['rieulsioskorean'] = 0x313D;
  8409. t['rieulthieuthkorean'] = 0x313E;
  8410. t['rieultikeutkorean'] = 0x316A;
  8411. t['rieulyeorinhieuhkorean'] = 0x316D;
  8412. t['rightangle'] = 0x221F;
  8413. t['righttackbelowcmb'] = 0x0319;
  8414. t['righttriangle'] = 0x22BF;
  8415. t['rihiragana'] = 0x308A;
  8416. t['rikatakana'] = 0x30EA;
  8417. t['rikatakanahalfwidth'] = 0xFF98;
  8418. t['ring'] = 0x02DA;
  8419. t['ringbelowcmb'] = 0x0325;
  8420. t['ringcmb'] = 0x030A;
  8421. t['ringhalfleft'] = 0x02BF;
  8422. t['ringhalfleftarmenian'] = 0x0559;
  8423. t['ringhalfleftbelowcmb'] = 0x031C;
  8424. t['ringhalfleftcentered'] = 0x02D3;
  8425. t['ringhalfright'] = 0x02BE;
  8426. t['ringhalfrightbelowcmb'] = 0x0339;
  8427. t['ringhalfrightcentered'] = 0x02D2;
  8428. t['rinvertedbreve'] = 0x0213;
  8429. t['rittorusquare'] = 0x3351;
  8430. t['rlinebelow'] = 0x1E5F;
  8431. t['rlongleg'] = 0x027C;
  8432. t['rlonglegturned'] = 0x027A;
  8433. t['rmonospace'] = 0xFF52;
  8434. t['rohiragana'] = 0x308D;
  8435. t['rokatakana'] = 0x30ED;
  8436. t['rokatakanahalfwidth'] = 0xFF9B;
  8437. t['roruathai'] = 0x0E23;
  8438. t['rparen'] = 0x24AD;
  8439. t['rrabengali'] = 0x09DC;
  8440. t['rradeva'] = 0x0931;
  8441. t['rragurmukhi'] = 0x0A5C;
  8442. t['rreharabic'] = 0x0691;
  8443. t['rrehfinalarabic'] = 0xFB8D;
  8444. t['rrvocalicbengali'] = 0x09E0;
  8445. t['rrvocalicdeva'] = 0x0960;
  8446. t['rrvocalicgujarati'] = 0x0AE0;
  8447. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8448. t['rrvocalicvowelsigndeva'] = 0x0944;
  8449. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8450. t['rsuperior'] = 0xF6F1;
  8451. t['rtblock'] = 0x2590;
  8452. t['rturned'] = 0x0279;
  8453. t['rturnedsuperior'] = 0x02B4;
  8454. t['ruhiragana'] = 0x308B;
  8455. t['rukatakana'] = 0x30EB;
  8456. t['rukatakanahalfwidth'] = 0xFF99;
  8457. t['rupeemarkbengali'] = 0x09F2;
  8458. t['rupeesignbengali'] = 0x09F3;
  8459. t['rupiah'] = 0xF6DD;
  8460. t['ruthai'] = 0x0E24;
  8461. t['rvocalicbengali'] = 0x098B;
  8462. t['rvocalicdeva'] = 0x090B;
  8463. t['rvocalicgujarati'] = 0x0A8B;
  8464. t['rvocalicvowelsignbengali'] = 0x09C3;
  8465. t['rvocalicvowelsigndeva'] = 0x0943;
  8466. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8467. t['s'] = 0x0073;
  8468. t['sabengali'] = 0x09B8;
  8469. t['sacute'] = 0x015B;
  8470. t['sacutedotaccent'] = 0x1E65;
  8471. t['sadarabic'] = 0x0635;
  8472. t['sadeva'] = 0x0938;
  8473. t['sadfinalarabic'] = 0xFEBA;
  8474. t['sadinitialarabic'] = 0xFEBB;
  8475. t['sadmedialarabic'] = 0xFEBC;
  8476. t['sagujarati'] = 0x0AB8;
  8477. t['sagurmukhi'] = 0x0A38;
  8478. t['sahiragana'] = 0x3055;
  8479. t['sakatakana'] = 0x30B5;
  8480. t['sakatakanahalfwidth'] = 0xFF7B;
  8481. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8482. t['samekh'] = 0x05E1;
  8483. t['samekhdagesh'] = 0xFB41;
  8484. t['samekhdageshhebrew'] = 0xFB41;
  8485. t['samekhhebrew'] = 0x05E1;
  8486. t['saraaathai'] = 0x0E32;
  8487. t['saraaethai'] = 0x0E41;
  8488. t['saraaimaimalaithai'] = 0x0E44;
  8489. t['saraaimaimuanthai'] = 0x0E43;
  8490. t['saraamthai'] = 0x0E33;
  8491. t['saraathai'] = 0x0E30;
  8492. t['saraethai'] = 0x0E40;
  8493. t['saraiileftthai'] = 0xF886;
  8494. t['saraiithai'] = 0x0E35;
  8495. t['saraileftthai'] = 0xF885;
  8496. t['saraithai'] = 0x0E34;
  8497. t['saraothai'] = 0x0E42;
  8498. t['saraueeleftthai'] = 0xF888;
  8499. t['saraueethai'] = 0x0E37;
  8500. t['saraueleftthai'] = 0xF887;
  8501. t['sarauethai'] = 0x0E36;
  8502. t['sarauthai'] = 0x0E38;
  8503. t['sarauuthai'] = 0x0E39;
  8504. t['sbopomofo'] = 0x3119;
  8505. t['scaron'] = 0x0161;
  8506. t['scarondotaccent'] = 0x1E67;
  8507. t['scedilla'] = 0x015F;
  8508. t['schwa'] = 0x0259;
  8509. t['schwacyrillic'] = 0x04D9;
  8510. t['schwadieresiscyrillic'] = 0x04DB;
  8511. t['schwahook'] = 0x025A;
  8512. t['scircle'] = 0x24E2;
  8513. t['scircumflex'] = 0x015D;
  8514. t['scommaaccent'] = 0x0219;
  8515. t['sdotaccent'] = 0x1E61;
  8516. t['sdotbelow'] = 0x1E63;
  8517. t['sdotbelowdotaccent'] = 0x1E69;
  8518. t['seagullbelowcmb'] = 0x033C;
  8519. t['second'] = 0x2033;
  8520. t['secondtonechinese'] = 0x02CA;
  8521. t['section'] = 0x00A7;
  8522. t['seenarabic'] = 0x0633;
  8523. t['seenfinalarabic'] = 0xFEB2;
  8524. t['seeninitialarabic'] = 0xFEB3;
  8525. t['seenmedialarabic'] = 0xFEB4;
  8526. t['segol'] = 0x05B6;
  8527. t['segol13'] = 0x05B6;
  8528. t['segol1f'] = 0x05B6;
  8529. t['segol2c'] = 0x05B6;
  8530. t['segolhebrew'] = 0x05B6;
  8531. t['segolnarrowhebrew'] = 0x05B6;
  8532. t['segolquarterhebrew'] = 0x05B6;
  8533. t['segoltahebrew'] = 0x0592;
  8534. t['segolwidehebrew'] = 0x05B6;
  8535. t['seharmenian'] = 0x057D;
  8536. t['sehiragana'] = 0x305B;
  8537. t['sekatakana'] = 0x30BB;
  8538. t['sekatakanahalfwidth'] = 0xFF7E;
  8539. t['semicolon'] = 0x003B;
  8540. t['semicolonarabic'] = 0x061B;
  8541. t['semicolonmonospace'] = 0xFF1B;
  8542. t['semicolonsmall'] = 0xFE54;
  8543. t['semivoicedmarkkana'] = 0x309C;
  8544. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8545. t['sentisquare'] = 0x3322;
  8546. t['sentosquare'] = 0x3323;
  8547. t['seven'] = 0x0037;
  8548. t['sevenarabic'] = 0x0667;
  8549. t['sevenbengali'] = 0x09ED;
  8550. t['sevencircle'] = 0x2466;
  8551. t['sevencircleinversesansserif'] = 0x2790;
  8552. t['sevendeva'] = 0x096D;
  8553. t['seveneighths'] = 0x215E;
  8554. t['sevengujarati'] = 0x0AED;
  8555. t['sevengurmukhi'] = 0x0A6D;
  8556. t['sevenhackarabic'] = 0x0667;
  8557. t['sevenhangzhou'] = 0x3027;
  8558. t['sevenideographicparen'] = 0x3226;
  8559. t['seveninferior'] = 0x2087;
  8560. t['sevenmonospace'] = 0xFF17;
  8561. t['sevenoldstyle'] = 0xF737;
  8562. t['sevenparen'] = 0x247A;
  8563. t['sevenperiod'] = 0x248E;
  8564. t['sevenpersian'] = 0x06F7;
  8565. t['sevenroman'] = 0x2176;
  8566. t['sevensuperior'] = 0x2077;
  8567. t['seventeencircle'] = 0x2470;
  8568. t['seventeenparen'] = 0x2484;
  8569. t['seventeenperiod'] = 0x2498;
  8570. t['seventhai'] = 0x0E57;
  8571. t['sfthyphen'] = 0x00AD;
  8572. t['shaarmenian'] = 0x0577;
  8573. t['shabengali'] = 0x09B6;
  8574. t['shacyrillic'] = 0x0448;
  8575. t['shaddaarabic'] = 0x0651;
  8576. t['shaddadammaarabic'] = 0xFC61;
  8577. t['shaddadammatanarabic'] = 0xFC5E;
  8578. t['shaddafathaarabic'] = 0xFC60;
  8579. t['shaddakasraarabic'] = 0xFC62;
  8580. t['shaddakasratanarabic'] = 0xFC5F;
  8581. t['shade'] = 0x2592;
  8582. t['shadedark'] = 0x2593;
  8583. t['shadelight'] = 0x2591;
  8584. t['shademedium'] = 0x2592;
  8585. t['shadeva'] = 0x0936;
  8586. t['shagujarati'] = 0x0AB6;
  8587. t['shagurmukhi'] = 0x0A36;
  8588. t['shalshelethebrew'] = 0x0593;
  8589. t['shbopomofo'] = 0x3115;
  8590. t['shchacyrillic'] = 0x0449;
  8591. t['sheenarabic'] = 0x0634;
  8592. t['sheenfinalarabic'] = 0xFEB6;
  8593. t['sheeninitialarabic'] = 0xFEB7;
  8594. t['sheenmedialarabic'] = 0xFEB8;
  8595. t['sheicoptic'] = 0x03E3;
  8596. t['sheqel'] = 0x20AA;
  8597. t['sheqelhebrew'] = 0x20AA;
  8598. t['sheva'] = 0x05B0;
  8599. t['sheva115'] = 0x05B0;
  8600. t['sheva15'] = 0x05B0;
  8601. t['sheva22'] = 0x05B0;
  8602. t['sheva2e'] = 0x05B0;
  8603. t['shevahebrew'] = 0x05B0;
  8604. t['shevanarrowhebrew'] = 0x05B0;
  8605. t['shevaquarterhebrew'] = 0x05B0;
  8606. t['shevawidehebrew'] = 0x05B0;
  8607. t['shhacyrillic'] = 0x04BB;
  8608. t['shimacoptic'] = 0x03ED;
  8609. t['shin'] = 0x05E9;
  8610. t['shindagesh'] = 0xFB49;
  8611. t['shindageshhebrew'] = 0xFB49;
  8612. t['shindageshshindot'] = 0xFB2C;
  8613. t['shindageshshindothebrew'] = 0xFB2C;
  8614. t['shindageshsindot'] = 0xFB2D;
  8615. t['shindageshsindothebrew'] = 0xFB2D;
  8616. t['shindothebrew'] = 0x05C1;
  8617. t['shinhebrew'] = 0x05E9;
  8618. t['shinshindot'] = 0xFB2A;
  8619. t['shinshindothebrew'] = 0xFB2A;
  8620. t['shinsindot'] = 0xFB2B;
  8621. t['shinsindothebrew'] = 0xFB2B;
  8622. t['shook'] = 0x0282;
  8623. t['sigma'] = 0x03C3;
  8624. t['sigma1'] = 0x03C2;
  8625. t['sigmafinal'] = 0x03C2;
  8626. t['sigmalunatesymbolgreek'] = 0x03F2;
  8627. t['sihiragana'] = 0x3057;
  8628. t['sikatakana'] = 0x30B7;
  8629. t['sikatakanahalfwidth'] = 0xFF7C;
  8630. t['siluqhebrew'] = 0x05BD;
  8631. t['siluqlefthebrew'] = 0x05BD;
  8632. t['similar'] = 0x223C;
  8633. t['sindothebrew'] = 0x05C2;
  8634. t['siosacirclekorean'] = 0x3274;
  8635. t['siosaparenkorean'] = 0x3214;
  8636. t['sioscieuckorean'] = 0x317E;
  8637. t['sioscirclekorean'] = 0x3266;
  8638. t['sioskiyeokkorean'] = 0x317A;
  8639. t['sioskorean'] = 0x3145;
  8640. t['siosnieunkorean'] = 0x317B;
  8641. t['siosparenkorean'] = 0x3206;
  8642. t['siospieupkorean'] = 0x317D;
  8643. t['siostikeutkorean'] = 0x317C;
  8644. t['six'] = 0x0036;
  8645. t['sixarabic'] = 0x0666;
  8646. t['sixbengali'] = 0x09EC;
  8647. t['sixcircle'] = 0x2465;
  8648. t['sixcircleinversesansserif'] = 0x278F;
  8649. t['sixdeva'] = 0x096C;
  8650. t['sixgujarati'] = 0x0AEC;
  8651. t['sixgurmukhi'] = 0x0A6C;
  8652. t['sixhackarabic'] = 0x0666;
  8653. t['sixhangzhou'] = 0x3026;
  8654. t['sixideographicparen'] = 0x3225;
  8655. t['sixinferior'] = 0x2086;
  8656. t['sixmonospace'] = 0xFF16;
  8657. t['sixoldstyle'] = 0xF736;
  8658. t['sixparen'] = 0x2479;
  8659. t['sixperiod'] = 0x248D;
  8660. t['sixpersian'] = 0x06F6;
  8661. t['sixroman'] = 0x2175;
  8662. t['sixsuperior'] = 0x2076;
  8663. t['sixteencircle'] = 0x246F;
  8664. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8665. t['sixteenparen'] = 0x2483;
  8666. t['sixteenperiod'] = 0x2497;
  8667. t['sixthai'] = 0x0E56;
  8668. t['slash'] = 0x002F;
  8669. t['slashmonospace'] = 0xFF0F;
  8670. t['slong'] = 0x017F;
  8671. t['slongdotaccent'] = 0x1E9B;
  8672. t['smileface'] = 0x263A;
  8673. t['smonospace'] = 0xFF53;
  8674. t['sofpasuqhebrew'] = 0x05C3;
  8675. t['softhyphen'] = 0x00AD;
  8676. t['softsigncyrillic'] = 0x044C;
  8677. t['sohiragana'] = 0x305D;
  8678. t['sokatakana'] = 0x30BD;
  8679. t['sokatakanahalfwidth'] = 0xFF7F;
  8680. t['soliduslongoverlaycmb'] = 0x0338;
  8681. t['solidusshortoverlaycmb'] = 0x0337;
  8682. t['sorusithai'] = 0x0E29;
  8683. t['sosalathai'] = 0x0E28;
  8684. t['sosothai'] = 0x0E0B;
  8685. t['sosuathai'] = 0x0E2A;
  8686. t['space'] = 0x0020;
  8687. t['spacehackarabic'] = 0x0020;
  8688. t['spade'] = 0x2660;
  8689. t['spadesuitblack'] = 0x2660;
  8690. t['spadesuitwhite'] = 0x2664;
  8691. t['sparen'] = 0x24AE;
  8692. t['squarebelowcmb'] = 0x033B;
  8693. t['squarecc'] = 0x33C4;
  8694. t['squarecm'] = 0x339D;
  8695. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8696. t['squarehorizontalfill'] = 0x25A4;
  8697. t['squarekg'] = 0x338F;
  8698. t['squarekm'] = 0x339E;
  8699. t['squarekmcapital'] = 0x33CE;
  8700. t['squareln'] = 0x33D1;
  8701. t['squarelog'] = 0x33D2;
  8702. t['squaremg'] = 0x338E;
  8703. t['squaremil'] = 0x33D5;
  8704. t['squaremm'] = 0x339C;
  8705. t['squaremsquared'] = 0x33A1;
  8706. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8707. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8708. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8709. t['squareverticalfill'] = 0x25A5;
  8710. t['squarewhitewithsmallblack'] = 0x25A3;
  8711. t['srsquare'] = 0x33DB;
  8712. t['ssabengali'] = 0x09B7;
  8713. t['ssadeva'] = 0x0937;
  8714. t['ssagujarati'] = 0x0AB7;
  8715. t['ssangcieuckorean'] = 0x3149;
  8716. t['ssanghieuhkorean'] = 0x3185;
  8717. t['ssangieungkorean'] = 0x3180;
  8718. t['ssangkiyeokkorean'] = 0x3132;
  8719. t['ssangnieunkorean'] = 0x3165;
  8720. t['ssangpieupkorean'] = 0x3143;
  8721. t['ssangsioskorean'] = 0x3146;
  8722. t['ssangtikeutkorean'] = 0x3138;
  8723. t['ssuperior'] = 0xF6F2;
  8724. t['sterling'] = 0x00A3;
  8725. t['sterlingmonospace'] = 0xFFE1;
  8726. t['strokelongoverlaycmb'] = 0x0336;
  8727. t['strokeshortoverlaycmb'] = 0x0335;
  8728. t['subset'] = 0x2282;
  8729. t['subsetnotequal'] = 0x228A;
  8730. t['subsetorequal'] = 0x2286;
  8731. t['succeeds'] = 0x227B;
  8732. t['suchthat'] = 0x220B;
  8733. t['suhiragana'] = 0x3059;
  8734. t['sukatakana'] = 0x30B9;
  8735. t['sukatakanahalfwidth'] = 0xFF7D;
  8736. t['sukunarabic'] = 0x0652;
  8737. t['summation'] = 0x2211;
  8738. t['sun'] = 0x263C;
  8739. t['superset'] = 0x2283;
  8740. t['supersetnotequal'] = 0x228B;
  8741. t['supersetorequal'] = 0x2287;
  8742. t['svsquare'] = 0x33DC;
  8743. t['syouwaerasquare'] = 0x337C;
  8744. t['t'] = 0x0074;
  8745. t['tabengali'] = 0x09A4;
  8746. t['tackdown'] = 0x22A4;
  8747. t['tackleft'] = 0x22A3;
  8748. t['tadeva'] = 0x0924;
  8749. t['tagujarati'] = 0x0AA4;
  8750. t['tagurmukhi'] = 0x0A24;
  8751. t['taharabic'] = 0x0637;
  8752. t['tahfinalarabic'] = 0xFEC2;
  8753. t['tahinitialarabic'] = 0xFEC3;
  8754. t['tahiragana'] = 0x305F;
  8755. t['tahmedialarabic'] = 0xFEC4;
  8756. t['taisyouerasquare'] = 0x337D;
  8757. t['takatakana'] = 0x30BF;
  8758. t['takatakanahalfwidth'] = 0xFF80;
  8759. t['tatweelarabic'] = 0x0640;
  8760. t['tau'] = 0x03C4;
  8761. t['tav'] = 0x05EA;
  8762. t['tavdages'] = 0xFB4A;
  8763. t['tavdagesh'] = 0xFB4A;
  8764. t['tavdageshhebrew'] = 0xFB4A;
  8765. t['tavhebrew'] = 0x05EA;
  8766. t['tbar'] = 0x0167;
  8767. t['tbopomofo'] = 0x310A;
  8768. t['tcaron'] = 0x0165;
  8769. t['tccurl'] = 0x02A8;
  8770. t['tcedilla'] = 0x0163;
  8771. t['tcheharabic'] = 0x0686;
  8772. t['tchehfinalarabic'] = 0xFB7B;
  8773. t['tchehinitialarabic'] = 0xFB7C;
  8774. t['tchehmedialarabic'] = 0xFB7D;
  8775. t['tcircle'] = 0x24E3;
  8776. t['tcircumflexbelow'] = 0x1E71;
  8777. t['tcommaaccent'] = 0x0163;
  8778. t['tdieresis'] = 0x1E97;
  8779. t['tdotaccent'] = 0x1E6B;
  8780. t['tdotbelow'] = 0x1E6D;
  8781. t['tecyrillic'] = 0x0442;
  8782. t['tedescendercyrillic'] = 0x04AD;
  8783. t['teharabic'] = 0x062A;
  8784. t['tehfinalarabic'] = 0xFE96;
  8785. t['tehhahinitialarabic'] = 0xFCA2;
  8786. t['tehhahisolatedarabic'] = 0xFC0C;
  8787. t['tehinitialarabic'] = 0xFE97;
  8788. t['tehiragana'] = 0x3066;
  8789. t['tehjeeminitialarabic'] = 0xFCA1;
  8790. t['tehjeemisolatedarabic'] = 0xFC0B;
  8791. t['tehmarbutaarabic'] = 0x0629;
  8792. t['tehmarbutafinalarabic'] = 0xFE94;
  8793. t['tehmedialarabic'] = 0xFE98;
  8794. t['tehmeeminitialarabic'] = 0xFCA4;
  8795. t['tehmeemisolatedarabic'] = 0xFC0E;
  8796. t['tehnoonfinalarabic'] = 0xFC73;
  8797. t['tekatakana'] = 0x30C6;
  8798. t['tekatakanahalfwidth'] = 0xFF83;
  8799. t['telephone'] = 0x2121;
  8800. t['telephoneblack'] = 0x260E;
  8801. t['telishagedolahebrew'] = 0x05A0;
  8802. t['telishaqetanahebrew'] = 0x05A9;
  8803. t['tencircle'] = 0x2469;
  8804. t['tenideographicparen'] = 0x3229;
  8805. t['tenparen'] = 0x247D;
  8806. t['tenperiod'] = 0x2491;
  8807. t['tenroman'] = 0x2179;
  8808. t['tesh'] = 0x02A7;
  8809. t['tet'] = 0x05D8;
  8810. t['tetdagesh'] = 0xFB38;
  8811. t['tetdageshhebrew'] = 0xFB38;
  8812. t['tethebrew'] = 0x05D8;
  8813. t['tetsecyrillic'] = 0x04B5;
  8814. t['tevirhebrew'] = 0x059B;
  8815. t['tevirlefthebrew'] = 0x059B;
  8816. t['thabengali'] = 0x09A5;
  8817. t['thadeva'] = 0x0925;
  8818. t['thagujarati'] = 0x0AA5;
  8819. t['thagurmukhi'] = 0x0A25;
  8820. t['thalarabic'] = 0x0630;
  8821. t['thalfinalarabic'] = 0xFEAC;
  8822. t['thanthakhatlowleftthai'] = 0xF898;
  8823. t['thanthakhatlowrightthai'] = 0xF897;
  8824. t['thanthakhatthai'] = 0x0E4C;
  8825. t['thanthakhatupperleftthai'] = 0xF896;
  8826. t['theharabic'] = 0x062B;
  8827. t['thehfinalarabic'] = 0xFE9A;
  8828. t['thehinitialarabic'] = 0xFE9B;
  8829. t['thehmedialarabic'] = 0xFE9C;
  8830. t['thereexists'] = 0x2203;
  8831. t['therefore'] = 0x2234;
  8832. t['theta'] = 0x03B8;
  8833. t['theta1'] = 0x03D1;
  8834. t['thetasymbolgreek'] = 0x03D1;
  8835. t['thieuthacirclekorean'] = 0x3279;
  8836. t['thieuthaparenkorean'] = 0x3219;
  8837. t['thieuthcirclekorean'] = 0x326B;
  8838. t['thieuthkorean'] = 0x314C;
  8839. t['thieuthparenkorean'] = 0x320B;
  8840. t['thirteencircle'] = 0x246C;
  8841. t['thirteenparen'] = 0x2480;
  8842. t['thirteenperiod'] = 0x2494;
  8843. t['thonangmonthothai'] = 0x0E11;
  8844. t['thook'] = 0x01AD;
  8845. t['thophuthaothai'] = 0x0E12;
  8846. t['thorn'] = 0x00FE;
  8847. t['thothahanthai'] = 0x0E17;
  8848. t['thothanthai'] = 0x0E10;
  8849. t['thothongthai'] = 0x0E18;
  8850. t['thothungthai'] = 0x0E16;
  8851. t['thousandcyrillic'] = 0x0482;
  8852. t['thousandsseparatorarabic'] = 0x066C;
  8853. t['thousandsseparatorpersian'] = 0x066C;
  8854. t['three'] = 0x0033;
  8855. t['threearabic'] = 0x0663;
  8856. t['threebengali'] = 0x09E9;
  8857. t['threecircle'] = 0x2462;
  8858. t['threecircleinversesansserif'] = 0x278C;
  8859. t['threedeva'] = 0x0969;
  8860. t['threeeighths'] = 0x215C;
  8861. t['threegujarati'] = 0x0AE9;
  8862. t['threegurmukhi'] = 0x0A69;
  8863. t['threehackarabic'] = 0x0663;
  8864. t['threehangzhou'] = 0x3023;
  8865. t['threeideographicparen'] = 0x3222;
  8866. t['threeinferior'] = 0x2083;
  8867. t['threemonospace'] = 0xFF13;
  8868. t['threenumeratorbengali'] = 0x09F6;
  8869. t['threeoldstyle'] = 0xF733;
  8870. t['threeparen'] = 0x2476;
  8871. t['threeperiod'] = 0x248A;
  8872. t['threepersian'] = 0x06F3;
  8873. t['threequarters'] = 0x00BE;
  8874. t['threequartersemdash'] = 0xF6DE;
  8875. t['threeroman'] = 0x2172;
  8876. t['threesuperior'] = 0x00B3;
  8877. t['threethai'] = 0x0E53;
  8878. t['thzsquare'] = 0x3394;
  8879. t['tihiragana'] = 0x3061;
  8880. t['tikatakana'] = 0x30C1;
  8881. t['tikatakanahalfwidth'] = 0xFF81;
  8882. t['tikeutacirclekorean'] = 0x3270;
  8883. t['tikeutaparenkorean'] = 0x3210;
  8884. t['tikeutcirclekorean'] = 0x3262;
  8885. t['tikeutkorean'] = 0x3137;
  8886. t['tikeutparenkorean'] = 0x3202;
  8887. t['tilde'] = 0x02DC;
  8888. t['tildebelowcmb'] = 0x0330;
  8889. t['tildecmb'] = 0x0303;
  8890. t['tildecomb'] = 0x0303;
  8891. t['tildedoublecmb'] = 0x0360;
  8892. t['tildeoperator'] = 0x223C;
  8893. t['tildeoverlaycmb'] = 0x0334;
  8894. t['tildeverticalcmb'] = 0x033E;
  8895. t['timescircle'] = 0x2297;
  8896. t['tipehahebrew'] = 0x0596;
  8897. t['tipehalefthebrew'] = 0x0596;
  8898. t['tippigurmukhi'] = 0x0A70;
  8899. t['titlocyrilliccmb'] = 0x0483;
  8900. t['tiwnarmenian'] = 0x057F;
  8901. t['tlinebelow'] = 0x1E6F;
  8902. t['tmonospace'] = 0xFF54;
  8903. t['toarmenian'] = 0x0569;
  8904. t['tohiragana'] = 0x3068;
  8905. t['tokatakana'] = 0x30C8;
  8906. t['tokatakanahalfwidth'] = 0xFF84;
  8907. t['tonebarextrahighmod'] = 0x02E5;
  8908. t['tonebarextralowmod'] = 0x02E9;
  8909. t['tonebarhighmod'] = 0x02E6;
  8910. t['tonebarlowmod'] = 0x02E8;
  8911. t['tonebarmidmod'] = 0x02E7;
  8912. t['tonefive'] = 0x01BD;
  8913. t['tonesix'] = 0x0185;
  8914. t['tonetwo'] = 0x01A8;
  8915. t['tonos'] = 0x0384;
  8916. t['tonsquare'] = 0x3327;
  8917. t['topatakthai'] = 0x0E0F;
  8918. t['tortoiseshellbracketleft'] = 0x3014;
  8919. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8920. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8921. t['tortoiseshellbracketright'] = 0x3015;
  8922. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8923. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8924. t['totaothai'] = 0x0E15;
  8925. t['tpalatalhook'] = 0x01AB;
  8926. t['tparen'] = 0x24AF;
  8927. t['trademark'] = 0x2122;
  8928. t['trademarksans'] = 0xF8EA;
  8929. t['trademarkserif'] = 0xF6DB;
  8930. t['tretroflexhook'] = 0x0288;
  8931. t['triagdn'] = 0x25BC;
  8932. t['triaglf'] = 0x25C4;
  8933. t['triagrt'] = 0x25BA;
  8934. t['triagup'] = 0x25B2;
  8935. t['ts'] = 0x02A6;
  8936. t['tsadi'] = 0x05E6;
  8937. t['tsadidagesh'] = 0xFB46;
  8938. t['tsadidageshhebrew'] = 0xFB46;
  8939. t['tsadihebrew'] = 0x05E6;
  8940. t['tsecyrillic'] = 0x0446;
  8941. t['tsere'] = 0x05B5;
  8942. t['tsere12'] = 0x05B5;
  8943. t['tsere1e'] = 0x05B5;
  8944. t['tsere2b'] = 0x05B5;
  8945. t['tserehebrew'] = 0x05B5;
  8946. t['tserenarrowhebrew'] = 0x05B5;
  8947. t['tserequarterhebrew'] = 0x05B5;
  8948. t['tserewidehebrew'] = 0x05B5;
  8949. t['tshecyrillic'] = 0x045B;
  8950. t['tsuperior'] = 0xF6F3;
  8951. t['ttabengali'] = 0x099F;
  8952. t['ttadeva'] = 0x091F;
  8953. t['ttagujarati'] = 0x0A9F;
  8954. t['ttagurmukhi'] = 0x0A1F;
  8955. t['tteharabic'] = 0x0679;
  8956. t['ttehfinalarabic'] = 0xFB67;
  8957. t['ttehinitialarabic'] = 0xFB68;
  8958. t['ttehmedialarabic'] = 0xFB69;
  8959. t['tthabengali'] = 0x09A0;
  8960. t['tthadeva'] = 0x0920;
  8961. t['tthagujarati'] = 0x0AA0;
  8962. t['tthagurmukhi'] = 0x0A20;
  8963. t['tturned'] = 0x0287;
  8964. t['tuhiragana'] = 0x3064;
  8965. t['tukatakana'] = 0x30C4;
  8966. t['tukatakanahalfwidth'] = 0xFF82;
  8967. t['tusmallhiragana'] = 0x3063;
  8968. t['tusmallkatakana'] = 0x30C3;
  8969. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8970. t['twelvecircle'] = 0x246B;
  8971. t['twelveparen'] = 0x247F;
  8972. t['twelveperiod'] = 0x2493;
  8973. t['twelveroman'] = 0x217B;
  8974. t['twentycircle'] = 0x2473;
  8975. t['twentyhangzhou'] = 0x5344;
  8976. t['twentyparen'] = 0x2487;
  8977. t['twentyperiod'] = 0x249B;
  8978. t['two'] = 0x0032;
  8979. t['twoarabic'] = 0x0662;
  8980. t['twobengali'] = 0x09E8;
  8981. t['twocircle'] = 0x2461;
  8982. t['twocircleinversesansserif'] = 0x278B;
  8983. t['twodeva'] = 0x0968;
  8984. t['twodotenleader'] = 0x2025;
  8985. t['twodotleader'] = 0x2025;
  8986. t['twodotleadervertical'] = 0xFE30;
  8987. t['twogujarati'] = 0x0AE8;
  8988. t['twogurmukhi'] = 0x0A68;
  8989. t['twohackarabic'] = 0x0662;
  8990. t['twohangzhou'] = 0x3022;
  8991. t['twoideographicparen'] = 0x3221;
  8992. t['twoinferior'] = 0x2082;
  8993. t['twomonospace'] = 0xFF12;
  8994. t['twonumeratorbengali'] = 0x09F5;
  8995. t['twooldstyle'] = 0xF732;
  8996. t['twoparen'] = 0x2475;
  8997. t['twoperiod'] = 0x2489;
  8998. t['twopersian'] = 0x06F2;
  8999. t['tworoman'] = 0x2171;
  9000. t['twostroke'] = 0x01BB;
  9001. t['twosuperior'] = 0x00B2;
  9002. t['twothai'] = 0x0E52;
  9003. t['twothirds'] = 0x2154;
  9004. t['u'] = 0x0075;
  9005. t['uacute'] = 0x00FA;
  9006. t['ubar'] = 0x0289;
  9007. t['ubengali'] = 0x0989;
  9008. t['ubopomofo'] = 0x3128;
  9009. t['ubreve'] = 0x016D;
  9010. t['ucaron'] = 0x01D4;
  9011. t['ucircle'] = 0x24E4;
  9012. t['ucircumflex'] = 0x00FB;
  9013. t['ucircumflexbelow'] = 0x1E77;
  9014. t['ucyrillic'] = 0x0443;
  9015. t['udattadeva'] = 0x0951;
  9016. t['udblacute'] = 0x0171;
  9017. t['udblgrave'] = 0x0215;
  9018. t['udeva'] = 0x0909;
  9019. t['udieresis'] = 0x00FC;
  9020. t['udieresisacute'] = 0x01D8;
  9021. t['udieresisbelow'] = 0x1E73;
  9022. t['udieresiscaron'] = 0x01DA;
  9023. t['udieresiscyrillic'] = 0x04F1;
  9024. t['udieresisgrave'] = 0x01DC;
  9025. t['udieresismacron'] = 0x01D6;
  9026. t['udotbelow'] = 0x1EE5;
  9027. t['ugrave'] = 0x00F9;
  9028. t['ugujarati'] = 0x0A89;
  9029. t['ugurmukhi'] = 0x0A09;
  9030. t['uhiragana'] = 0x3046;
  9031. t['uhookabove'] = 0x1EE7;
  9032. t['uhorn'] = 0x01B0;
  9033. t['uhornacute'] = 0x1EE9;
  9034. t['uhorndotbelow'] = 0x1EF1;
  9035. t['uhorngrave'] = 0x1EEB;
  9036. t['uhornhookabove'] = 0x1EED;
  9037. t['uhorntilde'] = 0x1EEF;
  9038. t['uhungarumlaut'] = 0x0171;
  9039. t['uhungarumlautcyrillic'] = 0x04F3;
  9040. t['uinvertedbreve'] = 0x0217;
  9041. t['ukatakana'] = 0x30A6;
  9042. t['ukatakanahalfwidth'] = 0xFF73;
  9043. t['ukcyrillic'] = 0x0479;
  9044. t['ukorean'] = 0x315C;
  9045. t['umacron'] = 0x016B;
  9046. t['umacroncyrillic'] = 0x04EF;
  9047. t['umacrondieresis'] = 0x1E7B;
  9048. t['umatragurmukhi'] = 0x0A41;
  9049. t['umonospace'] = 0xFF55;
  9050. t['underscore'] = 0x005F;
  9051. t['underscoredbl'] = 0x2017;
  9052. t['underscoremonospace'] = 0xFF3F;
  9053. t['underscorevertical'] = 0xFE33;
  9054. t['underscorewavy'] = 0xFE4F;
  9055. t['union'] = 0x222A;
  9056. t['universal'] = 0x2200;
  9057. t['uogonek'] = 0x0173;
  9058. t['uparen'] = 0x24B0;
  9059. t['upblock'] = 0x2580;
  9060. t['upperdothebrew'] = 0x05C4;
  9061. t['upsilon'] = 0x03C5;
  9062. t['upsilondieresis'] = 0x03CB;
  9063. t['upsilondieresistonos'] = 0x03B0;
  9064. t['upsilonlatin'] = 0x028A;
  9065. t['upsilontonos'] = 0x03CD;
  9066. t['uptackbelowcmb'] = 0x031D;
  9067. t['uptackmod'] = 0x02D4;
  9068. t['uragurmukhi'] = 0x0A73;
  9069. t['uring'] = 0x016F;
  9070. t['ushortcyrillic'] = 0x045E;
  9071. t['usmallhiragana'] = 0x3045;
  9072. t['usmallkatakana'] = 0x30A5;
  9073. t['usmallkatakanahalfwidth'] = 0xFF69;
  9074. t['ustraightcyrillic'] = 0x04AF;
  9075. t['ustraightstrokecyrillic'] = 0x04B1;
  9076. t['utilde'] = 0x0169;
  9077. t['utildeacute'] = 0x1E79;
  9078. t['utildebelow'] = 0x1E75;
  9079. t['uubengali'] = 0x098A;
  9080. t['uudeva'] = 0x090A;
  9081. t['uugujarati'] = 0x0A8A;
  9082. t['uugurmukhi'] = 0x0A0A;
  9083. t['uumatragurmukhi'] = 0x0A42;
  9084. t['uuvowelsignbengali'] = 0x09C2;
  9085. t['uuvowelsigndeva'] = 0x0942;
  9086. t['uuvowelsigngujarati'] = 0x0AC2;
  9087. t['uvowelsignbengali'] = 0x09C1;
  9088. t['uvowelsigndeva'] = 0x0941;
  9089. t['uvowelsigngujarati'] = 0x0AC1;
  9090. t['v'] = 0x0076;
  9091. t['vadeva'] = 0x0935;
  9092. t['vagujarati'] = 0x0AB5;
  9093. t['vagurmukhi'] = 0x0A35;
  9094. t['vakatakana'] = 0x30F7;
  9095. t['vav'] = 0x05D5;
  9096. t['vavdagesh'] = 0xFB35;
  9097. t['vavdagesh65'] = 0xFB35;
  9098. t['vavdageshhebrew'] = 0xFB35;
  9099. t['vavhebrew'] = 0x05D5;
  9100. t['vavholam'] = 0xFB4B;
  9101. t['vavholamhebrew'] = 0xFB4B;
  9102. t['vavvavhebrew'] = 0x05F0;
  9103. t['vavyodhebrew'] = 0x05F1;
  9104. t['vcircle'] = 0x24E5;
  9105. t['vdotbelow'] = 0x1E7F;
  9106. t['vecyrillic'] = 0x0432;
  9107. t['veharabic'] = 0x06A4;
  9108. t['vehfinalarabic'] = 0xFB6B;
  9109. t['vehinitialarabic'] = 0xFB6C;
  9110. t['vehmedialarabic'] = 0xFB6D;
  9111. t['vekatakana'] = 0x30F9;
  9112. t['venus'] = 0x2640;
  9113. t['verticalbar'] = 0x007C;
  9114. t['verticallineabovecmb'] = 0x030D;
  9115. t['verticallinebelowcmb'] = 0x0329;
  9116. t['verticallinelowmod'] = 0x02CC;
  9117. t['verticallinemod'] = 0x02C8;
  9118. t['vewarmenian'] = 0x057E;
  9119. t['vhook'] = 0x028B;
  9120. t['vikatakana'] = 0x30F8;
  9121. t['viramabengali'] = 0x09CD;
  9122. t['viramadeva'] = 0x094D;
  9123. t['viramagujarati'] = 0x0ACD;
  9124. t['visargabengali'] = 0x0983;
  9125. t['visargadeva'] = 0x0903;
  9126. t['visargagujarati'] = 0x0A83;
  9127. t['vmonospace'] = 0xFF56;
  9128. t['voarmenian'] = 0x0578;
  9129. t['voicediterationhiragana'] = 0x309E;
  9130. t['voicediterationkatakana'] = 0x30FE;
  9131. t['voicedmarkkana'] = 0x309B;
  9132. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9133. t['vokatakana'] = 0x30FA;
  9134. t['vparen'] = 0x24B1;
  9135. t['vtilde'] = 0x1E7D;
  9136. t['vturned'] = 0x028C;
  9137. t['vuhiragana'] = 0x3094;
  9138. t['vukatakana'] = 0x30F4;
  9139. t['w'] = 0x0077;
  9140. t['wacute'] = 0x1E83;
  9141. t['waekorean'] = 0x3159;
  9142. t['wahiragana'] = 0x308F;
  9143. t['wakatakana'] = 0x30EF;
  9144. t['wakatakanahalfwidth'] = 0xFF9C;
  9145. t['wakorean'] = 0x3158;
  9146. t['wasmallhiragana'] = 0x308E;
  9147. t['wasmallkatakana'] = 0x30EE;
  9148. t['wattosquare'] = 0x3357;
  9149. t['wavedash'] = 0x301C;
  9150. t['wavyunderscorevertical'] = 0xFE34;
  9151. t['wawarabic'] = 0x0648;
  9152. t['wawfinalarabic'] = 0xFEEE;
  9153. t['wawhamzaabovearabic'] = 0x0624;
  9154. t['wawhamzaabovefinalarabic'] = 0xFE86;
  9155. t['wbsquare'] = 0x33DD;
  9156. t['wcircle'] = 0x24E6;
  9157. t['wcircumflex'] = 0x0175;
  9158. t['wdieresis'] = 0x1E85;
  9159. t['wdotaccent'] = 0x1E87;
  9160. t['wdotbelow'] = 0x1E89;
  9161. t['wehiragana'] = 0x3091;
  9162. t['weierstrass'] = 0x2118;
  9163. t['wekatakana'] = 0x30F1;
  9164. t['wekorean'] = 0x315E;
  9165. t['weokorean'] = 0x315D;
  9166. t['wgrave'] = 0x1E81;
  9167. t['whitebullet'] = 0x25E6;
  9168. t['whitecircle'] = 0x25CB;
  9169. t['whitecircleinverse'] = 0x25D9;
  9170. t['whitecornerbracketleft'] = 0x300E;
  9171. t['whitecornerbracketleftvertical'] = 0xFE43;
  9172. t['whitecornerbracketright'] = 0x300F;
  9173. t['whitecornerbracketrightvertical'] = 0xFE44;
  9174. t['whitediamond'] = 0x25C7;
  9175. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  9176. t['whitedownpointingsmalltriangle'] = 0x25BF;
  9177. t['whitedownpointingtriangle'] = 0x25BD;
  9178. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  9179. t['whiteleftpointingtriangle'] = 0x25C1;
  9180. t['whitelenticularbracketleft'] = 0x3016;
  9181. t['whitelenticularbracketright'] = 0x3017;
  9182. t['whiterightpointingsmalltriangle'] = 0x25B9;
  9183. t['whiterightpointingtriangle'] = 0x25B7;
  9184. t['whitesmallsquare'] = 0x25AB;
  9185. t['whitesmilingface'] = 0x263A;
  9186. t['whitesquare'] = 0x25A1;
  9187. t['whitestar'] = 0x2606;
  9188. t['whitetelephone'] = 0x260F;
  9189. t['whitetortoiseshellbracketleft'] = 0x3018;
  9190. t['whitetortoiseshellbracketright'] = 0x3019;
  9191. t['whiteuppointingsmalltriangle'] = 0x25B5;
  9192. t['whiteuppointingtriangle'] = 0x25B3;
  9193. t['wihiragana'] = 0x3090;
  9194. t['wikatakana'] = 0x30F0;
  9195. t['wikorean'] = 0x315F;
  9196. t['wmonospace'] = 0xFF57;
  9197. t['wohiragana'] = 0x3092;
  9198. t['wokatakana'] = 0x30F2;
  9199. t['wokatakanahalfwidth'] = 0xFF66;
  9200. t['won'] = 0x20A9;
  9201. t['wonmonospace'] = 0xFFE6;
  9202. t['wowaenthai'] = 0x0E27;
  9203. t['wparen'] = 0x24B2;
  9204. t['wring'] = 0x1E98;
  9205. t['wsuperior'] = 0x02B7;
  9206. t['wturned'] = 0x028D;
  9207. t['wynn'] = 0x01BF;
  9208. t['x'] = 0x0078;
  9209. t['xabovecmb'] = 0x033D;
  9210. t['xbopomofo'] = 0x3112;
  9211. t['xcircle'] = 0x24E7;
  9212. t['xdieresis'] = 0x1E8D;
  9213. t['xdotaccent'] = 0x1E8B;
  9214. t['xeharmenian'] = 0x056D;
  9215. t['xi'] = 0x03BE;
  9216. t['xmonospace'] = 0xFF58;
  9217. t['xparen'] = 0x24B3;
  9218. t['xsuperior'] = 0x02E3;
  9219. t['y'] = 0x0079;
  9220. t['yaadosquare'] = 0x334E;
  9221. t['yabengali'] = 0x09AF;
  9222. t['yacute'] = 0x00FD;
  9223. t['yadeva'] = 0x092F;
  9224. t['yaekorean'] = 0x3152;
  9225. t['yagujarati'] = 0x0AAF;
  9226. t['yagurmukhi'] = 0x0A2F;
  9227. t['yahiragana'] = 0x3084;
  9228. t['yakatakana'] = 0x30E4;
  9229. t['yakatakanahalfwidth'] = 0xFF94;
  9230. t['yakorean'] = 0x3151;
  9231. t['yamakkanthai'] = 0x0E4E;
  9232. t['yasmallhiragana'] = 0x3083;
  9233. t['yasmallkatakana'] = 0x30E3;
  9234. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  9235. t['yatcyrillic'] = 0x0463;
  9236. t['ycircle'] = 0x24E8;
  9237. t['ycircumflex'] = 0x0177;
  9238. t['ydieresis'] = 0x00FF;
  9239. t['ydotaccent'] = 0x1E8F;
  9240. t['ydotbelow'] = 0x1EF5;
  9241. t['yeharabic'] = 0x064A;
  9242. t['yehbarreearabic'] = 0x06D2;
  9243. t['yehbarreefinalarabic'] = 0xFBAF;
  9244. t['yehfinalarabic'] = 0xFEF2;
  9245. t['yehhamzaabovearabic'] = 0x0626;
  9246. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  9247. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  9248. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  9249. t['yehinitialarabic'] = 0xFEF3;
  9250. t['yehmedialarabic'] = 0xFEF4;
  9251. t['yehmeeminitialarabic'] = 0xFCDD;
  9252. t['yehmeemisolatedarabic'] = 0xFC58;
  9253. t['yehnoonfinalarabic'] = 0xFC94;
  9254. t['yehthreedotsbelowarabic'] = 0x06D1;
  9255. t['yekorean'] = 0x3156;
  9256. t['yen'] = 0x00A5;
  9257. t['yenmonospace'] = 0xFFE5;
  9258. t['yeokorean'] = 0x3155;
  9259. t['yeorinhieuhkorean'] = 0x3186;
  9260. t['yerahbenyomohebrew'] = 0x05AA;
  9261. t['yerahbenyomolefthebrew'] = 0x05AA;
  9262. t['yericyrillic'] = 0x044B;
  9263. t['yerudieresiscyrillic'] = 0x04F9;
  9264. t['yesieungkorean'] = 0x3181;
  9265. t['yesieungpansioskorean'] = 0x3183;
  9266. t['yesieungsioskorean'] = 0x3182;
  9267. t['yetivhebrew'] = 0x059A;
  9268. t['ygrave'] = 0x1EF3;
  9269. t['yhook'] = 0x01B4;
  9270. t['yhookabove'] = 0x1EF7;
  9271. t['yiarmenian'] = 0x0575;
  9272. t['yicyrillic'] = 0x0457;
  9273. t['yikorean'] = 0x3162;
  9274. t['yinyang'] = 0x262F;
  9275. t['yiwnarmenian'] = 0x0582;
  9276. t['ymonospace'] = 0xFF59;
  9277. t['yod'] = 0x05D9;
  9278. t['yoddagesh'] = 0xFB39;
  9279. t['yoddageshhebrew'] = 0xFB39;
  9280. t['yodhebrew'] = 0x05D9;
  9281. t['yodyodhebrew'] = 0x05F2;
  9282. t['yodyodpatahhebrew'] = 0xFB1F;
  9283. t['yohiragana'] = 0x3088;
  9284. t['yoikorean'] = 0x3189;
  9285. t['yokatakana'] = 0x30E8;
  9286. t['yokatakanahalfwidth'] = 0xFF96;
  9287. t['yokorean'] = 0x315B;
  9288. t['yosmallhiragana'] = 0x3087;
  9289. t['yosmallkatakana'] = 0x30E7;
  9290. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  9291. t['yotgreek'] = 0x03F3;
  9292. t['yoyaekorean'] = 0x3188;
  9293. t['yoyakorean'] = 0x3187;
  9294. t['yoyakthai'] = 0x0E22;
  9295. t['yoyingthai'] = 0x0E0D;
  9296. t['yparen'] = 0x24B4;
  9297. t['ypogegrammeni'] = 0x037A;
  9298. t['ypogegrammenigreekcmb'] = 0x0345;
  9299. t['yr'] = 0x01A6;
  9300. t['yring'] = 0x1E99;
  9301. t['ysuperior'] = 0x02B8;
  9302. t['ytilde'] = 0x1EF9;
  9303. t['yturned'] = 0x028E;
  9304. t['yuhiragana'] = 0x3086;
  9305. t['yuikorean'] = 0x318C;
  9306. t['yukatakana'] = 0x30E6;
  9307. t['yukatakanahalfwidth'] = 0xFF95;
  9308. t['yukorean'] = 0x3160;
  9309. t['yusbigcyrillic'] = 0x046B;
  9310. t['yusbigiotifiedcyrillic'] = 0x046D;
  9311. t['yuslittlecyrillic'] = 0x0467;
  9312. t['yuslittleiotifiedcyrillic'] = 0x0469;
  9313. t['yusmallhiragana'] = 0x3085;
  9314. t['yusmallkatakana'] = 0x30E5;
  9315. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  9316. t['yuyekorean'] = 0x318B;
  9317. t['yuyeokorean'] = 0x318A;
  9318. t['yyabengali'] = 0x09DF;
  9319. t['yyadeva'] = 0x095F;
  9320. t['z'] = 0x007A;
  9321. t['zaarmenian'] = 0x0566;
  9322. t['zacute'] = 0x017A;
  9323. t['zadeva'] = 0x095B;
  9324. t['zagurmukhi'] = 0x0A5B;
  9325. t['zaharabic'] = 0x0638;
  9326. t['zahfinalarabic'] = 0xFEC6;
  9327. t['zahinitialarabic'] = 0xFEC7;
  9328. t['zahiragana'] = 0x3056;
  9329. t['zahmedialarabic'] = 0xFEC8;
  9330. t['zainarabic'] = 0x0632;
  9331. t['zainfinalarabic'] = 0xFEB0;
  9332. t['zakatakana'] = 0x30B6;
  9333. t['zaqefgadolhebrew'] = 0x0595;
  9334. t['zaqefqatanhebrew'] = 0x0594;
  9335. t['zarqahebrew'] = 0x0598;
  9336. t['zayin'] = 0x05D6;
  9337. t['zayindagesh'] = 0xFB36;
  9338. t['zayindageshhebrew'] = 0xFB36;
  9339. t['zayinhebrew'] = 0x05D6;
  9340. t['zbopomofo'] = 0x3117;
  9341. t['zcaron'] = 0x017E;
  9342. t['zcircle'] = 0x24E9;
  9343. t['zcircumflex'] = 0x1E91;
  9344. t['zcurl'] = 0x0291;
  9345. t['zdot'] = 0x017C;
  9346. t['zdotaccent'] = 0x017C;
  9347. t['zdotbelow'] = 0x1E93;
  9348. t['zecyrillic'] = 0x0437;
  9349. t['zedescendercyrillic'] = 0x0499;
  9350. t['zedieresiscyrillic'] = 0x04DF;
  9351. t['zehiragana'] = 0x305C;
  9352. t['zekatakana'] = 0x30BC;
  9353. t['zero'] = 0x0030;
  9354. t['zeroarabic'] = 0x0660;
  9355. t['zerobengali'] = 0x09E6;
  9356. t['zerodeva'] = 0x0966;
  9357. t['zerogujarati'] = 0x0AE6;
  9358. t['zerogurmukhi'] = 0x0A66;
  9359. t['zerohackarabic'] = 0x0660;
  9360. t['zeroinferior'] = 0x2080;
  9361. t['zeromonospace'] = 0xFF10;
  9362. t['zerooldstyle'] = 0xF730;
  9363. t['zeropersian'] = 0x06F0;
  9364. t['zerosuperior'] = 0x2070;
  9365. t['zerothai'] = 0x0E50;
  9366. t['zerowidthjoiner'] = 0xFEFF;
  9367. t['zerowidthnonjoiner'] = 0x200C;
  9368. t['zerowidthspace'] = 0x200B;
  9369. t['zeta'] = 0x03B6;
  9370. t['zhbopomofo'] = 0x3113;
  9371. t['zhearmenian'] = 0x056A;
  9372. t['zhebrevecyrillic'] = 0x04C2;
  9373. t['zhecyrillic'] = 0x0436;
  9374. t['zhedescendercyrillic'] = 0x0497;
  9375. t['zhedieresiscyrillic'] = 0x04DD;
  9376. t['zihiragana'] = 0x3058;
  9377. t['zikatakana'] = 0x30B8;
  9378. t['zinorhebrew'] = 0x05AE;
  9379. t['zlinebelow'] = 0x1E95;
  9380. t['zmonospace'] = 0xFF5A;
  9381. t['zohiragana'] = 0x305E;
  9382. t['zokatakana'] = 0x30BE;
  9383. t['zparen'] = 0x24B5;
  9384. t['zretroflexhook'] = 0x0290;
  9385. t['zstroke'] = 0x01B6;
  9386. t['zuhiragana'] = 0x305A;
  9387. t['zukatakana'] = 0x30BA;
  9388. t['.notdef'] = 0x0000;
  9389. });
  9390. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9391. t['space'] = 0x0020;
  9392. t['a1'] = 0x2701;
  9393. t['a2'] = 0x2702;
  9394. t['a202'] = 0x2703;
  9395. t['a3'] = 0x2704;
  9396. t['a4'] = 0x260E;
  9397. t['a5'] = 0x2706;
  9398. t['a119'] = 0x2707;
  9399. t['a118'] = 0x2708;
  9400. t['a117'] = 0x2709;
  9401. t['a11'] = 0x261B;
  9402. t['a12'] = 0x261E;
  9403. t['a13'] = 0x270C;
  9404. t['a14'] = 0x270D;
  9405. t['a15'] = 0x270E;
  9406. t['a16'] = 0x270F;
  9407. t['a105'] = 0x2710;
  9408. t['a17'] = 0x2711;
  9409. t['a18'] = 0x2712;
  9410. t['a19'] = 0x2713;
  9411. t['a20'] = 0x2714;
  9412. t['a21'] = 0x2715;
  9413. t['a22'] = 0x2716;
  9414. t['a23'] = 0x2717;
  9415. t['a24'] = 0x2718;
  9416. t['a25'] = 0x2719;
  9417. t['a26'] = 0x271A;
  9418. t['a27'] = 0x271B;
  9419. t['a28'] = 0x271C;
  9420. t['a6'] = 0x271D;
  9421. t['a7'] = 0x271E;
  9422. t['a8'] = 0x271F;
  9423. t['a9'] = 0x2720;
  9424. t['a10'] = 0x2721;
  9425. t['a29'] = 0x2722;
  9426. t['a30'] = 0x2723;
  9427. t['a31'] = 0x2724;
  9428. t['a32'] = 0x2725;
  9429. t['a33'] = 0x2726;
  9430. t['a34'] = 0x2727;
  9431. t['a35'] = 0x2605;
  9432. t['a36'] = 0x2729;
  9433. t['a37'] = 0x272A;
  9434. t['a38'] = 0x272B;
  9435. t['a39'] = 0x272C;
  9436. t['a40'] = 0x272D;
  9437. t['a41'] = 0x272E;
  9438. t['a42'] = 0x272F;
  9439. t['a43'] = 0x2730;
  9440. t['a44'] = 0x2731;
  9441. t['a45'] = 0x2732;
  9442. t['a46'] = 0x2733;
  9443. t['a47'] = 0x2734;
  9444. t['a48'] = 0x2735;
  9445. t['a49'] = 0x2736;
  9446. t['a50'] = 0x2737;
  9447. t['a51'] = 0x2738;
  9448. t['a52'] = 0x2739;
  9449. t['a53'] = 0x273A;
  9450. t['a54'] = 0x273B;
  9451. t['a55'] = 0x273C;
  9452. t['a56'] = 0x273D;
  9453. t['a57'] = 0x273E;
  9454. t['a58'] = 0x273F;
  9455. t['a59'] = 0x2740;
  9456. t['a60'] = 0x2741;
  9457. t['a61'] = 0x2742;
  9458. t['a62'] = 0x2743;
  9459. t['a63'] = 0x2744;
  9460. t['a64'] = 0x2745;
  9461. t['a65'] = 0x2746;
  9462. t['a66'] = 0x2747;
  9463. t['a67'] = 0x2748;
  9464. t['a68'] = 0x2749;
  9465. t['a69'] = 0x274A;
  9466. t['a70'] = 0x274B;
  9467. t['a71'] = 0x25CF;
  9468. t['a72'] = 0x274D;
  9469. t['a73'] = 0x25A0;
  9470. t['a74'] = 0x274F;
  9471. t['a203'] = 0x2750;
  9472. t['a75'] = 0x2751;
  9473. t['a204'] = 0x2752;
  9474. t['a76'] = 0x25B2;
  9475. t['a77'] = 0x25BC;
  9476. t['a78'] = 0x25C6;
  9477. t['a79'] = 0x2756;
  9478. t['a81'] = 0x25D7;
  9479. t['a82'] = 0x2758;
  9480. t['a83'] = 0x2759;
  9481. t['a84'] = 0x275A;
  9482. t['a97'] = 0x275B;
  9483. t['a98'] = 0x275C;
  9484. t['a99'] = 0x275D;
  9485. t['a100'] = 0x275E;
  9486. t['a101'] = 0x2761;
  9487. t['a102'] = 0x2762;
  9488. t['a103'] = 0x2763;
  9489. t['a104'] = 0x2764;
  9490. t['a106'] = 0x2765;
  9491. t['a107'] = 0x2766;
  9492. t['a108'] = 0x2767;
  9493. t['a112'] = 0x2663;
  9494. t['a111'] = 0x2666;
  9495. t['a110'] = 0x2665;
  9496. t['a109'] = 0x2660;
  9497. t['a120'] = 0x2460;
  9498. t['a121'] = 0x2461;
  9499. t['a122'] = 0x2462;
  9500. t['a123'] = 0x2463;
  9501. t['a124'] = 0x2464;
  9502. t['a125'] = 0x2465;
  9503. t['a126'] = 0x2466;
  9504. t['a127'] = 0x2467;
  9505. t['a128'] = 0x2468;
  9506. t['a129'] = 0x2469;
  9507. t['a130'] = 0x2776;
  9508. t['a131'] = 0x2777;
  9509. t['a132'] = 0x2778;
  9510. t['a133'] = 0x2779;
  9511. t['a134'] = 0x277A;
  9512. t['a135'] = 0x277B;
  9513. t['a136'] = 0x277C;
  9514. t['a137'] = 0x277D;
  9515. t['a138'] = 0x277E;
  9516. t['a139'] = 0x277F;
  9517. t['a140'] = 0x2780;
  9518. t['a141'] = 0x2781;
  9519. t['a142'] = 0x2782;
  9520. t['a143'] = 0x2783;
  9521. t['a144'] = 0x2784;
  9522. t['a145'] = 0x2785;
  9523. t['a146'] = 0x2786;
  9524. t['a147'] = 0x2787;
  9525. t['a148'] = 0x2788;
  9526. t['a149'] = 0x2789;
  9527. t['a150'] = 0x278A;
  9528. t['a151'] = 0x278B;
  9529. t['a152'] = 0x278C;
  9530. t['a153'] = 0x278D;
  9531. t['a154'] = 0x278E;
  9532. t['a155'] = 0x278F;
  9533. t['a156'] = 0x2790;
  9534. t['a157'] = 0x2791;
  9535. t['a158'] = 0x2792;
  9536. t['a159'] = 0x2793;
  9537. t['a160'] = 0x2794;
  9538. t['a161'] = 0x2192;
  9539. t['a163'] = 0x2194;
  9540. t['a164'] = 0x2195;
  9541. t['a196'] = 0x2798;
  9542. t['a165'] = 0x2799;
  9543. t['a192'] = 0x279A;
  9544. t['a166'] = 0x279B;
  9545. t['a167'] = 0x279C;
  9546. t['a168'] = 0x279D;
  9547. t['a169'] = 0x279E;
  9548. t['a170'] = 0x279F;
  9549. t['a171'] = 0x27A0;
  9550. t['a172'] = 0x27A1;
  9551. t['a173'] = 0x27A2;
  9552. t['a162'] = 0x27A3;
  9553. t['a174'] = 0x27A4;
  9554. t['a175'] = 0x27A5;
  9555. t['a176'] = 0x27A6;
  9556. t['a177'] = 0x27A7;
  9557. t['a178'] = 0x27A8;
  9558. t['a179'] = 0x27A9;
  9559. t['a193'] = 0x27AA;
  9560. t['a180'] = 0x27AB;
  9561. t['a199'] = 0x27AC;
  9562. t['a181'] = 0x27AD;
  9563. t['a200'] = 0x27AE;
  9564. t['a182'] = 0x27AF;
  9565. t['a201'] = 0x27B1;
  9566. t['a183'] = 0x27B2;
  9567. t['a184'] = 0x27B3;
  9568. t['a197'] = 0x27B4;
  9569. t['a185'] = 0x27B5;
  9570. t['a194'] = 0x27B6;
  9571. t['a198'] = 0x27B7;
  9572. t['a186'] = 0x27B8;
  9573. t['a195'] = 0x27B9;
  9574. t['a187'] = 0x27BA;
  9575. t['a188'] = 0x27BB;
  9576. t['a189'] = 0x27BC;
  9577. t['a190'] = 0x27BD;
  9578. t['a191'] = 0x27BE;
  9579. t['a89'] = 0x2768; // 0xF8D7
  9580. t['a90'] = 0x2769; // 0xF8D8
  9581. t['a93'] = 0x276A; // 0xF8D9
  9582. t['a94'] = 0x276B; // 0xF8DA
  9583. t['a91'] = 0x276C; // 0xF8DB
  9584. t['a92'] = 0x276D; // 0xF8DC
  9585. t['a205'] = 0x276E; // 0xF8DD
  9586. t['a85'] = 0x276F; // 0xF8DE
  9587. t['a206'] = 0x2770; // 0xF8DF
  9588. t['a86'] = 0x2771; // 0xF8E0
  9589. t['a87'] = 0x2772; // 0xF8E1
  9590. t['a88'] = 0x2773; // 0xF8E2
  9591. t['a95'] = 0x2774; // 0xF8E3
  9592. t['a96'] = 0x2775; // 0xF8E4
  9593. t['.notdef'] = 0x0000;
  9594. });
  9595. exports.getGlyphsUnicode = getGlyphsUnicode;
  9596. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9597. }));
  9598. (function (root, factory) {
  9599. {
  9600. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9601. root.pdfjsCoreArithmeticDecoder);
  9602. }
  9603. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9604. var error = sharedUtil.error;
  9605. var log2 = sharedUtil.log2;
  9606. var readInt8 = sharedUtil.readInt8;
  9607. var readUint16 = sharedUtil.readUint16;
  9608. var readUint32 = sharedUtil.readUint32;
  9609. var shadow = sharedUtil.shadow;
  9610. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9611. var Jbig2Image = (function Jbig2ImageClosure() {
  9612. // Utility data structures
  9613. function ContextCache() {}
  9614. ContextCache.prototype = {
  9615. getContexts: function(id) {
  9616. if (id in this) {
  9617. return this[id];
  9618. }
  9619. return (this[id] = new Int8Array(1 << 16));
  9620. }
  9621. };
  9622. function DecodingContext(data, start, end) {
  9623. this.data = data;
  9624. this.start = start;
  9625. this.end = end;
  9626. }
  9627. DecodingContext.prototype = {
  9628. get decoder() {
  9629. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9630. return shadow(this, 'decoder', decoder);
  9631. },
  9632. get contextCache() {
  9633. var cache = new ContextCache();
  9634. return shadow(this, 'contextCache', cache);
  9635. }
  9636. };
  9637. // Annex A. Arithmetic Integer Decoding Procedure
  9638. // A.2 Procedure for decoding values
  9639. function decodeInteger(contextCache, procedure, decoder) {
  9640. var contexts = contextCache.getContexts(procedure);
  9641. var prev = 1;
  9642. function readBits(length) {
  9643. var v = 0;
  9644. for (var i = 0; i < length; i++) {
  9645. var bit = decoder.readBit(contexts, prev);
  9646. prev = (prev < 256 ? (prev << 1) | bit :
  9647. (((prev << 1) | bit) & 511) | 256);
  9648. v = (v << 1) | bit;
  9649. }
  9650. return v >>> 0;
  9651. }
  9652. var sign = readBits(1);
  9653. var value = readBits(1) ?
  9654. (readBits(1) ?
  9655. (readBits(1) ?
  9656. (readBits(1) ?
  9657. (readBits(1) ?
  9658. (readBits(32) + 4436) :
  9659. readBits(12) + 340) :
  9660. readBits(8) + 84) :
  9661. readBits(6) + 20) :
  9662. readBits(4) + 4) :
  9663. readBits(2);
  9664. return (sign === 0 ? value : (value > 0 ? -value : null));
  9665. }
  9666. // A.3 The IAID decoding procedure
  9667. function decodeIAID(contextCache, decoder, codeLength) {
  9668. var contexts = contextCache.getContexts('IAID');
  9669. var prev = 1;
  9670. for (var i = 0; i < codeLength; i++) {
  9671. var bit = decoder.readBit(contexts, prev);
  9672. prev = (prev << 1) | bit;
  9673. }
  9674. if (codeLength < 31) {
  9675. return prev & ((1 << codeLength) - 1);
  9676. }
  9677. return prev & 0x7FFFFFFF;
  9678. }
  9679. // 7.3 Segment types
  9680. var SegmentTypes = [
  9681. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9682. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9683. null, null, null, null, null, 'patternDictionary', null, null, null,
  9684. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9685. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9686. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9687. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9688. 'IntermediateGenericRefinementRegion', null,
  9689. 'ImmediateGenericRefinementRegion',
  9690. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9691. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9692. 'Tables', null, null, null, null, null, null, null, null,
  9693. 'Extension'
  9694. ];
  9695. var CodingTemplates = [
  9696. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9697. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9698. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9699. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9700. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9701. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9702. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9703. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9704. {x: -1, y: 0}],
  9705. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9706. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9707. ];
  9708. var RefinementTemplates = [
  9709. {
  9710. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9711. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9712. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9713. },
  9714. {
  9715. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9716. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9717. {x: 0, y: 1}, {x: 1, y: 1}]
  9718. }
  9719. ];
  9720. // See 6.2.5.7 Decoding the bitmap.
  9721. var ReusedContexts = [
  9722. 0x9B25, // 10011 0110010 0101
  9723. 0x0795, // 0011 110010 101
  9724. 0x00E5, // 001 11001 01
  9725. 0x0195 // 011001 0101
  9726. ];
  9727. var RefinementReusedContexts = [
  9728. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9729. 0x0008 // '0000' + '001000'
  9730. ];
  9731. function decodeBitmapTemplate0(width, height, decodingContext) {
  9732. var decoder = decodingContext.decoder;
  9733. var contexts = decodingContext.contextCache.getContexts('GB');
  9734. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9735. // ...ooooo....
  9736. // ..ooooooo... Context template for current pixel (X)
  9737. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9738. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9739. for (i = 0; i < height; i++) {
  9740. row = bitmap[i] = new Uint8Array(width);
  9741. row1 = (i < 1) ? row : bitmap[i - 1];
  9742. row2 = (i < 2) ? row : bitmap[i - 2];
  9743. // At the beginning of each row:
  9744. // Fill contextLabel with pixels that are above/right of (X)
  9745. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9746. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9747. (row1[3] << 4);
  9748. for (j = 0; j < width; j++) {
  9749. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9750. // At each pixel: Clear contextLabel pixels that are shifted
  9751. // out of the context, then add new ones.
  9752. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9753. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9754. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9755. }
  9756. }
  9757. return bitmap;
  9758. }
  9759. // 6.2 Generic Region Decoding Procedure
  9760. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9761. decodingContext) {
  9762. if (mmr) {
  9763. error('JBIG2 error: MMR encoding is not supported');
  9764. }
  9765. // Use optimized version for the most common case
  9766. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9767. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9768. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9769. return decodeBitmapTemplate0(width, height, decodingContext);
  9770. }
  9771. var useskip = !!skip;
  9772. var template = CodingTemplates[templateIndex].concat(at);
  9773. // Sorting is non-standard, and it is not required. But sorting increases
  9774. // the number of template bits that can be reused from the previous
  9775. // contextLabel in the main loop.
  9776. template.sort(function (a, b) {
  9777. return (a.y - b.y) || (a.x - b.x);
  9778. });
  9779. var templateLength = template.length;
  9780. var templateX = new Int8Array(templateLength);
  9781. var templateY = new Int8Array(templateLength);
  9782. var changingTemplateEntries = [];
  9783. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9784. var c, k;
  9785. for (k = 0; k < templateLength; k++) {
  9786. templateX[k] = template[k].x;
  9787. templateY[k] = template[k].y;
  9788. minX = Math.min(minX, template[k].x);
  9789. maxX = Math.max(maxX, template[k].x);
  9790. minY = Math.min(minY, template[k].y);
  9791. // Check if the template pixel appears in two consecutive context labels,
  9792. // so it can be reused. Otherwise, we add it to the list of changing
  9793. // template entries.
  9794. if (k < templateLength - 1 &&
  9795. template[k].y === template[k + 1].y &&
  9796. template[k].x === template[k + 1].x - 1) {
  9797. reuseMask |= 1 << (templateLength - 1 - k);
  9798. } else {
  9799. changingTemplateEntries.push(k);
  9800. }
  9801. }
  9802. var changingEntriesLength = changingTemplateEntries.length;
  9803. var changingTemplateX = new Int8Array(changingEntriesLength);
  9804. var changingTemplateY = new Int8Array(changingEntriesLength);
  9805. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9806. for (c = 0; c < changingEntriesLength; c++) {
  9807. k = changingTemplateEntries[c];
  9808. changingTemplateX[c] = template[k].x;
  9809. changingTemplateY[c] = template[k].y;
  9810. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9811. }
  9812. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9813. var sbb_left = -minX;
  9814. var sbb_top = -minY;
  9815. var sbb_right = width - maxX;
  9816. var pseudoPixelContext = ReusedContexts[templateIndex];
  9817. var row = new Uint8Array(width);
  9818. var bitmap = [];
  9819. var decoder = decodingContext.decoder;
  9820. var contexts = decodingContext.contextCache.getContexts('GB');
  9821. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9822. for (var i = 0; i < height; i++) {
  9823. if (prediction) {
  9824. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9825. ltp ^= sltp;
  9826. if (ltp) {
  9827. bitmap.push(row); // duplicate previous row
  9828. continue;
  9829. }
  9830. }
  9831. row = new Uint8Array(row);
  9832. bitmap.push(row);
  9833. for (j = 0; j < width; j++) {
  9834. if (useskip && skip[i][j]) {
  9835. row[j] = 0;
  9836. continue;
  9837. }
  9838. // Are we in the middle of a scanline, so we can reuse contextLabel
  9839. // bits?
  9840. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9841. // If yes, we can just shift the bits that are reusable and only
  9842. // fetch the remaining ones.
  9843. contextLabel = (contextLabel << 1) & reuseMask;
  9844. for (k = 0; k < changingEntriesLength; k++) {
  9845. i0 = i + changingTemplateY[k];
  9846. j0 = j + changingTemplateX[k];
  9847. bit = bitmap[i0][j0];
  9848. if (bit) {
  9849. bit = changingTemplateBit[k];
  9850. contextLabel |= bit;
  9851. }
  9852. }
  9853. } else {
  9854. // compute the contextLabel from scratch
  9855. contextLabel = 0;
  9856. shift = templateLength - 1;
  9857. for (k = 0; k < templateLength; k++, shift--) {
  9858. j0 = j + templateX[k];
  9859. if (j0 >= 0 && j0 < width) {
  9860. i0 = i + templateY[k];
  9861. if (i0 >= 0) {
  9862. bit = bitmap[i0][j0];
  9863. if (bit) {
  9864. contextLabel |= bit << shift;
  9865. }
  9866. }
  9867. }
  9868. }
  9869. }
  9870. var pixel = decoder.readBit(contexts, contextLabel);
  9871. row[j] = pixel;
  9872. }
  9873. }
  9874. return bitmap;
  9875. }
  9876. // 6.3.2 Generic Refinement Region Decoding Procedure
  9877. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9878. offsetX, offsetY, prediction, at,
  9879. decodingContext) {
  9880. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9881. if (templateIndex === 0) {
  9882. codingTemplate = codingTemplate.concat([at[0]]);
  9883. }
  9884. var codingTemplateLength = codingTemplate.length;
  9885. var codingTemplateX = new Int32Array(codingTemplateLength);
  9886. var codingTemplateY = new Int32Array(codingTemplateLength);
  9887. var k;
  9888. for (k = 0; k < codingTemplateLength; k++) {
  9889. codingTemplateX[k] = codingTemplate[k].x;
  9890. codingTemplateY[k] = codingTemplate[k].y;
  9891. }
  9892. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9893. if (templateIndex === 0) {
  9894. referenceTemplate = referenceTemplate.concat([at[1]]);
  9895. }
  9896. var referenceTemplateLength = referenceTemplate.length;
  9897. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9898. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9899. for (k = 0; k < referenceTemplateLength; k++) {
  9900. referenceTemplateX[k] = referenceTemplate[k].x;
  9901. referenceTemplateY[k] = referenceTemplate[k].y;
  9902. }
  9903. var referenceWidth = referenceBitmap[0].length;
  9904. var referenceHeight = referenceBitmap.length;
  9905. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9906. var bitmap = [];
  9907. var decoder = decodingContext.decoder;
  9908. var contexts = decodingContext.contextCache.getContexts('GR');
  9909. var ltp = 0;
  9910. for (var i = 0; i < height; i++) {
  9911. if (prediction) {
  9912. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9913. ltp ^= sltp;
  9914. if (ltp) {
  9915. error('JBIG2 error: prediction is not supported');
  9916. }
  9917. }
  9918. var row = new Uint8Array(width);
  9919. bitmap.push(row);
  9920. for (var j = 0; j < width; j++) {
  9921. var i0, j0;
  9922. var contextLabel = 0;
  9923. for (k = 0; k < codingTemplateLength; k++) {
  9924. i0 = i + codingTemplateY[k];
  9925. j0 = j + codingTemplateX[k];
  9926. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9927. contextLabel <<= 1; // out of bound pixel
  9928. } else {
  9929. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9930. }
  9931. }
  9932. for (k = 0; k < referenceTemplateLength; k++) {
  9933. i0 = i + referenceTemplateY[k] + offsetY;
  9934. j0 = j + referenceTemplateX[k] + offsetX;
  9935. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9936. j0 >= referenceWidth) {
  9937. contextLabel <<= 1; // out of bound pixel
  9938. } else {
  9939. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9940. }
  9941. }
  9942. var pixel = decoder.readBit(contexts, contextLabel);
  9943. row[j] = pixel;
  9944. }
  9945. }
  9946. return bitmap;
  9947. }
  9948. // 6.5.5 Decoding the symbol dictionary
  9949. function decodeSymbolDictionary(huffman, refinement, symbols,
  9950. numberOfNewSymbols, numberOfExportedSymbols,
  9951. huffmanTables, templateIndex, at,
  9952. refinementTemplateIndex, refinementAt,
  9953. decodingContext) {
  9954. if (huffman) {
  9955. error('JBIG2 error: huffman is not supported');
  9956. }
  9957. var newSymbols = [];
  9958. var currentHeight = 0;
  9959. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9960. var decoder = decodingContext.decoder;
  9961. var contextCache = decodingContext.contextCache;
  9962. while (newSymbols.length < numberOfNewSymbols) {
  9963. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9964. currentHeight += deltaHeight;
  9965. var currentWidth = 0;
  9966. var totalWidth = 0;
  9967. while (true) {
  9968. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9969. if (deltaWidth === null) {
  9970. break; // OOB
  9971. }
  9972. currentWidth += deltaWidth;
  9973. totalWidth += currentWidth;
  9974. var bitmap;
  9975. if (refinement) {
  9976. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9977. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9978. if (numberOfInstances > 1) {
  9979. bitmap = decodeTextRegion(huffman, refinement,
  9980. currentWidth, currentHeight, 0,
  9981. numberOfInstances, 1, //strip size
  9982. symbols.concat(newSymbols),
  9983. symbolCodeLength,
  9984. 0, //transposed
  9985. 0, //ds offset
  9986. 1, //top left 7.4.3.1.1
  9987. 0, //OR operator
  9988. huffmanTables,
  9989. refinementTemplateIndex, refinementAt,
  9990. decodingContext);
  9991. } else {
  9992. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9993. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9994. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9995. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9996. newSymbols[symbolId - symbols.length]);
  9997. bitmap = decodeRefinement(currentWidth, currentHeight,
  9998. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9999. decodingContext);
  10000. }
  10001. } else {
  10002. // 6.5.8.1 Direct-coded symbol bitmap
  10003. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10004. templateIndex, false, null, at, decodingContext);
  10005. }
  10006. newSymbols.push(bitmap);
  10007. }
  10008. }
  10009. // 6.5.10 Exported symbols
  10010. var exportedSymbols = [];
  10011. var flags = [], currentFlag = false;
  10012. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10013. while (flags.length < totalSymbolsLength) {
  10014. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10015. while (runLength--) {
  10016. flags.push(currentFlag);
  10017. }
  10018. currentFlag = !currentFlag;
  10019. }
  10020. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10021. if (flags[i]) {
  10022. exportedSymbols.push(symbols[i]);
  10023. }
  10024. }
  10025. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10026. if (flags[i]) {
  10027. exportedSymbols.push(newSymbols[j]);
  10028. }
  10029. }
  10030. return exportedSymbols;
  10031. }
  10032. function decodeTextRegion(huffman, refinement, width, height,
  10033. defaultPixelValue, numberOfSymbolInstances,
  10034. stripSize, inputSymbols, symbolCodeLength,
  10035. transposed, dsOffset, referenceCorner,
  10036. combinationOperator, huffmanTables,
  10037. refinementTemplateIndex, refinementAt,
  10038. decodingContext) {
  10039. if (huffman) {
  10040. error('JBIG2 error: huffman is not supported');
  10041. }
  10042. // Prepare bitmap
  10043. var bitmap = [];
  10044. var i, row;
  10045. for (i = 0; i < height; i++) {
  10046. row = new Uint8Array(width);
  10047. if (defaultPixelValue) {
  10048. for (var j = 0; j < width; j++) {
  10049. row[j] = defaultPixelValue;
  10050. }
  10051. }
  10052. bitmap.push(row);
  10053. }
  10054. var decoder = decodingContext.decoder;
  10055. var contextCache = decodingContext.contextCache;
  10056. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10057. var firstS = 0;
  10058. i = 0;
  10059. while (i < numberOfSymbolInstances) {
  10060. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10061. stripT += deltaT;
  10062. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10063. firstS += deltaFirstS;
  10064. var currentS = firstS;
  10065. do {
  10066. var currentT = (stripSize === 1 ? 0 :
  10067. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10068. var t = stripSize * stripT + currentT;
  10069. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10070. var applyRefinement = (refinement &&
  10071. decodeInteger(contextCache, 'IARI', decoder));
  10072. var symbolBitmap = inputSymbols[symbolId];
  10073. var symbolWidth = symbolBitmap[0].length;
  10074. var symbolHeight = symbolBitmap.length;
  10075. if (applyRefinement) {
  10076. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10077. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10078. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10079. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10080. symbolWidth += rdw;
  10081. symbolHeight += rdh;
  10082. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10083. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10084. (rdh >> 1) + rdy, false, refinementAt,
  10085. decodingContext);
  10086. }
  10087. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10088. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10089. var s2, t2, symbolRow;
  10090. if (transposed) {
  10091. // Place Symbol Bitmap from T1,S1
  10092. for (s2 = 0; s2 < symbolHeight; s2++) {
  10093. row = bitmap[offsetS + s2];
  10094. if (!row) {
  10095. continue;
  10096. }
  10097. symbolRow = symbolBitmap[s2];
  10098. // To ignore Parts of Symbol bitmap which goes
  10099. // outside bitmap region
  10100. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10101. switch (combinationOperator) {
  10102. case 0: // OR
  10103. for (t2 = 0; t2 < maxWidth; t2++) {
  10104. row[offsetT + t2] |= symbolRow[t2];
  10105. }
  10106. break;
  10107. case 2: // XOR
  10108. for (t2 = 0; t2 < maxWidth; t2++) {
  10109. row[offsetT + t2] ^= symbolRow[t2];
  10110. }
  10111. break;
  10112. default:
  10113. error('JBIG2 error: operator ' + combinationOperator +
  10114. ' is not supported');
  10115. }
  10116. }
  10117. currentS += symbolHeight - 1;
  10118. } else {
  10119. for (t2 = 0; t2 < symbolHeight; t2++) {
  10120. row = bitmap[offsetT + t2];
  10121. if (!row) {
  10122. continue;
  10123. }
  10124. symbolRow = symbolBitmap[t2];
  10125. switch (combinationOperator) {
  10126. case 0: // OR
  10127. for (s2 = 0; s2 < symbolWidth; s2++) {
  10128. row[offsetS + s2] |= symbolRow[s2];
  10129. }
  10130. break;
  10131. case 2: // XOR
  10132. for (s2 = 0; s2 < symbolWidth; s2++) {
  10133. row[offsetS + s2] ^= symbolRow[s2];
  10134. }
  10135. break;
  10136. default:
  10137. error('JBIG2 error: operator ' + combinationOperator +
  10138. ' is not supported');
  10139. }
  10140. }
  10141. currentS += symbolWidth - 1;
  10142. }
  10143. i++;
  10144. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  10145. if (deltaS === null) {
  10146. break; // OOB
  10147. }
  10148. currentS += deltaS + dsOffset;
  10149. } while (true);
  10150. }
  10151. return bitmap;
  10152. }
  10153. function readSegmentHeader(data, start) {
  10154. var segmentHeader = {};
  10155. segmentHeader.number = readUint32(data, start);
  10156. var flags = data[start + 4];
  10157. var segmentType = flags & 0x3F;
  10158. if (!SegmentTypes[segmentType]) {
  10159. error('JBIG2 error: invalid segment type: ' + segmentType);
  10160. }
  10161. segmentHeader.type = segmentType;
  10162. segmentHeader.typeName = SegmentTypes[segmentType];
  10163. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  10164. var pageAssociationFieldSize = !!(flags & 0x40);
  10165. var referredFlags = data[start + 5];
  10166. var referredToCount = (referredFlags >> 5) & 7;
  10167. var retainBits = [referredFlags & 31];
  10168. var position = start + 6;
  10169. if (referredFlags === 7) {
  10170. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  10171. position += 3;
  10172. var bytes = (referredToCount + 7) >> 3;
  10173. retainBits[0] = data[position++];
  10174. while (--bytes > 0) {
  10175. retainBits.push(data[position++]);
  10176. }
  10177. } else if (referredFlags === 5 || referredFlags === 6) {
  10178. error('JBIG2 error: invalid referred-to flags');
  10179. }
  10180. segmentHeader.retainBits = retainBits;
  10181. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  10182. (segmentHeader.number <= 65536 ? 2 : 4));
  10183. var referredTo = [];
  10184. var i, ii;
  10185. for (i = 0; i < referredToCount; i++) {
  10186. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  10187. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  10188. readUint32(data, position)));
  10189. referredTo.push(number);
  10190. position += referredToSegmentNumberSize;
  10191. }
  10192. segmentHeader.referredTo = referredTo;
  10193. if (!pageAssociationFieldSize) {
  10194. segmentHeader.pageAssociation = data[position++];
  10195. } else {
  10196. segmentHeader.pageAssociation = readUint32(data, position);
  10197. position += 4;
  10198. }
  10199. segmentHeader.length = readUint32(data, position);
  10200. position += 4;
  10201. if (segmentHeader.length === 0xFFFFFFFF) {
  10202. // 7.2.7 Segment data length, unknown segment length
  10203. if (segmentType === 38) { // ImmediateGenericRegion
  10204. var genericRegionInfo = readRegionSegmentInformation(data, position);
  10205. var genericRegionSegmentFlags = data[position +
  10206. RegionSegmentInformationFieldLength];
  10207. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  10208. // searching for the segment end
  10209. var searchPatternLength = 6;
  10210. var searchPattern = new Uint8Array(searchPatternLength);
  10211. if (!genericRegionMmr) {
  10212. searchPattern[0] = 0xFF;
  10213. searchPattern[1] = 0xAC;
  10214. }
  10215. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  10216. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  10217. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  10218. searchPattern[5] = genericRegionInfo.height & 0xFF;
  10219. for (i = position, ii = data.length; i < ii; i++) {
  10220. var j = 0;
  10221. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  10222. j++;
  10223. }
  10224. if (j === searchPatternLength) {
  10225. segmentHeader.length = i + searchPatternLength;
  10226. break;
  10227. }
  10228. }
  10229. if (segmentHeader.length === 0xFFFFFFFF) {
  10230. error('JBIG2 error: segment end was not found');
  10231. }
  10232. } else {
  10233. error('JBIG2 error: invalid unknown segment length');
  10234. }
  10235. }
  10236. segmentHeader.headerEnd = position;
  10237. return segmentHeader;
  10238. }
  10239. function readSegments(header, data, start, end) {
  10240. var segments = [];
  10241. var position = start;
  10242. while (position < end) {
  10243. var segmentHeader = readSegmentHeader(data, position);
  10244. position = segmentHeader.headerEnd;
  10245. var segment = {
  10246. header: segmentHeader,
  10247. data: data
  10248. };
  10249. if (!header.randomAccess) {
  10250. segment.start = position;
  10251. position += segmentHeader.length;
  10252. segment.end = position;
  10253. }
  10254. segments.push(segment);
  10255. if (segmentHeader.type === 51) {
  10256. break; // end of file is found
  10257. }
  10258. }
  10259. if (header.randomAccess) {
  10260. for (var i = 0, ii = segments.length; i < ii; i++) {
  10261. segments[i].start = position;
  10262. position += segments[i].header.length;
  10263. segments[i].end = position;
  10264. }
  10265. }
  10266. return segments;
  10267. }
  10268. // 7.4.1 Region segment information field
  10269. function readRegionSegmentInformation(data, start) {
  10270. return {
  10271. width: readUint32(data, start),
  10272. height: readUint32(data, start + 4),
  10273. x: readUint32(data, start + 8),
  10274. y: readUint32(data, start + 12),
  10275. combinationOperator: data[start + 16] & 7
  10276. };
  10277. }
  10278. var RegionSegmentInformationFieldLength = 17;
  10279. function processSegment(segment, visitor) {
  10280. var header = segment.header;
  10281. var data = segment.data, position = segment.start, end = segment.end;
  10282. var args, at, i, atLength;
  10283. switch (header.type) {
  10284. case 0: // SymbolDictionary
  10285. // 7.4.2 Symbol dictionary segment syntax
  10286. var dictionary = {};
  10287. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  10288. dictionary.huffman = !!(dictionaryFlags & 1);
  10289. dictionary.refinement = !!(dictionaryFlags & 2);
  10290. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  10291. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  10292. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  10293. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  10294. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  10295. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  10296. dictionary.template = (dictionaryFlags >> 10) & 3;
  10297. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  10298. position += 2;
  10299. if (!dictionary.huffman) {
  10300. atLength = dictionary.template === 0 ? 4 : 1;
  10301. at = [];
  10302. for (i = 0; i < atLength; i++) {
  10303. at.push({
  10304. x: readInt8(data, position),
  10305. y: readInt8(data, position + 1)
  10306. });
  10307. position += 2;
  10308. }
  10309. dictionary.at = at;
  10310. }
  10311. if (dictionary.refinement && !dictionary.refinementTemplate) {
  10312. at = [];
  10313. for (i = 0; i < 2; i++) {
  10314. at.push({
  10315. x: readInt8(data, position),
  10316. y: readInt8(data, position + 1)
  10317. });
  10318. position += 2;
  10319. }
  10320. dictionary.refinementAt = at;
  10321. }
  10322. dictionary.numberOfExportedSymbols = readUint32(data, position);
  10323. position += 4;
  10324. dictionary.numberOfNewSymbols = readUint32(data, position);
  10325. position += 4;
  10326. args = [dictionary, header.number, header.referredTo,
  10327. data, position, end];
  10328. break;
  10329. case 6: // ImmediateTextRegion
  10330. case 7: // ImmediateLosslessTextRegion
  10331. var textRegion = {};
  10332. textRegion.info = readRegionSegmentInformation(data, position);
  10333. position += RegionSegmentInformationFieldLength;
  10334. var textRegionSegmentFlags = readUint16(data, position);
  10335. position += 2;
  10336. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  10337. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  10338. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  10339. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  10340. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  10341. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  10342. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  10343. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  10344. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  10345. if (textRegion.huffman) {
  10346. var textRegionHuffmanFlags = readUint16(data, position);
  10347. position += 2;
  10348. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  10349. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  10350. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  10351. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  10352. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  10353. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  10354. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  10355. textRegion.huffmanRefinementSizeSelector =
  10356. !!(textRegionHuffmanFlags & 14);
  10357. }
  10358. if (textRegion.refinement && !textRegion.refinementTemplate) {
  10359. at = [];
  10360. for (i = 0; i < 2; i++) {
  10361. at.push({
  10362. x: readInt8(data, position),
  10363. y: readInt8(data, position + 1)
  10364. });
  10365. position += 2;
  10366. }
  10367. textRegion.refinementAt = at;
  10368. }
  10369. textRegion.numberOfSymbolInstances = readUint32(data, position);
  10370. position += 4;
  10371. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  10372. if (textRegion.huffman) {
  10373. error('JBIG2 error: huffman is not supported');
  10374. }
  10375. args = [textRegion, header.referredTo, data, position, end];
  10376. break;
  10377. case 38: // ImmediateGenericRegion
  10378. case 39: // ImmediateLosslessGenericRegion
  10379. var genericRegion = {};
  10380. genericRegion.info = readRegionSegmentInformation(data, position);
  10381. position += RegionSegmentInformationFieldLength;
  10382. var genericRegionSegmentFlags = data[position++];
  10383. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10384. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10385. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10386. if (!genericRegion.mmr) {
  10387. atLength = genericRegion.template === 0 ? 4 : 1;
  10388. at = [];
  10389. for (i = 0; i < atLength; i++) {
  10390. at.push({
  10391. x: readInt8(data, position),
  10392. y: readInt8(data, position + 1)
  10393. });
  10394. position += 2;
  10395. }
  10396. genericRegion.at = at;
  10397. }
  10398. args = [genericRegion, data, position, end];
  10399. break;
  10400. case 48: // PageInformation
  10401. var pageInfo = {
  10402. width: readUint32(data, position),
  10403. height: readUint32(data, position + 4),
  10404. resolutionX: readUint32(data, position + 8),
  10405. resolutionY: readUint32(data, position + 12)
  10406. };
  10407. if (pageInfo.height === 0xFFFFFFFF) {
  10408. delete pageInfo.height;
  10409. }
  10410. var pageSegmentFlags = data[position + 16];
  10411. var pageStripingInformation = readUint16(data, position + 17);
  10412. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10413. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10414. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10415. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10416. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10417. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10418. args = [pageInfo];
  10419. break;
  10420. case 49: // EndOfPage
  10421. break;
  10422. case 50: // EndOfStripe
  10423. break;
  10424. case 51: // EndOfFile
  10425. break;
  10426. case 62: // 7.4.15 defines 2 extension types which
  10427. // are comments and can be ignored.
  10428. break;
  10429. default:
  10430. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10431. header.type + ') is not implemented');
  10432. }
  10433. var callbackName = 'on' + header.typeName;
  10434. if (callbackName in visitor) {
  10435. visitor[callbackName].apply(visitor, args);
  10436. }
  10437. }
  10438. function processSegments(segments, visitor) {
  10439. for (var i = 0, ii = segments.length; i < ii; i++) {
  10440. processSegment(segments[i], visitor);
  10441. }
  10442. }
  10443. function parseJbig2(data, start, end) {
  10444. var position = start;
  10445. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10446. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10447. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10448. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10449. error('JBIG2 error: invalid header');
  10450. }
  10451. var header = {};
  10452. position += 8;
  10453. var flags = data[position++];
  10454. header.randomAccess = !(flags & 1);
  10455. if (!(flags & 2)) {
  10456. header.numberOfPages = readUint32(data, position);
  10457. position += 4;
  10458. }
  10459. var segments = readSegments(header, data, position, end);
  10460. error('Not implemented');
  10461. // processSegments(segments, new SimpleSegmentVisitor());
  10462. }
  10463. function parseJbig2Chunks(chunks) {
  10464. var visitor = new SimpleSegmentVisitor();
  10465. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10466. var chunk = chunks[i];
  10467. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10468. processSegments(segments, visitor);
  10469. }
  10470. return visitor.buffer;
  10471. }
  10472. function SimpleSegmentVisitor() {}
  10473. SimpleSegmentVisitor.prototype = {
  10474. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10475. this.currentPageInfo = info;
  10476. var rowSize = (info.width + 7) >> 3;
  10477. var buffer = new Uint8Array(rowSize * info.height);
  10478. // The contents of ArrayBuffers are initialized to 0.
  10479. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10480. if (info.defaultPixelValue) {
  10481. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10482. buffer[i] = 0xFF;
  10483. }
  10484. }
  10485. this.buffer = buffer;
  10486. },
  10487. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10488. var pageInfo = this.currentPageInfo;
  10489. var width = regionInfo.width, height = regionInfo.height;
  10490. var rowSize = (pageInfo.width + 7) >> 3;
  10491. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10492. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10493. var buffer = this.buffer;
  10494. var mask0 = 128 >> (regionInfo.x & 7);
  10495. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10496. var i, j, mask, offset;
  10497. switch (combinationOperator) {
  10498. case 0: // OR
  10499. for (i = 0; i < height; i++) {
  10500. mask = mask0;
  10501. offset = offset0;
  10502. for (j = 0; j < width; j++) {
  10503. if (bitmap[i][j]) {
  10504. buffer[offset] |= mask;
  10505. }
  10506. mask >>= 1;
  10507. if (!mask) {
  10508. mask = 128;
  10509. offset++;
  10510. }
  10511. }
  10512. offset0 += rowSize;
  10513. }
  10514. break;
  10515. case 2: // XOR
  10516. for (i = 0; i < height; i++) {
  10517. mask = mask0;
  10518. offset = offset0;
  10519. for (j = 0; j < width; j++) {
  10520. if (bitmap[i][j]) {
  10521. buffer[offset] ^= mask;
  10522. }
  10523. mask >>= 1;
  10524. if (!mask) {
  10525. mask = 128;
  10526. offset++;
  10527. }
  10528. }
  10529. offset0 += rowSize;
  10530. }
  10531. break;
  10532. default:
  10533. error('JBIG2 error: operator ' + combinationOperator +
  10534. ' is not supported');
  10535. }
  10536. },
  10537. onImmediateGenericRegion:
  10538. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10539. start, end) {
  10540. var regionInfo = region.info;
  10541. var decodingContext = new DecodingContext(data, start, end);
  10542. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10543. region.template, region.prediction, null,
  10544. region.at, decodingContext);
  10545. this.drawBitmap(regionInfo, bitmap);
  10546. },
  10547. onImmediateLosslessGenericRegion:
  10548. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10549. this.onImmediateGenericRegion.apply(this, arguments);
  10550. },
  10551. onSymbolDictionary:
  10552. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10553. currentSegment,
  10554. referredSegments,
  10555. data, start, end) {
  10556. var huffmanTables;
  10557. if (dictionary.huffman) {
  10558. error('JBIG2 error: huffman is not supported');
  10559. }
  10560. // Combines exported symbols from all referred segments
  10561. var symbols = this.symbols;
  10562. if (!symbols) {
  10563. this.symbols = symbols = {};
  10564. }
  10565. var inputSymbols = [];
  10566. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10567. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10568. }
  10569. var decodingContext = new DecodingContext(data, start, end);
  10570. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10571. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10572. dictionary.numberOfExportedSymbols, huffmanTables,
  10573. dictionary.template, dictionary.at,
  10574. dictionary.refinementTemplate, dictionary.refinementAt,
  10575. decodingContext);
  10576. },
  10577. onImmediateTextRegion:
  10578. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10579. referredSegments,
  10580. data, start, end) {
  10581. var regionInfo = region.info;
  10582. var huffmanTables;
  10583. // Combines exported symbols from all referred segments
  10584. var symbols = this.symbols;
  10585. var inputSymbols = [];
  10586. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10587. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10588. }
  10589. var symbolCodeLength = log2(inputSymbols.length);
  10590. var decodingContext = new DecodingContext(data, start, end);
  10591. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10592. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10593. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10594. symbolCodeLength, region.transposed, region.dsOffset,
  10595. region.referenceCorner, region.combinationOperator, huffmanTables,
  10596. region.refinementTemplate, region.refinementAt, decodingContext);
  10597. this.drawBitmap(regionInfo, bitmap);
  10598. },
  10599. onImmediateLosslessTextRegion:
  10600. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10601. this.onImmediateTextRegion.apply(this, arguments);
  10602. }
  10603. };
  10604. function Jbig2Image() {}
  10605. Jbig2Image.prototype = {
  10606. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10607. return parseJbig2Chunks(chunks);
  10608. }
  10609. };
  10610. return Jbig2Image;
  10611. })();
  10612. exports.Jbig2Image = Jbig2Image;
  10613. }));
  10614. (function (root, factory) {
  10615. {
  10616. factory((root.pdfjsCoreJpg = {}), root.pdfjsSharedUtil);
  10617. }
  10618. }(this, function (exports, sharedUtil) {
  10619. var error = sharedUtil.error;
  10620. /**
  10621. * This code was forked from https://github.com/notmasteryet/jpgjs.
  10622. * The original version was created by GitHub user notmasteryet.
  10623. *
  10624. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  10625. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  10626. * - The JFIF specification can be found in the JPEG File Interchange Format
  10627. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  10628. * - The Adobe Application-Specific JPEG markers in the
  10629. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  10630. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  10631. */
  10632. var JpegImage = (function JpegImageClosure() {
  10633. var dctZigZag = new Uint8Array([
  10634. 0,
  10635. 1, 8,
  10636. 16, 9, 2,
  10637. 3, 10, 17, 24,
  10638. 32, 25, 18, 11, 4,
  10639. 5, 12, 19, 26, 33, 40,
  10640. 48, 41, 34, 27, 20, 13, 6,
  10641. 7, 14, 21, 28, 35, 42, 49, 56,
  10642. 57, 50, 43, 36, 29, 22, 15,
  10643. 23, 30, 37, 44, 51, 58,
  10644. 59, 52, 45, 38, 31,
  10645. 39, 46, 53, 60,
  10646. 61, 54, 47,
  10647. 55, 62,
  10648. 63
  10649. ]);
  10650. var dctCos1 = 4017; // cos(pi/16)
  10651. var dctSin1 = 799; // sin(pi/16)
  10652. var dctCos3 = 3406; // cos(3*pi/16)
  10653. var dctSin3 = 2276; // sin(3*pi/16)
  10654. var dctCos6 = 1567; // cos(6*pi/16)
  10655. var dctSin6 = 3784; // sin(6*pi/16)
  10656. var dctSqrt2 = 5793; // sqrt(2)
  10657. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  10658. function JpegImage() {
  10659. this.decodeTransform = null;
  10660. this.colorTransform = -1;
  10661. }
  10662. function buildHuffmanTable(codeLengths, values) {
  10663. var k = 0, code = [], i, j, length = 16;
  10664. while (length > 0 && !codeLengths[length - 1]) {
  10665. length--;
  10666. }
  10667. code.push({children: [], index: 0});
  10668. var p = code[0], q;
  10669. for (i = 0; i < length; i++) {
  10670. for (j = 0; j < codeLengths[i]; j++) {
  10671. p = code.pop();
  10672. p.children[p.index] = values[k];
  10673. while (p.index > 0) {
  10674. p = code.pop();
  10675. }
  10676. p.index++;
  10677. code.push(p);
  10678. while (code.length <= i) {
  10679. code.push(q = {children: [], index: 0});
  10680. p.children[p.index] = q.children;
  10681. p = q;
  10682. }
  10683. k++;
  10684. }
  10685. if (i + 1 < length) {
  10686. // p here points to last code
  10687. code.push(q = {children: [], index: 0});
  10688. p.children[p.index] = q.children;
  10689. p = q;
  10690. }
  10691. }
  10692. return code[0].children;
  10693. }
  10694. function getBlockBufferOffset(component, row, col) {
  10695. return 64 * ((component.blocksPerLine + 1) * row + col);
  10696. }
  10697. function decodeScan(data, offset, frame, components, resetInterval,
  10698. spectralStart, spectralEnd, successivePrev, successive) {
  10699. var mcusPerLine = frame.mcusPerLine;
  10700. var progressive = frame.progressive;
  10701. var startOffset = offset, bitsData = 0, bitsCount = 0;
  10702. function readBit() {
  10703. if (bitsCount > 0) {
  10704. bitsCount--;
  10705. return (bitsData >> bitsCount) & 1;
  10706. }
  10707. bitsData = data[offset++];
  10708. if (bitsData === 0xFF) {
  10709. var nextByte = data[offset++];
  10710. if (nextByte) {
  10711. error('JPEG error: unexpected marker ' +
  10712. ((bitsData << 8) | nextByte).toString(16));
  10713. }
  10714. // unstuff 0
  10715. }
  10716. bitsCount = 7;
  10717. return bitsData >>> 7;
  10718. }
  10719. function decodeHuffman(tree) {
  10720. var node = tree;
  10721. while (true) {
  10722. node = node[readBit()];
  10723. if (typeof node === 'number') {
  10724. return node;
  10725. }
  10726. if (typeof node !== 'object') {
  10727. error('JPEG error: invalid huffman sequence');
  10728. }
  10729. }
  10730. }
  10731. function receive(length) {
  10732. var n = 0;
  10733. while (length > 0) {
  10734. n = (n << 1) | readBit();
  10735. length--;
  10736. }
  10737. return n;
  10738. }
  10739. function receiveAndExtend(length) {
  10740. if (length === 1) {
  10741. return readBit() === 1 ? 1 : -1;
  10742. }
  10743. var n = receive(length);
  10744. if (n >= 1 << (length - 1)) {
  10745. return n;
  10746. }
  10747. return n + (-1 << length) + 1;
  10748. }
  10749. function decodeBaseline(component, offset) {
  10750. var t = decodeHuffman(component.huffmanTableDC);
  10751. var diff = t === 0 ? 0 : receiveAndExtend(t);
  10752. component.blockData[offset] = (component.pred += diff);
  10753. var k = 1;
  10754. while (k < 64) {
  10755. var rs = decodeHuffman(component.huffmanTableAC);
  10756. var s = rs & 15, r = rs >> 4;
  10757. if (s === 0) {
  10758. if (r < 15) {
  10759. break;
  10760. }
  10761. k += 16;
  10762. continue;
  10763. }
  10764. k += r;
  10765. var z = dctZigZag[k];
  10766. component.blockData[offset + z] = receiveAndExtend(s);
  10767. k++;
  10768. }
  10769. }
  10770. function decodeDCFirst(component, offset) {
  10771. var t = decodeHuffman(component.huffmanTableDC);
  10772. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  10773. component.blockData[offset] = (component.pred += diff);
  10774. }
  10775. function decodeDCSuccessive(component, offset) {
  10776. component.blockData[offset] |= readBit() << successive;
  10777. }
  10778. var eobrun = 0;
  10779. function decodeACFirst(component, offset) {
  10780. if (eobrun > 0) {
  10781. eobrun--;
  10782. return;
  10783. }
  10784. var k = spectralStart, e = spectralEnd;
  10785. while (k <= e) {
  10786. var rs = decodeHuffman(component.huffmanTableAC);
  10787. var s = rs & 15, r = rs >> 4;
  10788. if (s === 0) {
  10789. if (r < 15) {
  10790. eobrun = receive(r) + (1 << r) - 1;
  10791. break;
  10792. }
  10793. k += 16;
  10794. continue;
  10795. }
  10796. k += r;
  10797. var z = dctZigZag[k];
  10798. component.blockData[offset + z] =
  10799. receiveAndExtend(s) * (1 << successive);
  10800. k++;
  10801. }
  10802. }
  10803. var successiveACState = 0, successiveACNextValue;
  10804. function decodeACSuccessive(component, offset) {
  10805. var k = spectralStart;
  10806. var e = spectralEnd;
  10807. var r = 0;
  10808. var s;
  10809. var rs;
  10810. while (k <= e) {
  10811. var z = dctZigZag[k];
  10812. switch (successiveACState) {
  10813. case 0: // initial state
  10814. rs = decodeHuffman(component.huffmanTableAC);
  10815. s = rs & 15;
  10816. r = rs >> 4;
  10817. if (s === 0) {
  10818. if (r < 15) {
  10819. eobrun = receive(r) + (1 << r);
  10820. successiveACState = 4;
  10821. } else {
  10822. r = 16;
  10823. successiveACState = 1;
  10824. }
  10825. } else {
  10826. if (s !== 1) {
  10827. error('JPEG error: invalid ACn encoding');
  10828. }
  10829. successiveACNextValue = receiveAndExtend(s);
  10830. successiveACState = r ? 2 : 3;
  10831. }
  10832. continue;
  10833. case 1: // skipping r zero items
  10834. case 2:
  10835. if (component.blockData[offset + z]) {
  10836. component.blockData[offset + z] += (readBit() << successive);
  10837. } else {
  10838. r--;
  10839. if (r === 0) {
  10840. successiveACState = successiveACState === 2 ? 3 : 0;
  10841. }
  10842. }
  10843. break;
  10844. case 3: // set value for a zero item
  10845. if (component.blockData[offset + z]) {
  10846. component.blockData[offset + z] += (readBit() << successive);
  10847. } else {
  10848. component.blockData[offset + z] =
  10849. successiveACNextValue << successive;
  10850. successiveACState = 0;
  10851. }
  10852. break;
  10853. case 4: // eob
  10854. if (component.blockData[offset + z]) {
  10855. component.blockData[offset + z] += (readBit() << successive);
  10856. }
  10857. break;
  10858. }
  10859. k++;
  10860. }
  10861. if (successiveACState === 4) {
  10862. eobrun--;
  10863. if (eobrun === 0) {
  10864. successiveACState = 0;
  10865. }
  10866. }
  10867. }
  10868. function decodeMcu(component, decode, mcu, row, col) {
  10869. var mcuRow = (mcu / mcusPerLine) | 0;
  10870. var mcuCol = mcu % mcusPerLine;
  10871. var blockRow = mcuRow * component.v + row;
  10872. var blockCol = mcuCol * component.h + col;
  10873. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10874. decode(component, offset);
  10875. }
  10876. function decodeBlock(component, decode, mcu) {
  10877. var blockRow = (mcu / component.blocksPerLine) | 0;
  10878. var blockCol = mcu % component.blocksPerLine;
  10879. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  10880. decode(component, offset);
  10881. }
  10882. var componentsLength = components.length;
  10883. var component, i, j, k, n;
  10884. var decodeFn;
  10885. if (progressive) {
  10886. if (spectralStart === 0) {
  10887. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  10888. } else {
  10889. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  10890. }
  10891. } else {
  10892. decodeFn = decodeBaseline;
  10893. }
  10894. var mcu = 0, marker;
  10895. var mcuExpected;
  10896. if (componentsLength === 1) {
  10897. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  10898. } else {
  10899. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  10900. }
  10901. if (!resetInterval) {
  10902. resetInterval = mcuExpected;
  10903. }
  10904. var h, v;
  10905. while (mcu < mcuExpected) {
  10906. // reset interval stuff
  10907. for (i = 0; i < componentsLength; i++) {
  10908. components[i].pred = 0;
  10909. }
  10910. eobrun = 0;
  10911. if (componentsLength === 1) {
  10912. component = components[0];
  10913. for (n = 0; n < resetInterval; n++) {
  10914. decodeBlock(component, decodeFn, mcu);
  10915. mcu++;
  10916. }
  10917. } else {
  10918. for (n = 0; n < resetInterval; n++) {
  10919. for (i = 0; i < componentsLength; i++) {
  10920. component = components[i];
  10921. h = component.h;
  10922. v = component.v;
  10923. for (j = 0; j < v; j++) {
  10924. for (k = 0; k < h; k++) {
  10925. decodeMcu(component, decodeFn, mcu, j, k);
  10926. }
  10927. }
  10928. }
  10929. mcu++;
  10930. }
  10931. }
  10932. // find marker
  10933. bitsCount = 0;
  10934. marker = (data[offset] << 8) | data[offset + 1];
  10935. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  10936. // those to attempt to find a valid marker (fixes issue4090.pdf).
  10937. while (data[offset] === 0x00 && offset < data.length - 1) {
  10938. offset++;
  10939. marker = (data[offset] << 8) | data[offset + 1];
  10940. }
  10941. if (marker <= 0xFF00) {
  10942. error('JPEG error: marker was not found');
  10943. }
  10944. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  10945. offset += 2;
  10946. } else {
  10947. break;
  10948. }
  10949. }
  10950. return offset - startOffset;
  10951. }
  10952. // A port of poppler's IDCT method which in turn is taken from:
  10953. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  10954. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  10955. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  10956. // 988-991.
  10957. function quantizeAndInverse(component, blockBufferOffset, p) {
  10958. var qt = component.quantizationTable, blockData = component.blockData;
  10959. var v0, v1, v2, v3, v4, v5, v6, v7;
  10960. var p0, p1, p2, p3, p4, p5, p6, p7;
  10961. var t;
  10962. if (!qt) {
  10963. error('JPEG error: missing required Quantization Table.');
  10964. }
  10965. // inverse DCT on rows
  10966. for (var row = 0; row < 64; row += 8) {
  10967. // gather block data
  10968. p0 = blockData[blockBufferOffset + row];
  10969. p1 = blockData[blockBufferOffset + row + 1];
  10970. p2 = blockData[blockBufferOffset + row + 2];
  10971. p3 = blockData[blockBufferOffset + row + 3];
  10972. p4 = blockData[blockBufferOffset + row + 4];
  10973. p5 = blockData[blockBufferOffset + row + 5];
  10974. p6 = blockData[blockBufferOffset + row + 6];
  10975. p7 = blockData[blockBufferOffset + row + 7];
  10976. // dequant p0
  10977. p0 *= qt[row];
  10978. // check for all-zero AC coefficients
  10979. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  10980. t = (dctSqrt2 * p0 + 512) >> 10;
  10981. p[row] = t;
  10982. p[row + 1] = t;
  10983. p[row + 2] = t;
  10984. p[row + 3] = t;
  10985. p[row + 4] = t;
  10986. p[row + 5] = t;
  10987. p[row + 6] = t;
  10988. p[row + 7] = t;
  10989. continue;
  10990. }
  10991. // dequant p1 ... p7
  10992. p1 *= qt[row + 1];
  10993. p2 *= qt[row + 2];
  10994. p3 *= qt[row + 3];
  10995. p4 *= qt[row + 4];
  10996. p5 *= qt[row + 5];
  10997. p6 *= qt[row + 6];
  10998. p7 *= qt[row + 7];
  10999. // stage 4
  11000. v0 = (dctSqrt2 * p0 + 128) >> 8;
  11001. v1 = (dctSqrt2 * p4 + 128) >> 8;
  11002. v2 = p2;
  11003. v3 = p6;
  11004. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  11005. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  11006. v5 = p3 << 4;
  11007. v6 = p5 << 4;
  11008. // stage 3
  11009. v0 = (v0 + v1 + 1) >> 1;
  11010. v1 = v0 - v1;
  11011. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  11012. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  11013. v3 = t;
  11014. v4 = (v4 + v6 + 1) >> 1;
  11015. v6 = v4 - v6;
  11016. v7 = (v7 + v5 + 1) >> 1;
  11017. v5 = v7 - v5;
  11018. // stage 2
  11019. v0 = (v0 + v3 + 1) >> 1;
  11020. v3 = v0 - v3;
  11021. v1 = (v1 + v2 + 1) >> 1;
  11022. v2 = v1 - v2;
  11023. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11024. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11025. v7 = t;
  11026. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11027. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11028. v6 = t;
  11029. // stage 1
  11030. p[row] = v0 + v7;
  11031. p[row + 7] = v0 - v7;
  11032. p[row + 1] = v1 + v6;
  11033. p[row + 6] = v1 - v6;
  11034. p[row + 2] = v2 + v5;
  11035. p[row + 5] = v2 - v5;
  11036. p[row + 3] = v3 + v4;
  11037. p[row + 4] = v3 - v4;
  11038. }
  11039. // inverse DCT on columns
  11040. for (var col = 0; col < 8; ++col) {
  11041. p0 = p[col];
  11042. p1 = p[col + 8];
  11043. p2 = p[col + 16];
  11044. p3 = p[col + 24];
  11045. p4 = p[col + 32];
  11046. p5 = p[col + 40];
  11047. p6 = p[col + 48];
  11048. p7 = p[col + 56];
  11049. // check for all-zero AC coefficients
  11050. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  11051. t = (dctSqrt2 * p0 + 8192) >> 14;
  11052. // convert to 8 bit
  11053. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  11054. blockData[blockBufferOffset + col] = t;
  11055. blockData[blockBufferOffset + col + 8] = t;
  11056. blockData[blockBufferOffset + col + 16] = t;
  11057. blockData[blockBufferOffset + col + 24] = t;
  11058. blockData[blockBufferOffset + col + 32] = t;
  11059. blockData[blockBufferOffset + col + 40] = t;
  11060. blockData[blockBufferOffset + col + 48] = t;
  11061. blockData[blockBufferOffset + col + 56] = t;
  11062. continue;
  11063. }
  11064. // stage 4
  11065. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  11066. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  11067. v2 = p2;
  11068. v3 = p6;
  11069. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  11070. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  11071. v5 = p3;
  11072. v6 = p5;
  11073. // stage 3
  11074. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  11075. // converting to UInt8 range later.
  11076. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  11077. v1 = v0 - v1;
  11078. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  11079. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  11080. v3 = t;
  11081. v4 = (v4 + v6 + 1) >> 1;
  11082. v6 = v4 - v6;
  11083. v7 = (v7 + v5 + 1) >> 1;
  11084. v5 = v7 - v5;
  11085. // stage 2
  11086. v0 = (v0 + v3 + 1) >> 1;
  11087. v3 = v0 - v3;
  11088. v1 = (v1 + v2 + 1) >> 1;
  11089. v2 = v1 - v2;
  11090. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  11091. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  11092. v7 = t;
  11093. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  11094. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  11095. v6 = t;
  11096. // stage 1
  11097. p0 = v0 + v7;
  11098. p7 = v0 - v7;
  11099. p1 = v1 + v6;
  11100. p6 = v1 - v6;
  11101. p2 = v2 + v5;
  11102. p5 = v2 - v5;
  11103. p3 = v3 + v4;
  11104. p4 = v3 - v4;
  11105. // convert to 8-bit integers
  11106. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  11107. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  11108. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  11109. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  11110. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  11111. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  11112. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  11113. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  11114. // store block data
  11115. blockData[blockBufferOffset + col] = p0;
  11116. blockData[blockBufferOffset + col + 8] = p1;
  11117. blockData[blockBufferOffset + col + 16] = p2;
  11118. blockData[blockBufferOffset + col + 24] = p3;
  11119. blockData[blockBufferOffset + col + 32] = p4;
  11120. blockData[blockBufferOffset + col + 40] = p5;
  11121. blockData[blockBufferOffset + col + 48] = p6;
  11122. blockData[blockBufferOffset + col + 56] = p7;
  11123. }
  11124. }
  11125. function buildComponentData(frame, component) {
  11126. var blocksPerLine = component.blocksPerLine;
  11127. var blocksPerColumn = component.blocksPerColumn;
  11128. var computationBuffer = new Int16Array(64);
  11129. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  11130. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  11131. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  11132. quantizeAndInverse(component, offset, computationBuffer);
  11133. }
  11134. }
  11135. return component.blockData;
  11136. }
  11137. function clamp0to255(a) {
  11138. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  11139. }
  11140. JpegImage.prototype = {
  11141. parse: function parse(data) {
  11142. function readUint16() {
  11143. var value = (data[offset] << 8) | data[offset + 1];
  11144. offset += 2;
  11145. return value;
  11146. }
  11147. function readDataBlock() {
  11148. var length = readUint16();
  11149. var array = data.subarray(offset, offset + length - 2);
  11150. offset += array.length;
  11151. return array;
  11152. }
  11153. function prepareComponents(frame) {
  11154. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  11155. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  11156. for (var i = 0; i < frame.components.length; i++) {
  11157. component = frame.components[i];
  11158. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  11159. component.h / frame.maxH);
  11160. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  11161. component.v / frame.maxV);
  11162. var blocksPerLineForMcu = mcusPerLine * component.h;
  11163. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  11164. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  11165. (blocksPerLineForMcu + 1);
  11166. component.blockData = new Int16Array(blocksBufferSize);
  11167. component.blocksPerLine = blocksPerLine;
  11168. component.blocksPerColumn = blocksPerColumn;
  11169. }
  11170. frame.mcusPerLine = mcusPerLine;
  11171. frame.mcusPerColumn = mcusPerColumn;
  11172. }
  11173. var offset = 0;
  11174. var jfif = null;
  11175. var adobe = null;
  11176. var frame, resetInterval;
  11177. var quantizationTables = [];
  11178. var huffmanTablesAC = [], huffmanTablesDC = [];
  11179. var fileMarker = readUint16();
  11180. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  11181. error('JPEG error: SOI not found');
  11182. }
  11183. fileMarker = readUint16();
  11184. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  11185. var i, j, l;
  11186. switch(fileMarker) {
  11187. case 0xFFE0: // APP0 (Application Specific)
  11188. case 0xFFE1: // APP1
  11189. case 0xFFE2: // APP2
  11190. case 0xFFE3: // APP3
  11191. case 0xFFE4: // APP4
  11192. case 0xFFE5: // APP5
  11193. case 0xFFE6: // APP6
  11194. case 0xFFE7: // APP7
  11195. case 0xFFE8: // APP8
  11196. case 0xFFE9: // APP9
  11197. case 0xFFEA: // APP10
  11198. case 0xFFEB: // APP11
  11199. case 0xFFEC: // APP12
  11200. case 0xFFED: // APP13
  11201. case 0xFFEE: // APP14
  11202. case 0xFFEF: // APP15
  11203. case 0xFFFE: // COM (Comment)
  11204. var appData = readDataBlock();
  11205. if (fileMarker === 0xFFE0) {
  11206. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  11207. appData[2] === 0x49 && appData[3] === 0x46 &&
  11208. appData[4] === 0) { // 'JFIF\x00'
  11209. jfif = {
  11210. version: { major: appData[5], minor: appData[6] },
  11211. densityUnits: appData[7],
  11212. xDensity: (appData[8] << 8) | appData[9],
  11213. yDensity: (appData[10] << 8) | appData[11],
  11214. thumbWidth: appData[12],
  11215. thumbHeight: appData[13],
  11216. thumbData: appData.subarray(14, 14 +
  11217. 3 * appData[12] * appData[13])
  11218. };
  11219. }
  11220. }
  11221. // TODO APP1 - Exif
  11222. if (fileMarker === 0xFFEE) {
  11223. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  11224. appData[2] === 0x6F && appData[3] === 0x62 &&
  11225. appData[4] === 0x65) { // 'Adobe'
  11226. adobe = {
  11227. version: (appData[5] << 8) | appData[6],
  11228. flags0: (appData[7] << 8) | appData[8],
  11229. flags1: (appData[9] << 8) | appData[10],
  11230. transformCode: appData[11]
  11231. };
  11232. }
  11233. }
  11234. break;
  11235. case 0xFFDB: // DQT (Define Quantization Tables)
  11236. var quantizationTablesLength = readUint16();
  11237. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  11238. var z;
  11239. while (offset < quantizationTablesEnd) {
  11240. var quantizationTableSpec = data[offset++];
  11241. var tableData = new Uint16Array(64);
  11242. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  11243. for (j = 0; j < 64; j++) {
  11244. z = dctZigZag[j];
  11245. tableData[z] = data[offset++];
  11246. }
  11247. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  11248. for (j = 0; j < 64; j++) {
  11249. z = dctZigZag[j];
  11250. tableData[z] = readUint16();
  11251. }
  11252. } else {
  11253. error('JPEG error: DQT - invalid table spec');
  11254. }
  11255. quantizationTables[quantizationTableSpec & 15] = tableData;
  11256. }
  11257. break;
  11258. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  11259. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  11260. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  11261. if (frame) {
  11262. error('JPEG error: Only single frame JPEGs supported');
  11263. }
  11264. readUint16(); // skip data length
  11265. frame = {};
  11266. frame.extended = (fileMarker === 0xFFC1);
  11267. frame.progressive = (fileMarker === 0xFFC2);
  11268. frame.precision = data[offset++];
  11269. frame.scanLines = readUint16();
  11270. frame.samplesPerLine = readUint16();
  11271. frame.components = [];
  11272. frame.componentIds = {};
  11273. var componentsCount = data[offset++], componentId;
  11274. var maxH = 0, maxV = 0;
  11275. for (i = 0; i < componentsCount; i++) {
  11276. componentId = data[offset];
  11277. var h = data[offset + 1] >> 4;
  11278. var v = data[offset + 1] & 15;
  11279. if (maxH < h) {
  11280. maxH = h;
  11281. }
  11282. if (maxV < v) {
  11283. maxV = v;
  11284. }
  11285. var qId = data[offset + 2];
  11286. l = frame.components.push({
  11287. h: h,
  11288. v: v,
  11289. quantizationId: qId,
  11290. quantizationTable: null, // See comment below.
  11291. });
  11292. frame.componentIds[componentId] = l - 1;
  11293. offset += 3;
  11294. }
  11295. frame.maxH = maxH;
  11296. frame.maxV = maxV;
  11297. prepareComponents(frame);
  11298. break;
  11299. case 0xFFC4: // DHT (Define Huffman Tables)
  11300. var huffmanLength = readUint16();
  11301. for (i = 2; i < huffmanLength;) {
  11302. var huffmanTableSpec = data[offset++];
  11303. var codeLengths = new Uint8Array(16);
  11304. var codeLengthSum = 0;
  11305. for (j = 0; j < 16; j++, offset++) {
  11306. codeLengthSum += (codeLengths[j] = data[offset]);
  11307. }
  11308. var huffmanValues = new Uint8Array(codeLengthSum);
  11309. for (j = 0; j < codeLengthSum; j++, offset++) {
  11310. huffmanValues[j] = data[offset];
  11311. }
  11312. i += 17 + codeLengthSum;
  11313. ((huffmanTableSpec >> 4) === 0 ?
  11314. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  11315. buildHuffmanTable(codeLengths, huffmanValues);
  11316. }
  11317. break;
  11318. case 0xFFDD: // DRI (Define Restart Interval)
  11319. readUint16(); // skip data length
  11320. resetInterval = readUint16();
  11321. break;
  11322. case 0xFFDA: // SOS (Start of Scan)
  11323. var scanLength = readUint16();
  11324. var selectorsCount = data[offset++];
  11325. var components = [], component;
  11326. for (i = 0; i < selectorsCount; i++) {
  11327. var componentIndex = frame.componentIds[data[offset++]];
  11328. component = frame.components[componentIndex];
  11329. var tableSpec = data[offset++];
  11330. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  11331. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  11332. components.push(component);
  11333. }
  11334. var spectralStart = data[offset++];
  11335. var spectralEnd = data[offset++];
  11336. var successiveApproximation = data[offset++];
  11337. var processed = decodeScan(data, offset,
  11338. frame, components, resetInterval,
  11339. spectralStart, spectralEnd,
  11340. successiveApproximation >> 4, successiveApproximation & 15);
  11341. offset += processed;
  11342. break;
  11343. case 0xFFFF: // Fill bytes
  11344. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  11345. offset--;
  11346. }
  11347. break;
  11348. default:
  11349. if (data[offset - 3] === 0xFF &&
  11350. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  11351. // could be incorrect encoding -- last 0xFF byte of the previous
  11352. // block was eaten by the encoder
  11353. offset -= 3;
  11354. break;
  11355. }
  11356. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  11357. }
  11358. fileMarker = readUint16();
  11359. }
  11360. this.width = frame.samplesPerLine;
  11361. this.height = frame.scanLines;
  11362. this.jfif = jfif;
  11363. this.adobe = adobe;
  11364. this.components = [];
  11365. for (i = 0; i < frame.components.length; i++) {
  11366. component = frame.components[i];
  11367. // Prevent errors when DQT markers are placed after SOF{n} markers,
  11368. // by assigning the `quantizationTable` entry after the entire image
  11369. // has been parsed (fixes issue7406.pdf).
  11370. var quantizationTable = quantizationTables[component.quantizationId];
  11371. if (quantizationTable) {
  11372. component.quantizationTable = quantizationTable;
  11373. }
  11374. this.components.push({
  11375. output: buildComponentData(frame, component),
  11376. scaleX: component.h / frame.maxH,
  11377. scaleY: component.v / frame.maxV,
  11378. blocksPerLine: component.blocksPerLine,
  11379. blocksPerColumn: component.blocksPerColumn
  11380. });
  11381. }
  11382. this.numComponents = this.components.length;
  11383. },
  11384. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  11385. var scaleX = this.width / width, scaleY = this.height / height;
  11386. var component, componentScaleX, componentScaleY, blocksPerScanline;
  11387. var x, y, i, j, k;
  11388. var index;
  11389. var offset = 0;
  11390. var output;
  11391. var numComponents = this.components.length;
  11392. var dataLength = width * height * numComponents;
  11393. var data = new Uint8Array(dataLength);
  11394. var xScaleBlockOffset = new Uint32Array(width);
  11395. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  11396. for (i = 0; i < numComponents; i++) {
  11397. component = this.components[i];
  11398. componentScaleX = component.scaleX * scaleX;
  11399. componentScaleY = component.scaleY * scaleY;
  11400. offset = i;
  11401. output = component.output;
  11402. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  11403. // precalculate the xScaleBlockOffset
  11404. for (x = 0; x < width; x++) {
  11405. j = 0 | (x * componentScaleX);
  11406. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  11407. }
  11408. // linearize the blocks of the component
  11409. for (y = 0; y < height; y++) {
  11410. j = 0 | (y * componentScaleY);
  11411. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  11412. for (x = 0; x < width; x++) {
  11413. data[offset] = output[index + xScaleBlockOffset[x]];
  11414. offset += numComponents;
  11415. }
  11416. }
  11417. }
  11418. // decodeTransform contains pairs of multiplier (-256..256) and additive
  11419. var transform = this.decodeTransform;
  11420. if (transform) {
  11421. for (i = 0; i < dataLength;) {
  11422. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  11423. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  11424. }
  11425. }
  11426. }
  11427. return data;
  11428. },
  11429. _isColorConversionNeeded: function isColorConversionNeeded() {
  11430. if (this.adobe && this.adobe.transformCode) {
  11431. // The adobe transform marker overrides any previous setting
  11432. return true;
  11433. } else if (this.numComponents === 3) {
  11434. if (!this.adobe && this.colorTransform === 0) {
  11435. // If the Adobe transform marker is not present and the image
  11436. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  11437. // then the colours should *not* be transformed.
  11438. return false;
  11439. }
  11440. return true;
  11441. } else { // `this.numComponents !== 3`
  11442. if (!this.adobe && this.colorTransform === 1) {
  11443. // If the Adobe transform marker is not present and the image
  11444. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  11445. // then the colours should be transformed.
  11446. return true;
  11447. }
  11448. return false;
  11449. }
  11450. },
  11451. _convertYccToRgb: function convertYccToRgb(data) {
  11452. var Y, Cb, Cr;
  11453. for (var i = 0, length = data.length; i < length; i += 3) {
  11454. Y = data[i ];
  11455. Cb = data[i + 1];
  11456. Cr = data[i + 2];
  11457. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  11458. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  11459. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  11460. }
  11461. return data;
  11462. },
  11463. _convertYcckToRgb: function convertYcckToRgb(data) {
  11464. var Y, Cb, Cr, k;
  11465. var offset = 0;
  11466. for (var i = 0, length = data.length; i < length; i += 4) {
  11467. Y = data[i];
  11468. Cb = data[i + 1];
  11469. Cr = data[i + 2];
  11470. k = data[i + 3];
  11471. var r = -122.67195406894 +
  11472. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  11473. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  11474. 0.154362151871126) +
  11475. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  11476. 0.00477271405408747 * k + 1.53380253221734) +
  11477. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  11478. 0.48357088451265) +
  11479. k * (-0.000336197177618394 * k + 0.484791561490776);
  11480. var g = 107.268039397724 +
  11481. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  11482. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  11483. 0.176491792462875) +
  11484. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  11485. 0.000770482631801132 * k - 0.151051492775562) +
  11486. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  11487. 0.25802910206845) +
  11488. k * (-0.000318913117588328 * k - 0.213742400323665);
  11489. var b = -20.810012546947 +
  11490. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  11491. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  11492. 0.814272968359295) +
  11493. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  11494. 0.000560833691242812 * k - 0.195152027534049) +
  11495. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  11496. 0.116935020465145) +
  11497. k * (-0.000343531996510555 * k + 0.24165260232407);
  11498. data[offset++] = clamp0to255(r);
  11499. data[offset++] = clamp0to255(g);
  11500. data[offset++] = clamp0to255(b);
  11501. }
  11502. return data;
  11503. },
  11504. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  11505. var Y, Cb, Cr;
  11506. for (var i = 0, length = data.length; i < length; i += 4) {
  11507. Y = data[i];
  11508. Cb = data[i + 1];
  11509. Cr = data[i + 2];
  11510. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  11511. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  11512. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  11513. // K in data[i + 3] is unchanged
  11514. }
  11515. return data;
  11516. },
  11517. _convertCmykToRgb: function convertCmykToRgb(data) {
  11518. var c, m, y, k;
  11519. var offset = 0;
  11520. var min = -255 * 255 * 255;
  11521. var scale = 1 / 255 / 255;
  11522. for (var i = 0, length = data.length; i < length; i += 4) {
  11523. c = data[i];
  11524. m = data[i + 1];
  11525. y = data[i + 2];
  11526. k = data[i + 3];
  11527. var r =
  11528. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  11529. 18.82290502165302 * y + 212.25662451639585 * k -
  11530. 72734.4411664936) +
  11531. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  11532. 17.873870861415444 * k - 1401.7366389350734) +
  11533. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  11534. 4465.541406466231) -
  11535. k * (21.86122147463605 * k + 48317.86113160301);
  11536. var g =
  11537. c * (8.841041422036149 * c + 60.118027045597366 * m +
  11538. 6.871425592049007 * y + 31.159100130055922 * k -
  11539. 20220.756542821975) +
  11540. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  11541. 131.35250912493976 * k - 48691.05921601825) +
  11542. y * (4.444339102852739 * y + 9.8632861493405 * k -
  11543. 6341.191035517494) -
  11544. k * (20.737325471181034 * k + 47890.15695978492);
  11545. var b =
  11546. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  11547. 30.89978309703729 * y - 0.23883238689178934 * k -
  11548. 3616.812083916688) +
  11549. m * (10.49593273432072 * m + 63.02378494754052 * y +
  11550. 50.606957656360734 * k - 28620.90484698408) +
  11551. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  11552. 49363.43385999684) -
  11553. k * (22.33816807309886 * k + 45932.16563550634);
  11554. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  11555. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  11556. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  11557. }
  11558. return data;
  11559. },
  11560. getData: function getData(width, height, forceRGBoutput) {
  11561. if (this.numComponents > 4) {
  11562. error('JPEG error: Unsupported color mode');
  11563. }
  11564. // type of data: Uint8Array(width * height * numComponents)
  11565. var data = this._getLinearizedBlockData(width, height);
  11566. if (this.numComponents === 1 && forceRGBoutput) {
  11567. var dataLength = data.length;
  11568. var rgbData = new Uint8Array(dataLength * 3);
  11569. var offset = 0;
  11570. for (var i = 0; i < dataLength; i++) {
  11571. var grayColor = data[i];
  11572. rgbData[offset++] = grayColor;
  11573. rgbData[offset++] = grayColor;
  11574. rgbData[offset++] = grayColor;
  11575. }
  11576. return rgbData;
  11577. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  11578. return this._convertYccToRgb(data);
  11579. } else if (this.numComponents === 4) {
  11580. if (this._isColorConversionNeeded()) {
  11581. if (forceRGBoutput) {
  11582. return this._convertYcckToRgb(data);
  11583. } else {
  11584. return this._convertYcckToCmyk(data);
  11585. }
  11586. } else if (forceRGBoutput) {
  11587. return this._convertCmykToRgb(data);
  11588. }
  11589. }
  11590. return data;
  11591. }
  11592. };
  11593. return JpegImage;
  11594. })();
  11595. exports.JpegImage = JpegImage;
  11596. }));
  11597. (function (root, factory) {
  11598. {
  11599. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11600. root.pdfjsCoreArithmeticDecoder);
  11601. }
  11602. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11603. var info = sharedUtil.info;
  11604. var warn = sharedUtil.warn;
  11605. var error = sharedUtil.error;
  11606. var log2 = sharedUtil.log2;
  11607. var readUint16 = sharedUtil.readUint16;
  11608. var readUint32 = sharedUtil.readUint32;
  11609. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11610. var JpxImage = (function JpxImageClosure() {
  11611. // Table E.1
  11612. var SubbandsGainLog2 = {
  11613. 'LL': 0,
  11614. 'LH': 1,
  11615. 'HL': 1,
  11616. 'HH': 2
  11617. };
  11618. function JpxImage() {
  11619. this.failOnCorruptedImage = false;
  11620. }
  11621. JpxImage.prototype = {
  11622. parse: function JpxImage_parse(data) {
  11623. var head = readUint16(data, 0);
  11624. // No box header, immediate start of codestream (SOC)
  11625. if (head === 0xFF4F) {
  11626. this.parseCodestream(data, 0, data.length);
  11627. return;
  11628. }
  11629. var position = 0, length = data.length;
  11630. while (position < length) {
  11631. var headerSize = 8;
  11632. var lbox = readUint32(data, position);
  11633. var tbox = readUint32(data, position + 4);
  11634. position += headerSize;
  11635. if (lbox === 1) {
  11636. // XLBox: read UInt64 according to spec.
  11637. // JavaScript's int precision of 53 bit should be sufficient here.
  11638. lbox = readUint32(data, position) * 4294967296 +
  11639. readUint32(data, position + 4);
  11640. position += 8;
  11641. headerSize += 8;
  11642. }
  11643. if (lbox === 0) {
  11644. lbox = length - position + headerSize;
  11645. }
  11646. if (lbox < headerSize) {
  11647. error('JPX Error: Invalid box field size');
  11648. }
  11649. var dataLength = lbox - headerSize;
  11650. var jumpDataLength = true;
  11651. switch (tbox) {
  11652. case 0x6A703268: // 'jp2h'
  11653. jumpDataLength = false; // parsing child boxes
  11654. break;
  11655. case 0x636F6C72: // 'colr'
  11656. // Colorspaces are not used, the CS from the PDF is used.
  11657. var method = data[position];
  11658. if (method === 1) {
  11659. // enumerated colorspace
  11660. var colorspace = readUint32(data, position + 3);
  11661. switch (colorspace) {
  11662. case 16: // this indicates a sRGB colorspace
  11663. case 17: // this indicates a grayscale colorspace
  11664. case 18: // this indicates a YUV colorspace
  11665. break;
  11666. default:
  11667. warn('Unknown colorspace ' + colorspace);
  11668. break;
  11669. }
  11670. } else if (method === 2) {
  11671. info('ICC profile not supported');
  11672. }
  11673. break;
  11674. case 0x6A703263: // 'jp2c'
  11675. this.parseCodestream(data, position, position + dataLength);
  11676. break;
  11677. case 0x6A502020: // 'jP\024\024'
  11678. if (0x0d0a870a !== readUint32(data, position)) {
  11679. warn('Invalid JP2 signature');
  11680. }
  11681. break;
  11682. // The following header types are valid but currently not used:
  11683. case 0x6A501A1A: // 'jP\032\032'
  11684. case 0x66747970: // 'ftyp'
  11685. case 0x72726571: // 'rreq'
  11686. case 0x72657320: // 'res '
  11687. case 0x69686472: // 'ihdr'
  11688. break;
  11689. default:
  11690. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11691. (tbox >> 16) & 0xFF,
  11692. (tbox >> 8) & 0xFF,
  11693. tbox & 0xFF);
  11694. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11695. break;
  11696. }
  11697. if (jumpDataLength) {
  11698. position += dataLength;
  11699. }
  11700. }
  11701. },
  11702. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11703. var newByte = stream.getByte();
  11704. while (newByte >= 0) {
  11705. var oldByte = newByte;
  11706. newByte = stream.getByte();
  11707. var code = (oldByte << 8) | newByte;
  11708. // Image and tile size (SIZ)
  11709. if (code === 0xFF51) {
  11710. stream.skip(4);
  11711. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11712. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11713. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11714. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11715. stream.skip(16);
  11716. var Csiz = stream.getUint16(); // Byte 36
  11717. this.width = Xsiz - XOsiz;
  11718. this.height = Ysiz - YOsiz;
  11719. this.componentsCount = Csiz;
  11720. // Results are always returned as Uint8Arrays
  11721. this.bitsPerComponent = 8;
  11722. return;
  11723. }
  11724. }
  11725. error('JPX Error: No size marker found in JPX stream');
  11726. },
  11727. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11728. var context = {};
  11729. var doNotRecover = false;
  11730. try {
  11731. var position = start;
  11732. while (position + 1 < end) {
  11733. var code = readUint16(data, position);
  11734. position += 2;
  11735. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11736. switch (code) {
  11737. case 0xFF4F: // Start of codestream (SOC)
  11738. context.mainHeader = true;
  11739. break;
  11740. case 0xFFD9: // End of codestream (EOC)
  11741. break;
  11742. case 0xFF51: // Image and tile size (SIZ)
  11743. length = readUint16(data, position);
  11744. var siz = {};
  11745. siz.Xsiz = readUint32(data, position + 4);
  11746. siz.Ysiz = readUint32(data, position + 8);
  11747. siz.XOsiz = readUint32(data, position + 12);
  11748. siz.YOsiz = readUint32(data, position + 16);
  11749. siz.XTsiz = readUint32(data, position + 20);
  11750. siz.YTsiz = readUint32(data, position + 24);
  11751. siz.XTOsiz = readUint32(data, position + 28);
  11752. siz.YTOsiz = readUint32(data, position + 32);
  11753. var componentsCount = readUint16(data, position + 36);
  11754. siz.Csiz = componentsCount;
  11755. var components = [];
  11756. j = position + 38;
  11757. for (var i = 0; i < componentsCount; i++) {
  11758. var component = {
  11759. precision: (data[j] & 0x7F) + 1,
  11760. isSigned: !!(data[j] & 0x80),
  11761. XRsiz: data[j + 1],
  11762. YRsiz: data[j + 1]
  11763. };
  11764. calculateComponentDimensions(component, siz);
  11765. components.push(component);
  11766. }
  11767. context.SIZ = siz;
  11768. context.components = components;
  11769. calculateTileGrids(context, components);
  11770. context.QCC = [];
  11771. context.COC = [];
  11772. break;
  11773. case 0xFF5C: // Quantization default (QCD)
  11774. length = readUint16(data, position);
  11775. var qcd = {};
  11776. j = position + 2;
  11777. sqcd = data[j++];
  11778. switch (sqcd & 0x1F) {
  11779. case 0:
  11780. spqcdSize = 8;
  11781. scalarExpounded = true;
  11782. break;
  11783. case 1:
  11784. spqcdSize = 16;
  11785. scalarExpounded = false;
  11786. break;
  11787. case 2:
  11788. spqcdSize = 16;
  11789. scalarExpounded = true;
  11790. break;
  11791. default:
  11792. throw new Error('Invalid SQcd value ' + sqcd);
  11793. }
  11794. qcd.noQuantization = (spqcdSize === 8);
  11795. qcd.scalarExpounded = scalarExpounded;
  11796. qcd.guardBits = sqcd >> 5;
  11797. spqcds = [];
  11798. while (j < length + position) {
  11799. var spqcd = {};
  11800. if (spqcdSize === 8) {
  11801. spqcd.epsilon = data[j++] >> 3;
  11802. spqcd.mu = 0;
  11803. } else {
  11804. spqcd.epsilon = data[j] >> 3;
  11805. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11806. j += 2;
  11807. }
  11808. spqcds.push(spqcd);
  11809. }
  11810. qcd.SPqcds = spqcds;
  11811. if (context.mainHeader) {
  11812. context.QCD = qcd;
  11813. } else {
  11814. context.currentTile.QCD = qcd;
  11815. context.currentTile.QCC = [];
  11816. }
  11817. break;
  11818. case 0xFF5D: // Quantization component (QCC)
  11819. length = readUint16(data, position);
  11820. var qcc = {};
  11821. j = position + 2;
  11822. var cqcc;
  11823. if (context.SIZ.Csiz < 257) {
  11824. cqcc = data[j++];
  11825. } else {
  11826. cqcc = readUint16(data, j);
  11827. j += 2;
  11828. }
  11829. sqcd = data[j++];
  11830. switch (sqcd & 0x1F) {
  11831. case 0:
  11832. spqcdSize = 8;
  11833. scalarExpounded = true;
  11834. break;
  11835. case 1:
  11836. spqcdSize = 16;
  11837. scalarExpounded = false;
  11838. break;
  11839. case 2:
  11840. spqcdSize = 16;
  11841. scalarExpounded = true;
  11842. break;
  11843. default:
  11844. throw new Error('Invalid SQcd value ' + sqcd);
  11845. }
  11846. qcc.noQuantization = (spqcdSize === 8);
  11847. qcc.scalarExpounded = scalarExpounded;
  11848. qcc.guardBits = sqcd >> 5;
  11849. spqcds = [];
  11850. while (j < (length + position)) {
  11851. spqcd = {};
  11852. if (spqcdSize === 8) {
  11853. spqcd.epsilon = data[j++] >> 3;
  11854. spqcd.mu = 0;
  11855. } else {
  11856. spqcd.epsilon = data[j] >> 3;
  11857. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11858. j += 2;
  11859. }
  11860. spqcds.push(spqcd);
  11861. }
  11862. qcc.SPqcds = spqcds;
  11863. if (context.mainHeader) {
  11864. context.QCC[cqcc] = qcc;
  11865. } else {
  11866. context.currentTile.QCC[cqcc] = qcc;
  11867. }
  11868. break;
  11869. case 0xFF52: // Coding style default (COD)
  11870. length = readUint16(data, position);
  11871. var cod = {};
  11872. j = position + 2;
  11873. var scod = data[j++];
  11874. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11875. cod.sopMarkerUsed = !!(scod & 2);
  11876. cod.ephMarkerUsed = !!(scod & 4);
  11877. cod.progressionOrder = data[j++];
  11878. cod.layersCount = readUint16(data, j);
  11879. j += 2;
  11880. cod.multipleComponentTransform = data[j++];
  11881. cod.decompositionLevelsCount = data[j++];
  11882. cod.xcb = (data[j++] & 0xF) + 2;
  11883. cod.ycb = (data[j++] & 0xF) + 2;
  11884. var blockStyle = data[j++];
  11885. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11886. cod.resetContextProbabilities = !!(blockStyle & 2);
  11887. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11888. cod.verticalyStripe = !!(blockStyle & 8);
  11889. cod.predictableTermination = !!(blockStyle & 16);
  11890. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11891. cod.reversibleTransformation = data[j++];
  11892. if (cod.entropyCoderWithCustomPrecincts) {
  11893. var precinctsSizes = [];
  11894. while (j < length + position) {
  11895. var precinctsSize = data[j++];
  11896. precinctsSizes.push({
  11897. PPx: precinctsSize & 0xF,
  11898. PPy: precinctsSize >> 4
  11899. });
  11900. }
  11901. cod.precinctsSizes = precinctsSizes;
  11902. }
  11903. var unsupported = [];
  11904. if (cod.selectiveArithmeticCodingBypass) {
  11905. unsupported.push('selectiveArithmeticCodingBypass');
  11906. }
  11907. if (cod.resetContextProbabilities) {
  11908. unsupported.push('resetContextProbabilities');
  11909. }
  11910. if (cod.terminationOnEachCodingPass) {
  11911. unsupported.push('terminationOnEachCodingPass');
  11912. }
  11913. if (cod.verticalyStripe) {
  11914. unsupported.push('verticalyStripe');
  11915. }
  11916. if (cod.predictableTermination) {
  11917. unsupported.push('predictableTermination');
  11918. }
  11919. if (unsupported.length > 0) {
  11920. doNotRecover = true;
  11921. throw new Error('Unsupported COD options (' +
  11922. unsupported.join(', ') + ')');
  11923. }
  11924. if (context.mainHeader) {
  11925. context.COD = cod;
  11926. } else {
  11927. context.currentTile.COD = cod;
  11928. context.currentTile.COC = [];
  11929. }
  11930. break;
  11931. case 0xFF90: // Start of tile-part (SOT)
  11932. length = readUint16(data, position);
  11933. tile = {};
  11934. tile.index = readUint16(data, position + 2);
  11935. tile.length = readUint32(data, position + 4);
  11936. tile.dataEnd = tile.length + position - 2;
  11937. tile.partIndex = data[position + 8];
  11938. tile.partsCount = data[position + 9];
  11939. context.mainHeader = false;
  11940. if (tile.partIndex === 0) {
  11941. // reset component specific settings
  11942. tile.COD = context.COD;
  11943. tile.COC = context.COC.slice(0); // clone of the global COC
  11944. tile.QCD = context.QCD;
  11945. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11946. }
  11947. context.currentTile = tile;
  11948. break;
  11949. case 0xFF93: // Start of data (SOD)
  11950. tile = context.currentTile;
  11951. if (tile.partIndex === 0) {
  11952. initializeTile(context, tile.index);
  11953. buildPackets(context);
  11954. }
  11955. // moving to the end of the data
  11956. length = tile.dataEnd - position;
  11957. parseTilePackets(context, data, position, length);
  11958. break;
  11959. case 0xFF55: // Tile-part lengths, main header (TLM)
  11960. case 0xFF57: // Packet length, main header (PLM)
  11961. case 0xFF58: // Packet length, tile-part header (PLT)
  11962. case 0xFF64: // Comment (COM)
  11963. length = readUint16(data, position);
  11964. // skipping content
  11965. break;
  11966. case 0xFF53: // Coding style component (COC)
  11967. throw new Error('Codestream code 0xFF53 (COC) is ' +
  11968. 'not implemented');
  11969. default:
  11970. throw new Error('Unknown codestream code: ' + code.toString(16));
  11971. }
  11972. position += length;
  11973. }
  11974. } catch (e) {
  11975. if (doNotRecover || this.failOnCorruptedImage) {
  11976. error('JPX Error: ' + e.message);
  11977. } else {
  11978. warn('JPX: Trying to recover from: ' + e.message);
  11979. }
  11980. }
  11981. this.tiles = transformComponents(context);
  11982. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11983. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11984. this.componentsCount = context.SIZ.Csiz;
  11985. }
  11986. };
  11987. function calculateComponentDimensions(component, siz) {
  11988. // Section B.2 Component mapping
  11989. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11990. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11991. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11992. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11993. component.width = component.x1 - component.x0;
  11994. component.height = component.y1 - component.y0;
  11995. }
  11996. function calculateTileGrids(context, components) {
  11997. var siz = context.SIZ;
  11998. // Section B.3 Division into tile and tile-components
  11999. var tile, tiles = [];
  12000. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12001. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12002. for (var q = 0; q < numYtiles; q++) {
  12003. for (var p = 0; p < numXtiles; p++) {
  12004. tile = {};
  12005. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12006. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12007. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12008. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12009. tile.width = tile.tx1 - tile.tx0;
  12010. tile.height = tile.ty1 - tile.ty0;
  12011. tile.components = [];
  12012. tiles.push(tile);
  12013. }
  12014. }
  12015. context.tiles = tiles;
  12016. var componentsCount = siz.Csiz;
  12017. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12018. var component = components[i];
  12019. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12020. var tileComponent = {};
  12021. tile = tiles[j];
  12022. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12023. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12024. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12025. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12026. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12027. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12028. tile.components[i] = tileComponent;
  12029. }
  12030. }
  12031. }
  12032. function getBlocksDimensions(context, component, r) {
  12033. var codOrCoc = component.codingStyleParameters;
  12034. var result = {};
  12035. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12036. result.PPx = 15;
  12037. result.PPy = 15;
  12038. } else {
  12039. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12040. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12041. }
  12042. // calculate codeblock size as described in section B.7
  12043. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12044. Math.min(codOrCoc.xcb, result.PPx));
  12045. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12046. Math.min(codOrCoc.ycb, result.PPy));
  12047. return result;
  12048. }
  12049. function buildPrecincts(context, resolution, dimensions) {
  12050. // Section B.6 Division resolution to precincts
  12051. var precinctWidth = 1 << dimensions.PPx;
  12052. var precinctHeight = 1 << dimensions.PPy;
  12053. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12054. // to precincts. Precinct partition divides a resolution according to width
  12055. // and height parameters. The subband that belongs to the resolution level
  12056. // has a different size than the level, unless it is the zero resolution.
  12057. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12058. // The precinct partitioning for a particular subband is derived from a
  12059. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12060. // resolution level)... The LL band associated with each resolution level is
  12061. // divided into precincts... Each of the resulting precinct regions is then
  12062. // mapped into its child subbands (if any) at the next lower resolution
  12063. // level. This is accomplished by using the coordinate transformation
  12064. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12065. // coordinates of a point in the LL band and child subband, respectively.
  12066. var isZeroRes = resolution.resLevel === 0;
  12067. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12068. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12069. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12070. Math.ceil(resolution.trx1 / precinctWidth) -
  12071. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12072. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12073. Math.ceil(resolution.try1 / precinctHeight) -
  12074. Math.floor(resolution.try0 / precinctHeight) : 0);
  12075. var numprecincts = numprecinctswide * numprecinctshigh;
  12076. resolution.precinctParameters = {
  12077. precinctWidth: precinctWidth,
  12078. precinctHeight: precinctHeight,
  12079. numprecinctswide: numprecinctswide,
  12080. numprecinctshigh: numprecinctshigh,
  12081. numprecincts: numprecincts,
  12082. precinctWidthInSubband: precinctWidthInSubband,
  12083. precinctHeightInSubband: precinctHeightInSubband
  12084. };
  12085. }
  12086. function buildCodeblocks(context, subband, dimensions) {
  12087. // Section B.7 Division sub-band into code-blocks
  12088. var xcb_ = dimensions.xcb_;
  12089. var ycb_ = dimensions.ycb_;
  12090. var codeblockWidth = 1 << xcb_;
  12091. var codeblockHeight = 1 << ycb_;
  12092. var cbx0 = subband.tbx0 >> xcb_;
  12093. var cby0 = subband.tby0 >> ycb_;
  12094. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12095. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12096. var precinctParameters = subband.resolution.precinctParameters;
  12097. var codeblocks = [];
  12098. var precincts = [];
  12099. var i, j, codeblock, precinctNumber;
  12100. for (j = cby0; j < cby1; j++) {
  12101. for (i = cbx0; i < cbx1; i++) {
  12102. codeblock = {
  12103. cbx: i,
  12104. cby: j,
  12105. tbx0: codeblockWidth * i,
  12106. tby0: codeblockHeight * j,
  12107. tbx1: codeblockWidth * (i + 1),
  12108. tby1: codeblockHeight * (j + 1)
  12109. };
  12110. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12111. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12112. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12113. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12114. // Calculate precinct number for this codeblock, codeblock position
  12115. // should be relative to its subband, use actual dimension and position
  12116. // See comment about codeblock group width and height
  12117. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12118. precinctParameters.precinctWidthInSubband);
  12119. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12120. precinctParameters.precinctHeightInSubband);
  12121. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12122. codeblock.precinctNumber = precinctNumber;
  12123. codeblock.subbandType = subband.type;
  12124. codeblock.Lblock = 3;
  12125. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12126. codeblock.tby1_ <= codeblock.tby0_) {
  12127. continue;
  12128. }
  12129. codeblocks.push(codeblock);
  12130. // building precinct for the sub-band
  12131. var precinct = precincts[precinctNumber];
  12132. if (precinct !== undefined) {
  12133. if (i < precinct.cbxMin) {
  12134. precinct.cbxMin = i;
  12135. } else if (i > precinct.cbxMax) {
  12136. precinct.cbxMax = i;
  12137. }
  12138. if (j < precinct.cbyMin) {
  12139. precinct.cbxMin = j;
  12140. } else if (j > precinct.cbyMax) {
  12141. precinct.cbyMax = j;
  12142. }
  12143. } else {
  12144. precincts[precinctNumber] = precinct = {
  12145. cbxMin: i,
  12146. cbyMin: j,
  12147. cbxMax: i,
  12148. cbyMax: j
  12149. };
  12150. }
  12151. codeblock.precinct = precinct;
  12152. }
  12153. }
  12154. subband.codeblockParameters = {
  12155. codeblockWidth: xcb_,
  12156. codeblockHeight: ycb_,
  12157. numcodeblockwide: cbx1 - cbx0 + 1,
  12158. numcodeblockhigh: cby1 - cby0 + 1
  12159. };
  12160. subband.codeblocks = codeblocks;
  12161. subband.precincts = precincts;
  12162. }
  12163. function createPacket(resolution, precinctNumber, layerNumber) {
  12164. var precinctCodeblocks = [];
  12165. // Section B.10.8 Order of info in packet
  12166. var subbands = resolution.subbands;
  12167. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12168. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12169. var subband = subbands[i];
  12170. var codeblocks = subband.codeblocks;
  12171. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12172. var codeblock = codeblocks[j];
  12173. if (codeblock.precinctNumber !== precinctNumber) {
  12174. continue;
  12175. }
  12176. precinctCodeblocks.push(codeblock);
  12177. }
  12178. }
  12179. return {
  12180. layerNumber: layerNumber,
  12181. codeblocks: precinctCodeblocks
  12182. };
  12183. }
  12184. function LayerResolutionComponentPositionIterator(context) {
  12185. var siz = context.SIZ;
  12186. var tileIndex = context.currentTile.index;
  12187. var tile = context.tiles[tileIndex];
  12188. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12189. var componentsCount = siz.Csiz;
  12190. var maxDecompositionLevelsCount = 0;
  12191. for (var q = 0; q < componentsCount; q++) {
  12192. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12193. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12194. }
  12195. var l = 0, r = 0, i = 0, k = 0;
  12196. this.nextPacket = function JpxImage_nextPacket() {
  12197. // Section B.12.1.1 Layer-resolution-component-position
  12198. for (; l < layersCount; l++) {
  12199. for (; r <= maxDecompositionLevelsCount; r++) {
  12200. for (; i < componentsCount; i++) {
  12201. var component = tile.components[i];
  12202. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12203. continue;
  12204. }
  12205. var resolution = component.resolutions[r];
  12206. var numprecincts = resolution.precinctParameters.numprecincts;
  12207. for (; k < numprecincts;) {
  12208. var packet = createPacket(resolution, k, l);
  12209. k++;
  12210. return packet;
  12211. }
  12212. k = 0;
  12213. }
  12214. i = 0;
  12215. }
  12216. r = 0;
  12217. }
  12218. error('JPX Error: Out of packets');
  12219. };
  12220. }
  12221. function ResolutionLayerComponentPositionIterator(context) {
  12222. var siz = context.SIZ;
  12223. var tileIndex = context.currentTile.index;
  12224. var tile = context.tiles[tileIndex];
  12225. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12226. var componentsCount = siz.Csiz;
  12227. var maxDecompositionLevelsCount = 0;
  12228. for (var q = 0; q < componentsCount; q++) {
  12229. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12230. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12231. }
  12232. var r = 0, l = 0, i = 0, k = 0;
  12233. this.nextPacket = function JpxImage_nextPacket() {
  12234. // Section B.12.1.2 Resolution-layer-component-position
  12235. for (; r <= maxDecompositionLevelsCount; r++) {
  12236. for (; l < layersCount; l++) {
  12237. for (; i < componentsCount; i++) {
  12238. var component = tile.components[i];
  12239. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12240. continue;
  12241. }
  12242. var resolution = component.resolutions[r];
  12243. var numprecincts = resolution.precinctParameters.numprecincts;
  12244. for (; k < numprecincts;) {
  12245. var packet = createPacket(resolution, k, l);
  12246. k++;
  12247. return packet;
  12248. }
  12249. k = 0;
  12250. }
  12251. i = 0;
  12252. }
  12253. l = 0;
  12254. }
  12255. error('JPX Error: Out of packets');
  12256. };
  12257. }
  12258. function ResolutionPositionComponentLayerIterator(context) {
  12259. var siz = context.SIZ;
  12260. var tileIndex = context.currentTile.index;
  12261. var tile = context.tiles[tileIndex];
  12262. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12263. var componentsCount = siz.Csiz;
  12264. var l, r, c, p;
  12265. var maxDecompositionLevelsCount = 0;
  12266. for (c = 0; c < componentsCount; c++) {
  12267. var component = tile.components[c];
  12268. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12269. component.codingStyleParameters.decompositionLevelsCount);
  12270. }
  12271. var maxNumPrecinctsInLevel = new Int32Array(
  12272. maxDecompositionLevelsCount + 1);
  12273. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12274. var maxNumPrecincts = 0;
  12275. for (c = 0; c < componentsCount; ++c) {
  12276. var resolutions = tile.components[c].resolutions;
  12277. if (r < resolutions.length) {
  12278. maxNumPrecincts = Math.max(maxNumPrecincts,
  12279. resolutions[r].precinctParameters.numprecincts);
  12280. }
  12281. }
  12282. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12283. }
  12284. l = 0;
  12285. r = 0;
  12286. c = 0;
  12287. p = 0;
  12288. this.nextPacket = function JpxImage_nextPacket() {
  12289. // Section B.12.1.3 Resolution-position-component-layer
  12290. for (; r <= maxDecompositionLevelsCount; r++) {
  12291. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12292. for (; c < componentsCount; c++) {
  12293. var component = tile.components[c];
  12294. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12295. continue;
  12296. }
  12297. var resolution = component.resolutions[r];
  12298. var numprecincts = resolution.precinctParameters.numprecincts;
  12299. if (p >= numprecincts) {
  12300. continue;
  12301. }
  12302. for (; l < layersCount;) {
  12303. var packet = createPacket(resolution, p, l);
  12304. l++;
  12305. return packet;
  12306. }
  12307. l = 0;
  12308. }
  12309. c = 0;
  12310. }
  12311. p = 0;
  12312. }
  12313. error('JPX Error: Out of packets');
  12314. };
  12315. }
  12316. function PositionComponentResolutionLayerIterator(context) {
  12317. var siz = context.SIZ;
  12318. var tileIndex = context.currentTile.index;
  12319. var tile = context.tiles[tileIndex];
  12320. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12321. var componentsCount = siz.Csiz;
  12322. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12323. var precinctsIterationSizes = precinctsSizes;
  12324. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12325. this.nextPacket = function JpxImage_nextPacket() {
  12326. // Section B.12.1.4 Position-component-resolution-layer
  12327. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12328. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12329. for (; c < componentsCount; c++) {
  12330. var component = tile.components[c];
  12331. var decompositionLevelsCount =
  12332. component.codingStyleParameters.decompositionLevelsCount;
  12333. for (; r <= decompositionLevelsCount; r++) {
  12334. var resolution = component.resolutions[r];
  12335. var sizeInImageScale =
  12336. precinctsSizes.components[c].resolutions[r];
  12337. var k = getPrecinctIndexIfExist(
  12338. px,
  12339. py,
  12340. sizeInImageScale,
  12341. precinctsIterationSizes,
  12342. resolution);
  12343. if (k === null) {
  12344. continue;
  12345. }
  12346. for (; l < layersCount;) {
  12347. var packet = createPacket(resolution, k, l);
  12348. l++;
  12349. return packet;
  12350. }
  12351. l = 0;
  12352. }
  12353. r = 0;
  12354. }
  12355. c = 0;
  12356. }
  12357. px = 0;
  12358. }
  12359. error('JPX Error: Out of packets');
  12360. };
  12361. }
  12362. function ComponentPositionResolutionLayerIterator(context) {
  12363. var siz = context.SIZ;
  12364. var tileIndex = context.currentTile.index;
  12365. var tile = context.tiles[tileIndex];
  12366. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12367. var componentsCount = siz.Csiz;
  12368. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12369. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12370. this.nextPacket = function JpxImage_nextPacket() {
  12371. // Section B.12.1.5 Component-position-resolution-layer
  12372. for (; c < componentsCount; ++c) {
  12373. var component = tile.components[c];
  12374. var precinctsIterationSizes = precinctsSizes.components[c];
  12375. var decompositionLevelsCount =
  12376. component.codingStyleParameters.decompositionLevelsCount;
  12377. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12378. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12379. for (; r <= decompositionLevelsCount; r++) {
  12380. var resolution = component.resolutions[r];
  12381. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12382. var k = getPrecinctIndexIfExist(
  12383. px,
  12384. py,
  12385. sizeInImageScale,
  12386. precinctsIterationSizes,
  12387. resolution);
  12388. if (k === null) {
  12389. continue;
  12390. }
  12391. for (; l < layersCount;) {
  12392. var packet = createPacket(resolution, k, l);
  12393. l++;
  12394. return packet;
  12395. }
  12396. l = 0;
  12397. }
  12398. r = 0;
  12399. }
  12400. px = 0;
  12401. }
  12402. py = 0;
  12403. }
  12404. error('JPX Error: Out of packets');
  12405. };
  12406. }
  12407. function getPrecinctIndexIfExist(
  12408. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12409. var posX = pxIndex * precinctIterationSizes.minWidth;
  12410. var posY = pyIndex * precinctIterationSizes.minHeight;
  12411. if (posX % sizeInImageScale.width !== 0 ||
  12412. posY % sizeInImageScale.height !== 0) {
  12413. return null;
  12414. }
  12415. var startPrecinctRowIndex =
  12416. (posY / sizeInImageScale.width) *
  12417. resolution.precinctParameters.numprecinctswide;
  12418. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12419. }
  12420. function getPrecinctSizesInImageScale(tile) {
  12421. var componentsCount = tile.components.length;
  12422. var minWidth = Number.MAX_VALUE;
  12423. var minHeight = Number.MAX_VALUE;
  12424. var maxNumWide = 0;
  12425. var maxNumHigh = 0;
  12426. var sizePerComponent = new Array(componentsCount);
  12427. for (var c = 0; c < componentsCount; c++) {
  12428. var component = tile.components[c];
  12429. var decompositionLevelsCount =
  12430. component.codingStyleParameters.decompositionLevelsCount;
  12431. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12432. var minWidthCurrentComponent = Number.MAX_VALUE;
  12433. var minHeightCurrentComponent = Number.MAX_VALUE;
  12434. var maxNumWideCurrentComponent = 0;
  12435. var maxNumHighCurrentComponent = 0;
  12436. var scale = 1;
  12437. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12438. var resolution = component.resolutions[r];
  12439. var widthCurrentResolution =
  12440. scale * resolution.precinctParameters.precinctWidth;
  12441. var heightCurrentResolution =
  12442. scale * resolution.precinctParameters.precinctHeight;
  12443. minWidthCurrentComponent = Math.min(
  12444. minWidthCurrentComponent,
  12445. widthCurrentResolution);
  12446. minHeightCurrentComponent = Math.min(
  12447. minHeightCurrentComponent,
  12448. heightCurrentResolution);
  12449. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12450. resolution.precinctParameters.numprecinctswide);
  12451. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12452. resolution.precinctParameters.numprecinctshigh);
  12453. sizePerResolution[r] = {
  12454. width: widthCurrentResolution,
  12455. height: heightCurrentResolution
  12456. };
  12457. scale <<= 1;
  12458. }
  12459. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12460. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12461. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12462. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12463. sizePerComponent[c] = {
  12464. resolutions: sizePerResolution,
  12465. minWidth: minWidthCurrentComponent,
  12466. minHeight: minHeightCurrentComponent,
  12467. maxNumWide: maxNumWideCurrentComponent,
  12468. maxNumHigh: maxNumHighCurrentComponent
  12469. };
  12470. }
  12471. return {
  12472. components: sizePerComponent,
  12473. minWidth: minWidth,
  12474. minHeight: minHeight,
  12475. maxNumWide: maxNumWide,
  12476. maxNumHigh: maxNumHigh
  12477. };
  12478. }
  12479. function buildPackets(context) {
  12480. var siz = context.SIZ;
  12481. var tileIndex = context.currentTile.index;
  12482. var tile = context.tiles[tileIndex];
  12483. var componentsCount = siz.Csiz;
  12484. // Creating resolutions and sub-bands for each component
  12485. for (var c = 0; c < componentsCount; c++) {
  12486. var component = tile.components[c];
  12487. var decompositionLevelsCount =
  12488. component.codingStyleParameters.decompositionLevelsCount;
  12489. // Section B.5 Resolution levels and sub-bands
  12490. var resolutions = [];
  12491. var subbands = [];
  12492. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12493. var blocksDimensions = getBlocksDimensions(context, component, r);
  12494. var resolution = {};
  12495. var scale = 1 << (decompositionLevelsCount - r);
  12496. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12497. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12498. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12499. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12500. resolution.resLevel = r;
  12501. buildPrecincts(context, resolution, blocksDimensions);
  12502. resolutions.push(resolution);
  12503. var subband;
  12504. if (r === 0) {
  12505. // one sub-band (LL) with last decomposition
  12506. subband = {};
  12507. subband.type = 'LL';
  12508. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12509. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12510. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12511. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12512. subband.resolution = resolution;
  12513. buildCodeblocks(context, subband, blocksDimensions);
  12514. subbands.push(subband);
  12515. resolution.subbands = [subband];
  12516. } else {
  12517. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12518. var resolutionSubbands = [];
  12519. // three sub-bands (HL, LH and HH) with rest of decompositions
  12520. subband = {};
  12521. subband.type = 'HL';
  12522. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12523. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12524. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12525. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12526. subband.resolution = resolution;
  12527. buildCodeblocks(context, subband, blocksDimensions);
  12528. subbands.push(subband);
  12529. resolutionSubbands.push(subband);
  12530. subband = {};
  12531. subband.type = 'LH';
  12532. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12533. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12534. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12535. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12536. subband.resolution = resolution;
  12537. buildCodeblocks(context, subband, blocksDimensions);
  12538. subbands.push(subband);
  12539. resolutionSubbands.push(subband);
  12540. subband = {};
  12541. subband.type = 'HH';
  12542. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12543. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12544. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12545. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12546. subband.resolution = resolution;
  12547. buildCodeblocks(context, subband, blocksDimensions);
  12548. subbands.push(subband);
  12549. resolutionSubbands.push(subband);
  12550. resolution.subbands = resolutionSubbands;
  12551. }
  12552. }
  12553. component.resolutions = resolutions;
  12554. component.subbands = subbands;
  12555. }
  12556. // Generate the packets sequence
  12557. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12558. switch (progressionOrder) {
  12559. case 0:
  12560. tile.packetsIterator =
  12561. new LayerResolutionComponentPositionIterator(context);
  12562. break;
  12563. case 1:
  12564. tile.packetsIterator =
  12565. new ResolutionLayerComponentPositionIterator(context);
  12566. break;
  12567. case 2:
  12568. tile.packetsIterator =
  12569. new ResolutionPositionComponentLayerIterator(context);
  12570. break;
  12571. case 3:
  12572. tile.packetsIterator =
  12573. new PositionComponentResolutionLayerIterator(context);
  12574. break;
  12575. case 4:
  12576. tile.packetsIterator =
  12577. new ComponentPositionResolutionLayerIterator(context);
  12578. break;
  12579. default:
  12580. error('JPX Error: Unsupported progression order ' + progressionOrder);
  12581. }
  12582. }
  12583. function parseTilePackets(context, data, offset, dataLength) {
  12584. var position = 0;
  12585. var buffer, bufferSize = 0, skipNextBit = false;
  12586. function readBits(count) {
  12587. while (bufferSize < count) {
  12588. var b = data[offset + position];
  12589. position++;
  12590. if (skipNextBit) {
  12591. buffer = (buffer << 7) | b;
  12592. bufferSize += 7;
  12593. skipNextBit = false;
  12594. } else {
  12595. buffer = (buffer << 8) | b;
  12596. bufferSize += 8;
  12597. }
  12598. if (b === 0xFF) {
  12599. skipNextBit = true;
  12600. }
  12601. }
  12602. bufferSize -= count;
  12603. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12604. }
  12605. function skipMarkerIfEqual(value) {
  12606. if (data[offset + position - 1] === 0xFF &&
  12607. data[offset + position] === value) {
  12608. skipBytes(1);
  12609. return true;
  12610. } else if (data[offset + position] === 0xFF &&
  12611. data[offset + position + 1] === value) {
  12612. skipBytes(2);
  12613. return true;
  12614. }
  12615. return false;
  12616. }
  12617. function skipBytes(count) {
  12618. position += count;
  12619. }
  12620. function alignToByte() {
  12621. bufferSize = 0;
  12622. if (skipNextBit) {
  12623. position++;
  12624. skipNextBit = false;
  12625. }
  12626. }
  12627. function readCodingpasses() {
  12628. if (readBits(1) === 0) {
  12629. return 1;
  12630. }
  12631. if (readBits(1) === 0) {
  12632. return 2;
  12633. }
  12634. var value = readBits(2);
  12635. if (value < 3) {
  12636. return value + 3;
  12637. }
  12638. value = readBits(5);
  12639. if (value < 31) {
  12640. return value + 6;
  12641. }
  12642. value = readBits(7);
  12643. return value + 37;
  12644. }
  12645. var tileIndex = context.currentTile.index;
  12646. var tile = context.tiles[tileIndex];
  12647. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12648. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12649. var packetsIterator = tile.packetsIterator;
  12650. while (position < dataLength) {
  12651. alignToByte();
  12652. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12653. // Skip also marker segment length and packet sequence ID
  12654. skipBytes(4);
  12655. }
  12656. var packet = packetsIterator.nextPacket();
  12657. if (!readBits(1)) {
  12658. continue;
  12659. }
  12660. var layerNumber = packet.layerNumber;
  12661. var queue = [], codeblock;
  12662. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12663. codeblock = packet.codeblocks[i];
  12664. var precinct = codeblock.precinct;
  12665. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12666. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12667. var codeblockIncluded = false;
  12668. var firstTimeInclusion = false;
  12669. var valueReady;
  12670. if (codeblock['included'] !== undefined) {
  12671. codeblockIncluded = !!readBits(1);
  12672. } else {
  12673. // reading inclusion tree
  12674. precinct = codeblock.precinct;
  12675. var inclusionTree, zeroBitPlanesTree;
  12676. if (precinct['inclusionTree'] !== undefined) {
  12677. inclusionTree = precinct.inclusionTree;
  12678. } else {
  12679. // building inclusion and zero bit-planes trees
  12680. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12681. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12682. inclusionTree = new InclusionTree(width, height, layerNumber);
  12683. zeroBitPlanesTree = new TagTree(width, height);
  12684. precinct.inclusionTree = inclusionTree;
  12685. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12686. }
  12687. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12688. while (true) {
  12689. if (readBits(1)) {
  12690. valueReady = !inclusionTree.nextLevel();
  12691. if (valueReady) {
  12692. codeblock.included = true;
  12693. codeblockIncluded = firstTimeInclusion = true;
  12694. break;
  12695. }
  12696. } else {
  12697. inclusionTree.incrementValue(layerNumber);
  12698. break;
  12699. }
  12700. }
  12701. }
  12702. }
  12703. if (!codeblockIncluded) {
  12704. continue;
  12705. }
  12706. if (firstTimeInclusion) {
  12707. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12708. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12709. while (true) {
  12710. if (readBits(1)) {
  12711. valueReady = !zeroBitPlanesTree.nextLevel();
  12712. if (valueReady) {
  12713. break;
  12714. }
  12715. } else {
  12716. zeroBitPlanesTree.incrementValue();
  12717. }
  12718. }
  12719. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12720. }
  12721. var codingpasses = readCodingpasses();
  12722. while (readBits(1)) {
  12723. codeblock.Lblock++;
  12724. }
  12725. var codingpassesLog2 = log2(codingpasses);
  12726. // rounding down log2
  12727. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12728. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12729. var codedDataLength = readBits(bits);
  12730. queue.push({
  12731. codeblock: codeblock,
  12732. codingpasses: codingpasses,
  12733. dataLength: codedDataLength
  12734. });
  12735. }
  12736. alignToByte();
  12737. if (ephMarkerUsed) {
  12738. skipMarkerIfEqual(0x92);
  12739. }
  12740. while (queue.length > 0) {
  12741. var packetItem = queue.shift();
  12742. codeblock = packetItem.codeblock;
  12743. if (codeblock['data'] === undefined) {
  12744. codeblock.data = [];
  12745. }
  12746. codeblock.data.push({
  12747. data: data,
  12748. start: offset + position,
  12749. end: offset + position + packetItem.dataLength,
  12750. codingpasses: packetItem.codingpasses
  12751. });
  12752. position += packetItem.dataLength;
  12753. }
  12754. }
  12755. return position;
  12756. }
  12757. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12758. delta, mb, reversible, segmentationSymbolUsed) {
  12759. var x0 = subband.tbx0;
  12760. var y0 = subband.tby0;
  12761. var width = subband.tbx1 - subband.tbx0;
  12762. var codeblocks = subband.codeblocks;
  12763. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12764. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12765. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12766. var codeblock = codeblocks[i];
  12767. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12768. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12769. if (blockWidth === 0 || blockHeight === 0) {
  12770. continue;
  12771. }
  12772. if (codeblock['data'] === undefined) {
  12773. continue;
  12774. }
  12775. var bitModel, currentCodingpassType;
  12776. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12777. codeblock.zeroBitPlanes, mb);
  12778. currentCodingpassType = 2; // first bit plane starts from cleanup
  12779. // collect data
  12780. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12781. var j, jj, dataItem;
  12782. for (j = 0, jj = data.length; j < jj; j++) {
  12783. dataItem = data[j];
  12784. totalLength += dataItem.end - dataItem.start;
  12785. codingpasses += dataItem.codingpasses;
  12786. }
  12787. var encodedData = new Uint8Array(totalLength);
  12788. var position = 0;
  12789. for (j = 0, jj = data.length; j < jj; j++) {
  12790. dataItem = data[j];
  12791. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12792. encodedData.set(chunk, position);
  12793. position += chunk.length;
  12794. }
  12795. // decoding the item
  12796. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12797. bitModel.setDecoder(decoder);
  12798. for (j = 0; j < codingpasses; j++) {
  12799. switch (currentCodingpassType) {
  12800. case 0:
  12801. bitModel.runSignificancePropagationPass();
  12802. break;
  12803. case 1:
  12804. bitModel.runMagnitudeRefinementPass();
  12805. break;
  12806. case 2:
  12807. bitModel.runCleanupPass();
  12808. if (segmentationSymbolUsed) {
  12809. bitModel.checkSegmentationSymbol();
  12810. }
  12811. break;
  12812. }
  12813. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12814. }
  12815. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12816. var sign = bitModel.coefficentsSign;
  12817. var magnitude = bitModel.coefficentsMagnitude;
  12818. var bitsDecoded = bitModel.bitsDecoded;
  12819. var magnitudeCorrection = reversible ? 0 : 0.5;
  12820. var k, n, nb;
  12821. position = 0;
  12822. // Do the interleaving of Section F.3.3 here, so we do not need
  12823. // to copy later. LL level is not interleaved, just copied.
  12824. var interleave = (subband.type !== 'LL');
  12825. for (j = 0; j < blockHeight; j++) {
  12826. var row = (offset / width) | 0; // row in the non-interleaved subband
  12827. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12828. for (k = 0; k < blockWidth; k++) {
  12829. n = magnitude[position];
  12830. if (n !== 0) {
  12831. n = (n + magnitudeCorrection) * delta;
  12832. if (sign[position] !== 0) {
  12833. n = -n;
  12834. }
  12835. nb = bitsDecoded[position];
  12836. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12837. if (reversible && (nb >= mb)) {
  12838. coefficients[pos] = n;
  12839. } else {
  12840. coefficients[pos] = n * (1 << (mb - nb));
  12841. }
  12842. }
  12843. offset++;
  12844. position++;
  12845. }
  12846. offset += width - blockWidth;
  12847. }
  12848. }
  12849. }
  12850. function transformTile(context, tile, c) {
  12851. var component = tile.components[c];
  12852. var codingStyleParameters = component.codingStyleParameters;
  12853. var quantizationParameters = component.quantizationParameters;
  12854. var decompositionLevelsCount =
  12855. codingStyleParameters.decompositionLevelsCount;
  12856. var spqcds = quantizationParameters.SPqcds;
  12857. var scalarExpounded = quantizationParameters.scalarExpounded;
  12858. var guardBits = quantizationParameters.guardBits;
  12859. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12860. var precision = context.components[c].precision;
  12861. var reversible = codingStyleParameters.reversibleTransformation;
  12862. var transform = (reversible ? new ReversibleTransform() :
  12863. new IrreversibleTransform());
  12864. var subbandCoefficients = [];
  12865. var b = 0;
  12866. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12867. var resolution = component.resolutions[i];
  12868. var width = resolution.trx1 - resolution.trx0;
  12869. var height = resolution.try1 - resolution.try0;
  12870. // Allocate space for the whole sublevel.
  12871. var coefficients = new Float32Array(width * height);
  12872. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12873. var mu, epsilon;
  12874. if (!scalarExpounded) {
  12875. // formula E-5
  12876. mu = spqcds[0].mu;
  12877. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12878. } else {
  12879. mu = spqcds[b].mu;
  12880. epsilon = spqcds[b].epsilon;
  12881. b++;
  12882. }
  12883. var subband = resolution.subbands[j];
  12884. var gainLog2 = SubbandsGainLog2[subband.type];
  12885. // calculate quantization coefficient (Section E.1.1.1)
  12886. var delta = (reversible ? 1 :
  12887. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12888. var mb = (guardBits + epsilon - 1);
  12889. // In the first resolution level, copyCoefficients will fill the
  12890. // whole array with coefficients. In the succeeding passes,
  12891. // copyCoefficients will consecutively fill in the values that belong
  12892. // to the interleaved positions of the HL, LH, and HH coefficients.
  12893. // The LL coefficients will then be interleaved in Transform.iterate().
  12894. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12895. reversible, segmentationSymbolUsed);
  12896. }
  12897. subbandCoefficients.push({
  12898. width: width,
  12899. height: height,
  12900. items: coefficients
  12901. });
  12902. }
  12903. var result = transform.calculate(subbandCoefficients,
  12904. component.tcx0, component.tcy0);
  12905. return {
  12906. left: component.tcx0,
  12907. top: component.tcy0,
  12908. width: result.width,
  12909. height: result.height,
  12910. items: result.items
  12911. };
  12912. }
  12913. function transformComponents(context) {
  12914. var siz = context.SIZ;
  12915. var components = context.components;
  12916. var componentsCount = siz.Csiz;
  12917. var resultImages = [];
  12918. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12919. var tile = context.tiles[i];
  12920. var transformedTiles = [];
  12921. var c;
  12922. for (c = 0; c < componentsCount; c++) {
  12923. transformedTiles[c] = transformTile(context, tile, c);
  12924. }
  12925. var tile0 = transformedTiles[0];
  12926. var out = new Uint8Array(tile0.items.length * componentsCount);
  12927. var result = {
  12928. left: tile0.left,
  12929. top: tile0.top,
  12930. width: tile0.width,
  12931. height: tile0.height,
  12932. items: out
  12933. };
  12934. // Section G.2.2 Inverse multi component transform
  12935. var shift, offset, max, min, maxK;
  12936. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12937. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12938. var fourComponents = componentsCount === 4;
  12939. var y0items = transformedTiles[0].items;
  12940. var y1items = transformedTiles[1].items;
  12941. var y2items = transformedTiles[2].items;
  12942. var y3items = fourComponents ? transformedTiles[3].items : null;
  12943. // HACK: The multiple component transform formulas below assume that
  12944. // all components have the same precision. With this in mind, we
  12945. // compute shift and offset only once.
  12946. shift = components[0].precision - 8;
  12947. offset = (128 << shift) + 0.5;
  12948. max = 255 * (1 << shift);
  12949. maxK = max * 0.5;
  12950. min = -maxK;
  12951. var component0 = tile.components[0];
  12952. var alpha01 = componentsCount - 3;
  12953. jj = y0items.length;
  12954. if (!component0.codingStyleParameters.reversibleTransformation) {
  12955. // inverse irreversible multiple component transform
  12956. for (j = 0; j < jj; j++, pos += alpha01) {
  12957. y0 = y0items[j] + offset;
  12958. y1 = y1items[j];
  12959. y2 = y2items[j];
  12960. r = y0 + 1.402 * y2;
  12961. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12962. b = y0 + 1.772 * y1;
  12963. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12964. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12965. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12966. }
  12967. } else {
  12968. // inverse reversible multiple component transform
  12969. for (j = 0; j < jj; j++, pos += alpha01) {
  12970. y0 = y0items[j] + offset;
  12971. y1 = y1items[j];
  12972. y2 = y2items[j];
  12973. g = y0 - ((y2 + y1) >> 2);
  12974. r = g + y2;
  12975. b = g + y1;
  12976. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12977. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12978. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12979. }
  12980. }
  12981. if (fourComponents) {
  12982. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12983. k = y3items[j];
  12984. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12985. }
  12986. }
  12987. } else { // no multi-component transform
  12988. for (c = 0; c < componentsCount; c++) {
  12989. var items = transformedTiles[c].items;
  12990. shift = components[c].precision - 8;
  12991. offset = (128 << shift) + 0.5;
  12992. max = (127.5 * (1 << shift));
  12993. min = -max;
  12994. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12995. val = items[j];
  12996. out[pos] = val <= min ? 0 :
  12997. val >= max ? 255 : (val + offset) >> shift;
  12998. pos += componentsCount;
  12999. }
  13000. }
  13001. }
  13002. resultImages.push(result);
  13003. }
  13004. return resultImages;
  13005. }
  13006. function initializeTile(context, tileIndex) {
  13007. var siz = context.SIZ;
  13008. var componentsCount = siz.Csiz;
  13009. var tile = context.tiles[tileIndex];
  13010. for (var c = 0; c < componentsCount; c++) {
  13011. var component = tile.components[c];
  13012. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13013. context.currentTile.QCC[c] : context.currentTile.QCD);
  13014. component.quantizationParameters = qcdOrQcc;
  13015. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13016. context.currentTile.COC[c] : context.currentTile.COD);
  13017. component.codingStyleParameters = codOrCoc;
  13018. }
  13019. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13020. }
  13021. // Section B.10.2 Tag trees
  13022. var TagTree = (function TagTreeClosure() {
  13023. function TagTree(width, height) {
  13024. var levelsLength = log2(Math.max(width, height)) + 1;
  13025. this.levels = [];
  13026. for (var i = 0; i < levelsLength; i++) {
  13027. var level = {
  13028. width: width,
  13029. height: height,
  13030. items: []
  13031. };
  13032. this.levels.push(level);
  13033. width = Math.ceil(width / 2);
  13034. height = Math.ceil(height / 2);
  13035. }
  13036. }
  13037. TagTree.prototype = {
  13038. reset: function TagTree_reset(i, j) {
  13039. var currentLevel = 0, value = 0, level;
  13040. while (currentLevel < this.levels.length) {
  13041. level = this.levels[currentLevel];
  13042. var index = i + j * level.width;
  13043. if (level.items[index] !== undefined) {
  13044. value = level.items[index];
  13045. break;
  13046. }
  13047. level.index = index;
  13048. i >>= 1;
  13049. j >>= 1;
  13050. currentLevel++;
  13051. }
  13052. currentLevel--;
  13053. level = this.levels[currentLevel];
  13054. level.items[level.index] = value;
  13055. this.currentLevel = currentLevel;
  13056. delete this.value;
  13057. },
  13058. incrementValue: function TagTree_incrementValue() {
  13059. var level = this.levels[this.currentLevel];
  13060. level.items[level.index]++;
  13061. },
  13062. nextLevel: function TagTree_nextLevel() {
  13063. var currentLevel = this.currentLevel;
  13064. var level = this.levels[currentLevel];
  13065. var value = level.items[level.index];
  13066. currentLevel--;
  13067. if (currentLevel < 0) {
  13068. this.value = value;
  13069. return false;
  13070. }
  13071. this.currentLevel = currentLevel;
  13072. level = this.levels[currentLevel];
  13073. level.items[level.index] = value;
  13074. return true;
  13075. }
  13076. };
  13077. return TagTree;
  13078. })();
  13079. var InclusionTree = (function InclusionTreeClosure() {
  13080. function InclusionTree(width, height, defaultValue) {
  13081. var levelsLength = log2(Math.max(width, height)) + 1;
  13082. this.levels = [];
  13083. for (var i = 0; i < levelsLength; i++) {
  13084. var items = new Uint8Array(width * height);
  13085. for (var j = 0, jj = items.length; j < jj; j++) {
  13086. items[j] = defaultValue;
  13087. }
  13088. var level = {
  13089. width: width,
  13090. height: height,
  13091. items: items
  13092. };
  13093. this.levels.push(level);
  13094. width = Math.ceil(width / 2);
  13095. height = Math.ceil(height / 2);
  13096. }
  13097. }
  13098. InclusionTree.prototype = {
  13099. reset: function InclusionTree_reset(i, j, stopValue) {
  13100. var currentLevel = 0;
  13101. while (currentLevel < this.levels.length) {
  13102. var level = this.levels[currentLevel];
  13103. var index = i + j * level.width;
  13104. level.index = index;
  13105. var value = level.items[index];
  13106. if (value === 0xFF) {
  13107. break;
  13108. }
  13109. if (value > stopValue) {
  13110. this.currentLevel = currentLevel;
  13111. // already know about this one, propagating the value to top levels
  13112. this.propagateValues();
  13113. return false;
  13114. }
  13115. i >>= 1;
  13116. j >>= 1;
  13117. currentLevel++;
  13118. }
  13119. this.currentLevel = currentLevel - 1;
  13120. return true;
  13121. },
  13122. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13123. var level = this.levels[this.currentLevel];
  13124. level.items[level.index] = stopValue + 1;
  13125. this.propagateValues();
  13126. },
  13127. propagateValues: function InclusionTree_propagateValues() {
  13128. var levelIndex = this.currentLevel;
  13129. var level = this.levels[levelIndex];
  13130. var currentValue = level.items[level.index];
  13131. while (--levelIndex >= 0) {
  13132. level = this.levels[levelIndex];
  13133. level.items[level.index] = currentValue;
  13134. }
  13135. },
  13136. nextLevel: function InclusionTree_nextLevel() {
  13137. var currentLevel = this.currentLevel;
  13138. var level = this.levels[currentLevel];
  13139. var value = level.items[level.index];
  13140. level.items[level.index] = 0xFF;
  13141. currentLevel--;
  13142. if (currentLevel < 0) {
  13143. return false;
  13144. }
  13145. this.currentLevel = currentLevel;
  13146. level = this.levels[currentLevel];
  13147. level.items[level.index] = value;
  13148. return true;
  13149. }
  13150. };
  13151. return InclusionTree;
  13152. })();
  13153. // Section D. Coefficient bit modeling
  13154. var BitModel = (function BitModelClosure() {
  13155. var UNIFORM_CONTEXT = 17;
  13156. var RUNLENGTH_CONTEXT = 18;
  13157. // Table D-1
  13158. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13159. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13160. var LLAndLHContextsLabel = new Uint8Array([
  13161. 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,
  13162. 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,
  13163. 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
  13164. ]);
  13165. var HLContextLabel = new Uint8Array([
  13166. 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,
  13167. 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,
  13168. 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
  13169. ]);
  13170. var HHContextLabel = new Uint8Array([
  13171. 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,
  13172. 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,
  13173. 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
  13174. ]);
  13175. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13176. this.width = width;
  13177. this.height = height;
  13178. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13179. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13180. var coefficientCount = width * height;
  13181. // coefficients outside the encoding region treated as insignificant
  13182. // add border state cells for significanceState
  13183. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13184. this.coefficentsSign = new Uint8Array(coefficientCount);
  13185. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13186. mb > 6 ? new Uint16Array(coefficientCount) :
  13187. new Uint8Array(coefficientCount);
  13188. this.processingFlags = new Uint8Array(coefficientCount);
  13189. var bitsDecoded = new Uint8Array(coefficientCount);
  13190. if (zeroBitPlanes !== 0) {
  13191. for (var i = 0; i < coefficientCount; i++) {
  13192. bitsDecoded[i] = zeroBitPlanes;
  13193. }
  13194. }
  13195. this.bitsDecoded = bitsDecoded;
  13196. this.reset();
  13197. }
  13198. BitModel.prototype = {
  13199. setDecoder: function BitModel_setDecoder(decoder) {
  13200. this.decoder = decoder;
  13201. },
  13202. reset: function BitModel_reset() {
  13203. // We have 17 contexts that are accessed via context labels,
  13204. // plus the uniform and runlength context.
  13205. this.contexts = new Int8Array(19);
  13206. // Contexts are packed into 1 byte:
  13207. // highest 7 bits carry the index, lowest bit carries mps
  13208. this.contexts[0] = (4 << 1) | 0;
  13209. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13210. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13211. },
  13212. setNeighborsSignificance:
  13213. function BitModel_setNeighborsSignificance(row, column, index) {
  13214. var neighborsSignificance = this.neighborsSignificance;
  13215. var width = this.width, height = this.height;
  13216. var left = (column > 0);
  13217. var right = (column + 1 < width);
  13218. var i;
  13219. if (row > 0) {
  13220. i = index - width;
  13221. if (left) {
  13222. neighborsSignificance[i - 1] += 0x10;
  13223. }
  13224. if (right) {
  13225. neighborsSignificance[i + 1] += 0x10;
  13226. }
  13227. neighborsSignificance[i] += 0x04;
  13228. }
  13229. if (row + 1 < height) {
  13230. i = index + width;
  13231. if (left) {
  13232. neighborsSignificance[i - 1] += 0x10;
  13233. }
  13234. if (right) {
  13235. neighborsSignificance[i + 1] += 0x10;
  13236. }
  13237. neighborsSignificance[i] += 0x04;
  13238. }
  13239. if (left) {
  13240. neighborsSignificance[index - 1] += 0x01;
  13241. }
  13242. if (right) {
  13243. neighborsSignificance[index + 1] += 0x01;
  13244. }
  13245. neighborsSignificance[index] |= 0x80;
  13246. },
  13247. runSignificancePropagationPass:
  13248. function BitModel_runSignificancePropagationPass() {
  13249. var decoder = this.decoder;
  13250. var width = this.width, height = this.height;
  13251. var coefficentsMagnitude = this.coefficentsMagnitude;
  13252. var coefficentsSign = this.coefficentsSign;
  13253. var neighborsSignificance = this.neighborsSignificance;
  13254. var processingFlags = this.processingFlags;
  13255. var contexts = this.contexts;
  13256. var labels = this.contextLabelTable;
  13257. var bitsDecoded = this.bitsDecoded;
  13258. var processedInverseMask = ~1;
  13259. var processedMask = 1;
  13260. var firstMagnitudeBitMask = 2;
  13261. for (var i0 = 0; i0 < height; i0 += 4) {
  13262. for (var j = 0; j < width; j++) {
  13263. var index = i0 * width + j;
  13264. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13265. var i = i0 + i1;
  13266. if (i >= height) {
  13267. break;
  13268. }
  13269. // clear processed flag first
  13270. processingFlags[index] &= processedInverseMask;
  13271. if (coefficentsMagnitude[index] ||
  13272. !neighborsSignificance[index]) {
  13273. continue;
  13274. }
  13275. var contextLabel = labels[neighborsSignificance[index]];
  13276. var decision = decoder.readBit(contexts, contextLabel);
  13277. if (decision) {
  13278. var sign = this.decodeSignBit(i, j, index);
  13279. coefficentsSign[index] = sign;
  13280. coefficentsMagnitude[index] = 1;
  13281. this.setNeighborsSignificance(i, j, index);
  13282. processingFlags[index] |= firstMagnitudeBitMask;
  13283. }
  13284. bitsDecoded[index]++;
  13285. processingFlags[index] |= processedMask;
  13286. }
  13287. }
  13288. }
  13289. },
  13290. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13291. var width = this.width, height = this.height;
  13292. var coefficentsMagnitude = this.coefficentsMagnitude;
  13293. var coefficentsSign = this.coefficentsSign;
  13294. var contribution, sign0, sign1, significance1;
  13295. var contextLabel, decoded;
  13296. // calculate horizontal contribution
  13297. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13298. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13299. sign1 = coefficentsSign[index + 1];
  13300. if (significance1) {
  13301. sign0 = coefficentsSign[index - 1];
  13302. contribution = 1 - sign1 - sign0;
  13303. } else {
  13304. contribution = 1 - sign1 - sign1;
  13305. }
  13306. } else if (significance1) {
  13307. sign0 = coefficentsSign[index - 1];
  13308. contribution = 1 - sign0 - sign0;
  13309. } else {
  13310. contribution = 0;
  13311. }
  13312. var horizontalContribution = 3 * contribution;
  13313. // calculate vertical contribution and combine with the horizontal
  13314. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13315. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13316. sign1 = coefficentsSign[index + width];
  13317. if (significance1) {
  13318. sign0 = coefficentsSign[index - width];
  13319. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13320. } else {
  13321. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13322. }
  13323. } else if (significance1) {
  13324. sign0 = coefficentsSign[index - width];
  13325. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13326. } else {
  13327. contribution = horizontalContribution;
  13328. }
  13329. if (contribution >= 0) {
  13330. contextLabel = 9 + contribution;
  13331. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13332. } else {
  13333. contextLabel = 9 - contribution;
  13334. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13335. }
  13336. return decoded;
  13337. },
  13338. runMagnitudeRefinementPass:
  13339. function BitModel_runMagnitudeRefinementPass() {
  13340. var decoder = this.decoder;
  13341. var width = this.width, height = this.height;
  13342. var coefficentsMagnitude = this.coefficentsMagnitude;
  13343. var neighborsSignificance = this.neighborsSignificance;
  13344. var contexts = this.contexts;
  13345. var bitsDecoded = this.bitsDecoded;
  13346. var processingFlags = this.processingFlags;
  13347. var processedMask = 1;
  13348. var firstMagnitudeBitMask = 2;
  13349. var length = width * height;
  13350. var width4 = width * 4;
  13351. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13352. indexNext = Math.min(length, index0 + width4);
  13353. for (var j = 0; j < width; j++) {
  13354. for (var index = index0 + j; index < indexNext; index += width) {
  13355. // significant but not those that have just become
  13356. if (!coefficentsMagnitude[index] ||
  13357. (processingFlags[index] & processedMask) !== 0) {
  13358. continue;
  13359. }
  13360. var contextLabel = 16;
  13361. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13362. processingFlags[index] ^= firstMagnitudeBitMask;
  13363. // first refinement
  13364. var significance = neighborsSignificance[index] & 127;
  13365. contextLabel = significance === 0 ? 15 : 14;
  13366. }
  13367. var bit = decoder.readBit(contexts, contextLabel);
  13368. coefficentsMagnitude[index] =
  13369. (coefficentsMagnitude[index] << 1) | bit;
  13370. bitsDecoded[index]++;
  13371. processingFlags[index] |= processedMask;
  13372. }
  13373. }
  13374. }
  13375. },
  13376. runCleanupPass: function BitModel_runCleanupPass() {
  13377. var decoder = this.decoder;
  13378. var width = this.width, height = this.height;
  13379. var neighborsSignificance = this.neighborsSignificance;
  13380. var coefficentsMagnitude = this.coefficentsMagnitude;
  13381. var coefficentsSign = this.coefficentsSign;
  13382. var contexts = this.contexts;
  13383. var labels = this.contextLabelTable;
  13384. var bitsDecoded = this.bitsDecoded;
  13385. var processingFlags = this.processingFlags;
  13386. var processedMask = 1;
  13387. var firstMagnitudeBitMask = 2;
  13388. var oneRowDown = width;
  13389. var twoRowsDown = width * 2;
  13390. var threeRowsDown = width * 3;
  13391. var iNext;
  13392. for (var i0 = 0; i0 < height; i0 = iNext) {
  13393. iNext = Math.min(i0 + 4, height);
  13394. var indexBase = i0 * width;
  13395. var checkAllEmpty = i0 + 3 < height;
  13396. for (var j = 0; j < width; j++) {
  13397. var index0 = indexBase + j;
  13398. // using the property: labels[neighborsSignificance[index]] === 0
  13399. // when neighborsSignificance[index] === 0
  13400. var allEmpty = (checkAllEmpty &&
  13401. processingFlags[index0] === 0 &&
  13402. processingFlags[index0 + oneRowDown] === 0 &&
  13403. processingFlags[index0 + twoRowsDown] === 0 &&
  13404. processingFlags[index0 + threeRowsDown] === 0 &&
  13405. neighborsSignificance[index0] === 0 &&
  13406. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13407. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13408. neighborsSignificance[index0 + threeRowsDown] === 0);
  13409. var i1 = 0, index = index0;
  13410. var i = i0, sign;
  13411. if (allEmpty) {
  13412. var hasSignificantCoefficent =
  13413. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13414. if (!hasSignificantCoefficent) {
  13415. bitsDecoded[index0]++;
  13416. bitsDecoded[index0 + oneRowDown]++;
  13417. bitsDecoded[index0 + twoRowsDown]++;
  13418. bitsDecoded[index0 + threeRowsDown]++;
  13419. continue; // next column
  13420. }
  13421. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13422. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13423. if (i1 !== 0) {
  13424. i = i0 + i1;
  13425. index += i1 * width;
  13426. }
  13427. sign = this.decodeSignBit(i, j, index);
  13428. coefficentsSign[index] = sign;
  13429. coefficentsMagnitude[index] = 1;
  13430. this.setNeighborsSignificance(i, j, index);
  13431. processingFlags[index] |= firstMagnitudeBitMask;
  13432. index = index0;
  13433. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13434. bitsDecoded[index]++;
  13435. }
  13436. i1++;
  13437. }
  13438. for (i = i0 + i1; i < iNext; i++, index += width) {
  13439. if (coefficentsMagnitude[index] ||
  13440. (processingFlags[index] & processedMask) !== 0) {
  13441. continue;
  13442. }
  13443. var contextLabel = labels[neighborsSignificance[index]];
  13444. var decision = decoder.readBit(contexts, contextLabel);
  13445. if (decision === 1) {
  13446. sign = this.decodeSignBit(i, j, index);
  13447. coefficentsSign[index] = sign;
  13448. coefficentsMagnitude[index] = 1;
  13449. this.setNeighborsSignificance(i, j, index);
  13450. processingFlags[index] |= firstMagnitudeBitMask;
  13451. }
  13452. bitsDecoded[index]++;
  13453. }
  13454. }
  13455. }
  13456. },
  13457. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13458. var decoder = this.decoder;
  13459. var contexts = this.contexts;
  13460. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13461. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13462. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13463. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13464. if (symbol !== 0xA) {
  13465. error('JPX Error: Invalid segmentation symbol');
  13466. }
  13467. }
  13468. };
  13469. return BitModel;
  13470. })();
  13471. // Section F, Discrete wavelet transformation
  13472. var Transform = (function TransformClosure() {
  13473. function Transform() {}
  13474. Transform.prototype.calculate =
  13475. function transformCalculate(subbands, u0, v0) {
  13476. var ll = subbands[0];
  13477. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13478. ll = this.iterate(ll, subbands[i], u0, v0);
  13479. }
  13480. return ll;
  13481. };
  13482. Transform.prototype.extend = function extend(buffer, offset, size) {
  13483. // Section F.3.7 extending... using max extension of 4
  13484. var i1 = offset - 1, j1 = offset + 1;
  13485. var i2 = offset + size - 2, j2 = offset + size;
  13486. buffer[i1--] = buffer[j1++];
  13487. buffer[j2++] = buffer[i2--];
  13488. buffer[i1--] = buffer[j1++];
  13489. buffer[j2++] = buffer[i2--];
  13490. buffer[i1--] = buffer[j1++];
  13491. buffer[j2++] = buffer[i2--];
  13492. buffer[i1] = buffer[j1];
  13493. buffer[j2] = buffer[i2];
  13494. };
  13495. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13496. u0, v0) {
  13497. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13498. var width = hl_lh_hh.width;
  13499. var height = hl_lh_hh.height;
  13500. var items = hl_lh_hh.items;
  13501. var i, j, k, l, u, v;
  13502. // Interleave LL according to Section F.3.3
  13503. for (k = 0, i = 0; i < llHeight; i++) {
  13504. l = i * 2 * width;
  13505. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13506. items[l] = llItems[k];
  13507. }
  13508. }
  13509. // The LL band is not needed anymore.
  13510. llItems = ll.items = null;
  13511. var bufferPadding = 4;
  13512. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13513. // Section F.3.4 HOR_SR
  13514. if (width === 1) {
  13515. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13516. if ((u0 & 1) !== 0) {
  13517. for (v = 0, k = 0; v < height; v++, k += width) {
  13518. items[k] *= 0.5;
  13519. }
  13520. }
  13521. } else {
  13522. for (v = 0, k = 0; v < height; v++, k += width) {
  13523. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13524. this.extend(rowBuffer, bufferPadding, width);
  13525. this.filter(rowBuffer, bufferPadding, width);
  13526. items.set(
  13527. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13528. k);
  13529. }
  13530. }
  13531. // Accesses to the items array can take long, because it may not fit into
  13532. // CPU cache and has to be fetched from main memory. Since subsequent
  13533. // accesses to the items array are not local when reading columns, we
  13534. // have a cache miss every time. To reduce cache misses, get up to
  13535. // 'numBuffers' items at a time and store them into the individual
  13536. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13537. var numBuffers = 16;
  13538. var colBuffers = [];
  13539. for (i = 0; i < numBuffers; i++) {
  13540. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13541. }
  13542. var b, currentBuffer = 0;
  13543. ll = bufferPadding + height;
  13544. // Section F.3.5 VER_SR
  13545. if (height === 1) {
  13546. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13547. if ((v0 & 1) !== 0) {
  13548. for (u = 0; u < width; u++) {
  13549. items[u] *= 0.5;
  13550. }
  13551. }
  13552. } else {
  13553. for (u = 0; u < width; u++) {
  13554. // if we ran out of buffers, copy several image columns at once
  13555. if (currentBuffer === 0) {
  13556. numBuffers = Math.min(width - u, numBuffers);
  13557. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13558. for (b = 0; b < numBuffers; b++) {
  13559. colBuffers[b][l] = items[k + b];
  13560. }
  13561. }
  13562. currentBuffer = numBuffers;
  13563. }
  13564. currentBuffer--;
  13565. var buffer = colBuffers[currentBuffer];
  13566. this.extend(buffer, bufferPadding, height);
  13567. this.filter(buffer, bufferPadding, height);
  13568. // If this is last buffer in this group of buffers, flush all buffers.
  13569. if (currentBuffer === 0) {
  13570. k = u - numBuffers + 1;
  13571. for (l = bufferPadding; l < ll; k += width, l++) {
  13572. for (b = 0; b < numBuffers; b++) {
  13573. items[k + b] = colBuffers[b][l];
  13574. }
  13575. }
  13576. }
  13577. }
  13578. }
  13579. return {
  13580. width: width,
  13581. height: height,
  13582. items: items
  13583. };
  13584. };
  13585. return Transform;
  13586. })();
  13587. // Section 3.8.2 Irreversible 9-7 filter
  13588. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13589. function IrreversibleTransform() {
  13590. Transform.call(this);
  13591. }
  13592. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13593. IrreversibleTransform.prototype.filter =
  13594. function irreversibleTransformFilter(x, offset, length) {
  13595. var len = length >> 1;
  13596. offset = offset | 0;
  13597. var j, n, current, next;
  13598. var alpha = -1.586134342059924;
  13599. var beta = -0.052980118572961;
  13600. var gamma = 0.882911075530934;
  13601. var delta = 0.443506852043971;
  13602. var K = 1.230174104914001;
  13603. var K_ = 1 / K;
  13604. // step 1 is combined with step 3
  13605. // step 2
  13606. j = offset - 3;
  13607. for (n = len + 4; n--; j += 2) {
  13608. x[j] *= K_;
  13609. }
  13610. // step 1 & 3
  13611. j = offset - 2;
  13612. current = delta * x[j -1];
  13613. for (n = len + 3; n--; j += 2) {
  13614. next = delta * x[j + 1];
  13615. x[j] = K * x[j] - current - next;
  13616. if (n--) {
  13617. j += 2;
  13618. current = delta * x[j + 1];
  13619. x[j] = K * x[j] - current - next;
  13620. } else {
  13621. break;
  13622. }
  13623. }
  13624. // step 4
  13625. j = offset - 1;
  13626. current = gamma * x[j - 1];
  13627. for (n = len + 2; n--; j += 2) {
  13628. next = gamma * x[j + 1];
  13629. x[j] -= current + next;
  13630. if (n--) {
  13631. j += 2;
  13632. current = gamma * x[j + 1];
  13633. x[j] -= current + next;
  13634. } else {
  13635. break;
  13636. }
  13637. }
  13638. // step 5
  13639. j = offset;
  13640. current = beta * x[j - 1];
  13641. for (n = len + 1; n--; j += 2) {
  13642. next = beta * x[j + 1];
  13643. x[j] -= current + next;
  13644. if (n--) {
  13645. j += 2;
  13646. current = beta * x[j + 1];
  13647. x[j] -= current + next;
  13648. } else {
  13649. break;
  13650. }
  13651. }
  13652. // step 6
  13653. if (len !== 0) {
  13654. j = offset + 1;
  13655. current = alpha * x[j - 1];
  13656. for (n = len; n--; j += 2) {
  13657. next = alpha * x[j + 1];
  13658. x[j] -= current + next;
  13659. if (n--) {
  13660. j += 2;
  13661. current = alpha * x[j + 1];
  13662. x[j] -= current + next;
  13663. } else {
  13664. break;
  13665. }
  13666. }
  13667. }
  13668. };
  13669. return IrreversibleTransform;
  13670. })();
  13671. // Section 3.8.1 Reversible 5-3 filter
  13672. var ReversibleTransform = (function ReversibleTransformClosure() {
  13673. function ReversibleTransform() {
  13674. Transform.call(this);
  13675. }
  13676. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13677. ReversibleTransform.prototype.filter =
  13678. function reversibleTransformFilter(x, offset, length) {
  13679. var len = length >> 1;
  13680. offset = offset | 0;
  13681. var j, n;
  13682. for (j = offset, n = len + 1; n--; j += 2) {
  13683. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13684. }
  13685. for (j = offset + 1, n = len; n--; j += 2) {
  13686. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13687. }
  13688. };
  13689. return ReversibleTransform;
  13690. })();
  13691. return JpxImage;
  13692. })();
  13693. exports.JpxImage = JpxImage;
  13694. }));
  13695. (function (root, factory) {
  13696. {
  13697. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13698. }
  13699. }(this, function (exports, sharedUtil) {
  13700. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13701. // The Metrics object contains glyph widths (in glyph space units).
  13702. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13703. // space unit corresponds to 1/1000th of text space unit.
  13704. var getMetrics = getLookupTableFactory(function (t) {
  13705. t['Courier'] = 600;
  13706. t['Courier-Bold'] = 600;
  13707. t['Courier-BoldOblique'] = 600;
  13708. t['Courier-Oblique'] = 600;
  13709. t['Helvetica'] = getLookupTableFactory(function (t) {
  13710. t['space'] = 278;
  13711. t['exclam'] = 278;
  13712. t['quotedbl'] = 355;
  13713. t['numbersign'] = 556;
  13714. t['dollar'] = 556;
  13715. t['percent'] = 889;
  13716. t['ampersand'] = 667;
  13717. t['quoteright'] = 222;
  13718. t['parenleft'] = 333;
  13719. t['parenright'] = 333;
  13720. t['asterisk'] = 389;
  13721. t['plus'] = 584;
  13722. t['comma'] = 278;
  13723. t['hyphen'] = 333;
  13724. t['period'] = 278;
  13725. t['slash'] = 278;
  13726. t['zero'] = 556;
  13727. t['one'] = 556;
  13728. t['two'] = 556;
  13729. t['three'] = 556;
  13730. t['four'] = 556;
  13731. t['five'] = 556;
  13732. t['six'] = 556;
  13733. t['seven'] = 556;
  13734. t['eight'] = 556;
  13735. t['nine'] = 556;
  13736. t['colon'] = 278;
  13737. t['semicolon'] = 278;
  13738. t['less'] = 584;
  13739. t['equal'] = 584;
  13740. t['greater'] = 584;
  13741. t['question'] = 556;
  13742. t['at'] = 1015;
  13743. t['A'] = 667;
  13744. t['B'] = 667;
  13745. t['C'] = 722;
  13746. t['D'] = 722;
  13747. t['E'] = 667;
  13748. t['F'] = 611;
  13749. t['G'] = 778;
  13750. t['H'] = 722;
  13751. t['I'] = 278;
  13752. t['J'] = 500;
  13753. t['K'] = 667;
  13754. t['L'] = 556;
  13755. t['M'] = 833;
  13756. t['N'] = 722;
  13757. t['O'] = 778;
  13758. t['P'] = 667;
  13759. t['Q'] = 778;
  13760. t['R'] = 722;
  13761. t['S'] = 667;
  13762. t['T'] = 611;
  13763. t['U'] = 722;
  13764. t['V'] = 667;
  13765. t['W'] = 944;
  13766. t['X'] = 667;
  13767. t['Y'] = 667;
  13768. t['Z'] = 611;
  13769. t['bracketleft'] = 278;
  13770. t['backslash'] = 278;
  13771. t['bracketright'] = 278;
  13772. t['asciicircum'] = 469;
  13773. t['underscore'] = 556;
  13774. t['quoteleft'] = 222;
  13775. t['a'] = 556;
  13776. t['b'] = 556;
  13777. t['c'] = 500;
  13778. t['d'] = 556;
  13779. t['e'] = 556;
  13780. t['f'] = 278;
  13781. t['g'] = 556;
  13782. t['h'] = 556;
  13783. t['i'] = 222;
  13784. t['j'] = 222;
  13785. t['k'] = 500;
  13786. t['l'] = 222;
  13787. t['m'] = 833;
  13788. t['n'] = 556;
  13789. t['o'] = 556;
  13790. t['p'] = 556;
  13791. t['q'] = 556;
  13792. t['r'] = 333;
  13793. t['s'] = 500;
  13794. t['t'] = 278;
  13795. t['u'] = 556;
  13796. t['v'] = 500;
  13797. t['w'] = 722;
  13798. t['x'] = 500;
  13799. t['y'] = 500;
  13800. t['z'] = 500;
  13801. t['braceleft'] = 334;
  13802. t['bar'] = 260;
  13803. t['braceright'] = 334;
  13804. t['asciitilde'] = 584;
  13805. t['exclamdown'] = 333;
  13806. t['cent'] = 556;
  13807. t['sterling'] = 556;
  13808. t['fraction'] = 167;
  13809. t['yen'] = 556;
  13810. t['florin'] = 556;
  13811. t['section'] = 556;
  13812. t['currency'] = 556;
  13813. t['quotesingle'] = 191;
  13814. t['quotedblleft'] = 333;
  13815. t['guillemotleft'] = 556;
  13816. t['guilsinglleft'] = 333;
  13817. t['guilsinglright'] = 333;
  13818. t['fi'] = 500;
  13819. t['fl'] = 500;
  13820. t['endash'] = 556;
  13821. t['dagger'] = 556;
  13822. t['daggerdbl'] = 556;
  13823. t['periodcentered'] = 278;
  13824. t['paragraph'] = 537;
  13825. t['bullet'] = 350;
  13826. t['quotesinglbase'] = 222;
  13827. t['quotedblbase'] = 333;
  13828. t['quotedblright'] = 333;
  13829. t['guillemotright'] = 556;
  13830. t['ellipsis'] = 1000;
  13831. t['perthousand'] = 1000;
  13832. t['questiondown'] = 611;
  13833. t['grave'] = 333;
  13834. t['acute'] = 333;
  13835. t['circumflex'] = 333;
  13836. t['tilde'] = 333;
  13837. t['macron'] = 333;
  13838. t['breve'] = 333;
  13839. t['dotaccent'] = 333;
  13840. t['dieresis'] = 333;
  13841. t['ring'] = 333;
  13842. t['cedilla'] = 333;
  13843. t['hungarumlaut'] = 333;
  13844. t['ogonek'] = 333;
  13845. t['caron'] = 333;
  13846. t['emdash'] = 1000;
  13847. t['AE'] = 1000;
  13848. t['ordfeminine'] = 370;
  13849. t['Lslash'] = 556;
  13850. t['Oslash'] = 778;
  13851. t['OE'] = 1000;
  13852. t['ordmasculine'] = 365;
  13853. t['ae'] = 889;
  13854. t['dotlessi'] = 278;
  13855. t['lslash'] = 222;
  13856. t['oslash'] = 611;
  13857. t['oe'] = 944;
  13858. t['germandbls'] = 611;
  13859. t['Idieresis'] = 278;
  13860. t['eacute'] = 556;
  13861. t['abreve'] = 556;
  13862. t['uhungarumlaut'] = 556;
  13863. t['ecaron'] = 556;
  13864. t['Ydieresis'] = 667;
  13865. t['divide'] = 584;
  13866. t['Yacute'] = 667;
  13867. t['Acircumflex'] = 667;
  13868. t['aacute'] = 556;
  13869. t['Ucircumflex'] = 722;
  13870. t['yacute'] = 500;
  13871. t['scommaaccent'] = 500;
  13872. t['ecircumflex'] = 556;
  13873. t['Uring'] = 722;
  13874. t['Udieresis'] = 722;
  13875. t['aogonek'] = 556;
  13876. t['Uacute'] = 722;
  13877. t['uogonek'] = 556;
  13878. t['Edieresis'] = 667;
  13879. t['Dcroat'] = 722;
  13880. t['commaaccent'] = 250;
  13881. t['copyright'] = 737;
  13882. t['Emacron'] = 667;
  13883. t['ccaron'] = 500;
  13884. t['aring'] = 556;
  13885. t['Ncommaaccent'] = 722;
  13886. t['lacute'] = 222;
  13887. t['agrave'] = 556;
  13888. t['Tcommaaccent'] = 611;
  13889. t['Cacute'] = 722;
  13890. t['atilde'] = 556;
  13891. t['Edotaccent'] = 667;
  13892. t['scaron'] = 500;
  13893. t['scedilla'] = 500;
  13894. t['iacute'] = 278;
  13895. t['lozenge'] = 471;
  13896. t['Rcaron'] = 722;
  13897. t['Gcommaaccent'] = 778;
  13898. t['ucircumflex'] = 556;
  13899. t['acircumflex'] = 556;
  13900. t['Amacron'] = 667;
  13901. t['rcaron'] = 333;
  13902. t['ccedilla'] = 500;
  13903. t['Zdotaccent'] = 611;
  13904. t['Thorn'] = 667;
  13905. t['Omacron'] = 778;
  13906. t['Racute'] = 722;
  13907. t['Sacute'] = 667;
  13908. t['dcaron'] = 643;
  13909. t['Umacron'] = 722;
  13910. t['uring'] = 556;
  13911. t['threesuperior'] = 333;
  13912. t['Ograve'] = 778;
  13913. t['Agrave'] = 667;
  13914. t['Abreve'] = 667;
  13915. t['multiply'] = 584;
  13916. t['uacute'] = 556;
  13917. t['Tcaron'] = 611;
  13918. t['partialdiff'] = 476;
  13919. t['ydieresis'] = 500;
  13920. t['Nacute'] = 722;
  13921. t['icircumflex'] = 278;
  13922. t['Ecircumflex'] = 667;
  13923. t['adieresis'] = 556;
  13924. t['edieresis'] = 556;
  13925. t['cacute'] = 500;
  13926. t['nacute'] = 556;
  13927. t['umacron'] = 556;
  13928. t['Ncaron'] = 722;
  13929. t['Iacute'] = 278;
  13930. t['plusminus'] = 584;
  13931. t['brokenbar'] = 260;
  13932. t['registered'] = 737;
  13933. t['Gbreve'] = 778;
  13934. t['Idotaccent'] = 278;
  13935. t['summation'] = 600;
  13936. t['Egrave'] = 667;
  13937. t['racute'] = 333;
  13938. t['omacron'] = 556;
  13939. t['Zacute'] = 611;
  13940. t['Zcaron'] = 611;
  13941. t['greaterequal'] = 549;
  13942. t['Eth'] = 722;
  13943. t['Ccedilla'] = 722;
  13944. t['lcommaaccent'] = 222;
  13945. t['tcaron'] = 317;
  13946. t['eogonek'] = 556;
  13947. t['Uogonek'] = 722;
  13948. t['Aacute'] = 667;
  13949. t['Adieresis'] = 667;
  13950. t['egrave'] = 556;
  13951. t['zacute'] = 500;
  13952. t['iogonek'] = 222;
  13953. t['Oacute'] = 778;
  13954. t['oacute'] = 556;
  13955. t['amacron'] = 556;
  13956. t['sacute'] = 500;
  13957. t['idieresis'] = 278;
  13958. t['Ocircumflex'] = 778;
  13959. t['Ugrave'] = 722;
  13960. t['Delta'] = 612;
  13961. t['thorn'] = 556;
  13962. t['twosuperior'] = 333;
  13963. t['Odieresis'] = 778;
  13964. t['mu'] = 556;
  13965. t['igrave'] = 278;
  13966. t['ohungarumlaut'] = 556;
  13967. t['Eogonek'] = 667;
  13968. t['dcroat'] = 556;
  13969. t['threequarters'] = 834;
  13970. t['Scedilla'] = 667;
  13971. t['lcaron'] = 299;
  13972. t['Kcommaaccent'] = 667;
  13973. t['Lacute'] = 556;
  13974. t['trademark'] = 1000;
  13975. t['edotaccent'] = 556;
  13976. t['Igrave'] = 278;
  13977. t['Imacron'] = 278;
  13978. t['Lcaron'] = 556;
  13979. t['onehalf'] = 834;
  13980. t['lessequal'] = 549;
  13981. t['ocircumflex'] = 556;
  13982. t['ntilde'] = 556;
  13983. t['Uhungarumlaut'] = 722;
  13984. t['Eacute'] = 667;
  13985. t['emacron'] = 556;
  13986. t['gbreve'] = 556;
  13987. t['onequarter'] = 834;
  13988. t['Scaron'] = 667;
  13989. t['Scommaaccent'] = 667;
  13990. t['Ohungarumlaut'] = 778;
  13991. t['degree'] = 400;
  13992. t['ograve'] = 556;
  13993. t['Ccaron'] = 722;
  13994. t['ugrave'] = 556;
  13995. t['radical'] = 453;
  13996. t['Dcaron'] = 722;
  13997. t['rcommaaccent'] = 333;
  13998. t['Ntilde'] = 722;
  13999. t['otilde'] = 556;
  14000. t['Rcommaaccent'] = 722;
  14001. t['Lcommaaccent'] = 556;
  14002. t['Atilde'] = 667;
  14003. t['Aogonek'] = 667;
  14004. t['Aring'] = 667;
  14005. t['Otilde'] = 778;
  14006. t['zdotaccent'] = 500;
  14007. t['Ecaron'] = 667;
  14008. t['Iogonek'] = 278;
  14009. t['kcommaaccent'] = 500;
  14010. t['minus'] = 584;
  14011. t['Icircumflex'] = 278;
  14012. t['ncaron'] = 556;
  14013. t['tcommaaccent'] = 278;
  14014. t['logicalnot'] = 584;
  14015. t['odieresis'] = 556;
  14016. t['udieresis'] = 556;
  14017. t['notequal'] = 549;
  14018. t['gcommaaccent'] = 556;
  14019. t['eth'] = 556;
  14020. t['zcaron'] = 500;
  14021. t['ncommaaccent'] = 556;
  14022. t['onesuperior'] = 333;
  14023. t['imacron'] = 278;
  14024. t['Euro'] = 556;
  14025. });
  14026. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  14027. t['space'] = 278;
  14028. t['exclam'] = 333;
  14029. t['quotedbl'] = 474;
  14030. t['numbersign'] = 556;
  14031. t['dollar'] = 556;
  14032. t['percent'] = 889;
  14033. t['ampersand'] = 722;
  14034. t['quoteright'] = 278;
  14035. t['parenleft'] = 333;
  14036. t['parenright'] = 333;
  14037. t['asterisk'] = 389;
  14038. t['plus'] = 584;
  14039. t['comma'] = 278;
  14040. t['hyphen'] = 333;
  14041. t['period'] = 278;
  14042. t['slash'] = 278;
  14043. t['zero'] = 556;
  14044. t['one'] = 556;
  14045. t['two'] = 556;
  14046. t['three'] = 556;
  14047. t['four'] = 556;
  14048. t['five'] = 556;
  14049. t['six'] = 556;
  14050. t['seven'] = 556;
  14051. t['eight'] = 556;
  14052. t['nine'] = 556;
  14053. t['colon'] = 333;
  14054. t['semicolon'] = 333;
  14055. t['less'] = 584;
  14056. t['equal'] = 584;
  14057. t['greater'] = 584;
  14058. t['question'] = 611;
  14059. t['at'] = 975;
  14060. t['A'] = 722;
  14061. t['B'] = 722;
  14062. t['C'] = 722;
  14063. t['D'] = 722;
  14064. t['E'] = 667;
  14065. t['F'] = 611;
  14066. t['G'] = 778;
  14067. t['H'] = 722;
  14068. t['I'] = 278;
  14069. t['J'] = 556;
  14070. t['K'] = 722;
  14071. t['L'] = 611;
  14072. t['M'] = 833;
  14073. t['N'] = 722;
  14074. t['O'] = 778;
  14075. t['P'] = 667;
  14076. t['Q'] = 778;
  14077. t['R'] = 722;
  14078. t['S'] = 667;
  14079. t['T'] = 611;
  14080. t['U'] = 722;
  14081. t['V'] = 667;
  14082. t['W'] = 944;
  14083. t['X'] = 667;
  14084. t['Y'] = 667;
  14085. t['Z'] = 611;
  14086. t['bracketleft'] = 333;
  14087. t['backslash'] = 278;
  14088. t['bracketright'] = 333;
  14089. t['asciicircum'] = 584;
  14090. t['underscore'] = 556;
  14091. t['quoteleft'] = 278;
  14092. t['a'] = 556;
  14093. t['b'] = 611;
  14094. t['c'] = 556;
  14095. t['d'] = 611;
  14096. t['e'] = 556;
  14097. t['f'] = 333;
  14098. t['g'] = 611;
  14099. t['h'] = 611;
  14100. t['i'] = 278;
  14101. t['j'] = 278;
  14102. t['k'] = 556;
  14103. t['l'] = 278;
  14104. t['m'] = 889;
  14105. t['n'] = 611;
  14106. t['o'] = 611;
  14107. t['p'] = 611;
  14108. t['q'] = 611;
  14109. t['r'] = 389;
  14110. t['s'] = 556;
  14111. t['t'] = 333;
  14112. t['u'] = 611;
  14113. t['v'] = 556;
  14114. t['w'] = 778;
  14115. t['x'] = 556;
  14116. t['y'] = 556;
  14117. t['z'] = 500;
  14118. t['braceleft'] = 389;
  14119. t['bar'] = 280;
  14120. t['braceright'] = 389;
  14121. t['asciitilde'] = 584;
  14122. t['exclamdown'] = 333;
  14123. t['cent'] = 556;
  14124. t['sterling'] = 556;
  14125. t['fraction'] = 167;
  14126. t['yen'] = 556;
  14127. t['florin'] = 556;
  14128. t['section'] = 556;
  14129. t['currency'] = 556;
  14130. t['quotesingle'] = 238;
  14131. t['quotedblleft'] = 500;
  14132. t['guillemotleft'] = 556;
  14133. t['guilsinglleft'] = 333;
  14134. t['guilsinglright'] = 333;
  14135. t['fi'] = 611;
  14136. t['fl'] = 611;
  14137. t['endash'] = 556;
  14138. t['dagger'] = 556;
  14139. t['daggerdbl'] = 556;
  14140. t['periodcentered'] = 278;
  14141. t['paragraph'] = 556;
  14142. t['bullet'] = 350;
  14143. t['quotesinglbase'] = 278;
  14144. t['quotedblbase'] = 500;
  14145. t['quotedblright'] = 500;
  14146. t['guillemotright'] = 556;
  14147. t['ellipsis'] = 1000;
  14148. t['perthousand'] = 1000;
  14149. t['questiondown'] = 611;
  14150. t['grave'] = 333;
  14151. t['acute'] = 333;
  14152. t['circumflex'] = 333;
  14153. t['tilde'] = 333;
  14154. t['macron'] = 333;
  14155. t['breve'] = 333;
  14156. t['dotaccent'] = 333;
  14157. t['dieresis'] = 333;
  14158. t['ring'] = 333;
  14159. t['cedilla'] = 333;
  14160. t['hungarumlaut'] = 333;
  14161. t['ogonek'] = 333;
  14162. t['caron'] = 333;
  14163. t['emdash'] = 1000;
  14164. t['AE'] = 1000;
  14165. t['ordfeminine'] = 370;
  14166. t['Lslash'] = 611;
  14167. t['Oslash'] = 778;
  14168. t['OE'] = 1000;
  14169. t['ordmasculine'] = 365;
  14170. t['ae'] = 889;
  14171. t['dotlessi'] = 278;
  14172. t['lslash'] = 278;
  14173. t['oslash'] = 611;
  14174. t['oe'] = 944;
  14175. t['germandbls'] = 611;
  14176. t['Idieresis'] = 278;
  14177. t['eacute'] = 556;
  14178. t['abreve'] = 556;
  14179. t['uhungarumlaut'] = 611;
  14180. t['ecaron'] = 556;
  14181. t['Ydieresis'] = 667;
  14182. t['divide'] = 584;
  14183. t['Yacute'] = 667;
  14184. t['Acircumflex'] = 722;
  14185. t['aacute'] = 556;
  14186. t['Ucircumflex'] = 722;
  14187. t['yacute'] = 556;
  14188. t['scommaaccent'] = 556;
  14189. t['ecircumflex'] = 556;
  14190. t['Uring'] = 722;
  14191. t['Udieresis'] = 722;
  14192. t['aogonek'] = 556;
  14193. t['Uacute'] = 722;
  14194. t['uogonek'] = 611;
  14195. t['Edieresis'] = 667;
  14196. t['Dcroat'] = 722;
  14197. t['commaaccent'] = 250;
  14198. t['copyright'] = 737;
  14199. t['Emacron'] = 667;
  14200. t['ccaron'] = 556;
  14201. t['aring'] = 556;
  14202. t['Ncommaaccent'] = 722;
  14203. t['lacute'] = 278;
  14204. t['agrave'] = 556;
  14205. t['Tcommaaccent'] = 611;
  14206. t['Cacute'] = 722;
  14207. t['atilde'] = 556;
  14208. t['Edotaccent'] = 667;
  14209. t['scaron'] = 556;
  14210. t['scedilla'] = 556;
  14211. t['iacute'] = 278;
  14212. t['lozenge'] = 494;
  14213. t['Rcaron'] = 722;
  14214. t['Gcommaaccent'] = 778;
  14215. t['ucircumflex'] = 611;
  14216. t['acircumflex'] = 556;
  14217. t['Amacron'] = 722;
  14218. t['rcaron'] = 389;
  14219. t['ccedilla'] = 556;
  14220. t['Zdotaccent'] = 611;
  14221. t['Thorn'] = 667;
  14222. t['Omacron'] = 778;
  14223. t['Racute'] = 722;
  14224. t['Sacute'] = 667;
  14225. t['dcaron'] = 743;
  14226. t['Umacron'] = 722;
  14227. t['uring'] = 611;
  14228. t['threesuperior'] = 333;
  14229. t['Ograve'] = 778;
  14230. t['Agrave'] = 722;
  14231. t['Abreve'] = 722;
  14232. t['multiply'] = 584;
  14233. t['uacute'] = 611;
  14234. t['Tcaron'] = 611;
  14235. t['partialdiff'] = 494;
  14236. t['ydieresis'] = 556;
  14237. t['Nacute'] = 722;
  14238. t['icircumflex'] = 278;
  14239. t['Ecircumflex'] = 667;
  14240. t['adieresis'] = 556;
  14241. t['edieresis'] = 556;
  14242. t['cacute'] = 556;
  14243. t['nacute'] = 611;
  14244. t['umacron'] = 611;
  14245. t['Ncaron'] = 722;
  14246. t['Iacute'] = 278;
  14247. t['plusminus'] = 584;
  14248. t['brokenbar'] = 280;
  14249. t['registered'] = 737;
  14250. t['Gbreve'] = 778;
  14251. t['Idotaccent'] = 278;
  14252. t['summation'] = 600;
  14253. t['Egrave'] = 667;
  14254. t['racute'] = 389;
  14255. t['omacron'] = 611;
  14256. t['Zacute'] = 611;
  14257. t['Zcaron'] = 611;
  14258. t['greaterequal'] = 549;
  14259. t['Eth'] = 722;
  14260. t['Ccedilla'] = 722;
  14261. t['lcommaaccent'] = 278;
  14262. t['tcaron'] = 389;
  14263. t['eogonek'] = 556;
  14264. t['Uogonek'] = 722;
  14265. t['Aacute'] = 722;
  14266. t['Adieresis'] = 722;
  14267. t['egrave'] = 556;
  14268. t['zacute'] = 500;
  14269. t['iogonek'] = 278;
  14270. t['Oacute'] = 778;
  14271. t['oacute'] = 611;
  14272. t['amacron'] = 556;
  14273. t['sacute'] = 556;
  14274. t['idieresis'] = 278;
  14275. t['Ocircumflex'] = 778;
  14276. t['Ugrave'] = 722;
  14277. t['Delta'] = 612;
  14278. t['thorn'] = 611;
  14279. t['twosuperior'] = 333;
  14280. t['Odieresis'] = 778;
  14281. t['mu'] = 611;
  14282. t['igrave'] = 278;
  14283. t['ohungarumlaut'] = 611;
  14284. t['Eogonek'] = 667;
  14285. t['dcroat'] = 611;
  14286. t['threequarters'] = 834;
  14287. t['Scedilla'] = 667;
  14288. t['lcaron'] = 400;
  14289. t['Kcommaaccent'] = 722;
  14290. t['Lacute'] = 611;
  14291. t['trademark'] = 1000;
  14292. t['edotaccent'] = 556;
  14293. t['Igrave'] = 278;
  14294. t['Imacron'] = 278;
  14295. t['Lcaron'] = 611;
  14296. t['onehalf'] = 834;
  14297. t['lessequal'] = 549;
  14298. t['ocircumflex'] = 611;
  14299. t['ntilde'] = 611;
  14300. t['Uhungarumlaut'] = 722;
  14301. t['Eacute'] = 667;
  14302. t['emacron'] = 556;
  14303. t['gbreve'] = 611;
  14304. t['onequarter'] = 834;
  14305. t['Scaron'] = 667;
  14306. t['Scommaaccent'] = 667;
  14307. t['Ohungarumlaut'] = 778;
  14308. t['degree'] = 400;
  14309. t['ograve'] = 611;
  14310. t['Ccaron'] = 722;
  14311. t['ugrave'] = 611;
  14312. t['radical'] = 549;
  14313. t['Dcaron'] = 722;
  14314. t['rcommaaccent'] = 389;
  14315. t['Ntilde'] = 722;
  14316. t['otilde'] = 611;
  14317. t['Rcommaaccent'] = 722;
  14318. t['Lcommaaccent'] = 611;
  14319. t['Atilde'] = 722;
  14320. t['Aogonek'] = 722;
  14321. t['Aring'] = 722;
  14322. t['Otilde'] = 778;
  14323. t['zdotaccent'] = 500;
  14324. t['Ecaron'] = 667;
  14325. t['Iogonek'] = 278;
  14326. t['kcommaaccent'] = 556;
  14327. t['minus'] = 584;
  14328. t['Icircumflex'] = 278;
  14329. t['ncaron'] = 611;
  14330. t['tcommaaccent'] = 333;
  14331. t['logicalnot'] = 584;
  14332. t['odieresis'] = 611;
  14333. t['udieresis'] = 611;
  14334. t['notequal'] = 549;
  14335. t['gcommaaccent'] = 611;
  14336. t['eth'] = 611;
  14337. t['zcaron'] = 500;
  14338. t['ncommaaccent'] = 611;
  14339. t['onesuperior'] = 333;
  14340. t['imacron'] = 278;
  14341. t['Euro'] = 556;
  14342. });
  14343. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14344. t['space'] = 278;
  14345. t['exclam'] = 333;
  14346. t['quotedbl'] = 474;
  14347. t['numbersign'] = 556;
  14348. t['dollar'] = 556;
  14349. t['percent'] = 889;
  14350. t['ampersand'] = 722;
  14351. t['quoteright'] = 278;
  14352. t['parenleft'] = 333;
  14353. t['parenright'] = 333;
  14354. t['asterisk'] = 389;
  14355. t['plus'] = 584;
  14356. t['comma'] = 278;
  14357. t['hyphen'] = 333;
  14358. t['period'] = 278;
  14359. t['slash'] = 278;
  14360. t['zero'] = 556;
  14361. t['one'] = 556;
  14362. t['two'] = 556;
  14363. t['three'] = 556;
  14364. t['four'] = 556;
  14365. t['five'] = 556;
  14366. t['six'] = 556;
  14367. t['seven'] = 556;
  14368. t['eight'] = 556;
  14369. t['nine'] = 556;
  14370. t['colon'] = 333;
  14371. t['semicolon'] = 333;
  14372. t['less'] = 584;
  14373. t['equal'] = 584;
  14374. t['greater'] = 584;
  14375. t['question'] = 611;
  14376. t['at'] = 975;
  14377. t['A'] = 722;
  14378. t['B'] = 722;
  14379. t['C'] = 722;
  14380. t['D'] = 722;
  14381. t['E'] = 667;
  14382. t['F'] = 611;
  14383. t['G'] = 778;
  14384. t['H'] = 722;
  14385. t['I'] = 278;
  14386. t['J'] = 556;
  14387. t['K'] = 722;
  14388. t['L'] = 611;
  14389. t['M'] = 833;
  14390. t['N'] = 722;
  14391. t['O'] = 778;
  14392. t['P'] = 667;
  14393. t['Q'] = 778;
  14394. t['R'] = 722;
  14395. t['S'] = 667;
  14396. t['T'] = 611;
  14397. t['U'] = 722;
  14398. t['V'] = 667;
  14399. t['W'] = 944;
  14400. t['X'] = 667;
  14401. t['Y'] = 667;
  14402. t['Z'] = 611;
  14403. t['bracketleft'] = 333;
  14404. t['backslash'] = 278;
  14405. t['bracketright'] = 333;
  14406. t['asciicircum'] = 584;
  14407. t['underscore'] = 556;
  14408. t['quoteleft'] = 278;
  14409. t['a'] = 556;
  14410. t['b'] = 611;
  14411. t['c'] = 556;
  14412. t['d'] = 611;
  14413. t['e'] = 556;
  14414. t['f'] = 333;
  14415. t['g'] = 611;
  14416. t['h'] = 611;
  14417. t['i'] = 278;
  14418. t['j'] = 278;
  14419. t['k'] = 556;
  14420. t['l'] = 278;
  14421. t['m'] = 889;
  14422. t['n'] = 611;
  14423. t['o'] = 611;
  14424. t['p'] = 611;
  14425. t['q'] = 611;
  14426. t['r'] = 389;
  14427. t['s'] = 556;
  14428. t['t'] = 333;
  14429. t['u'] = 611;
  14430. t['v'] = 556;
  14431. t['w'] = 778;
  14432. t['x'] = 556;
  14433. t['y'] = 556;
  14434. t['z'] = 500;
  14435. t['braceleft'] = 389;
  14436. t['bar'] = 280;
  14437. t['braceright'] = 389;
  14438. t['asciitilde'] = 584;
  14439. t['exclamdown'] = 333;
  14440. t['cent'] = 556;
  14441. t['sterling'] = 556;
  14442. t['fraction'] = 167;
  14443. t['yen'] = 556;
  14444. t['florin'] = 556;
  14445. t['section'] = 556;
  14446. t['currency'] = 556;
  14447. t['quotesingle'] = 238;
  14448. t['quotedblleft'] = 500;
  14449. t['guillemotleft'] = 556;
  14450. t['guilsinglleft'] = 333;
  14451. t['guilsinglright'] = 333;
  14452. t['fi'] = 611;
  14453. t['fl'] = 611;
  14454. t['endash'] = 556;
  14455. t['dagger'] = 556;
  14456. t['daggerdbl'] = 556;
  14457. t['periodcentered'] = 278;
  14458. t['paragraph'] = 556;
  14459. t['bullet'] = 350;
  14460. t['quotesinglbase'] = 278;
  14461. t['quotedblbase'] = 500;
  14462. t['quotedblright'] = 500;
  14463. t['guillemotright'] = 556;
  14464. t['ellipsis'] = 1000;
  14465. t['perthousand'] = 1000;
  14466. t['questiondown'] = 611;
  14467. t['grave'] = 333;
  14468. t['acute'] = 333;
  14469. t['circumflex'] = 333;
  14470. t['tilde'] = 333;
  14471. t['macron'] = 333;
  14472. t['breve'] = 333;
  14473. t['dotaccent'] = 333;
  14474. t['dieresis'] = 333;
  14475. t['ring'] = 333;
  14476. t['cedilla'] = 333;
  14477. t['hungarumlaut'] = 333;
  14478. t['ogonek'] = 333;
  14479. t['caron'] = 333;
  14480. t['emdash'] = 1000;
  14481. t['AE'] = 1000;
  14482. t['ordfeminine'] = 370;
  14483. t['Lslash'] = 611;
  14484. t['Oslash'] = 778;
  14485. t['OE'] = 1000;
  14486. t['ordmasculine'] = 365;
  14487. t['ae'] = 889;
  14488. t['dotlessi'] = 278;
  14489. t['lslash'] = 278;
  14490. t['oslash'] = 611;
  14491. t['oe'] = 944;
  14492. t['germandbls'] = 611;
  14493. t['Idieresis'] = 278;
  14494. t['eacute'] = 556;
  14495. t['abreve'] = 556;
  14496. t['uhungarumlaut'] = 611;
  14497. t['ecaron'] = 556;
  14498. t['Ydieresis'] = 667;
  14499. t['divide'] = 584;
  14500. t['Yacute'] = 667;
  14501. t['Acircumflex'] = 722;
  14502. t['aacute'] = 556;
  14503. t['Ucircumflex'] = 722;
  14504. t['yacute'] = 556;
  14505. t['scommaaccent'] = 556;
  14506. t['ecircumflex'] = 556;
  14507. t['Uring'] = 722;
  14508. t['Udieresis'] = 722;
  14509. t['aogonek'] = 556;
  14510. t['Uacute'] = 722;
  14511. t['uogonek'] = 611;
  14512. t['Edieresis'] = 667;
  14513. t['Dcroat'] = 722;
  14514. t['commaaccent'] = 250;
  14515. t['copyright'] = 737;
  14516. t['Emacron'] = 667;
  14517. t['ccaron'] = 556;
  14518. t['aring'] = 556;
  14519. t['Ncommaaccent'] = 722;
  14520. t['lacute'] = 278;
  14521. t['agrave'] = 556;
  14522. t['Tcommaaccent'] = 611;
  14523. t['Cacute'] = 722;
  14524. t['atilde'] = 556;
  14525. t['Edotaccent'] = 667;
  14526. t['scaron'] = 556;
  14527. t['scedilla'] = 556;
  14528. t['iacute'] = 278;
  14529. t['lozenge'] = 494;
  14530. t['Rcaron'] = 722;
  14531. t['Gcommaaccent'] = 778;
  14532. t['ucircumflex'] = 611;
  14533. t['acircumflex'] = 556;
  14534. t['Amacron'] = 722;
  14535. t['rcaron'] = 389;
  14536. t['ccedilla'] = 556;
  14537. t['Zdotaccent'] = 611;
  14538. t['Thorn'] = 667;
  14539. t['Omacron'] = 778;
  14540. t['Racute'] = 722;
  14541. t['Sacute'] = 667;
  14542. t['dcaron'] = 743;
  14543. t['Umacron'] = 722;
  14544. t['uring'] = 611;
  14545. t['threesuperior'] = 333;
  14546. t['Ograve'] = 778;
  14547. t['Agrave'] = 722;
  14548. t['Abreve'] = 722;
  14549. t['multiply'] = 584;
  14550. t['uacute'] = 611;
  14551. t['Tcaron'] = 611;
  14552. t['partialdiff'] = 494;
  14553. t['ydieresis'] = 556;
  14554. t['Nacute'] = 722;
  14555. t['icircumflex'] = 278;
  14556. t['Ecircumflex'] = 667;
  14557. t['adieresis'] = 556;
  14558. t['edieresis'] = 556;
  14559. t['cacute'] = 556;
  14560. t['nacute'] = 611;
  14561. t['umacron'] = 611;
  14562. t['Ncaron'] = 722;
  14563. t['Iacute'] = 278;
  14564. t['plusminus'] = 584;
  14565. t['brokenbar'] = 280;
  14566. t['registered'] = 737;
  14567. t['Gbreve'] = 778;
  14568. t['Idotaccent'] = 278;
  14569. t['summation'] = 600;
  14570. t['Egrave'] = 667;
  14571. t['racute'] = 389;
  14572. t['omacron'] = 611;
  14573. t['Zacute'] = 611;
  14574. t['Zcaron'] = 611;
  14575. t['greaterequal'] = 549;
  14576. t['Eth'] = 722;
  14577. t['Ccedilla'] = 722;
  14578. t['lcommaaccent'] = 278;
  14579. t['tcaron'] = 389;
  14580. t['eogonek'] = 556;
  14581. t['Uogonek'] = 722;
  14582. t['Aacute'] = 722;
  14583. t['Adieresis'] = 722;
  14584. t['egrave'] = 556;
  14585. t['zacute'] = 500;
  14586. t['iogonek'] = 278;
  14587. t['Oacute'] = 778;
  14588. t['oacute'] = 611;
  14589. t['amacron'] = 556;
  14590. t['sacute'] = 556;
  14591. t['idieresis'] = 278;
  14592. t['Ocircumflex'] = 778;
  14593. t['Ugrave'] = 722;
  14594. t['Delta'] = 612;
  14595. t['thorn'] = 611;
  14596. t['twosuperior'] = 333;
  14597. t['Odieresis'] = 778;
  14598. t['mu'] = 611;
  14599. t['igrave'] = 278;
  14600. t['ohungarumlaut'] = 611;
  14601. t['Eogonek'] = 667;
  14602. t['dcroat'] = 611;
  14603. t['threequarters'] = 834;
  14604. t['Scedilla'] = 667;
  14605. t['lcaron'] = 400;
  14606. t['Kcommaaccent'] = 722;
  14607. t['Lacute'] = 611;
  14608. t['trademark'] = 1000;
  14609. t['edotaccent'] = 556;
  14610. t['Igrave'] = 278;
  14611. t['Imacron'] = 278;
  14612. t['Lcaron'] = 611;
  14613. t['onehalf'] = 834;
  14614. t['lessequal'] = 549;
  14615. t['ocircumflex'] = 611;
  14616. t['ntilde'] = 611;
  14617. t['Uhungarumlaut'] = 722;
  14618. t['Eacute'] = 667;
  14619. t['emacron'] = 556;
  14620. t['gbreve'] = 611;
  14621. t['onequarter'] = 834;
  14622. t['Scaron'] = 667;
  14623. t['Scommaaccent'] = 667;
  14624. t['Ohungarumlaut'] = 778;
  14625. t['degree'] = 400;
  14626. t['ograve'] = 611;
  14627. t['Ccaron'] = 722;
  14628. t['ugrave'] = 611;
  14629. t['radical'] = 549;
  14630. t['Dcaron'] = 722;
  14631. t['rcommaaccent'] = 389;
  14632. t['Ntilde'] = 722;
  14633. t['otilde'] = 611;
  14634. t['Rcommaaccent'] = 722;
  14635. t['Lcommaaccent'] = 611;
  14636. t['Atilde'] = 722;
  14637. t['Aogonek'] = 722;
  14638. t['Aring'] = 722;
  14639. t['Otilde'] = 778;
  14640. t['zdotaccent'] = 500;
  14641. t['Ecaron'] = 667;
  14642. t['Iogonek'] = 278;
  14643. t['kcommaaccent'] = 556;
  14644. t['minus'] = 584;
  14645. t['Icircumflex'] = 278;
  14646. t['ncaron'] = 611;
  14647. t['tcommaaccent'] = 333;
  14648. t['logicalnot'] = 584;
  14649. t['odieresis'] = 611;
  14650. t['udieresis'] = 611;
  14651. t['notequal'] = 549;
  14652. t['gcommaaccent'] = 611;
  14653. t['eth'] = 611;
  14654. t['zcaron'] = 500;
  14655. t['ncommaaccent'] = 611;
  14656. t['onesuperior'] = 333;
  14657. t['imacron'] = 278;
  14658. t['Euro'] = 556;
  14659. });
  14660. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14661. t['space'] = 278;
  14662. t['exclam'] = 278;
  14663. t['quotedbl'] = 355;
  14664. t['numbersign'] = 556;
  14665. t['dollar'] = 556;
  14666. t['percent'] = 889;
  14667. t['ampersand'] = 667;
  14668. t['quoteright'] = 222;
  14669. t['parenleft'] = 333;
  14670. t['parenright'] = 333;
  14671. t['asterisk'] = 389;
  14672. t['plus'] = 584;
  14673. t['comma'] = 278;
  14674. t['hyphen'] = 333;
  14675. t['period'] = 278;
  14676. t['slash'] = 278;
  14677. t['zero'] = 556;
  14678. t['one'] = 556;
  14679. t['two'] = 556;
  14680. t['three'] = 556;
  14681. t['four'] = 556;
  14682. t['five'] = 556;
  14683. t['six'] = 556;
  14684. t['seven'] = 556;
  14685. t['eight'] = 556;
  14686. t['nine'] = 556;
  14687. t['colon'] = 278;
  14688. t['semicolon'] = 278;
  14689. t['less'] = 584;
  14690. t['equal'] = 584;
  14691. t['greater'] = 584;
  14692. t['question'] = 556;
  14693. t['at'] = 1015;
  14694. t['A'] = 667;
  14695. t['B'] = 667;
  14696. t['C'] = 722;
  14697. t['D'] = 722;
  14698. t['E'] = 667;
  14699. t['F'] = 611;
  14700. t['G'] = 778;
  14701. t['H'] = 722;
  14702. t['I'] = 278;
  14703. t['J'] = 500;
  14704. t['K'] = 667;
  14705. t['L'] = 556;
  14706. t['M'] = 833;
  14707. t['N'] = 722;
  14708. t['O'] = 778;
  14709. t['P'] = 667;
  14710. t['Q'] = 778;
  14711. t['R'] = 722;
  14712. t['S'] = 667;
  14713. t['T'] = 611;
  14714. t['U'] = 722;
  14715. t['V'] = 667;
  14716. t['W'] = 944;
  14717. t['X'] = 667;
  14718. t['Y'] = 667;
  14719. t['Z'] = 611;
  14720. t['bracketleft'] = 278;
  14721. t['backslash'] = 278;
  14722. t['bracketright'] = 278;
  14723. t['asciicircum'] = 469;
  14724. t['underscore'] = 556;
  14725. t['quoteleft'] = 222;
  14726. t['a'] = 556;
  14727. t['b'] = 556;
  14728. t['c'] = 500;
  14729. t['d'] = 556;
  14730. t['e'] = 556;
  14731. t['f'] = 278;
  14732. t['g'] = 556;
  14733. t['h'] = 556;
  14734. t['i'] = 222;
  14735. t['j'] = 222;
  14736. t['k'] = 500;
  14737. t['l'] = 222;
  14738. t['m'] = 833;
  14739. t['n'] = 556;
  14740. t['o'] = 556;
  14741. t['p'] = 556;
  14742. t['q'] = 556;
  14743. t['r'] = 333;
  14744. t['s'] = 500;
  14745. t['t'] = 278;
  14746. t['u'] = 556;
  14747. t['v'] = 500;
  14748. t['w'] = 722;
  14749. t['x'] = 500;
  14750. t['y'] = 500;
  14751. t['z'] = 500;
  14752. t['braceleft'] = 334;
  14753. t['bar'] = 260;
  14754. t['braceright'] = 334;
  14755. t['asciitilde'] = 584;
  14756. t['exclamdown'] = 333;
  14757. t['cent'] = 556;
  14758. t['sterling'] = 556;
  14759. t['fraction'] = 167;
  14760. t['yen'] = 556;
  14761. t['florin'] = 556;
  14762. t['section'] = 556;
  14763. t['currency'] = 556;
  14764. t['quotesingle'] = 191;
  14765. t['quotedblleft'] = 333;
  14766. t['guillemotleft'] = 556;
  14767. t['guilsinglleft'] = 333;
  14768. t['guilsinglright'] = 333;
  14769. t['fi'] = 500;
  14770. t['fl'] = 500;
  14771. t['endash'] = 556;
  14772. t['dagger'] = 556;
  14773. t['daggerdbl'] = 556;
  14774. t['periodcentered'] = 278;
  14775. t['paragraph'] = 537;
  14776. t['bullet'] = 350;
  14777. t['quotesinglbase'] = 222;
  14778. t['quotedblbase'] = 333;
  14779. t['quotedblright'] = 333;
  14780. t['guillemotright'] = 556;
  14781. t['ellipsis'] = 1000;
  14782. t['perthousand'] = 1000;
  14783. t['questiondown'] = 611;
  14784. t['grave'] = 333;
  14785. t['acute'] = 333;
  14786. t['circumflex'] = 333;
  14787. t['tilde'] = 333;
  14788. t['macron'] = 333;
  14789. t['breve'] = 333;
  14790. t['dotaccent'] = 333;
  14791. t['dieresis'] = 333;
  14792. t['ring'] = 333;
  14793. t['cedilla'] = 333;
  14794. t['hungarumlaut'] = 333;
  14795. t['ogonek'] = 333;
  14796. t['caron'] = 333;
  14797. t['emdash'] = 1000;
  14798. t['AE'] = 1000;
  14799. t['ordfeminine'] = 370;
  14800. t['Lslash'] = 556;
  14801. t['Oslash'] = 778;
  14802. t['OE'] = 1000;
  14803. t['ordmasculine'] = 365;
  14804. t['ae'] = 889;
  14805. t['dotlessi'] = 278;
  14806. t['lslash'] = 222;
  14807. t['oslash'] = 611;
  14808. t['oe'] = 944;
  14809. t['germandbls'] = 611;
  14810. t['Idieresis'] = 278;
  14811. t['eacute'] = 556;
  14812. t['abreve'] = 556;
  14813. t['uhungarumlaut'] = 556;
  14814. t['ecaron'] = 556;
  14815. t['Ydieresis'] = 667;
  14816. t['divide'] = 584;
  14817. t['Yacute'] = 667;
  14818. t['Acircumflex'] = 667;
  14819. t['aacute'] = 556;
  14820. t['Ucircumflex'] = 722;
  14821. t['yacute'] = 500;
  14822. t['scommaaccent'] = 500;
  14823. t['ecircumflex'] = 556;
  14824. t['Uring'] = 722;
  14825. t['Udieresis'] = 722;
  14826. t['aogonek'] = 556;
  14827. t['Uacute'] = 722;
  14828. t['uogonek'] = 556;
  14829. t['Edieresis'] = 667;
  14830. t['Dcroat'] = 722;
  14831. t['commaaccent'] = 250;
  14832. t['copyright'] = 737;
  14833. t['Emacron'] = 667;
  14834. t['ccaron'] = 500;
  14835. t['aring'] = 556;
  14836. t['Ncommaaccent'] = 722;
  14837. t['lacute'] = 222;
  14838. t['agrave'] = 556;
  14839. t['Tcommaaccent'] = 611;
  14840. t['Cacute'] = 722;
  14841. t['atilde'] = 556;
  14842. t['Edotaccent'] = 667;
  14843. t['scaron'] = 500;
  14844. t['scedilla'] = 500;
  14845. t['iacute'] = 278;
  14846. t['lozenge'] = 471;
  14847. t['Rcaron'] = 722;
  14848. t['Gcommaaccent'] = 778;
  14849. t['ucircumflex'] = 556;
  14850. t['acircumflex'] = 556;
  14851. t['Amacron'] = 667;
  14852. t['rcaron'] = 333;
  14853. t['ccedilla'] = 500;
  14854. t['Zdotaccent'] = 611;
  14855. t['Thorn'] = 667;
  14856. t['Omacron'] = 778;
  14857. t['Racute'] = 722;
  14858. t['Sacute'] = 667;
  14859. t['dcaron'] = 643;
  14860. t['Umacron'] = 722;
  14861. t['uring'] = 556;
  14862. t['threesuperior'] = 333;
  14863. t['Ograve'] = 778;
  14864. t['Agrave'] = 667;
  14865. t['Abreve'] = 667;
  14866. t['multiply'] = 584;
  14867. t['uacute'] = 556;
  14868. t['Tcaron'] = 611;
  14869. t['partialdiff'] = 476;
  14870. t['ydieresis'] = 500;
  14871. t['Nacute'] = 722;
  14872. t['icircumflex'] = 278;
  14873. t['Ecircumflex'] = 667;
  14874. t['adieresis'] = 556;
  14875. t['edieresis'] = 556;
  14876. t['cacute'] = 500;
  14877. t['nacute'] = 556;
  14878. t['umacron'] = 556;
  14879. t['Ncaron'] = 722;
  14880. t['Iacute'] = 278;
  14881. t['plusminus'] = 584;
  14882. t['brokenbar'] = 260;
  14883. t['registered'] = 737;
  14884. t['Gbreve'] = 778;
  14885. t['Idotaccent'] = 278;
  14886. t['summation'] = 600;
  14887. t['Egrave'] = 667;
  14888. t['racute'] = 333;
  14889. t['omacron'] = 556;
  14890. t['Zacute'] = 611;
  14891. t['Zcaron'] = 611;
  14892. t['greaterequal'] = 549;
  14893. t['Eth'] = 722;
  14894. t['Ccedilla'] = 722;
  14895. t['lcommaaccent'] = 222;
  14896. t['tcaron'] = 317;
  14897. t['eogonek'] = 556;
  14898. t['Uogonek'] = 722;
  14899. t['Aacute'] = 667;
  14900. t['Adieresis'] = 667;
  14901. t['egrave'] = 556;
  14902. t['zacute'] = 500;
  14903. t['iogonek'] = 222;
  14904. t['Oacute'] = 778;
  14905. t['oacute'] = 556;
  14906. t['amacron'] = 556;
  14907. t['sacute'] = 500;
  14908. t['idieresis'] = 278;
  14909. t['Ocircumflex'] = 778;
  14910. t['Ugrave'] = 722;
  14911. t['Delta'] = 612;
  14912. t['thorn'] = 556;
  14913. t['twosuperior'] = 333;
  14914. t['Odieresis'] = 778;
  14915. t['mu'] = 556;
  14916. t['igrave'] = 278;
  14917. t['ohungarumlaut'] = 556;
  14918. t['Eogonek'] = 667;
  14919. t['dcroat'] = 556;
  14920. t['threequarters'] = 834;
  14921. t['Scedilla'] = 667;
  14922. t['lcaron'] = 299;
  14923. t['Kcommaaccent'] = 667;
  14924. t['Lacute'] = 556;
  14925. t['trademark'] = 1000;
  14926. t['edotaccent'] = 556;
  14927. t['Igrave'] = 278;
  14928. t['Imacron'] = 278;
  14929. t['Lcaron'] = 556;
  14930. t['onehalf'] = 834;
  14931. t['lessequal'] = 549;
  14932. t['ocircumflex'] = 556;
  14933. t['ntilde'] = 556;
  14934. t['Uhungarumlaut'] = 722;
  14935. t['Eacute'] = 667;
  14936. t['emacron'] = 556;
  14937. t['gbreve'] = 556;
  14938. t['onequarter'] = 834;
  14939. t['Scaron'] = 667;
  14940. t['Scommaaccent'] = 667;
  14941. t['Ohungarumlaut'] = 778;
  14942. t['degree'] = 400;
  14943. t['ograve'] = 556;
  14944. t['Ccaron'] = 722;
  14945. t['ugrave'] = 556;
  14946. t['radical'] = 453;
  14947. t['Dcaron'] = 722;
  14948. t['rcommaaccent'] = 333;
  14949. t['Ntilde'] = 722;
  14950. t['otilde'] = 556;
  14951. t['Rcommaaccent'] = 722;
  14952. t['Lcommaaccent'] = 556;
  14953. t['Atilde'] = 667;
  14954. t['Aogonek'] = 667;
  14955. t['Aring'] = 667;
  14956. t['Otilde'] = 778;
  14957. t['zdotaccent'] = 500;
  14958. t['Ecaron'] = 667;
  14959. t['Iogonek'] = 278;
  14960. t['kcommaaccent'] = 500;
  14961. t['minus'] = 584;
  14962. t['Icircumflex'] = 278;
  14963. t['ncaron'] = 556;
  14964. t['tcommaaccent'] = 278;
  14965. t['logicalnot'] = 584;
  14966. t['odieresis'] = 556;
  14967. t['udieresis'] = 556;
  14968. t['notequal'] = 549;
  14969. t['gcommaaccent'] = 556;
  14970. t['eth'] = 556;
  14971. t['zcaron'] = 500;
  14972. t['ncommaaccent'] = 556;
  14973. t['onesuperior'] = 333;
  14974. t['imacron'] = 278;
  14975. t['Euro'] = 556;
  14976. });
  14977. t['Symbol'] = getLookupTableFactory(function (t) {
  14978. t['space'] = 250;
  14979. t['exclam'] = 333;
  14980. t['universal'] = 713;
  14981. t['numbersign'] = 500;
  14982. t['existential'] = 549;
  14983. t['percent'] = 833;
  14984. t['ampersand'] = 778;
  14985. t['suchthat'] = 439;
  14986. t['parenleft'] = 333;
  14987. t['parenright'] = 333;
  14988. t['asteriskmath'] = 500;
  14989. t['plus'] = 549;
  14990. t['comma'] = 250;
  14991. t['minus'] = 549;
  14992. t['period'] = 250;
  14993. t['slash'] = 278;
  14994. t['zero'] = 500;
  14995. t['one'] = 500;
  14996. t['two'] = 500;
  14997. t['three'] = 500;
  14998. t['four'] = 500;
  14999. t['five'] = 500;
  15000. t['six'] = 500;
  15001. t['seven'] = 500;
  15002. t['eight'] = 500;
  15003. t['nine'] = 500;
  15004. t['colon'] = 278;
  15005. t['semicolon'] = 278;
  15006. t['less'] = 549;
  15007. t['equal'] = 549;
  15008. t['greater'] = 549;
  15009. t['question'] = 444;
  15010. t['congruent'] = 549;
  15011. t['Alpha'] = 722;
  15012. t['Beta'] = 667;
  15013. t['Chi'] = 722;
  15014. t['Delta'] = 612;
  15015. t['Epsilon'] = 611;
  15016. t['Phi'] = 763;
  15017. t['Gamma'] = 603;
  15018. t['Eta'] = 722;
  15019. t['Iota'] = 333;
  15020. t['theta1'] = 631;
  15021. t['Kappa'] = 722;
  15022. t['Lambda'] = 686;
  15023. t['Mu'] = 889;
  15024. t['Nu'] = 722;
  15025. t['Omicron'] = 722;
  15026. t['Pi'] = 768;
  15027. t['Theta'] = 741;
  15028. t['Rho'] = 556;
  15029. t['Sigma'] = 592;
  15030. t['Tau'] = 611;
  15031. t['Upsilon'] = 690;
  15032. t['sigma1'] = 439;
  15033. t['Omega'] = 768;
  15034. t['Xi'] = 645;
  15035. t['Psi'] = 795;
  15036. t['Zeta'] = 611;
  15037. t['bracketleft'] = 333;
  15038. t['therefore'] = 863;
  15039. t['bracketright'] = 333;
  15040. t['perpendicular'] = 658;
  15041. t['underscore'] = 500;
  15042. t['radicalex'] = 500;
  15043. t['alpha'] = 631;
  15044. t['beta'] = 549;
  15045. t['chi'] = 549;
  15046. t['delta'] = 494;
  15047. t['epsilon'] = 439;
  15048. t['phi'] = 521;
  15049. t['gamma'] = 411;
  15050. t['eta'] = 603;
  15051. t['iota'] = 329;
  15052. t['phi1'] = 603;
  15053. t['kappa'] = 549;
  15054. t['lambda'] = 549;
  15055. t['mu'] = 576;
  15056. t['nu'] = 521;
  15057. t['omicron'] = 549;
  15058. t['pi'] = 549;
  15059. t['theta'] = 521;
  15060. t['rho'] = 549;
  15061. t['sigma'] = 603;
  15062. t['tau'] = 439;
  15063. t['upsilon'] = 576;
  15064. t['omega1'] = 713;
  15065. t['omega'] = 686;
  15066. t['xi'] = 493;
  15067. t['psi'] = 686;
  15068. t['zeta'] = 494;
  15069. t['braceleft'] = 480;
  15070. t['bar'] = 200;
  15071. t['braceright'] = 480;
  15072. t['similar'] = 549;
  15073. t['Euro'] = 750;
  15074. t['Upsilon1'] = 620;
  15075. t['minute'] = 247;
  15076. t['lessequal'] = 549;
  15077. t['fraction'] = 167;
  15078. t['infinity'] = 713;
  15079. t['florin'] = 500;
  15080. t['club'] = 753;
  15081. t['diamond'] = 753;
  15082. t['heart'] = 753;
  15083. t['spade'] = 753;
  15084. t['arrowboth'] = 1042;
  15085. t['arrowleft'] = 987;
  15086. t['arrowup'] = 603;
  15087. t['arrowright'] = 987;
  15088. t['arrowdown'] = 603;
  15089. t['degree'] = 400;
  15090. t['plusminus'] = 549;
  15091. t['second'] = 411;
  15092. t['greaterequal'] = 549;
  15093. t['multiply'] = 549;
  15094. t['proportional'] = 713;
  15095. t['partialdiff'] = 494;
  15096. t['bullet'] = 460;
  15097. t['divide'] = 549;
  15098. t['notequal'] = 549;
  15099. t['equivalence'] = 549;
  15100. t['approxequal'] = 549;
  15101. t['ellipsis'] = 1000;
  15102. t['arrowvertex'] = 603;
  15103. t['arrowhorizex'] = 1000;
  15104. t['carriagereturn'] = 658;
  15105. t['aleph'] = 823;
  15106. t['Ifraktur'] = 686;
  15107. t['Rfraktur'] = 795;
  15108. t['weierstrass'] = 987;
  15109. t['circlemultiply'] = 768;
  15110. t['circleplus'] = 768;
  15111. t['emptyset'] = 823;
  15112. t['intersection'] = 768;
  15113. t['union'] = 768;
  15114. t['propersuperset'] = 713;
  15115. t['reflexsuperset'] = 713;
  15116. t['notsubset'] = 713;
  15117. t['propersubset'] = 713;
  15118. t['reflexsubset'] = 713;
  15119. t['element'] = 713;
  15120. t['notelement'] = 713;
  15121. t['angle'] = 768;
  15122. t['gradient'] = 713;
  15123. t['registerserif'] = 790;
  15124. t['copyrightserif'] = 790;
  15125. t['trademarkserif'] = 890;
  15126. t['product'] = 823;
  15127. t['radical'] = 549;
  15128. t['dotmath'] = 250;
  15129. t['logicalnot'] = 713;
  15130. t['logicaland'] = 603;
  15131. t['logicalor'] = 603;
  15132. t['arrowdblboth'] = 1042;
  15133. t['arrowdblleft'] = 987;
  15134. t['arrowdblup'] = 603;
  15135. t['arrowdblright'] = 987;
  15136. t['arrowdbldown'] = 603;
  15137. t['lozenge'] = 494;
  15138. t['angleleft'] = 329;
  15139. t['registersans'] = 790;
  15140. t['copyrightsans'] = 790;
  15141. t['trademarksans'] = 786;
  15142. t['summation'] = 713;
  15143. t['parenlefttp'] = 384;
  15144. t['parenleftex'] = 384;
  15145. t['parenleftbt'] = 384;
  15146. t['bracketlefttp'] = 384;
  15147. t['bracketleftex'] = 384;
  15148. t['bracketleftbt'] = 384;
  15149. t['bracelefttp'] = 494;
  15150. t['braceleftmid'] = 494;
  15151. t['braceleftbt'] = 494;
  15152. t['braceex'] = 494;
  15153. t['angleright'] = 329;
  15154. t['integral'] = 274;
  15155. t['integraltp'] = 686;
  15156. t['integralex'] = 686;
  15157. t['integralbt'] = 686;
  15158. t['parenrighttp'] = 384;
  15159. t['parenrightex'] = 384;
  15160. t['parenrightbt'] = 384;
  15161. t['bracketrighttp'] = 384;
  15162. t['bracketrightex'] = 384;
  15163. t['bracketrightbt'] = 384;
  15164. t['bracerighttp'] = 494;
  15165. t['bracerightmid'] = 494;
  15166. t['bracerightbt'] = 494;
  15167. t['apple'] = 790;
  15168. });
  15169. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15170. t['space'] = 250;
  15171. t['exclam'] = 333;
  15172. t['quotedbl'] = 408;
  15173. t['numbersign'] = 500;
  15174. t['dollar'] = 500;
  15175. t['percent'] = 833;
  15176. t['ampersand'] = 778;
  15177. t['quoteright'] = 333;
  15178. t['parenleft'] = 333;
  15179. t['parenright'] = 333;
  15180. t['asterisk'] = 500;
  15181. t['plus'] = 564;
  15182. t['comma'] = 250;
  15183. t['hyphen'] = 333;
  15184. t['period'] = 250;
  15185. t['slash'] = 278;
  15186. t['zero'] = 500;
  15187. t['one'] = 500;
  15188. t['two'] = 500;
  15189. t['three'] = 500;
  15190. t['four'] = 500;
  15191. t['five'] = 500;
  15192. t['six'] = 500;
  15193. t['seven'] = 500;
  15194. t['eight'] = 500;
  15195. t['nine'] = 500;
  15196. t['colon'] = 278;
  15197. t['semicolon'] = 278;
  15198. t['less'] = 564;
  15199. t['equal'] = 564;
  15200. t['greater'] = 564;
  15201. t['question'] = 444;
  15202. t['at'] = 921;
  15203. t['A'] = 722;
  15204. t['B'] = 667;
  15205. t['C'] = 667;
  15206. t['D'] = 722;
  15207. t['E'] = 611;
  15208. t['F'] = 556;
  15209. t['G'] = 722;
  15210. t['H'] = 722;
  15211. t['I'] = 333;
  15212. t['J'] = 389;
  15213. t['K'] = 722;
  15214. t['L'] = 611;
  15215. t['M'] = 889;
  15216. t['N'] = 722;
  15217. t['O'] = 722;
  15218. t['P'] = 556;
  15219. t['Q'] = 722;
  15220. t['R'] = 667;
  15221. t['S'] = 556;
  15222. t['T'] = 611;
  15223. t['U'] = 722;
  15224. t['V'] = 722;
  15225. t['W'] = 944;
  15226. t['X'] = 722;
  15227. t['Y'] = 722;
  15228. t['Z'] = 611;
  15229. t['bracketleft'] = 333;
  15230. t['backslash'] = 278;
  15231. t['bracketright'] = 333;
  15232. t['asciicircum'] = 469;
  15233. t['underscore'] = 500;
  15234. t['quoteleft'] = 333;
  15235. t['a'] = 444;
  15236. t['b'] = 500;
  15237. t['c'] = 444;
  15238. t['d'] = 500;
  15239. t['e'] = 444;
  15240. t['f'] = 333;
  15241. t['g'] = 500;
  15242. t['h'] = 500;
  15243. t['i'] = 278;
  15244. t['j'] = 278;
  15245. t['k'] = 500;
  15246. t['l'] = 278;
  15247. t['m'] = 778;
  15248. t['n'] = 500;
  15249. t['o'] = 500;
  15250. t['p'] = 500;
  15251. t['q'] = 500;
  15252. t['r'] = 333;
  15253. t['s'] = 389;
  15254. t['t'] = 278;
  15255. t['u'] = 500;
  15256. t['v'] = 500;
  15257. t['w'] = 722;
  15258. t['x'] = 500;
  15259. t['y'] = 500;
  15260. t['z'] = 444;
  15261. t['braceleft'] = 480;
  15262. t['bar'] = 200;
  15263. t['braceright'] = 480;
  15264. t['asciitilde'] = 541;
  15265. t['exclamdown'] = 333;
  15266. t['cent'] = 500;
  15267. t['sterling'] = 500;
  15268. t['fraction'] = 167;
  15269. t['yen'] = 500;
  15270. t['florin'] = 500;
  15271. t['section'] = 500;
  15272. t['currency'] = 500;
  15273. t['quotesingle'] = 180;
  15274. t['quotedblleft'] = 444;
  15275. t['guillemotleft'] = 500;
  15276. t['guilsinglleft'] = 333;
  15277. t['guilsinglright'] = 333;
  15278. t['fi'] = 556;
  15279. t['fl'] = 556;
  15280. t['endash'] = 500;
  15281. t['dagger'] = 500;
  15282. t['daggerdbl'] = 500;
  15283. t['periodcentered'] = 250;
  15284. t['paragraph'] = 453;
  15285. t['bullet'] = 350;
  15286. t['quotesinglbase'] = 333;
  15287. t['quotedblbase'] = 444;
  15288. t['quotedblright'] = 444;
  15289. t['guillemotright'] = 500;
  15290. t['ellipsis'] = 1000;
  15291. t['perthousand'] = 1000;
  15292. t['questiondown'] = 444;
  15293. t['grave'] = 333;
  15294. t['acute'] = 333;
  15295. t['circumflex'] = 333;
  15296. t['tilde'] = 333;
  15297. t['macron'] = 333;
  15298. t['breve'] = 333;
  15299. t['dotaccent'] = 333;
  15300. t['dieresis'] = 333;
  15301. t['ring'] = 333;
  15302. t['cedilla'] = 333;
  15303. t['hungarumlaut'] = 333;
  15304. t['ogonek'] = 333;
  15305. t['caron'] = 333;
  15306. t['emdash'] = 1000;
  15307. t['AE'] = 889;
  15308. t['ordfeminine'] = 276;
  15309. t['Lslash'] = 611;
  15310. t['Oslash'] = 722;
  15311. t['OE'] = 889;
  15312. t['ordmasculine'] = 310;
  15313. t['ae'] = 667;
  15314. t['dotlessi'] = 278;
  15315. t['lslash'] = 278;
  15316. t['oslash'] = 500;
  15317. t['oe'] = 722;
  15318. t['germandbls'] = 500;
  15319. t['Idieresis'] = 333;
  15320. t['eacute'] = 444;
  15321. t['abreve'] = 444;
  15322. t['uhungarumlaut'] = 500;
  15323. t['ecaron'] = 444;
  15324. t['Ydieresis'] = 722;
  15325. t['divide'] = 564;
  15326. t['Yacute'] = 722;
  15327. t['Acircumflex'] = 722;
  15328. t['aacute'] = 444;
  15329. t['Ucircumflex'] = 722;
  15330. t['yacute'] = 500;
  15331. t['scommaaccent'] = 389;
  15332. t['ecircumflex'] = 444;
  15333. t['Uring'] = 722;
  15334. t['Udieresis'] = 722;
  15335. t['aogonek'] = 444;
  15336. t['Uacute'] = 722;
  15337. t['uogonek'] = 500;
  15338. t['Edieresis'] = 611;
  15339. t['Dcroat'] = 722;
  15340. t['commaaccent'] = 250;
  15341. t['copyright'] = 760;
  15342. t['Emacron'] = 611;
  15343. t['ccaron'] = 444;
  15344. t['aring'] = 444;
  15345. t['Ncommaaccent'] = 722;
  15346. t['lacute'] = 278;
  15347. t['agrave'] = 444;
  15348. t['Tcommaaccent'] = 611;
  15349. t['Cacute'] = 667;
  15350. t['atilde'] = 444;
  15351. t['Edotaccent'] = 611;
  15352. t['scaron'] = 389;
  15353. t['scedilla'] = 389;
  15354. t['iacute'] = 278;
  15355. t['lozenge'] = 471;
  15356. t['Rcaron'] = 667;
  15357. t['Gcommaaccent'] = 722;
  15358. t['ucircumflex'] = 500;
  15359. t['acircumflex'] = 444;
  15360. t['Amacron'] = 722;
  15361. t['rcaron'] = 333;
  15362. t['ccedilla'] = 444;
  15363. t['Zdotaccent'] = 611;
  15364. t['Thorn'] = 556;
  15365. t['Omacron'] = 722;
  15366. t['Racute'] = 667;
  15367. t['Sacute'] = 556;
  15368. t['dcaron'] = 588;
  15369. t['Umacron'] = 722;
  15370. t['uring'] = 500;
  15371. t['threesuperior'] = 300;
  15372. t['Ograve'] = 722;
  15373. t['Agrave'] = 722;
  15374. t['Abreve'] = 722;
  15375. t['multiply'] = 564;
  15376. t['uacute'] = 500;
  15377. t['Tcaron'] = 611;
  15378. t['partialdiff'] = 476;
  15379. t['ydieresis'] = 500;
  15380. t['Nacute'] = 722;
  15381. t['icircumflex'] = 278;
  15382. t['Ecircumflex'] = 611;
  15383. t['adieresis'] = 444;
  15384. t['edieresis'] = 444;
  15385. t['cacute'] = 444;
  15386. t['nacute'] = 500;
  15387. t['umacron'] = 500;
  15388. t['Ncaron'] = 722;
  15389. t['Iacute'] = 333;
  15390. t['plusminus'] = 564;
  15391. t['brokenbar'] = 200;
  15392. t['registered'] = 760;
  15393. t['Gbreve'] = 722;
  15394. t['Idotaccent'] = 333;
  15395. t['summation'] = 600;
  15396. t['Egrave'] = 611;
  15397. t['racute'] = 333;
  15398. t['omacron'] = 500;
  15399. t['Zacute'] = 611;
  15400. t['Zcaron'] = 611;
  15401. t['greaterequal'] = 549;
  15402. t['Eth'] = 722;
  15403. t['Ccedilla'] = 667;
  15404. t['lcommaaccent'] = 278;
  15405. t['tcaron'] = 326;
  15406. t['eogonek'] = 444;
  15407. t['Uogonek'] = 722;
  15408. t['Aacute'] = 722;
  15409. t['Adieresis'] = 722;
  15410. t['egrave'] = 444;
  15411. t['zacute'] = 444;
  15412. t['iogonek'] = 278;
  15413. t['Oacute'] = 722;
  15414. t['oacute'] = 500;
  15415. t['amacron'] = 444;
  15416. t['sacute'] = 389;
  15417. t['idieresis'] = 278;
  15418. t['Ocircumflex'] = 722;
  15419. t['Ugrave'] = 722;
  15420. t['Delta'] = 612;
  15421. t['thorn'] = 500;
  15422. t['twosuperior'] = 300;
  15423. t['Odieresis'] = 722;
  15424. t['mu'] = 500;
  15425. t['igrave'] = 278;
  15426. t['ohungarumlaut'] = 500;
  15427. t['Eogonek'] = 611;
  15428. t['dcroat'] = 500;
  15429. t['threequarters'] = 750;
  15430. t['Scedilla'] = 556;
  15431. t['lcaron'] = 344;
  15432. t['Kcommaaccent'] = 722;
  15433. t['Lacute'] = 611;
  15434. t['trademark'] = 980;
  15435. t['edotaccent'] = 444;
  15436. t['Igrave'] = 333;
  15437. t['Imacron'] = 333;
  15438. t['Lcaron'] = 611;
  15439. t['onehalf'] = 750;
  15440. t['lessequal'] = 549;
  15441. t['ocircumflex'] = 500;
  15442. t['ntilde'] = 500;
  15443. t['Uhungarumlaut'] = 722;
  15444. t['Eacute'] = 611;
  15445. t['emacron'] = 444;
  15446. t['gbreve'] = 500;
  15447. t['onequarter'] = 750;
  15448. t['Scaron'] = 556;
  15449. t['Scommaaccent'] = 556;
  15450. t['Ohungarumlaut'] = 722;
  15451. t['degree'] = 400;
  15452. t['ograve'] = 500;
  15453. t['Ccaron'] = 667;
  15454. t['ugrave'] = 500;
  15455. t['radical'] = 453;
  15456. t['Dcaron'] = 722;
  15457. t['rcommaaccent'] = 333;
  15458. t['Ntilde'] = 722;
  15459. t['otilde'] = 500;
  15460. t['Rcommaaccent'] = 667;
  15461. t['Lcommaaccent'] = 611;
  15462. t['Atilde'] = 722;
  15463. t['Aogonek'] = 722;
  15464. t['Aring'] = 722;
  15465. t['Otilde'] = 722;
  15466. t['zdotaccent'] = 444;
  15467. t['Ecaron'] = 611;
  15468. t['Iogonek'] = 333;
  15469. t['kcommaaccent'] = 500;
  15470. t['minus'] = 564;
  15471. t['Icircumflex'] = 333;
  15472. t['ncaron'] = 500;
  15473. t['tcommaaccent'] = 278;
  15474. t['logicalnot'] = 564;
  15475. t['odieresis'] = 500;
  15476. t['udieresis'] = 500;
  15477. t['notequal'] = 549;
  15478. t['gcommaaccent'] = 500;
  15479. t['eth'] = 500;
  15480. t['zcaron'] = 444;
  15481. t['ncommaaccent'] = 500;
  15482. t['onesuperior'] = 300;
  15483. t['imacron'] = 278;
  15484. t['Euro'] = 500;
  15485. });
  15486. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15487. t['space'] = 250;
  15488. t['exclam'] = 333;
  15489. t['quotedbl'] = 555;
  15490. t['numbersign'] = 500;
  15491. t['dollar'] = 500;
  15492. t['percent'] = 1000;
  15493. t['ampersand'] = 833;
  15494. t['quoteright'] = 333;
  15495. t['parenleft'] = 333;
  15496. t['parenright'] = 333;
  15497. t['asterisk'] = 500;
  15498. t['plus'] = 570;
  15499. t['comma'] = 250;
  15500. t['hyphen'] = 333;
  15501. t['period'] = 250;
  15502. t['slash'] = 278;
  15503. t['zero'] = 500;
  15504. t['one'] = 500;
  15505. t['two'] = 500;
  15506. t['three'] = 500;
  15507. t['four'] = 500;
  15508. t['five'] = 500;
  15509. t['six'] = 500;
  15510. t['seven'] = 500;
  15511. t['eight'] = 500;
  15512. t['nine'] = 500;
  15513. t['colon'] = 333;
  15514. t['semicolon'] = 333;
  15515. t['less'] = 570;
  15516. t['equal'] = 570;
  15517. t['greater'] = 570;
  15518. t['question'] = 500;
  15519. t['at'] = 930;
  15520. t['A'] = 722;
  15521. t['B'] = 667;
  15522. t['C'] = 722;
  15523. t['D'] = 722;
  15524. t['E'] = 667;
  15525. t['F'] = 611;
  15526. t['G'] = 778;
  15527. t['H'] = 778;
  15528. t['I'] = 389;
  15529. t['J'] = 500;
  15530. t['K'] = 778;
  15531. t['L'] = 667;
  15532. t['M'] = 944;
  15533. t['N'] = 722;
  15534. t['O'] = 778;
  15535. t['P'] = 611;
  15536. t['Q'] = 778;
  15537. t['R'] = 722;
  15538. t['S'] = 556;
  15539. t['T'] = 667;
  15540. t['U'] = 722;
  15541. t['V'] = 722;
  15542. t['W'] = 1000;
  15543. t['X'] = 722;
  15544. t['Y'] = 722;
  15545. t['Z'] = 667;
  15546. t['bracketleft'] = 333;
  15547. t['backslash'] = 278;
  15548. t['bracketright'] = 333;
  15549. t['asciicircum'] = 581;
  15550. t['underscore'] = 500;
  15551. t['quoteleft'] = 333;
  15552. t['a'] = 500;
  15553. t['b'] = 556;
  15554. t['c'] = 444;
  15555. t['d'] = 556;
  15556. t['e'] = 444;
  15557. t['f'] = 333;
  15558. t['g'] = 500;
  15559. t['h'] = 556;
  15560. t['i'] = 278;
  15561. t['j'] = 333;
  15562. t['k'] = 556;
  15563. t['l'] = 278;
  15564. t['m'] = 833;
  15565. t['n'] = 556;
  15566. t['o'] = 500;
  15567. t['p'] = 556;
  15568. t['q'] = 556;
  15569. t['r'] = 444;
  15570. t['s'] = 389;
  15571. t['t'] = 333;
  15572. t['u'] = 556;
  15573. t['v'] = 500;
  15574. t['w'] = 722;
  15575. t['x'] = 500;
  15576. t['y'] = 500;
  15577. t['z'] = 444;
  15578. t['braceleft'] = 394;
  15579. t['bar'] = 220;
  15580. t['braceright'] = 394;
  15581. t['asciitilde'] = 520;
  15582. t['exclamdown'] = 333;
  15583. t['cent'] = 500;
  15584. t['sterling'] = 500;
  15585. t['fraction'] = 167;
  15586. t['yen'] = 500;
  15587. t['florin'] = 500;
  15588. t['section'] = 500;
  15589. t['currency'] = 500;
  15590. t['quotesingle'] = 278;
  15591. t['quotedblleft'] = 500;
  15592. t['guillemotleft'] = 500;
  15593. t['guilsinglleft'] = 333;
  15594. t['guilsinglright'] = 333;
  15595. t['fi'] = 556;
  15596. t['fl'] = 556;
  15597. t['endash'] = 500;
  15598. t['dagger'] = 500;
  15599. t['daggerdbl'] = 500;
  15600. t['periodcentered'] = 250;
  15601. t['paragraph'] = 540;
  15602. t['bullet'] = 350;
  15603. t['quotesinglbase'] = 333;
  15604. t['quotedblbase'] = 500;
  15605. t['quotedblright'] = 500;
  15606. t['guillemotright'] = 500;
  15607. t['ellipsis'] = 1000;
  15608. t['perthousand'] = 1000;
  15609. t['questiondown'] = 500;
  15610. t['grave'] = 333;
  15611. t['acute'] = 333;
  15612. t['circumflex'] = 333;
  15613. t['tilde'] = 333;
  15614. t['macron'] = 333;
  15615. t['breve'] = 333;
  15616. t['dotaccent'] = 333;
  15617. t['dieresis'] = 333;
  15618. t['ring'] = 333;
  15619. t['cedilla'] = 333;
  15620. t['hungarumlaut'] = 333;
  15621. t['ogonek'] = 333;
  15622. t['caron'] = 333;
  15623. t['emdash'] = 1000;
  15624. t['AE'] = 1000;
  15625. t['ordfeminine'] = 300;
  15626. t['Lslash'] = 667;
  15627. t['Oslash'] = 778;
  15628. t['OE'] = 1000;
  15629. t['ordmasculine'] = 330;
  15630. t['ae'] = 722;
  15631. t['dotlessi'] = 278;
  15632. t['lslash'] = 278;
  15633. t['oslash'] = 500;
  15634. t['oe'] = 722;
  15635. t['germandbls'] = 556;
  15636. t['Idieresis'] = 389;
  15637. t['eacute'] = 444;
  15638. t['abreve'] = 500;
  15639. t['uhungarumlaut'] = 556;
  15640. t['ecaron'] = 444;
  15641. t['Ydieresis'] = 722;
  15642. t['divide'] = 570;
  15643. t['Yacute'] = 722;
  15644. t['Acircumflex'] = 722;
  15645. t['aacute'] = 500;
  15646. t['Ucircumflex'] = 722;
  15647. t['yacute'] = 500;
  15648. t['scommaaccent'] = 389;
  15649. t['ecircumflex'] = 444;
  15650. t['Uring'] = 722;
  15651. t['Udieresis'] = 722;
  15652. t['aogonek'] = 500;
  15653. t['Uacute'] = 722;
  15654. t['uogonek'] = 556;
  15655. t['Edieresis'] = 667;
  15656. t['Dcroat'] = 722;
  15657. t['commaaccent'] = 250;
  15658. t['copyright'] = 747;
  15659. t['Emacron'] = 667;
  15660. t['ccaron'] = 444;
  15661. t['aring'] = 500;
  15662. t['Ncommaaccent'] = 722;
  15663. t['lacute'] = 278;
  15664. t['agrave'] = 500;
  15665. t['Tcommaaccent'] = 667;
  15666. t['Cacute'] = 722;
  15667. t['atilde'] = 500;
  15668. t['Edotaccent'] = 667;
  15669. t['scaron'] = 389;
  15670. t['scedilla'] = 389;
  15671. t['iacute'] = 278;
  15672. t['lozenge'] = 494;
  15673. t['Rcaron'] = 722;
  15674. t['Gcommaaccent'] = 778;
  15675. t['ucircumflex'] = 556;
  15676. t['acircumflex'] = 500;
  15677. t['Amacron'] = 722;
  15678. t['rcaron'] = 444;
  15679. t['ccedilla'] = 444;
  15680. t['Zdotaccent'] = 667;
  15681. t['Thorn'] = 611;
  15682. t['Omacron'] = 778;
  15683. t['Racute'] = 722;
  15684. t['Sacute'] = 556;
  15685. t['dcaron'] = 672;
  15686. t['Umacron'] = 722;
  15687. t['uring'] = 556;
  15688. t['threesuperior'] = 300;
  15689. t['Ograve'] = 778;
  15690. t['Agrave'] = 722;
  15691. t['Abreve'] = 722;
  15692. t['multiply'] = 570;
  15693. t['uacute'] = 556;
  15694. t['Tcaron'] = 667;
  15695. t['partialdiff'] = 494;
  15696. t['ydieresis'] = 500;
  15697. t['Nacute'] = 722;
  15698. t['icircumflex'] = 278;
  15699. t['Ecircumflex'] = 667;
  15700. t['adieresis'] = 500;
  15701. t['edieresis'] = 444;
  15702. t['cacute'] = 444;
  15703. t['nacute'] = 556;
  15704. t['umacron'] = 556;
  15705. t['Ncaron'] = 722;
  15706. t['Iacute'] = 389;
  15707. t['plusminus'] = 570;
  15708. t['brokenbar'] = 220;
  15709. t['registered'] = 747;
  15710. t['Gbreve'] = 778;
  15711. t['Idotaccent'] = 389;
  15712. t['summation'] = 600;
  15713. t['Egrave'] = 667;
  15714. t['racute'] = 444;
  15715. t['omacron'] = 500;
  15716. t['Zacute'] = 667;
  15717. t['Zcaron'] = 667;
  15718. t['greaterequal'] = 549;
  15719. t['Eth'] = 722;
  15720. t['Ccedilla'] = 722;
  15721. t['lcommaaccent'] = 278;
  15722. t['tcaron'] = 416;
  15723. t['eogonek'] = 444;
  15724. t['Uogonek'] = 722;
  15725. t['Aacute'] = 722;
  15726. t['Adieresis'] = 722;
  15727. t['egrave'] = 444;
  15728. t['zacute'] = 444;
  15729. t['iogonek'] = 278;
  15730. t['Oacute'] = 778;
  15731. t['oacute'] = 500;
  15732. t['amacron'] = 500;
  15733. t['sacute'] = 389;
  15734. t['idieresis'] = 278;
  15735. t['Ocircumflex'] = 778;
  15736. t['Ugrave'] = 722;
  15737. t['Delta'] = 612;
  15738. t['thorn'] = 556;
  15739. t['twosuperior'] = 300;
  15740. t['Odieresis'] = 778;
  15741. t['mu'] = 556;
  15742. t['igrave'] = 278;
  15743. t['ohungarumlaut'] = 500;
  15744. t['Eogonek'] = 667;
  15745. t['dcroat'] = 556;
  15746. t['threequarters'] = 750;
  15747. t['Scedilla'] = 556;
  15748. t['lcaron'] = 394;
  15749. t['Kcommaaccent'] = 778;
  15750. t['Lacute'] = 667;
  15751. t['trademark'] = 1000;
  15752. t['edotaccent'] = 444;
  15753. t['Igrave'] = 389;
  15754. t['Imacron'] = 389;
  15755. t['Lcaron'] = 667;
  15756. t['onehalf'] = 750;
  15757. t['lessequal'] = 549;
  15758. t['ocircumflex'] = 500;
  15759. t['ntilde'] = 556;
  15760. t['Uhungarumlaut'] = 722;
  15761. t['Eacute'] = 667;
  15762. t['emacron'] = 444;
  15763. t['gbreve'] = 500;
  15764. t['onequarter'] = 750;
  15765. t['Scaron'] = 556;
  15766. t['Scommaaccent'] = 556;
  15767. t['Ohungarumlaut'] = 778;
  15768. t['degree'] = 400;
  15769. t['ograve'] = 500;
  15770. t['Ccaron'] = 722;
  15771. t['ugrave'] = 556;
  15772. t['radical'] = 549;
  15773. t['Dcaron'] = 722;
  15774. t['rcommaaccent'] = 444;
  15775. t['Ntilde'] = 722;
  15776. t['otilde'] = 500;
  15777. t['Rcommaaccent'] = 722;
  15778. t['Lcommaaccent'] = 667;
  15779. t['Atilde'] = 722;
  15780. t['Aogonek'] = 722;
  15781. t['Aring'] = 722;
  15782. t['Otilde'] = 778;
  15783. t['zdotaccent'] = 444;
  15784. t['Ecaron'] = 667;
  15785. t['Iogonek'] = 389;
  15786. t['kcommaaccent'] = 556;
  15787. t['minus'] = 570;
  15788. t['Icircumflex'] = 389;
  15789. t['ncaron'] = 556;
  15790. t['tcommaaccent'] = 333;
  15791. t['logicalnot'] = 570;
  15792. t['odieresis'] = 500;
  15793. t['udieresis'] = 556;
  15794. t['notequal'] = 549;
  15795. t['gcommaaccent'] = 500;
  15796. t['eth'] = 500;
  15797. t['zcaron'] = 444;
  15798. t['ncommaaccent'] = 556;
  15799. t['onesuperior'] = 300;
  15800. t['imacron'] = 278;
  15801. t['Euro'] = 500;
  15802. });
  15803. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15804. t['space'] = 250;
  15805. t['exclam'] = 389;
  15806. t['quotedbl'] = 555;
  15807. t['numbersign'] = 500;
  15808. t['dollar'] = 500;
  15809. t['percent'] = 833;
  15810. t['ampersand'] = 778;
  15811. t['quoteright'] = 333;
  15812. t['parenleft'] = 333;
  15813. t['parenright'] = 333;
  15814. t['asterisk'] = 500;
  15815. t['plus'] = 570;
  15816. t['comma'] = 250;
  15817. t['hyphen'] = 333;
  15818. t['period'] = 250;
  15819. t['slash'] = 278;
  15820. t['zero'] = 500;
  15821. t['one'] = 500;
  15822. t['two'] = 500;
  15823. t['three'] = 500;
  15824. t['four'] = 500;
  15825. t['five'] = 500;
  15826. t['six'] = 500;
  15827. t['seven'] = 500;
  15828. t['eight'] = 500;
  15829. t['nine'] = 500;
  15830. t['colon'] = 333;
  15831. t['semicolon'] = 333;
  15832. t['less'] = 570;
  15833. t['equal'] = 570;
  15834. t['greater'] = 570;
  15835. t['question'] = 500;
  15836. t['at'] = 832;
  15837. t['A'] = 667;
  15838. t['B'] = 667;
  15839. t['C'] = 667;
  15840. t['D'] = 722;
  15841. t['E'] = 667;
  15842. t['F'] = 667;
  15843. t['G'] = 722;
  15844. t['H'] = 778;
  15845. t['I'] = 389;
  15846. t['J'] = 500;
  15847. t['K'] = 667;
  15848. t['L'] = 611;
  15849. t['M'] = 889;
  15850. t['N'] = 722;
  15851. t['O'] = 722;
  15852. t['P'] = 611;
  15853. t['Q'] = 722;
  15854. t['R'] = 667;
  15855. t['S'] = 556;
  15856. t['T'] = 611;
  15857. t['U'] = 722;
  15858. t['V'] = 667;
  15859. t['W'] = 889;
  15860. t['X'] = 667;
  15861. t['Y'] = 611;
  15862. t['Z'] = 611;
  15863. t['bracketleft'] = 333;
  15864. t['backslash'] = 278;
  15865. t['bracketright'] = 333;
  15866. t['asciicircum'] = 570;
  15867. t['underscore'] = 500;
  15868. t['quoteleft'] = 333;
  15869. t['a'] = 500;
  15870. t['b'] = 500;
  15871. t['c'] = 444;
  15872. t['d'] = 500;
  15873. t['e'] = 444;
  15874. t['f'] = 333;
  15875. t['g'] = 500;
  15876. t['h'] = 556;
  15877. t['i'] = 278;
  15878. t['j'] = 278;
  15879. t['k'] = 500;
  15880. t['l'] = 278;
  15881. t['m'] = 778;
  15882. t['n'] = 556;
  15883. t['o'] = 500;
  15884. t['p'] = 500;
  15885. t['q'] = 500;
  15886. t['r'] = 389;
  15887. t['s'] = 389;
  15888. t['t'] = 278;
  15889. t['u'] = 556;
  15890. t['v'] = 444;
  15891. t['w'] = 667;
  15892. t['x'] = 500;
  15893. t['y'] = 444;
  15894. t['z'] = 389;
  15895. t['braceleft'] = 348;
  15896. t['bar'] = 220;
  15897. t['braceright'] = 348;
  15898. t['asciitilde'] = 570;
  15899. t['exclamdown'] = 389;
  15900. t['cent'] = 500;
  15901. t['sterling'] = 500;
  15902. t['fraction'] = 167;
  15903. t['yen'] = 500;
  15904. t['florin'] = 500;
  15905. t['section'] = 500;
  15906. t['currency'] = 500;
  15907. t['quotesingle'] = 278;
  15908. t['quotedblleft'] = 500;
  15909. t['guillemotleft'] = 500;
  15910. t['guilsinglleft'] = 333;
  15911. t['guilsinglright'] = 333;
  15912. t['fi'] = 556;
  15913. t['fl'] = 556;
  15914. t['endash'] = 500;
  15915. t['dagger'] = 500;
  15916. t['daggerdbl'] = 500;
  15917. t['periodcentered'] = 250;
  15918. t['paragraph'] = 500;
  15919. t['bullet'] = 350;
  15920. t['quotesinglbase'] = 333;
  15921. t['quotedblbase'] = 500;
  15922. t['quotedblright'] = 500;
  15923. t['guillemotright'] = 500;
  15924. t['ellipsis'] = 1000;
  15925. t['perthousand'] = 1000;
  15926. t['questiondown'] = 500;
  15927. t['grave'] = 333;
  15928. t['acute'] = 333;
  15929. t['circumflex'] = 333;
  15930. t['tilde'] = 333;
  15931. t['macron'] = 333;
  15932. t['breve'] = 333;
  15933. t['dotaccent'] = 333;
  15934. t['dieresis'] = 333;
  15935. t['ring'] = 333;
  15936. t['cedilla'] = 333;
  15937. t['hungarumlaut'] = 333;
  15938. t['ogonek'] = 333;
  15939. t['caron'] = 333;
  15940. t['emdash'] = 1000;
  15941. t['AE'] = 944;
  15942. t['ordfeminine'] = 266;
  15943. t['Lslash'] = 611;
  15944. t['Oslash'] = 722;
  15945. t['OE'] = 944;
  15946. t['ordmasculine'] = 300;
  15947. t['ae'] = 722;
  15948. t['dotlessi'] = 278;
  15949. t['lslash'] = 278;
  15950. t['oslash'] = 500;
  15951. t['oe'] = 722;
  15952. t['germandbls'] = 500;
  15953. t['Idieresis'] = 389;
  15954. t['eacute'] = 444;
  15955. t['abreve'] = 500;
  15956. t['uhungarumlaut'] = 556;
  15957. t['ecaron'] = 444;
  15958. t['Ydieresis'] = 611;
  15959. t['divide'] = 570;
  15960. t['Yacute'] = 611;
  15961. t['Acircumflex'] = 667;
  15962. t['aacute'] = 500;
  15963. t['Ucircumflex'] = 722;
  15964. t['yacute'] = 444;
  15965. t['scommaaccent'] = 389;
  15966. t['ecircumflex'] = 444;
  15967. t['Uring'] = 722;
  15968. t['Udieresis'] = 722;
  15969. t['aogonek'] = 500;
  15970. t['Uacute'] = 722;
  15971. t['uogonek'] = 556;
  15972. t['Edieresis'] = 667;
  15973. t['Dcroat'] = 722;
  15974. t['commaaccent'] = 250;
  15975. t['copyright'] = 747;
  15976. t['Emacron'] = 667;
  15977. t['ccaron'] = 444;
  15978. t['aring'] = 500;
  15979. t['Ncommaaccent'] = 722;
  15980. t['lacute'] = 278;
  15981. t['agrave'] = 500;
  15982. t['Tcommaaccent'] = 611;
  15983. t['Cacute'] = 667;
  15984. t['atilde'] = 500;
  15985. t['Edotaccent'] = 667;
  15986. t['scaron'] = 389;
  15987. t['scedilla'] = 389;
  15988. t['iacute'] = 278;
  15989. t['lozenge'] = 494;
  15990. t['Rcaron'] = 667;
  15991. t['Gcommaaccent'] = 722;
  15992. t['ucircumflex'] = 556;
  15993. t['acircumflex'] = 500;
  15994. t['Amacron'] = 667;
  15995. t['rcaron'] = 389;
  15996. t['ccedilla'] = 444;
  15997. t['Zdotaccent'] = 611;
  15998. t['Thorn'] = 611;
  15999. t['Omacron'] = 722;
  16000. t['Racute'] = 667;
  16001. t['Sacute'] = 556;
  16002. t['dcaron'] = 608;
  16003. t['Umacron'] = 722;
  16004. t['uring'] = 556;
  16005. t['threesuperior'] = 300;
  16006. t['Ograve'] = 722;
  16007. t['Agrave'] = 667;
  16008. t['Abreve'] = 667;
  16009. t['multiply'] = 570;
  16010. t['uacute'] = 556;
  16011. t['Tcaron'] = 611;
  16012. t['partialdiff'] = 494;
  16013. t['ydieresis'] = 444;
  16014. t['Nacute'] = 722;
  16015. t['icircumflex'] = 278;
  16016. t['Ecircumflex'] = 667;
  16017. t['adieresis'] = 500;
  16018. t['edieresis'] = 444;
  16019. t['cacute'] = 444;
  16020. t['nacute'] = 556;
  16021. t['umacron'] = 556;
  16022. t['Ncaron'] = 722;
  16023. t['Iacute'] = 389;
  16024. t['plusminus'] = 570;
  16025. t['brokenbar'] = 220;
  16026. t['registered'] = 747;
  16027. t['Gbreve'] = 722;
  16028. t['Idotaccent'] = 389;
  16029. t['summation'] = 600;
  16030. t['Egrave'] = 667;
  16031. t['racute'] = 389;
  16032. t['omacron'] = 500;
  16033. t['Zacute'] = 611;
  16034. t['Zcaron'] = 611;
  16035. t['greaterequal'] = 549;
  16036. t['Eth'] = 722;
  16037. t['Ccedilla'] = 667;
  16038. t['lcommaaccent'] = 278;
  16039. t['tcaron'] = 366;
  16040. t['eogonek'] = 444;
  16041. t['Uogonek'] = 722;
  16042. t['Aacute'] = 667;
  16043. t['Adieresis'] = 667;
  16044. t['egrave'] = 444;
  16045. t['zacute'] = 389;
  16046. t['iogonek'] = 278;
  16047. t['Oacute'] = 722;
  16048. t['oacute'] = 500;
  16049. t['amacron'] = 500;
  16050. t['sacute'] = 389;
  16051. t['idieresis'] = 278;
  16052. t['Ocircumflex'] = 722;
  16053. t['Ugrave'] = 722;
  16054. t['Delta'] = 612;
  16055. t['thorn'] = 500;
  16056. t['twosuperior'] = 300;
  16057. t['Odieresis'] = 722;
  16058. t['mu'] = 576;
  16059. t['igrave'] = 278;
  16060. t['ohungarumlaut'] = 500;
  16061. t['Eogonek'] = 667;
  16062. t['dcroat'] = 500;
  16063. t['threequarters'] = 750;
  16064. t['Scedilla'] = 556;
  16065. t['lcaron'] = 382;
  16066. t['Kcommaaccent'] = 667;
  16067. t['Lacute'] = 611;
  16068. t['trademark'] = 1000;
  16069. t['edotaccent'] = 444;
  16070. t['Igrave'] = 389;
  16071. t['Imacron'] = 389;
  16072. t['Lcaron'] = 611;
  16073. t['onehalf'] = 750;
  16074. t['lessequal'] = 549;
  16075. t['ocircumflex'] = 500;
  16076. t['ntilde'] = 556;
  16077. t['Uhungarumlaut'] = 722;
  16078. t['Eacute'] = 667;
  16079. t['emacron'] = 444;
  16080. t['gbreve'] = 500;
  16081. t['onequarter'] = 750;
  16082. t['Scaron'] = 556;
  16083. t['Scommaaccent'] = 556;
  16084. t['Ohungarumlaut'] = 722;
  16085. t['degree'] = 400;
  16086. t['ograve'] = 500;
  16087. t['Ccaron'] = 667;
  16088. t['ugrave'] = 556;
  16089. t['radical'] = 549;
  16090. t['Dcaron'] = 722;
  16091. t['rcommaaccent'] = 389;
  16092. t['Ntilde'] = 722;
  16093. t['otilde'] = 500;
  16094. t['Rcommaaccent'] = 667;
  16095. t['Lcommaaccent'] = 611;
  16096. t['Atilde'] = 667;
  16097. t['Aogonek'] = 667;
  16098. t['Aring'] = 667;
  16099. t['Otilde'] = 722;
  16100. t['zdotaccent'] = 389;
  16101. t['Ecaron'] = 667;
  16102. t['Iogonek'] = 389;
  16103. t['kcommaaccent'] = 500;
  16104. t['minus'] = 606;
  16105. t['Icircumflex'] = 389;
  16106. t['ncaron'] = 556;
  16107. t['tcommaaccent'] = 278;
  16108. t['logicalnot'] = 606;
  16109. t['odieresis'] = 500;
  16110. t['udieresis'] = 556;
  16111. t['notequal'] = 549;
  16112. t['gcommaaccent'] = 500;
  16113. t['eth'] = 500;
  16114. t['zcaron'] = 389;
  16115. t['ncommaaccent'] = 556;
  16116. t['onesuperior'] = 300;
  16117. t['imacron'] = 278;
  16118. t['Euro'] = 500;
  16119. });
  16120. t['Times-Italic'] = getLookupTableFactory(function (t) {
  16121. t['space'] = 250;
  16122. t['exclam'] = 333;
  16123. t['quotedbl'] = 420;
  16124. t['numbersign'] = 500;
  16125. t['dollar'] = 500;
  16126. t['percent'] = 833;
  16127. t['ampersand'] = 778;
  16128. t['quoteright'] = 333;
  16129. t['parenleft'] = 333;
  16130. t['parenright'] = 333;
  16131. t['asterisk'] = 500;
  16132. t['plus'] = 675;
  16133. t['comma'] = 250;
  16134. t['hyphen'] = 333;
  16135. t['period'] = 250;
  16136. t['slash'] = 278;
  16137. t['zero'] = 500;
  16138. t['one'] = 500;
  16139. t['two'] = 500;
  16140. t['three'] = 500;
  16141. t['four'] = 500;
  16142. t['five'] = 500;
  16143. t['six'] = 500;
  16144. t['seven'] = 500;
  16145. t['eight'] = 500;
  16146. t['nine'] = 500;
  16147. t['colon'] = 333;
  16148. t['semicolon'] = 333;
  16149. t['less'] = 675;
  16150. t['equal'] = 675;
  16151. t['greater'] = 675;
  16152. t['question'] = 500;
  16153. t['at'] = 920;
  16154. t['A'] = 611;
  16155. t['B'] = 611;
  16156. t['C'] = 667;
  16157. t['D'] = 722;
  16158. t['E'] = 611;
  16159. t['F'] = 611;
  16160. t['G'] = 722;
  16161. t['H'] = 722;
  16162. t['I'] = 333;
  16163. t['J'] = 444;
  16164. t['K'] = 667;
  16165. t['L'] = 556;
  16166. t['M'] = 833;
  16167. t['N'] = 667;
  16168. t['O'] = 722;
  16169. t['P'] = 611;
  16170. t['Q'] = 722;
  16171. t['R'] = 611;
  16172. t['S'] = 500;
  16173. t['T'] = 556;
  16174. t['U'] = 722;
  16175. t['V'] = 611;
  16176. t['W'] = 833;
  16177. t['X'] = 611;
  16178. t['Y'] = 556;
  16179. t['Z'] = 556;
  16180. t['bracketleft'] = 389;
  16181. t['backslash'] = 278;
  16182. t['bracketright'] = 389;
  16183. t['asciicircum'] = 422;
  16184. t['underscore'] = 500;
  16185. t['quoteleft'] = 333;
  16186. t['a'] = 500;
  16187. t['b'] = 500;
  16188. t['c'] = 444;
  16189. t['d'] = 500;
  16190. t['e'] = 444;
  16191. t['f'] = 278;
  16192. t['g'] = 500;
  16193. t['h'] = 500;
  16194. t['i'] = 278;
  16195. t['j'] = 278;
  16196. t['k'] = 444;
  16197. t['l'] = 278;
  16198. t['m'] = 722;
  16199. t['n'] = 500;
  16200. t['o'] = 500;
  16201. t['p'] = 500;
  16202. t['q'] = 500;
  16203. t['r'] = 389;
  16204. t['s'] = 389;
  16205. t['t'] = 278;
  16206. t['u'] = 500;
  16207. t['v'] = 444;
  16208. t['w'] = 667;
  16209. t['x'] = 444;
  16210. t['y'] = 444;
  16211. t['z'] = 389;
  16212. t['braceleft'] = 400;
  16213. t['bar'] = 275;
  16214. t['braceright'] = 400;
  16215. t['asciitilde'] = 541;
  16216. t['exclamdown'] = 389;
  16217. t['cent'] = 500;
  16218. t['sterling'] = 500;
  16219. t['fraction'] = 167;
  16220. t['yen'] = 500;
  16221. t['florin'] = 500;
  16222. t['section'] = 500;
  16223. t['currency'] = 500;
  16224. t['quotesingle'] = 214;
  16225. t['quotedblleft'] = 556;
  16226. t['guillemotleft'] = 500;
  16227. t['guilsinglleft'] = 333;
  16228. t['guilsinglright'] = 333;
  16229. t['fi'] = 500;
  16230. t['fl'] = 500;
  16231. t['endash'] = 500;
  16232. t['dagger'] = 500;
  16233. t['daggerdbl'] = 500;
  16234. t['periodcentered'] = 250;
  16235. t['paragraph'] = 523;
  16236. t['bullet'] = 350;
  16237. t['quotesinglbase'] = 333;
  16238. t['quotedblbase'] = 556;
  16239. t['quotedblright'] = 556;
  16240. t['guillemotright'] = 500;
  16241. t['ellipsis'] = 889;
  16242. t['perthousand'] = 1000;
  16243. t['questiondown'] = 500;
  16244. t['grave'] = 333;
  16245. t['acute'] = 333;
  16246. t['circumflex'] = 333;
  16247. t['tilde'] = 333;
  16248. t['macron'] = 333;
  16249. t['breve'] = 333;
  16250. t['dotaccent'] = 333;
  16251. t['dieresis'] = 333;
  16252. t['ring'] = 333;
  16253. t['cedilla'] = 333;
  16254. t['hungarumlaut'] = 333;
  16255. t['ogonek'] = 333;
  16256. t['caron'] = 333;
  16257. t['emdash'] = 889;
  16258. t['AE'] = 889;
  16259. t['ordfeminine'] = 276;
  16260. t['Lslash'] = 556;
  16261. t['Oslash'] = 722;
  16262. t['OE'] = 944;
  16263. t['ordmasculine'] = 310;
  16264. t['ae'] = 667;
  16265. t['dotlessi'] = 278;
  16266. t['lslash'] = 278;
  16267. t['oslash'] = 500;
  16268. t['oe'] = 667;
  16269. t['germandbls'] = 500;
  16270. t['Idieresis'] = 333;
  16271. t['eacute'] = 444;
  16272. t['abreve'] = 500;
  16273. t['uhungarumlaut'] = 500;
  16274. t['ecaron'] = 444;
  16275. t['Ydieresis'] = 556;
  16276. t['divide'] = 675;
  16277. t['Yacute'] = 556;
  16278. t['Acircumflex'] = 611;
  16279. t['aacute'] = 500;
  16280. t['Ucircumflex'] = 722;
  16281. t['yacute'] = 444;
  16282. t['scommaaccent'] = 389;
  16283. t['ecircumflex'] = 444;
  16284. t['Uring'] = 722;
  16285. t['Udieresis'] = 722;
  16286. t['aogonek'] = 500;
  16287. t['Uacute'] = 722;
  16288. t['uogonek'] = 500;
  16289. t['Edieresis'] = 611;
  16290. t['Dcroat'] = 722;
  16291. t['commaaccent'] = 250;
  16292. t['copyright'] = 760;
  16293. t['Emacron'] = 611;
  16294. t['ccaron'] = 444;
  16295. t['aring'] = 500;
  16296. t['Ncommaaccent'] = 667;
  16297. t['lacute'] = 278;
  16298. t['agrave'] = 500;
  16299. t['Tcommaaccent'] = 556;
  16300. t['Cacute'] = 667;
  16301. t['atilde'] = 500;
  16302. t['Edotaccent'] = 611;
  16303. t['scaron'] = 389;
  16304. t['scedilla'] = 389;
  16305. t['iacute'] = 278;
  16306. t['lozenge'] = 471;
  16307. t['Rcaron'] = 611;
  16308. t['Gcommaaccent'] = 722;
  16309. t['ucircumflex'] = 500;
  16310. t['acircumflex'] = 500;
  16311. t['Amacron'] = 611;
  16312. t['rcaron'] = 389;
  16313. t['ccedilla'] = 444;
  16314. t['Zdotaccent'] = 556;
  16315. t['Thorn'] = 611;
  16316. t['Omacron'] = 722;
  16317. t['Racute'] = 611;
  16318. t['Sacute'] = 500;
  16319. t['dcaron'] = 544;
  16320. t['Umacron'] = 722;
  16321. t['uring'] = 500;
  16322. t['threesuperior'] = 300;
  16323. t['Ograve'] = 722;
  16324. t['Agrave'] = 611;
  16325. t['Abreve'] = 611;
  16326. t['multiply'] = 675;
  16327. t['uacute'] = 500;
  16328. t['Tcaron'] = 556;
  16329. t['partialdiff'] = 476;
  16330. t['ydieresis'] = 444;
  16331. t['Nacute'] = 667;
  16332. t['icircumflex'] = 278;
  16333. t['Ecircumflex'] = 611;
  16334. t['adieresis'] = 500;
  16335. t['edieresis'] = 444;
  16336. t['cacute'] = 444;
  16337. t['nacute'] = 500;
  16338. t['umacron'] = 500;
  16339. t['Ncaron'] = 667;
  16340. t['Iacute'] = 333;
  16341. t['plusminus'] = 675;
  16342. t['brokenbar'] = 275;
  16343. t['registered'] = 760;
  16344. t['Gbreve'] = 722;
  16345. t['Idotaccent'] = 333;
  16346. t['summation'] = 600;
  16347. t['Egrave'] = 611;
  16348. t['racute'] = 389;
  16349. t['omacron'] = 500;
  16350. t['Zacute'] = 556;
  16351. t['Zcaron'] = 556;
  16352. t['greaterequal'] = 549;
  16353. t['Eth'] = 722;
  16354. t['Ccedilla'] = 667;
  16355. t['lcommaaccent'] = 278;
  16356. t['tcaron'] = 300;
  16357. t['eogonek'] = 444;
  16358. t['Uogonek'] = 722;
  16359. t['Aacute'] = 611;
  16360. t['Adieresis'] = 611;
  16361. t['egrave'] = 444;
  16362. t['zacute'] = 389;
  16363. t['iogonek'] = 278;
  16364. t['Oacute'] = 722;
  16365. t['oacute'] = 500;
  16366. t['amacron'] = 500;
  16367. t['sacute'] = 389;
  16368. t['idieresis'] = 278;
  16369. t['Ocircumflex'] = 722;
  16370. t['Ugrave'] = 722;
  16371. t['Delta'] = 612;
  16372. t['thorn'] = 500;
  16373. t['twosuperior'] = 300;
  16374. t['Odieresis'] = 722;
  16375. t['mu'] = 500;
  16376. t['igrave'] = 278;
  16377. t['ohungarumlaut'] = 500;
  16378. t['Eogonek'] = 611;
  16379. t['dcroat'] = 500;
  16380. t['threequarters'] = 750;
  16381. t['Scedilla'] = 500;
  16382. t['lcaron'] = 300;
  16383. t['Kcommaaccent'] = 667;
  16384. t['Lacute'] = 556;
  16385. t['trademark'] = 980;
  16386. t['edotaccent'] = 444;
  16387. t['Igrave'] = 333;
  16388. t['Imacron'] = 333;
  16389. t['Lcaron'] = 611;
  16390. t['onehalf'] = 750;
  16391. t['lessequal'] = 549;
  16392. t['ocircumflex'] = 500;
  16393. t['ntilde'] = 500;
  16394. t['Uhungarumlaut'] = 722;
  16395. t['Eacute'] = 611;
  16396. t['emacron'] = 444;
  16397. t['gbreve'] = 500;
  16398. t['onequarter'] = 750;
  16399. t['Scaron'] = 500;
  16400. t['Scommaaccent'] = 500;
  16401. t['Ohungarumlaut'] = 722;
  16402. t['degree'] = 400;
  16403. t['ograve'] = 500;
  16404. t['Ccaron'] = 667;
  16405. t['ugrave'] = 500;
  16406. t['radical'] = 453;
  16407. t['Dcaron'] = 722;
  16408. t['rcommaaccent'] = 389;
  16409. t['Ntilde'] = 667;
  16410. t['otilde'] = 500;
  16411. t['Rcommaaccent'] = 611;
  16412. t['Lcommaaccent'] = 556;
  16413. t['Atilde'] = 611;
  16414. t['Aogonek'] = 611;
  16415. t['Aring'] = 611;
  16416. t['Otilde'] = 722;
  16417. t['zdotaccent'] = 389;
  16418. t['Ecaron'] = 611;
  16419. t['Iogonek'] = 333;
  16420. t['kcommaaccent'] = 444;
  16421. t['minus'] = 675;
  16422. t['Icircumflex'] = 333;
  16423. t['ncaron'] = 500;
  16424. t['tcommaaccent'] = 278;
  16425. t['logicalnot'] = 675;
  16426. t['odieresis'] = 500;
  16427. t['udieresis'] = 500;
  16428. t['notequal'] = 549;
  16429. t['gcommaaccent'] = 500;
  16430. t['eth'] = 500;
  16431. t['zcaron'] = 389;
  16432. t['ncommaaccent'] = 500;
  16433. t['onesuperior'] = 300;
  16434. t['imacron'] = 278;
  16435. t['Euro'] = 500;
  16436. });
  16437. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16438. t['space'] = 278;
  16439. t['a1'] = 974;
  16440. t['a2'] = 961;
  16441. t['a202'] = 974;
  16442. t['a3'] = 980;
  16443. t['a4'] = 719;
  16444. t['a5'] = 789;
  16445. t['a119'] = 790;
  16446. t['a118'] = 791;
  16447. t['a117'] = 690;
  16448. t['a11'] = 960;
  16449. t['a12'] = 939;
  16450. t['a13'] = 549;
  16451. t['a14'] = 855;
  16452. t['a15'] = 911;
  16453. t['a16'] = 933;
  16454. t['a105'] = 911;
  16455. t['a17'] = 945;
  16456. t['a18'] = 974;
  16457. t['a19'] = 755;
  16458. t['a20'] = 846;
  16459. t['a21'] = 762;
  16460. t['a22'] = 761;
  16461. t['a23'] = 571;
  16462. t['a24'] = 677;
  16463. t['a25'] = 763;
  16464. t['a26'] = 760;
  16465. t['a27'] = 759;
  16466. t['a28'] = 754;
  16467. t['a6'] = 494;
  16468. t['a7'] = 552;
  16469. t['a8'] = 537;
  16470. t['a9'] = 577;
  16471. t['a10'] = 692;
  16472. t['a29'] = 786;
  16473. t['a30'] = 788;
  16474. t['a31'] = 788;
  16475. t['a32'] = 790;
  16476. t['a33'] = 793;
  16477. t['a34'] = 794;
  16478. t['a35'] = 816;
  16479. t['a36'] = 823;
  16480. t['a37'] = 789;
  16481. t['a38'] = 841;
  16482. t['a39'] = 823;
  16483. t['a40'] = 833;
  16484. t['a41'] = 816;
  16485. t['a42'] = 831;
  16486. t['a43'] = 923;
  16487. t['a44'] = 744;
  16488. t['a45'] = 723;
  16489. t['a46'] = 749;
  16490. t['a47'] = 790;
  16491. t['a48'] = 792;
  16492. t['a49'] = 695;
  16493. t['a50'] = 776;
  16494. t['a51'] = 768;
  16495. t['a52'] = 792;
  16496. t['a53'] = 759;
  16497. t['a54'] = 707;
  16498. t['a55'] = 708;
  16499. t['a56'] = 682;
  16500. t['a57'] = 701;
  16501. t['a58'] = 826;
  16502. t['a59'] = 815;
  16503. t['a60'] = 789;
  16504. t['a61'] = 789;
  16505. t['a62'] = 707;
  16506. t['a63'] = 687;
  16507. t['a64'] = 696;
  16508. t['a65'] = 689;
  16509. t['a66'] = 786;
  16510. t['a67'] = 787;
  16511. t['a68'] = 713;
  16512. t['a69'] = 791;
  16513. t['a70'] = 785;
  16514. t['a71'] = 791;
  16515. t['a72'] = 873;
  16516. t['a73'] = 761;
  16517. t['a74'] = 762;
  16518. t['a203'] = 762;
  16519. t['a75'] = 759;
  16520. t['a204'] = 759;
  16521. t['a76'] = 892;
  16522. t['a77'] = 892;
  16523. t['a78'] = 788;
  16524. t['a79'] = 784;
  16525. t['a81'] = 438;
  16526. t['a82'] = 138;
  16527. t['a83'] = 277;
  16528. t['a84'] = 415;
  16529. t['a97'] = 392;
  16530. t['a98'] = 392;
  16531. t['a99'] = 668;
  16532. t['a100'] = 668;
  16533. t['a89'] = 390;
  16534. t['a90'] = 390;
  16535. t['a93'] = 317;
  16536. t['a94'] = 317;
  16537. t['a91'] = 276;
  16538. t['a92'] = 276;
  16539. t['a205'] = 509;
  16540. t['a85'] = 509;
  16541. t['a206'] = 410;
  16542. t['a86'] = 410;
  16543. t['a87'] = 234;
  16544. t['a88'] = 234;
  16545. t['a95'] = 334;
  16546. t['a96'] = 334;
  16547. t['a101'] = 732;
  16548. t['a102'] = 544;
  16549. t['a103'] = 544;
  16550. t['a104'] = 910;
  16551. t['a106'] = 667;
  16552. t['a107'] = 760;
  16553. t['a108'] = 760;
  16554. t['a112'] = 776;
  16555. t['a111'] = 595;
  16556. t['a110'] = 694;
  16557. t['a109'] = 626;
  16558. t['a120'] = 788;
  16559. t['a121'] = 788;
  16560. t['a122'] = 788;
  16561. t['a123'] = 788;
  16562. t['a124'] = 788;
  16563. t['a125'] = 788;
  16564. t['a126'] = 788;
  16565. t['a127'] = 788;
  16566. t['a128'] = 788;
  16567. t['a129'] = 788;
  16568. t['a130'] = 788;
  16569. t['a131'] = 788;
  16570. t['a132'] = 788;
  16571. t['a133'] = 788;
  16572. t['a134'] = 788;
  16573. t['a135'] = 788;
  16574. t['a136'] = 788;
  16575. t['a137'] = 788;
  16576. t['a138'] = 788;
  16577. t['a139'] = 788;
  16578. t['a140'] = 788;
  16579. t['a141'] = 788;
  16580. t['a142'] = 788;
  16581. t['a143'] = 788;
  16582. t['a144'] = 788;
  16583. t['a145'] = 788;
  16584. t['a146'] = 788;
  16585. t['a147'] = 788;
  16586. t['a148'] = 788;
  16587. t['a149'] = 788;
  16588. t['a150'] = 788;
  16589. t['a151'] = 788;
  16590. t['a152'] = 788;
  16591. t['a153'] = 788;
  16592. t['a154'] = 788;
  16593. t['a155'] = 788;
  16594. t['a156'] = 788;
  16595. t['a157'] = 788;
  16596. t['a158'] = 788;
  16597. t['a159'] = 788;
  16598. t['a160'] = 894;
  16599. t['a161'] = 838;
  16600. t['a163'] = 1016;
  16601. t['a164'] = 458;
  16602. t['a196'] = 748;
  16603. t['a165'] = 924;
  16604. t['a192'] = 748;
  16605. t['a166'] = 918;
  16606. t['a167'] = 927;
  16607. t['a168'] = 928;
  16608. t['a169'] = 928;
  16609. t['a170'] = 834;
  16610. t['a171'] = 873;
  16611. t['a172'] = 828;
  16612. t['a173'] = 924;
  16613. t['a162'] = 924;
  16614. t['a174'] = 917;
  16615. t['a175'] = 930;
  16616. t['a176'] = 931;
  16617. t['a177'] = 463;
  16618. t['a178'] = 883;
  16619. t['a179'] = 836;
  16620. t['a193'] = 836;
  16621. t['a180'] = 867;
  16622. t['a199'] = 867;
  16623. t['a181'] = 696;
  16624. t['a200'] = 696;
  16625. t['a182'] = 874;
  16626. t['a201'] = 874;
  16627. t['a183'] = 760;
  16628. t['a184'] = 946;
  16629. t['a197'] = 771;
  16630. t['a185'] = 865;
  16631. t['a194'] = 771;
  16632. t['a198'] = 888;
  16633. t['a186'] = 967;
  16634. t['a195'] = 888;
  16635. t['a187'] = 831;
  16636. t['a188'] = 873;
  16637. t['a189'] = 927;
  16638. t['a190'] = 970;
  16639. t['a191'] = 918;
  16640. });
  16641. });
  16642. exports.getMetrics = getMetrics;
  16643. }));
  16644. (function (root, factory) {
  16645. {
  16646. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16647. }
  16648. }(this, function (exports, sharedUtil) {
  16649. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16650. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16651. // Workaround for missing math precision in JS.
  16652. var MASK_HIGH = 0xffff0000;
  16653. var MASK_LOW = 0xffff;
  16654. function MurmurHash3_64 (seed) {
  16655. var SEED = 0xc3d2e1f0;
  16656. this.h1 = seed ? seed & 0xffffffff : SEED;
  16657. this.h2 = seed ? seed & 0xffffffff : SEED;
  16658. }
  16659. var alwaysUseUint32ArrayView = false;
  16660. // old webkits have issues with non-aligned arrays
  16661. try {
  16662. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16663. } catch (e) {
  16664. alwaysUseUint32ArrayView = true;
  16665. }
  16666. MurmurHash3_64.prototype = {
  16667. update: function MurmurHash3_64_update(input) {
  16668. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16669. var i;
  16670. if (typeof input === 'string') {
  16671. var data = new Uint8Array(input.length * 2);
  16672. var length = 0;
  16673. for (i = 0; i < input.length; i++) {
  16674. var code = input.charCodeAt(i);
  16675. if (code <= 0xff) {
  16676. data[length++] = code;
  16677. }
  16678. else {
  16679. data[length++] = code >>> 8;
  16680. data[length++] = code & 0xff;
  16681. }
  16682. }
  16683. } else if (input instanceof Uint8Array) {
  16684. data = input;
  16685. length = data.length;
  16686. } else if (typeof input === 'object' && ('length' in input)) {
  16687. // processing regular arrays as well, e.g. for IE9
  16688. data = input;
  16689. length = data.length;
  16690. useUint32ArrayView = true;
  16691. } else {
  16692. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16693. 'Input must be a string or array.');
  16694. }
  16695. var blockCounts = length >> 2;
  16696. var tailLength = length - blockCounts * 4;
  16697. // we don't care about endianness here
  16698. var dataUint32 = useUint32ArrayView ?
  16699. new Uint32ArrayView(data, blockCounts) :
  16700. new Uint32Array(data.buffer, 0, blockCounts);
  16701. var k1 = 0;
  16702. var k2 = 0;
  16703. var h1 = this.h1;
  16704. var h2 = this.h2;
  16705. var C1 = 0xcc9e2d51;
  16706. var C2 = 0x1b873593;
  16707. var C1_LOW = C1 & MASK_LOW;
  16708. var C2_LOW = C2 & MASK_LOW;
  16709. for (i = 0; i < blockCounts; i++) {
  16710. if (i & 1) {
  16711. k1 = dataUint32[i];
  16712. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16713. k1 = k1 << 15 | k1 >>> 17;
  16714. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16715. h1 ^= k1;
  16716. h1 = h1 << 13 | h1 >>> 19;
  16717. h1 = h1 * 5 + 0xe6546b64;
  16718. } else {
  16719. k2 = dataUint32[i];
  16720. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16721. k2 = k2 << 15 | k2 >>> 17;
  16722. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16723. h2 ^= k2;
  16724. h2 = h2 << 13 | h2 >>> 19;
  16725. h2 = h2 * 5 + 0xe6546b64;
  16726. }
  16727. }
  16728. k1 = 0;
  16729. switch (tailLength) {
  16730. case 3:
  16731. k1 ^= data[blockCounts * 4 + 2] << 16;
  16732. /* falls through */
  16733. case 2:
  16734. k1 ^= data[blockCounts * 4 + 1] << 8;
  16735. /* falls through */
  16736. case 1:
  16737. k1 ^= data[blockCounts * 4];
  16738. /* falls through */
  16739. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16740. k1 = k1 << 15 | k1 >>> 17;
  16741. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16742. if (blockCounts & 1) {
  16743. h1 ^= k1;
  16744. } else {
  16745. h2 ^= k1;
  16746. }
  16747. }
  16748. this.h1 = h1;
  16749. this.h2 = h2;
  16750. return this;
  16751. },
  16752. hexdigest: function MurmurHash3_64_hexdigest () {
  16753. var h1 = this.h1;
  16754. var h2 = this.h2;
  16755. h1 ^= h2 >>> 1;
  16756. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16757. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16758. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16759. h1 ^= h2 >>> 1;
  16760. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16761. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16762. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16763. h1 ^= h2 >>> 1;
  16764. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16765. var hex = (arr[i] >>> 0).toString(16);
  16766. while (hex.length < 8) {
  16767. hex = '0' + hex;
  16768. }
  16769. str += hex;
  16770. }
  16771. return str;
  16772. }
  16773. };
  16774. return MurmurHash3_64;
  16775. })();
  16776. exports.MurmurHash3_64 = MurmurHash3_64;
  16777. }));
  16778. (function (root, factory) {
  16779. {
  16780. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16781. }
  16782. }(this, function (exports, sharedUtil) {
  16783. var isArray = sharedUtil.isArray;
  16784. var Name = (function NameClosure() {
  16785. function Name(name) {
  16786. this.name = name;
  16787. }
  16788. Name.prototype = {};
  16789. var nameCache = Object.create(null);
  16790. Name.get = function Name_get(name) {
  16791. var nameValue = nameCache[name];
  16792. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16793. };
  16794. return Name;
  16795. })();
  16796. var Cmd = (function CmdClosure() {
  16797. function Cmd(cmd) {
  16798. this.cmd = cmd;
  16799. }
  16800. Cmd.prototype = {};
  16801. var cmdCache = Object.create(null);
  16802. Cmd.get = function Cmd_get(cmd) {
  16803. var cmdValue = cmdCache[cmd];
  16804. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16805. };
  16806. return Cmd;
  16807. })();
  16808. var Dict = (function DictClosure() {
  16809. var nonSerializable = function nonSerializableClosure() {
  16810. return nonSerializable; // creating closure on some variable
  16811. };
  16812. // xref is optional
  16813. function Dict(xref) {
  16814. // Map should only be used internally, use functions below to access.
  16815. this.map = Object.create(null);
  16816. this.xref = xref;
  16817. this.objId = null;
  16818. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16819. }
  16820. Dict.prototype = {
  16821. assignXref: function Dict_assignXref(newXref) {
  16822. this.xref = newXref;
  16823. },
  16824. // automatically dereferences Ref objects
  16825. get: function Dict_get(key1, key2, key3) {
  16826. var value;
  16827. var xref = this.xref;
  16828. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16829. typeof key2 === 'undefined') {
  16830. return xref ? xref.fetchIfRef(value) : value;
  16831. }
  16832. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16833. typeof key3 === 'undefined') {
  16834. return xref ? xref.fetchIfRef(value) : value;
  16835. }
  16836. value = this.map[key3] || null;
  16837. return xref ? xref.fetchIfRef(value) : value;
  16838. },
  16839. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16840. getAsync: function Dict_getAsync(key1, key2, key3) {
  16841. var value;
  16842. var xref = this.xref;
  16843. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16844. typeof key2 === 'undefined') {
  16845. if (xref) {
  16846. return xref.fetchIfRefAsync(value);
  16847. }
  16848. return Promise.resolve(value);
  16849. }
  16850. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16851. typeof key3 === 'undefined') {
  16852. if (xref) {
  16853. return xref.fetchIfRefAsync(value);
  16854. }
  16855. return Promise.resolve(value);
  16856. }
  16857. value = this.map[key3] || null;
  16858. if (xref) {
  16859. return xref.fetchIfRefAsync(value);
  16860. }
  16861. return Promise.resolve(value);
  16862. },
  16863. // Same as get(), but dereferences all elements if the result is an Array.
  16864. getArray: function Dict_getArray(key1, key2, key3) {
  16865. var value = this.get(key1, key2, key3);
  16866. var xref = this.xref;
  16867. if (!isArray(value) || !xref) {
  16868. return value;
  16869. }
  16870. value = value.slice(); // Ensure that we don't modify the Dict data.
  16871. for (var i = 0, ii = value.length; i < ii; i++) {
  16872. if (!isRef(value[i])) {
  16873. continue;
  16874. }
  16875. value[i] = xref.fetch(value[i]);
  16876. }
  16877. return value;
  16878. },
  16879. // no dereferencing
  16880. getRaw: function Dict_getRaw(key) {
  16881. return this.map[key];
  16882. },
  16883. getKeys: function Dict_getKeys() {
  16884. return Object.keys(this.map);
  16885. },
  16886. set: function Dict_set(key, value) {
  16887. this.map[key] = value;
  16888. },
  16889. has: function Dict_has(key) {
  16890. return key in this.map;
  16891. },
  16892. forEach: function Dict_forEach(callback) {
  16893. for (var key in this.map) {
  16894. callback(key, this.get(key));
  16895. }
  16896. }
  16897. };
  16898. Dict.empty = new Dict(null);
  16899. Dict.merge = function Dict_merge(xref, dictArray) {
  16900. var mergedDict = new Dict(xref);
  16901. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16902. var dict = dictArray[i];
  16903. if (!isDict(dict)) {
  16904. continue;
  16905. }
  16906. for (var keyName in dict.map) {
  16907. if (mergedDict.map[keyName]) {
  16908. continue;
  16909. }
  16910. mergedDict.map[keyName] = dict.map[keyName];
  16911. }
  16912. }
  16913. return mergedDict;
  16914. };
  16915. return Dict;
  16916. })();
  16917. var Ref = (function RefClosure() {
  16918. function Ref(num, gen) {
  16919. this.num = num;
  16920. this.gen = gen;
  16921. }
  16922. Ref.prototype = {
  16923. toString: function Ref_toString() {
  16924. // This function is hot, so we make the string as compact as possible.
  16925. // |this.gen| is almost always zero, so we treat that case specially.
  16926. var str = this.num + 'R';
  16927. if (this.gen !== 0) {
  16928. str += this.gen;
  16929. }
  16930. return str;
  16931. }
  16932. };
  16933. return Ref;
  16934. })();
  16935. // The reference is identified by number and generation.
  16936. // This structure stores only one instance of the reference.
  16937. var RefSet = (function RefSetClosure() {
  16938. function RefSet() {
  16939. this.dict = Object.create(null);
  16940. }
  16941. RefSet.prototype = {
  16942. has: function RefSet_has(ref) {
  16943. return ref.toString() in this.dict;
  16944. },
  16945. put: function RefSet_put(ref) {
  16946. this.dict[ref.toString()] = true;
  16947. },
  16948. remove: function RefSet_remove(ref) {
  16949. delete this.dict[ref.toString()];
  16950. }
  16951. };
  16952. return RefSet;
  16953. })();
  16954. var RefSetCache = (function RefSetCacheClosure() {
  16955. function RefSetCache() {
  16956. this.dict = Object.create(null);
  16957. }
  16958. RefSetCache.prototype = {
  16959. get: function RefSetCache_get(ref) {
  16960. return this.dict[ref.toString()];
  16961. },
  16962. has: function RefSetCache_has(ref) {
  16963. return ref.toString() in this.dict;
  16964. },
  16965. put: function RefSetCache_put(ref, obj) {
  16966. this.dict[ref.toString()] = obj;
  16967. },
  16968. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16969. this.dict[ref.toString()] = this.get(aliasRef);
  16970. },
  16971. forEach: function RefSetCache_forEach(fn, thisArg) {
  16972. for (var i in this.dict) {
  16973. fn.call(thisArg, this.dict[i]);
  16974. }
  16975. },
  16976. clear: function RefSetCache_clear() {
  16977. this.dict = Object.create(null);
  16978. }
  16979. };
  16980. return RefSetCache;
  16981. })();
  16982. function isName(v, name) {
  16983. return v instanceof Name && (name === undefined || v.name === name);
  16984. }
  16985. function isCmd(v, cmd) {
  16986. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16987. }
  16988. function isDict(v, type) {
  16989. return v instanceof Dict &&
  16990. (type === undefined || isName(v.get('Type'), type));
  16991. }
  16992. function isRef(v) {
  16993. return v instanceof Ref;
  16994. }
  16995. function isRefsEqual(v1, v2) {
  16996. return v1.num === v2.num && v1.gen === v2.gen;
  16997. }
  16998. function isStream(v) {
  16999. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  17000. }
  17001. exports.Cmd = Cmd;
  17002. exports.Dict = Dict;
  17003. exports.Name = Name;
  17004. exports.Ref = Ref;
  17005. exports.RefSet = RefSet;
  17006. exports.RefSetCache = RefSetCache;
  17007. exports.isCmd = isCmd;
  17008. exports.isDict = isDict;
  17009. exports.isName = isName;
  17010. exports.isRef = isRef;
  17011. exports.isRefsEqual = isRefsEqual;
  17012. exports.isStream = isStream;
  17013. }));
  17014. (function (root, factory) {
  17015. {
  17016. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  17017. }
  17018. }(this, function (exports, sharedUtil) {
  17019. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17020. /**
  17021. * Hold a map of decoded fonts and of the standard fourteen Type1
  17022. * fonts and their acronyms.
  17023. */
  17024. var getStdFontMap = getLookupTableFactory(function (t) {
  17025. t['ArialNarrow'] = 'Helvetica';
  17026. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  17027. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  17028. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  17029. t['ArialBlack'] = 'Helvetica';
  17030. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  17031. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  17032. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  17033. t['Arial'] = 'Helvetica';
  17034. t['Arial-Bold'] = 'Helvetica-Bold';
  17035. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  17036. t['Arial-Italic'] = 'Helvetica-Oblique';
  17037. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  17038. t['Arial-BoldMT'] = 'Helvetica-Bold';
  17039. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  17040. t['ArialMT'] = 'Helvetica';
  17041. t['Courier-Bold'] = 'Courier-Bold';
  17042. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  17043. t['Courier-Italic'] = 'Courier-Oblique';
  17044. t['CourierNew'] = 'Courier';
  17045. t['CourierNew-Bold'] = 'Courier-Bold';
  17046. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  17047. t['CourierNew-Italic'] = 'Courier-Oblique';
  17048. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  17049. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  17050. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  17051. t['CourierNewPSMT'] = 'Courier';
  17052. t['Helvetica'] = 'Helvetica';
  17053. t['Helvetica-Bold'] = 'Helvetica-Bold';
  17054. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  17055. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  17056. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  17057. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  17058. t['Symbol-Bold'] = 'Symbol';
  17059. t['Symbol-BoldItalic'] = 'Symbol';
  17060. t['Symbol-Italic'] = 'Symbol';
  17061. t['TimesNewRoman'] = 'Times-Roman';
  17062. t['TimesNewRoman-Bold'] = 'Times-Bold';
  17063. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  17064. t['TimesNewRoman-Italic'] = 'Times-Italic';
  17065. t['TimesNewRomanPS'] = 'Times-Roman';
  17066. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  17067. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  17068. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  17069. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  17070. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  17071. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  17072. t['TimesNewRomanPSMT'] = 'Times-Roman';
  17073. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  17074. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  17075. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  17076. });
  17077. /**
  17078. * Holds the map of the non-standard fonts that might be included as
  17079. * a standard fonts without glyph data.
  17080. */
  17081. var getNonStdFontMap = getLookupTableFactory(function (t) {
  17082. t['CenturyGothic'] = 'Helvetica';
  17083. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  17084. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  17085. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  17086. t['ComicSansMS'] = 'Comic Sans MS';
  17087. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  17088. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  17089. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  17090. t['LucidaConsole'] = 'Courier';
  17091. t['LucidaConsole-Bold'] = 'Courier-Bold';
  17092. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  17093. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  17094. t['MS-Gothic'] = 'MS Gothic';
  17095. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  17096. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  17097. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  17098. t['MS-Mincho'] = 'MS Mincho';
  17099. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  17100. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  17101. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  17102. t['MS-PGothic'] = 'MS PGothic';
  17103. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  17104. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  17105. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  17106. t['MS-PMincho'] = 'MS PMincho';
  17107. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  17108. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  17109. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  17110. t['Wingdings'] = 'ZapfDingbats';
  17111. });
  17112. var getSerifFonts = getLookupTableFactory(function (t) {
  17113. t['Adobe Jenson'] = true;
  17114. t['Adobe Text'] = true;
  17115. t['Albertus'] = true;
  17116. t['Aldus'] = true;
  17117. t['Alexandria'] = true;
  17118. t['Algerian'] = true;
  17119. t['American Typewriter'] = true;
  17120. t['Antiqua'] = true;
  17121. t['Apex'] = true;
  17122. t['Arno'] = true;
  17123. t['Aster'] = true;
  17124. t['Aurora'] = true;
  17125. t['Baskerville'] = true;
  17126. t['Bell'] = true;
  17127. t['Bembo'] = true;
  17128. t['Bembo Schoolbook'] = true;
  17129. t['Benguiat'] = true;
  17130. t['Berkeley Old Style'] = true;
  17131. t['Bernhard Modern'] = true;
  17132. t['Berthold City'] = true;
  17133. t['Bodoni'] = true;
  17134. t['Bauer Bodoni'] = true;
  17135. t['Book Antiqua'] = true;
  17136. t['Bookman'] = true;
  17137. t['Bordeaux Roman'] = true;
  17138. t['Californian FB'] = true;
  17139. t['Calisto'] = true;
  17140. t['Calvert'] = true;
  17141. t['Capitals'] = true;
  17142. t['Cambria'] = true;
  17143. t['Cartier'] = true;
  17144. t['Caslon'] = true;
  17145. t['Catull'] = true;
  17146. t['Centaur'] = true;
  17147. t['Century Old Style'] = true;
  17148. t['Century Schoolbook'] = true;
  17149. t['Chaparral'] = true;
  17150. t['Charis SIL'] = true;
  17151. t['Cheltenham'] = true;
  17152. t['Cholla Slab'] = true;
  17153. t['Clarendon'] = true;
  17154. t['Clearface'] = true;
  17155. t['Cochin'] = true;
  17156. t['Colonna'] = true;
  17157. t['Computer Modern'] = true;
  17158. t['Concrete Roman'] = true;
  17159. t['Constantia'] = true;
  17160. t['Cooper Black'] = true;
  17161. t['Corona'] = true;
  17162. t['Ecotype'] = true;
  17163. t['Egyptienne'] = true;
  17164. t['Elephant'] = true;
  17165. t['Excelsior'] = true;
  17166. t['Fairfield'] = true;
  17167. t['FF Scala'] = true;
  17168. t['Folkard'] = true;
  17169. t['Footlight'] = true;
  17170. t['FreeSerif'] = true;
  17171. t['Friz Quadrata'] = true;
  17172. t['Garamond'] = true;
  17173. t['Gentium'] = true;
  17174. t['Georgia'] = true;
  17175. t['Gloucester'] = true;
  17176. t['Goudy Old Style'] = true;
  17177. t['Goudy Schoolbook'] = true;
  17178. t['Goudy Pro Font'] = true;
  17179. t['Granjon'] = true;
  17180. t['Guardian Egyptian'] = true;
  17181. t['Heather'] = true;
  17182. t['Hercules'] = true;
  17183. t['High Tower Text'] = true;
  17184. t['Hiroshige'] = true;
  17185. t['Hoefler Text'] = true;
  17186. t['Humana Serif'] = true;
  17187. t['Imprint'] = true;
  17188. t['Ionic No. 5'] = true;
  17189. t['Janson'] = true;
  17190. t['Joanna'] = true;
  17191. t['Korinna'] = true;
  17192. t['Lexicon'] = true;
  17193. t['Liberation Serif'] = true;
  17194. t['Linux Libertine'] = true;
  17195. t['Literaturnaya'] = true;
  17196. t['Lucida'] = true;
  17197. t['Lucida Bright'] = true;
  17198. t['Melior'] = true;
  17199. t['Memphis'] = true;
  17200. t['Miller'] = true;
  17201. t['Minion'] = true;
  17202. t['Modern'] = true;
  17203. t['Mona Lisa'] = true;
  17204. t['Mrs Eaves'] = true;
  17205. t['MS Serif'] = true;
  17206. t['Museo Slab'] = true;
  17207. t['New York'] = true;
  17208. t['Nimbus Roman'] = true;
  17209. t['NPS Rawlinson Roadway'] = true;
  17210. t['Palatino'] = true;
  17211. t['Perpetua'] = true;
  17212. t['Plantin'] = true;
  17213. t['Plantin Schoolbook'] = true;
  17214. t['Playbill'] = true;
  17215. t['Poor Richard'] = true;
  17216. t['Rawlinson Roadway'] = true;
  17217. t['Renault'] = true;
  17218. t['Requiem'] = true;
  17219. t['Rockwell'] = true;
  17220. t['Roman'] = true;
  17221. t['Rotis Serif'] = true;
  17222. t['Sabon'] = true;
  17223. t['Scala'] = true;
  17224. t['Seagull'] = true;
  17225. t['Sistina'] = true;
  17226. t['Souvenir'] = true;
  17227. t['STIX'] = true;
  17228. t['Stone Informal'] = true;
  17229. t['Stone Serif'] = true;
  17230. t['Sylfaen'] = true;
  17231. t['Times'] = true;
  17232. t['Trajan'] = true;
  17233. t['Trinité'] = true;
  17234. t['Trump Mediaeval'] = true;
  17235. t['Utopia'] = true;
  17236. t['Vale Type'] = true;
  17237. t['Bitstream Vera'] = true;
  17238. t['Vera Serif'] = true;
  17239. t['Versailles'] = true;
  17240. t['Wanted'] = true;
  17241. t['Weiss'] = true;
  17242. t['Wide Latin'] = true;
  17243. t['Windsor'] = true;
  17244. t['XITS'] = true;
  17245. });
  17246. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17247. t['Dingbats'] = true;
  17248. t['Symbol'] = true;
  17249. t['ZapfDingbats'] = true;
  17250. });
  17251. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17252. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17253. // for all glyphs, but common for some set of the standard fonts.
  17254. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17255. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17256. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17257. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17258. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17259. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17260. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17261. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17262. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17263. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17264. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17265. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17266. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17267. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17268. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17269. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17270. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17271. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17272. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17273. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17274. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17275. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17276. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17277. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17278. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17279. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17280. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17281. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17282. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17283. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17284. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17285. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17286. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17287. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17288. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17289. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17290. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17291. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17292. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17293. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17294. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17295. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17296. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17297. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17298. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17299. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17300. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17301. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17302. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17303. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17304. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17305. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17306. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17307. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17308. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17309. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17310. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17311. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17312. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17313. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17314. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17315. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17316. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17317. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17318. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17319. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17320. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17321. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17322. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17323. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17324. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17325. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17326. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17327. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17328. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17329. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17330. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17331. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17332. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17333. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17334. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17335. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17336. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17337. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17338. t[3416] = 8377;
  17339. });
  17340. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17341. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17342. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17343. var getSupplementalGlyphMapForArialBlack =
  17344. getLookupTableFactory(function (t) {
  17345. t[227] = 322; t[264] = 261; t[291] = 346;
  17346. });
  17347. exports.getStdFontMap = getStdFontMap;
  17348. exports.getNonStdFontMap = getNonStdFontMap;
  17349. exports.getSerifFonts = getSerifFonts;
  17350. exports.getSymbolsFonts = getSymbolsFonts;
  17351. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17352. exports.getSupplementalGlyphMapForArialBlack =
  17353. getSupplementalGlyphMapForArialBlack;
  17354. }));
  17355. (function (root, factory) {
  17356. {
  17357. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17358. }
  17359. }(this, function (exports, sharedUtil) {
  17360. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17361. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17362. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17363. // chars to the similar equivalents in the normal characters range.
  17364. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17365. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17366. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17367. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17368. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17369. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17370. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17371. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17372. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17373. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17374. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17375. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17376. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17377. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17378. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17379. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17380. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17381. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17382. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17383. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17384. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17385. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17386. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17387. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17388. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17389. });
  17390. function mapSpecialUnicodeValues(code) {
  17391. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17392. return 0;
  17393. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17394. return (getSpecialPUASymbols()[code] || code);
  17395. }
  17396. return code;
  17397. }
  17398. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17399. var unicode = glyphsUnicodeMap[name];
  17400. if (unicode !== undefined) {
  17401. return unicode;
  17402. }
  17403. if (!name) {
  17404. return -1;
  17405. }
  17406. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17407. if (name[0] === 'u') {
  17408. var nameLen = name.length, hexStr;
  17409. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17410. hexStr = name.substr(3);
  17411. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17412. hexStr = name.substr(1);
  17413. } else {
  17414. return -1;
  17415. }
  17416. // Check for upper-case hexadecimal characters, to avoid false positives.
  17417. if (hexStr === hexStr.toUpperCase()) {
  17418. unicode = parseInt(hexStr, 16);
  17419. if (unicode >= 0) {
  17420. return unicode;
  17421. }
  17422. }
  17423. }
  17424. return -1;
  17425. }
  17426. var UnicodeRanges = [
  17427. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17428. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17429. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17430. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17431. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17432. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17433. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17434. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17435. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17436. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17437. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17438. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17439. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17440. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17441. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17442. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17443. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17444. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17445. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17446. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17447. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17448. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17449. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17450. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17451. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17452. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17453. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17454. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17455. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17456. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17457. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17458. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17459. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17460. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17461. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17462. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17463. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17464. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17465. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17466. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17467. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17468. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17469. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17470. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17471. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17472. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17473. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17474. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17475. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17476. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17477. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17478. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17479. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17480. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17481. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17482. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17483. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17484. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17485. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17486. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17487. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17488. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17489. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17490. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17491. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17492. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17493. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17494. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17495. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17496. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17497. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17498. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17499. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17500. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17501. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17502. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17503. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17504. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17505. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17506. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17507. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17508. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17509. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17510. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17511. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17512. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17513. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17514. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17515. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17516. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17517. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17518. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17519. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17520. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17521. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17522. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17523. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17524. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17525. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17526. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17527. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17528. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17529. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17530. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17531. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17532. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17533. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17534. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17535. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17536. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17537. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17538. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17539. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17540. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17541. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17542. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17543. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17544. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17545. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17546. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17547. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17548. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17549. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17550. ];
  17551. function getUnicodeRangeFor(value) {
  17552. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17553. var range = UnicodeRanges[i];
  17554. if (value >= range.begin && value < range.end) {
  17555. return i;
  17556. }
  17557. }
  17558. return -1;
  17559. }
  17560. function isRTLRangeFor(value) {
  17561. var range = UnicodeRanges[13];
  17562. if (value >= range.begin && value < range.end) {
  17563. return true;
  17564. }
  17565. range = UnicodeRanges[11];
  17566. if (value >= range.begin && value < range.end) {
  17567. return true;
  17568. }
  17569. return false;
  17570. }
  17571. // The normalization table is obtained by filtering the Unicode characters
  17572. // database with <compat> entries.
  17573. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17574. t['\u00A8'] = '\u0020\u0308';
  17575. t['\u00AF'] = '\u0020\u0304';
  17576. t['\u00B4'] = '\u0020\u0301';
  17577. t['\u00B5'] = '\u03BC';
  17578. t['\u00B8'] = '\u0020\u0327';
  17579. t['\u0132'] = '\u0049\u004A';
  17580. t['\u0133'] = '\u0069\u006A';
  17581. t['\u013F'] = '\u004C\u00B7';
  17582. t['\u0140'] = '\u006C\u00B7';
  17583. t['\u0149'] = '\u02BC\u006E';
  17584. t['\u017F'] = '\u0073';
  17585. t['\u01C4'] = '\u0044\u017D';
  17586. t['\u01C5'] = '\u0044\u017E';
  17587. t['\u01C6'] = '\u0064\u017E';
  17588. t['\u01C7'] = '\u004C\u004A';
  17589. t['\u01C8'] = '\u004C\u006A';
  17590. t['\u01C9'] = '\u006C\u006A';
  17591. t['\u01CA'] = '\u004E\u004A';
  17592. t['\u01CB'] = '\u004E\u006A';
  17593. t['\u01CC'] = '\u006E\u006A';
  17594. t['\u01F1'] = '\u0044\u005A';
  17595. t['\u01F2'] = '\u0044\u007A';
  17596. t['\u01F3'] = '\u0064\u007A';
  17597. t['\u02D8'] = '\u0020\u0306';
  17598. t['\u02D9'] = '\u0020\u0307';
  17599. t['\u02DA'] = '\u0020\u030A';
  17600. t['\u02DB'] = '\u0020\u0328';
  17601. t['\u02DC'] = '\u0020\u0303';
  17602. t['\u02DD'] = '\u0020\u030B';
  17603. t['\u037A'] = '\u0020\u0345';
  17604. t['\u0384'] = '\u0020\u0301';
  17605. t['\u03D0'] = '\u03B2';
  17606. t['\u03D1'] = '\u03B8';
  17607. t['\u03D2'] = '\u03A5';
  17608. t['\u03D5'] = '\u03C6';
  17609. t['\u03D6'] = '\u03C0';
  17610. t['\u03F0'] = '\u03BA';
  17611. t['\u03F1'] = '\u03C1';
  17612. t['\u03F2'] = '\u03C2';
  17613. t['\u03F4'] = '\u0398';
  17614. t['\u03F5'] = '\u03B5';
  17615. t['\u03F9'] = '\u03A3';
  17616. t['\u0587'] = '\u0565\u0582';
  17617. t['\u0675'] = '\u0627\u0674';
  17618. t['\u0676'] = '\u0648\u0674';
  17619. t['\u0677'] = '\u06C7\u0674';
  17620. t['\u0678'] = '\u064A\u0674';
  17621. t['\u0E33'] = '\u0E4D\u0E32';
  17622. t['\u0EB3'] = '\u0ECD\u0EB2';
  17623. t['\u0EDC'] = '\u0EAB\u0E99';
  17624. t['\u0EDD'] = '\u0EAB\u0EA1';
  17625. t['\u0F77'] = '\u0FB2\u0F81';
  17626. t['\u0F79'] = '\u0FB3\u0F81';
  17627. t['\u1E9A'] = '\u0061\u02BE';
  17628. t['\u1FBD'] = '\u0020\u0313';
  17629. t['\u1FBF'] = '\u0020\u0313';
  17630. t['\u1FC0'] = '\u0020\u0342';
  17631. t['\u1FFE'] = '\u0020\u0314';
  17632. t['\u2002'] = '\u0020';
  17633. t['\u2003'] = '\u0020';
  17634. t['\u2004'] = '\u0020';
  17635. t['\u2005'] = '\u0020';
  17636. t['\u2006'] = '\u0020';
  17637. t['\u2008'] = '\u0020';
  17638. t['\u2009'] = '\u0020';
  17639. t['\u200A'] = '\u0020';
  17640. t['\u2017'] = '\u0020\u0333';
  17641. t['\u2024'] = '\u002E';
  17642. t['\u2025'] = '\u002E\u002E';
  17643. t['\u2026'] = '\u002E\u002E\u002E';
  17644. t['\u2033'] = '\u2032\u2032';
  17645. t['\u2034'] = '\u2032\u2032\u2032';
  17646. t['\u2036'] = '\u2035\u2035';
  17647. t['\u2037'] = '\u2035\u2035\u2035';
  17648. t['\u203C'] = '\u0021\u0021';
  17649. t['\u203E'] = '\u0020\u0305';
  17650. t['\u2047'] = '\u003F\u003F';
  17651. t['\u2048'] = '\u003F\u0021';
  17652. t['\u2049'] = '\u0021\u003F';
  17653. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17654. t['\u205F'] = '\u0020';
  17655. t['\u20A8'] = '\u0052\u0073';
  17656. t['\u2100'] = '\u0061\u002F\u0063';
  17657. t['\u2101'] = '\u0061\u002F\u0073';
  17658. t['\u2103'] = '\u00B0\u0043';
  17659. t['\u2105'] = '\u0063\u002F\u006F';
  17660. t['\u2106'] = '\u0063\u002F\u0075';
  17661. t['\u2107'] = '\u0190';
  17662. t['\u2109'] = '\u00B0\u0046';
  17663. t['\u2116'] = '\u004E\u006F';
  17664. t['\u2121'] = '\u0054\u0045\u004C';
  17665. t['\u2135'] = '\u05D0';
  17666. t['\u2136'] = '\u05D1';
  17667. t['\u2137'] = '\u05D2';
  17668. t['\u2138'] = '\u05D3';
  17669. t['\u213B'] = '\u0046\u0041\u0058';
  17670. t['\u2160'] = '\u0049';
  17671. t['\u2161'] = '\u0049\u0049';
  17672. t['\u2162'] = '\u0049\u0049\u0049';
  17673. t['\u2163'] = '\u0049\u0056';
  17674. t['\u2164'] = '\u0056';
  17675. t['\u2165'] = '\u0056\u0049';
  17676. t['\u2166'] = '\u0056\u0049\u0049';
  17677. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17678. t['\u2168'] = '\u0049\u0058';
  17679. t['\u2169'] = '\u0058';
  17680. t['\u216A'] = '\u0058\u0049';
  17681. t['\u216B'] = '\u0058\u0049\u0049';
  17682. t['\u216C'] = '\u004C';
  17683. t['\u216D'] = '\u0043';
  17684. t['\u216E'] = '\u0044';
  17685. t['\u216F'] = '\u004D';
  17686. t['\u2170'] = '\u0069';
  17687. t['\u2171'] = '\u0069\u0069';
  17688. t['\u2172'] = '\u0069\u0069\u0069';
  17689. t['\u2173'] = '\u0069\u0076';
  17690. t['\u2174'] = '\u0076';
  17691. t['\u2175'] = '\u0076\u0069';
  17692. t['\u2176'] = '\u0076\u0069\u0069';
  17693. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17694. t['\u2178'] = '\u0069\u0078';
  17695. t['\u2179'] = '\u0078';
  17696. t['\u217A'] = '\u0078\u0069';
  17697. t['\u217B'] = '\u0078\u0069\u0069';
  17698. t['\u217C'] = '\u006C';
  17699. t['\u217D'] = '\u0063';
  17700. t['\u217E'] = '\u0064';
  17701. t['\u217F'] = '\u006D';
  17702. t['\u222C'] = '\u222B\u222B';
  17703. t['\u222D'] = '\u222B\u222B\u222B';
  17704. t['\u222F'] = '\u222E\u222E';
  17705. t['\u2230'] = '\u222E\u222E\u222E';
  17706. t['\u2474'] = '\u0028\u0031\u0029';
  17707. t['\u2475'] = '\u0028\u0032\u0029';
  17708. t['\u2476'] = '\u0028\u0033\u0029';
  17709. t['\u2477'] = '\u0028\u0034\u0029';
  17710. t['\u2478'] = '\u0028\u0035\u0029';
  17711. t['\u2479'] = '\u0028\u0036\u0029';
  17712. t['\u247A'] = '\u0028\u0037\u0029';
  17713. t['\u247B'] = '\u0028\u0038\u0029';
  17714. t['\u247C'] = '\u0028\u0039\u0029';
  17715. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17716. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17717. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17718. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17719. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17720. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17721. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17722. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17723. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17724. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17725. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17726. t['\u2488'] = '\u0031\u002E';
  17727. t['\u2489'] = '\u0032\u002E';
  17728. t['\u248A'] = '\u0033\u002E';
  17729. t['\u248B'] = '\u0034\u002E';
  17730. t['\u248C'] = '\u0035\u002E';
  17731. t['\u248D'] = '\u0036\u002E';
  17732. t['\u248E'] = '\u0037\u002E';
  17733. t['\u248F'] = '\u0038\u002E';
  17734. t['\u2490'] = '\u0039\u002E';
  17735. t['\u2491'] = '\u0031\u0030\u002E';
  17736. t['\u2492'] = '\u0031\u0031\u002E';
  17737. t['\u2493'] = '\u0031\u0032\u002E';
  17738. t['\u2494'] = '\u0031\u0033\u002E';
  17739. t['\u2495'] = '\u0031\u0034\u002E';
  17740. t['\u2496'] = '\u0031\u0035\u002E';
  17741. t['\u2497'] = '\u0031\u0036\u002E';
  17742. t['\u2498'] = '\u0031\u0037\u002E';
  17743. t['\u2499'] = '\u0031\u0038\u002E';
  17744. t['\u249A'] = '\u0031\u0039\u002E';
  17745. t['\u249B'] = '\u0032\u0030\u002E';
  17746. t['\u249C'] = '\u0028\u0061\u0029';
  17747. t['\u249D'] = '\u0028\u0062\u0029';
  17748. t['\u249E'] = '\u0028\u0063\u0029';
  17749. t['\u249F'] = '\u0028\u0064\u0029';
  17750. t['\u24A0'] = '\u0028\u0065\u0029';
  17751. t['\u24A1'] = '\u0028\u0066\u0029';
  17752. t['\u24A2'] = '\u0028\u0067\u0029';
  17753. t['\u24A3'] = '\u0028\u0068\u0029';
  17754. t['\u24A4'] = '\u0028\u0069\u0029';
  17755. t['\u24A5'] = '\u0028\u006A\u0029';
  17756. t['\u24A6'] = '\u0028\u006B\u0029';
  17757. t['\u24A7'] = '\u0028\u006C\u0029';
  17758. t['\u24A8'] = '\u0028\u006D\u0029';
  17759. t['\u24A9'] = '\u0028\u006E\u0029';
  17760. t['\u24AA'] = '\u0028\u006F\u0029';
  17761. t['\u24AB'] = '\u0028\u0070\u0029';
  17762. t['\u24AC'] = '\u0028\u0071\u0029';
  17763. t['\u24AD'] = '\u0028\u0072\u0029';
  17764. t['\u24AE'] = '\u0028\u0073\u0029';
  17765. t['\u24AF'] = '\u0028\u0074\u0029';
  17766. t['\u24B0'] = '\u0028\u0075\u0029';
  17767. t['\u24B1'] = '\u0028\u0076\u0029';
  17768. t['\u24B2'] = '\u0028\u0077\u0029';
  17769. t['\u24B3'] = '\u0028\u0078\u0029';
  17770. t['\u24B4'] = '\u0028\u0079\u0029';
  17771. t['\u24B5'] = '\u0028\u007A\u0029';
  17772. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17773. t['\u2A74'] = '\u003A\u003A\u003D';
  17774. t['\u2A75'] = '\u003D\u003D';
  17775. t['\u2A76'] = '\u003D\u003D\u003D';
  17776. t['\u2E9F'] = '\u6BCD';
  17777. t['\u2EF3'] = '\u9F9F';
  17778. t['\u2F00'] = '\u4E00';
  17779. t['\u2F01'] = '\u4E28';
  17780. t['\u2F02'] = '\u4E36';
  17781. t['\u2F03'] = '\u4E3F';
  17782. t['\u2F04'] = '\u4E59';
  17783. t['\u2F05'] = '\u4E85';
  17784. t['\u2F06'] = '\u4E8C';
  17785. t['\u2F07'] = '\u4EA0';
  17786. t['\u2F08'] = '\u4EBA';
  17787. t['\u2F09'] = '\u513F';
  17788. t['\u2F0A'] = '\u5165';
  17789. t['\u2F0B'] = '\u516B';
  17790. t['\u2F0C'] = '\u5182';
  17791. t['\u2F0D'] = '\u5196';
  17792. t['\u2F0E'] = '\u51AB';
  17793. t['\u2F0F'] = '\u51E0';
  17794. t['\u2F10'] = '\u51F5';
  17795. t['\u2F11'] = '\u5200';
  17796. t['\u2F12'] = '\u529B';
  17797. t['\u2F13'] = '\u52F9';
  17798. t['\u2F14'] = '\u5315';
  17799. t['\u2F15'] = '\u531A';
  17800. t['\u2F16'] = '\u5338';
  17801. t['\u2F17'] = '\u5341';
  17802. t['\u2F18'] = '\u535C';
  17803. t['\u2F19'] = '\u5369';
  17804. t['\u2F1A'] = '\u5382';
  17805. t['\u2F1B'] = '\u53B6';
  17806. t['\u2F1C'] = '\u53C8';
  17807. t['\u2F1D'] = '\u53E3';
  17808. t['\u2F1E'] = '\u56D7';
  17809. t['\u2F1F'] = '\u571F';
  17810. t['\u2F20'] = '\u58EB';
  17811. t['\u2F21'] = '\u5902';
  17812. t['\u2F22'] = '\u590A';
  17813. t['\u2F23'] = '\u5915';
  17814. t['\u2F24'] = '\u5927';
  17815. t['\u2F25'] = '\u5973';
  17816. t['\u2F26'] = '\u5B50';
  17817. t['\u2F27'] = '\u5B80';
  17818. t['\u2F28'] = '\u5BF8';
  17819. t['\u2F29'] = '\u5C0F';
  17820. t['\u2F2A'] = '\u5C22';
  17821. t['\u2F2B'] = '\u5C38';
  17822. t['\u2F2C'] = '\u5C6E';
  17823. t['\u2F2D'] = '\u5C71';
  17824. t['\u2F2E'] = '\u5DDB';
  17825. t['\u2F2F'] = '\u5DE5';
  17826. t['\u2F30'] = '\u5DF1';
  17827. t['\u2F31'] = '\u5DFE';
  17828. t['\u2F32'] = '\u5E72';
  17829. t['\u2F33'] = '\u5E7A';
  17830. t['\u2F34'] = '\u5E7F';
  17831. t['\u2F35'] = '\u5EF4';
  17832. t['\u2F36'] = '\u5EFE';
  17833. t['\u2F37'] = '\u5F0B';
  17834. t['\u2F38'] = '\u5F13';
  17835. t['\u2F39'] = '\u5F50';
  17836. t['\u2F3A'] = '\u5F61';
  17837. t['\u2F3B'] = '\u5F73';
  17838. t['\u2F3C'] = '\u5FC3';
  17839. t['\u2F3D'] = '\u6208';
  17840. t['\u2F3E'] = '\u6236';
  17841. t['\u2F3F'] = '\u624B';
  17842. t['\u2F40'] = '\u652F';
  17843. t['\u2F41'] = '\u6534';
  17844. t['\u2F42'] = '\u6587';
  17845. t['\u2F43'] = '\u6597';
  17846. t['\u2F44'] = '\u65A4';
  17847. t['\u2F45'] = '\u65B9';
  17848. t['\u2F46'] = '\u65E0';
  17849. t['\u2F47'] = '\u65E5';
  17850. t['\u2F48'] = '\u66F0';
  17851. t['\u2F49'] = '\u6708';
  17852. t['\u2F4A'] = '\u6728';
  17853. t['\u2F4B'] = '\u6B20';
  17854. t['\u2F4C'] = '\u6B62';
  17855. t['\u2F4D'] = '\u6B79';
  17856. t['\u2F4E'] = '\u6BB3';
  17857. t['\u2F4F'] = '\u6BCB';
  17858. t['\u2F50'] = '\u6BD4';
  17859. t['\u2F51'] = '\u6BDB';
  17860. t['\u2F52'] = '\u6C0F';
  17861. t['\u2F53'] = '\u6C14';
  17862. t['\u2F54'] = '\u6C34';
  17863. t['\u2F55'] = '\u706B';
  17864. t['\u2F56'] = '\u722A';
  17865. t['\u2F57'] = '\u7236';
  17866. t['\u2F58'] = '\u723B';
  17867. t['\u2F59'] = '\u723F';
  17868. t['\u2F5A'] = '\u7247';
  17869. t['\u2F5B'] = '\u7259';
  17870. t['\u2F5C'] = '\u725B';
  17871. t['\u2F5D'] = '\u72AC';
  17872. t['\u2F5E'] = '\u7384';
  17873. t['\u2F5F'] = '\u7389';
  17874. t['\u2F60'] = '\u74DC';
  17875. t['\u2F61'] = '\u74E6';
  17876. t['\u2F62'] = '\u7518';
  17877. t['\u2F63'] = '\u751F';
  17878. t['\u2F64'] = '\u7528';
  17879. t['\u2F65'] = '\u7530';
  17880. t['\u2F66'] = '\u758B';
  17881. t['\u2F67'] = '\u7592';
  17882. t['\u2F68'] = '\u7676';
  17883. t['\u2F69'] = '\u767D';
  17884. t['\u2F6A'] = '\u76AE';
  17885. t['\u2F6B'] = '\u76BF';
  17886. t['\u2F6C'] = '\u76EE';
  17887. t['\u2F6D'] = '\u77DB';
  17888. t['\u2F6E'] = '\u77E2';
  17889. t['\u2F6F'] = '\u77F3';
  17890. t['\u2F70'] = '\u793A';
  17891. t['\u2F71'] = '\u79B8';
  17892. t['\u2F72'] = '\u79BE';
  17893. t['\u2F73'] = '\u7A74';
  17894. t['\u2F74'] = '\u7ACB';
  17895. t['\u2F75'] = '\u7AF9';
  17896. t['\u2F76'] = '\u7C73';
  17897. t['\u2F77'] = '\u7CF8';
  17898. t['\u2F78'] = '\u7F36';
  17899. t['\u2F79'] = '\u7F51';
  17900. t['\u2F7A'] = '\u7F8A';
  17901. t['\u2F7B'] = '\u7FBD';
  17902. t['\u2F7C'] = '\u8001';
  17903. t['\u2F7D'] = '\u800C';
  17904. t['\u2F7E'] = '\u8012';
  17905. t['\u2F7F'] = '\u8033';
  17906. t['\u2F80'] = '\u807F';
  17907. t['\u2F81'] = '\u8089';
  17908. t['\u2F82'] = '\u81E3';
  17909. t['\u2F83'] = '\u81EA';
  17910. t['\u2F84'] = '\u81F3';
  17911. t['\u2F85'] = '\u81FC';
  17912. t['\u2F86'] = '\u820C';
  17913. t['\u2F87'] = '\u821B';
  17914. t['\u2F88'] = '\u821F';
  17915. t['\u2F89'] = '\u826E';
  17916. t['\u2F8A'] = '\u8272';
  17917. t['\u2F8B'] = '\u8278';
  17918. t['\u2F8C'] = '\u864D';
  17919. t['\u2F8D'] = '\u866B';
  17920. t['\u2F8E'] = '\u8840';
  17921. t['\u2F8F'] = '\u884C';
  17922. t['\u2F90'] = '\u8863';
  17923. t['\u2F91'] = '\u897E';
  17924. t['\u2F92'] = '\u898B';
  17925. t['\u2F93'] = '\u89D2';
  17926. t['\u2F94'] = '\u8A00';
  17927. t['\u2F95'] = '\u8C37';
  17928. t['\u2F96'] = '\u8C46';
  17929. t['\u2F97'] = '\u8C55';
  17930. t['\u2F98'] = '\u8C78';
  17931. t['\u2F99'] = '\u8C9D';
  17932. t['\u2F9A'] = '\u8D64';
  17933. t['\u2F9B'] = '\u8D70';
  17934. t['\u2F9C'] = '\u8DB3';
  17935. t['\u2F9D'] = '\u8EAB';
  17936. t['\u2F9E'] = '\u8ECA';
  17937. t['\u2F9F'] = '\u8F9B';
  17938. t['\u2FA0'] = '\u8FB0';
  17939. t['\u2FA1'] = '\u8FB5';
  17940. t['\u2FA2'] = '\u9091';
  17941. t['\u2FA3'] = '\u9149';
  17942. t['\u2FA4'] = '\u91C6';
  17943. t['\u2FA5'] = '\u91CC';
  17944. t['\u2FA6'] = '\u91D1';
  17945. t['\u2FA7'] = '\u9577';
  17946. t['\u2FA8'] = '\u9580';
  17947. t['\u2FA9'] = '\u961C';
  17948. t['\u2FAA'] = '\u96B6';
  17949. t['\u2FAB'] = '\u96B9';
  17950. t['\u2FAC'] = '\u96E8';
  17951. t['\u2FAD'] = '\u9751';
  17952. t['\u2FAE'] = '\u975E';
  17953. t['\u2FAF'] = '\u9762';
  17954. t['\u2FB0'] = '\u9769';
  17955. t['\u2FB1'] = '\u97CB';
  17956. t['\u2FB2'] = '\u97ED';
  17957. t['\u2FB3'] = '\u97F3';
  17958. t['\u2FB4'] = '\u9801';
  17959. t['\u2FB5'] = '\u98A8';
  17960. t['\u2FB6'] = '\u98DB';
  17961. t['\u2FB7'] = '\u98DF';
  17962. t['\u2FB8'] = '\u9996';
  17963. t['\u2FB9'] = '\u9999';
  17964. t['\u2FBA'] = '\u99AC';
  17965. t['\u2FBB'] = '\u9AA8';
  17966. t['\u2FBC'] = '\u9AD8';
  17967. t['\u2FBD'] = '\u9ADF';
  17968. t['\u2FBE'] = '\u9B25';
  17969. t['\u2FBF'] = '\u9B2F';
  17970. t['\u2FC0'] = '\u9B32';
  17971. t['\u2FC1'] = '\u9B3C';
  17972. t['\u2FC2'] = '\u9B5A';
  17973. t['\u2FC3'] = '\u9CE5';
  17974. t['\u2FC4'] = '\u9E75';
  17975. t['\u2FC5'] = '\u9E7F';
  17976. t['\u2FC6'] = '\u9EA5';
  17977. t['\u2FC7'] = '\u9EBB';
  17978. t['\u2FC8'] = '\u9EC3';
  17979. t['\u2FC9'] = '\u9ECD';
  17980. t['\u2FCA'] = '\u9ED1';
  17981. t['\u2FCB'] = '\u9EF9';
  17982. t['\u2FCC'] = '\u9EFD';
  17983. t['\u2FCD'] = '\u9F0E';
  17984. t['\u2FCE'] = '\u9F13';
  17985. t['\u2FCF'] = '\u9F20';
  17986. t['\u2FD0'] = '\u9F3B';
  17987. t['\u2FD1'] = '\u9F4A';
  17988. t['\u2FD2'] = '\u9F52';
  17989. t['\u2FD3'] = '\u9F8D';
  17990. t['\u2FD4'] = '\u9F9C';
  17991. t['\u2FD5'] = '\u9FA0';
  17992. t['\u3036'] = '\u3012';
  17993. t['\u3038'] = '\u5341';
  17994. t['\u3039'] = '\u5344';
  17995. t['\u303A'] = '\u5345';
  17996. t['\u309B'] = '\u0020\u3099';
  17997. t['\u309C'] = '\u0020\u309A';
  17998. t['\u3131'] = '\u1100';
  17999. t['\u3132'] = '\u1101';
  18000. t['\u3133'] = '\u11AA';
  18001. t['\u3134'] = '\u1102';
  18002. t['\u3135'] = '\u11AC';
  18003. t['\u3136'] = '\u11AD';
  18004. t['\u3137'] = '\u1103';
  18005. t['\u3138'] = '\u1104';
  18006. t['\u3139'] = '\u1105';
  18007. t['\u313A'] = '\u11B0';
  18008. t['\u313B'] = '\u11B1';
  18009. t['\u313C'] = '\u11B2';
  18010. t['\u313D'] = '\u11B3';
  18011. t['\u313E'] = '\u11B4';
  18012. t['\u313F'] = '\u11B5';
  18013. t['\u3140'] = '\u111A';
  18014. t['\u3141'] = '\u1106';
  18015. t['\u3142'] = '\u1107';
  18016. t['\u3143'] = '\u1108';
  18017. t['\u3144'] = '\u1121';
  18018. t['\u3145'] = '\u1109';
  18019. t['\u3146'] = '\u110A';
  18020. t['\u3147'] = '\u110B';
  18021. t['\u3148'] = '\u110C';
  18022. t['\u3149'] = '\u110D';
  18023. t['\u314A'] = '\u110E';
  18024. t['\u314B'] = '\u110F';
  18025. t['\u314C'] = '\u1110';
  18026. t['\u314D'] = '\u1111';
  18027. t['\u314E'] = '\u1112';
  18028. t['\u314F'] = '\u1161';
  18029. t['\u3150'] = '\u1162';
  18030. t['\u3151'] = '\u1163';
  18031. t['\u3152'] = '\u1164';
  18032. t['\u3153'] = '\u1165';
  18033. t['\u3154'] = '\u1166';
  18034. t['\u3155'] = '\u1167';
  18035. t['\u3156'] = '\u1168';
  18036. t['\u3157'] = '\u1169';
  18037. t['\u3158'] = '\u116A';
  18038. t['\u3159'] = '\u116B';
  18039. t['\u315A'] = '\u116C';
  18040. t['\u315B'] = '\u116D';
  18041. t['\u315C'] = '\u116E';
  18042. t['\u315D'] = '\u116F';
  18043. t['\u315E'] = '\u1170';
  18044. t['\u315F'] = '\u1171';
  18045. t['\u3160'] = '\u1172';
  18046. t['\u3161'] = '\u1173';
  18047. t['\u3162'] = '\u1174';
  18048. t['\u3163'] = '\u1175';
  18049. t['\u3164'] = '\u1160';
  18050. t['\u3165'] = '\u1114';
  18051. t['\u3166'] = '\u1115';
  18052. t['\u3167'] = '\u11C7';
  18053. t['\u3168'] = '\u11C8';
  18054. t['\u3169'] = '\u11CC';
  18055. t['\u316A'] = '\u11CE';
  18056. t['\u316B'] = '\u11D3';
  18057. t['\u316C'] = '\u11D7';
  18058. t['\u316D'] = '\u11D9';
  18059. t['\u316E'] = '\u111C';
  18060. t['\u316F'] = '\u11DD';
  18061. t['\u3170'] = '\u11DF';
  18062. t['\u3171'] = '\u111D';
  18063. t['\u3172'] = '\u111E';
  18064. t['\u3173'] = '\u1120';
  18065. t['\u3174'] = '\u1122';
  18066. t['\u3175'] = '\u1123';
  18067. t['\u3176'] = '\u1127';
  18068. t['\u3177'] = '\u1129';
  18069. t['\u3178'] = '\u112B';
  18070. t['\u3179'] = '\u112C';
  18071. t['\u317A'] = '\u112D';
  18072. t['\u317B'] = '\u112E';
  18073. t['\u317C'] = '\u112F';
  18074. t['\u317D'] = '\u1132';
  18075. t['\u317E'] = '\u1136';
  18076. t['\u317F'] = '\u1140';
  18077. t['\u3180'] = '\u1147';
  18078. t['\u3181'] = '\u114C';
  18079. t['\u3182'] = '\u11F1';
  18080. t['\u3183'] = '\u11F2';
  18081. t['\u3184'] = '\u1157';
  18082. t['\u3185'] = '\u1158';
  18083. t['\u3186'] = '\u1159';
  18084. t['\u3187'] = '\u1184';
  18085. t['\u3188'] = '\u1185';
  18086. t['\u3189'] = '\u1188';
  18087. t['\u318A'] = '\u1191';
  18088. t['\u318B'] = '\u1192';
  18089. t['\u318C'] = '\u1194';
  18090. t['\u318D'] = '\u119E';
  18091. t['\u318E'] = '\u11A1';
  18092. t['\u3200'] = '\u0028\u1100\u0029';
  18093. t['\u3201'] = '\u0028\u1102\u0029';
  18094. t['\u3202'] = '\u0028\u1103\u0029';
  18095. t['\u3203'] = '\u0028\u1105\u0029';
  18096. t['\u3204'] = '\u0028\u1106\u0029';
  18097. t['\u3205'] = '\u0028\u1107\u0029';
  18098. t['\u3206'] = '\u0028\u1109\u0029';
  18099. t['\u3207'] = '\u0028\u110B\u0029';
  18100. t['\u3208'] = '\u0028\u110C\u0029';
  18101. t['\u3209'] = '\u0028\u110E\u0029';
  18102. t['\u320A'] = '\u0028\u110F\u0029';
  18103. t['\u320B'] = '\u0028\u1110\u0029';
  18104. t['\u320C'] = '\u0028\u1111\u0029';
  18105. t['\u320D'] = '\u0028\u1112\u0029';
  18106. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  18107. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  18108. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  18109. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  18110. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  18111. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  18112. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  18113. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  18114. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  18115. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  18116. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  18117. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  18118. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  18119. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  18120. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  18121. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  18122. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  18123. t['\u3220'] = '\u0028\u4E00\u0029';
  18124. t['\u3221'] = '\u0028\u4E8C\u0029';
  18125. t['\u3222'] = '\u0028\u4E09\u0029';
  18126. t['\u3223'] = '\u0028\u56DB\u0029';
  18127. t['\u3224'] = '\u0028\u4E94\u0029';
  18128. t['\u3225'] = '\u0028\u516D\u0029';
  18129. t['\u3226'] = '\u0028\u4E03\u0029';
  18130. t['\u3227'] = '\u0028\u516B\u0029';
  18131. t['\u3228'] = '\u0028\u4E5D\u0029';
  18132. t['\u3229'] = '\u0028\u5341\u0029';
  18133. t['\u322A'] = '\u0028\u6708\u0029';
  18134. t['\u322B'] = '\u0028\u706B\u0029';
  18135. t['\u322C'] = '\u0028\u6C34\u0029';
  18136. t['\u322D'] = '\u0028\u6728\u0029';
  18137. t['\u322E'] = '\u0028\u91D1\u0029';
  18138. t['\u322F'] = '\u0028\u571F\u0029';
  18139. t['\u3230'] = '\u0028\u65E5\u0029';
  18140. t['\u3231'] = '\u0028\u682A\u0029';
  18141. t['\u3232'] = '\u0028\u6709\u0029';
  18142. t['\u3233'] = '\u0028\u793E\u0029';
  18143. t['\u3234'] = '\u0028\u540D\u0029';
  18144. t['\u3235'] = '\u0028\u7279\u0029';
  18145. t['\u3236'] = '\u0028\u8CA1\u0029';
  18146. t['\u3237'] = '\u0028\u795D\u0029';
  18147. t['\u3238'] = '\u0028\u52B4\u0029';
  18148. t['\u3239'] = '\u0028\u4EE3\u0029';
  18149. t['\u323A'] = '\u0028\u547C\u0029';
  18150. t['\u323B'] = '\u0028\u5B66\u0029';
  18151. t['\u323C'] = '\u0028\u76E3\u0029';
  18152. t['\u323D'] = '\u0028\u4F01\u0029';
  18153. t['\u323E'] = '\u0028\u8CC7\u0029';
  18154. t['\u323F'] = '\u0028\u5354\u0029';
  18155. t['\u3240'] = '\u0028\u796D\u0029';
  18156. t['\u3241'] = '\u0028\u4F11\u0029';
  18157. t['\u3242'] = '\u0028\u81EA\u0029';
  18158. t['\u3243'] = '\u0028\u81F3\u0029';
  18159. t['\u32C0'] = '\u0031\u6708';
  18160. t['\u32C1'] = '\u0032\u6708';
  18161. t['\u32C2'] = '\u0033\u6708';
  18162. t['\u32C3'] = '\u0034\u6708';
  18163. t['\u32C4'] = '\u0035\u6708';
  18164. t['\u32C5'] = '\u0036\u6708';
  18165. t['\u32C6'] = '\u0037\u6708';
  18166. t['\u32C7'] = '\u0038\u6708';
  18167. t['\u32C8'] = '\u0039\u6708';
  18168. t['\u32C9'] = '\u0031\u0030\u6708';
  18169. t['\u32CA'] = '\u0031\u0031\u6708';
  18170. t['\u32CB'] = '\u0031\u0032\u6708';
  18171. t['\u3358'] = '\u0030\u70B9';
  18172. t['\u3359'] = '\u0031\u70B9';
  18173. t['\u335A'] = '\u0032\u70B9';
  18174. t['\u335B'] = '\u0033\u70B9';
  18175. t['\u335C'] = '\u0034\u70B9';
  18176. t['\u335D'] = '\u0035\u70B9';
  18177. t['\u335E'] = '\u0036\u70B9';
  18178. t['\u335F'] = '\u0037\u70B9';
  18179. t['\u3360'] = '\u0038\u70B9';
  18180. t['\u3361'] = '\u0039\u70B9';
  18181. t['\u3362'] = '\u0031\u0030\u70B9';
  18182. t['\u3363'] = '\u0031\u0031\u70B9';
  18183. t['\u3364'] = '\u0031\u0032\u70B9';
  18184. t['\u3365'] = '\u0031\u0033\u70B9';
  18185. t['\u3366'] = '\u0031\u0034\u70B9';
  18186. t['\u3367'] = '\u0031\u0035\u70B9';
  18187. t['\u3368'] = '\u0031\u0036\u70B9';
  18188. t['\u3369'] = '\u0031\u0037\u70B9';
  18189. t['\u336A'] = '\u0031\u0038\u70B9';
  18190. t['\u336B'] = '\u0031\u0039\u70B9';
  18191. t['\u336C'] = '\u0032\u0030\u70B9';
  18192. t['\u336D'] = '\u0032\u0031\u70B9';
  18193. t['\u336E'] = '\u0032\u0032\u70B9';
  18194. t['\u336F'] = '\u0032\u0033\u70B9';
  18195. t['\u3370'] = '\u0032\u0034\u70B9';
  18196. t['\u33E0'] = '\u0031\u65E5';
  18197. t['\u33E1'] = '\u0032\u65E5';
  18198. t['\u33E2'] = '\u0033\u65E5';
  18199. t['\u33E3'] = '\u0034\u65E5';
  18200. t['\u33E4'] = '\u0035\u65E5';
  18201. t['\u33E5'] = '\u0036\u65E5';
  18202. t['\u33E6'] = '\u0037\u65E5';
  18203. t['\u33E7'] = '\u0038\u65E5';
  18204. t['\u33E8'] = '\u0039\u65E5';
  18205. t['\u33E9'] = '\u0031\u0030\u65E5';
  18206. t['\u33EA'] = '\u0031\u0031\u65E5';
  18207. t['\u33EB'] = '\u0031\u0032\u65E5';
  18208. t['\u33EC'] = '\u0031\u0033\u65E5';
  18209. t['\u33ED'] = '\u0031\u0034\u65E5';
  18210. t['\u33EE'] = '\u0031\u0035\u65E5';
  18211. t['\u33EF'] = '\u0031\u0036\u65E5';
  18212. t['\u33F0'] = '\u0031\u0037\u65E5';
  18213. t['\u33F1'] = '\u0031\u0038\u65E5';
  18214. t['\u33F2'] = '\u0031\u0039\u65E5';
  18215. t['\u33F3'] = '\u0032\u0030\u65E5';
  18216. t['\u33F4'] = '\u0032\u0031\u65E5';
  18217. t['\u33F5'] = '\u0032\u0032\u65E5';
  18218. t['\u33F6'] = '\u0032\u0033\u65E5';
  18219. t['\u33F7'] = '\u0032\u0034\u65E5';
  18220. t['\u33F8'] = '\u0032\u0035\u65E5';
  18221. t['\u33F9'] = '\u0032\u0036\u65E5';
  18222. t['\u33FA'] = '\u0032\u0037\u65E5';
  18223. t['\u33FB'] = '\u0032\u0038\u65E5';
  18224. t['\u33FC'] = '\u0032\u0039\u65E5';
  18225. t['\u33FD'] = '\u0033\u0030\u65E5';
  18226. t['\u33FE'] = '\u0033\u0031\u65E5';
  18227. t['\uFB00'] = '\u0066\u0066';
  18228. t['\uFB01'] = '\u0066\u0069';
  18229. t['\uFB02'] = '\u0066\u006C';
  18230. t['\uFB03'] = '\u0066\u0066\u0069';
  18231. t['\uFB04'] = '\u0066\u0066\u006C';
  18232. t['\uFB05'] = '\u017F\u0074';
  18233. t['\uFB06'] = '\u0073\u0074';
  18234. t['\uFB13'] = '\u0574\u0576';
  18235. t['\uFB14'] = '\u0574\u0565';
  18236. t['\uFB15'] = '\u0574\u056B';
  18237. t['\uFB16'] = '\u057E\u0576';
  18238. t['\uFB17'] = '\u0574\u056D';
  18239. t['\uFB4F'] = '\u05D0\u05DC';
  18240. t['\uFB50'] = '\u0671';
  18241. t['\uFB51'] = '\u0671';
  18242. t['\uFB52'] = '\u067B';
  18243. t['\uFB53'] = '\u067B';
  18244. t['\uFB54'] = '\u067B';
  18245. t['\uFB55'] = '\u067B';
  18246. t['\uFB56'] = '\u067E';
  18247. t['\uFB57'] = '\u067E';
  18248. t['\uFB58'] = '\u067E';
  18249. t['\uFB59'] = '\u067E';
  18250. t['\uFB5A'] = '\u0680';
  18251. t['\uFB5B'] = '\u0680';
  18252. t['\uFB5C'] = '\u0680';
  18253. t['\uFB5D'] = '\u0680';
  18254. t['\uFB5E'] = '\u067A';
  18255. t['\uFB5F'] = '\u067A';
  18256. t['\uFB60'] = '\u067A';
  18257. t['\uFB61'] = '\u067A';
  18258. t['\uFB62'] = '\u067F';
  18259. t['\uFB63'] = '\u067F';
  18260. t['\uFB64'] = '\u067F';
  18261. t['\uFB65'] = '\u067F';
  18262. t['\uFB66'] = '\u0679';
  18263. t['\uFB67'] = '\u0679';
  18264. t['\uFB68'] = '\u0679';
  18265. t['\uFB69'] = '\u0679';
  18266. t['\uFB6A'] = '\u06A4';
  18267. t['\uFB6B'] = '\u06A4';
  18268. t['\uFB6C'] = '\u06A4';
  18269. t['\uFB6D'] = '\u06A4';
  18270. t['\uFB6E'] = '\u06A6';
  18271. t['\uFB6F'] = '\u06A6';
  18272. t['\uFB70'] = '\u06A6';
  18273. t['\uFB71'] = '\u06A6';
  18274. t['\uFB72'] = '\u0684';
  18275. t['\uFB73'] = '\u0684';
  18276. t['\uFB74'] = '\u0684';
  18277. t['\uFB75'] = '\u0684';
  18278. t['\uFB76'] = '\u0683';
  18279. t['\uFB77'] = '\u0683';
  18280. t['\uFB78'] = '\u0683';
  18281. t['\uFB79'] = '\u0683';
  18282. t['\uFB7A'] = '\u0686';
  18283. t['\uFB7B'] = '\u0686';
  18284. t['\uFB7C'] = '\u0686';
  18285. t['\uFB7D'] = '\u0686';
  18286. t['\uFB7E'] = '\u0687';
  18287. t['\uFB7F'] = '\u0687';
  18288. t['\uFB80'] = '\u0687';
  18289. t['\uFB81'] = '\u0687';
  18290. t['\uFB82'] = '\u068D';
  18291. t['\uFB83'] = '\u068D';
  18292. t['\uFB84'] = '\u068C';
  18293. t['\uFB85'] = '\u068C';
  18294. t['\uFB86'] = '\u068E';
  18295. t['\uFB87'] = '\u068E';
  18296. t['\uFB88'] = '\u0688';
  18297. t['\uFB89'] = '\u0688';
  18298. t['\uFB8A'] = '\u0698';
  18299. t['\uFB8B'] = '\u0698';
  18300. t['\uFB8C'] = '\u0691';
  18301. t['\uFB8D'] = '\u0691';
  18302. t['\uFB8E'] = '\u06A9';
  18303. t['\uFB8F'] = '\u06A9';
  18304. t['\uFB90'] = '\u06A9';
  18305. t['\uFB91'] = '\u06A9';
  18306. t['\uFB92'] = '\u06AF';
  18307. t['\uFB93'] = '\u06AF';
  18308. t['\uFB94'] = '\u06AF';
  18309. t['\uFB95'] = '\u06AF';
  18310. t['\uFB96'] = '\u06B3';
  18311. t['\uFB97'] = '\u06B3';
  18312. t['\uFB98'] = '\u06B3';
  18313. t['\uFB99'] = '\u06B3';
  18314. t['\uFB9A'] = '\u06B1';
  18315. t['\uFB9B'] = '\u06B1';
  18316. t['\uFB9C'] = '\u06B1';
  18317. t['\uFB9D'] = '\u06B1';
  18318. t['\uFB9E'] = '\u06BA';
  18319. t['\uFB9F'] = '\u06BA';
  18320. t['\uFBA0'] = '\u06BB';
  18321. t['\uFBA1'] = '\u06BB';
  18322. t['\uFBA2'] = '\u06BB';
  18323. t['\uFBA3'] = '\u06BB';
  18324. t['\uFBA4'] = '\u06C0';
  18325. t['\uFBA5'] = '\u06C0';
  18326. t['\uFBA6'] = '\u06C1';
  18327. t['\uFBA7'] = '\u06C1';
  18328. t['\uFBA8'] = '\u06C1';
  18329. t['\uFBA9'] = '\u06C1';
  18330. t['\uFBAA'] = '\u06BE';
  18331. t['\uFBAB'] = '\u06BE';
  18332. t['\uFBAC'] = '\u06BE';
  18333. t['\uFBAD'] = '\u06BE';
  18334. t['\uFBAE'] = '\u06D2';
  18335. t['\uFBAF'] = '\u06D2';
  18336. t['\uFBB0'] = '\u06D3';
  18337. t['\uFBB1'] = '\u06D3';
  18338. t['\uFBD3'] = '\u06AD';
  18339. t['\uFBD4'] = '\u06AD';
  18340. t['\uFBD5'] = '\u06AD';
  18341. t['\uFBD6'] = '\u06AD';
  18342. t['\uFBD7'] = '\u06C7';
  18343. t['\uFBD8'] = '\u06C7';
  18344. t['\uFBD9'] = '\u06C6';
  18345. t['\uFBDA'] = '\u06C6';
  18346. t['\uFBDB'] = '\u06C8';
  18347. t['\uFBDC'] = '\u06C8';
  18348. t['\uFBDD'] = '\u0677';
  18349. t['\uFBDE'] = '\u06CB';
  18350. t['\uFBDF'] = '\u06CB';
  18351. t['\uFBE0'] = '\u06C5';
  18352. t['\uFBE1'] = '\u06C5';
  18353. t['\uFBE2'] = '\u06C9';
  18354. t['\uFBE3'] = '\u06C9';
  18355. t['\uFBE4'] = '\u06D0';
  18356. t['\uFBE5'] = '\u06D0';
  18357. t['\uFBE6'] = '\u06D0';
  18358. t['\uFBE7'] = '\u06D0';
  18359. t['\uFBE8'] = '\u0649';
  18360. t['\uFBE9'] = '\u0649';
  18361. t['\uFBEA'] = '\u0626\u0627';
  18362. t['\uFBEB'] = '\u0626\u0627';
  18363. t['\uFBEC'] = '\u0626\u06D5';
  18364. t['\uFBED'] = '\u0626\u06D5';
  18365. t['\uFBEE'] = '\u0626\u0648';
  18366. t['\uFBEF'] = '\u0626\u0648';
  18367. t['\uFBF0'] = '\u0626\u06C7';
  18368. t['\uFBF1'] = '\u0626\u06C7';
  18369. t['\uFBF2'] = '\u0626\u06C6';
  18370. t['\uFBF3'] = '\u0626\u06C6';
  18371. t['\uFBF4'] = '\u0626\u06C8';
  18372. t['\uFBF5'] = '\u0626\u06C8';
  18373. t['\uFBF6'] = '\u0626\u06D0';
  18374. t['\uFBF7'] = '\u0626\u06D0';
  18375. t['\uFBF8'] = '\u0626\u06D0';
  18376. t['\uFBF9'] = '\u0626\u0649';
  18377. t['\uFBFA'] = '\u0626\u0649';
  18378. t['\uFBFB'] = '\u0626\u0649';
  18379. t['\uFBFC'] = '\u06CC';
  18380. t['\uFBFD'] = '\u06CC';
  18381. t['\uFBFE'] = '\u06CC';
  18382. t['\uFBFF'] = '\u06CC';
  18383. t['\uFC00'] = '\u0626\u062C';
  18384. t['\uFC01'] = '\u0626\u062D';
  18385. t['\uFC02'] = '\u0626\u0645';
  18386. t['\uFC03'] = '\u0626\u0649';
  18387. t['\uFC04'] = '\u0626\u064A';
  18388. t['\uFC05'] = '\u0628\u062C';
  18389. t['\uFC06'] = '\u0628\u062D';
  18390. t['\uFC07'] = '\u0628\u062E';
  18391. t['\uFC08'] = '\u0628\u0645';
  18392. t['\uFC09'] = '\u0628\u0649';
  18393. t['\uFC0A'] = '\u0628\u064A';
  18394. t['\uFC0B'] = '\u062A\u062C';
  18395. t['\uFC0C'] = '\u062A\u062D';
  18396. t['\uFC0D'] = '\u062A\u062E';
  18397. t['\uFC0E'] = '\u062A\u0645';
  18398. t['\uFC0F'] = '\u062A\u0649';
  18399. t['\uFC10'] = '\u062A\u064A';
  18400. t['\uFC11'] = '\u062B\u062C';
  18401. t['\uFC12'] = '\u062B\u0645';
  18402. t['\uFC13'] = '\u062B\u0649';
  18403. t['\uFC14'] = '\u062B\u064A';
  18404. t['\uFC15'] = '\u062C\u062D';
  18405. t['\uFC16'] = '\u062C\u0645';
  18406. t['\uFC17'] = '\u062D\u062C';
  18407. t['\uFC18'] = '\u062D\u0645';
  18408. t['\uFC19'] = '\u062E\u062C';
  18409. t['\uFC1A'] = '\u062E\u062D';
  18410. t['\uFC1B'] = '\u062E\u0645';
  18411. t['\uFC1C'] = '\u0633\u062C';
  18412. t['\uFC1D'] = '\u0633\u062D';
  18413. t['\uFC1E'] = '\u0633\u062E';
  18414. t['\uFC1F'] = '\u0633\u0645';
  18415. t['\uFC20'] = '\u0635\u062D';
  18416. t['\uFC21'] = '\u0635\u0645';
  18417. t['\uFC22'] = '\u0636\u062C';
  18418. t['\uFC23'] = '\u0636\u062D';
  18419. t['\uFC24'] = '\u0636\u062E';
  18420. t['\uFC25'] = '\u0636\u0645';
  18421. t['\uFC26'] = '\u0637\u062D';
  18422. t['\uFC27'] = '\u0637\u0645';
  18423. t['\uFC28'] = '\u0638\u0645';
  18424. t['\uFC29'] = '\u0639\u062C';
  18425. t['\uFC2A'] = '\u0639\u0645';
  18426. t['\uFC2B'] = '\u063A\u062C';
  18427. t['\uFC2C'] = '\u063A\u0645';
  18428. t['\uFC2D'] = '\u0641\u062C';
  18429. t['\uFC2E'] = '\u0641\u062D';
  18430. t['\uFC2F'] = '\u0641\u062E';
  18431. t['\uFC30'] = '\u0641\u0645';
  18432. t['\uFC31'] = '\u0641\u0649';
  18433. t['\uFC32'] = '\u0641\u064A';
  18434. t['\uFC33'] = '\u0642\u062D';
  18435. t['\uFC34'] = '\u0642\u0645';
  18436. t['\uFC35'] = '\u0642\u0649';
  18437. t['\uFC36'] = '\u0642\u064A';
  18438. t['\uFC37'] = '\u0643\u0627';
  18439. t['\uFC38'] = '\u0643\u062C';
  18440. t['\uFC39'] = '\u0643\u062D';
  18441. t['\uFC3A'] = '\u0643\u062E';
  18442. t['\uFC3B'] = '\u0643\u0644';
  18443. t['\uFC3C'] = '\u0643\u0645';
  18444. t['\uFC3D'] = '\u0643\u0649';
  18445. t['\uFC3E'] = '\u0643\u064A';
  18446. t['\uFC3F'] = '\u0644\u062C';
  18447. t['\uFC40'] = '\u0644\u062D';
  18448. t['\uFC41'] = '\u0644\u062E';
  18449. t['\uFC42'] = '\u0644\u0645';
  18450. t['\uFC43'] = '\u0644\u0649';
  18451. t['\uFC44'] = '\u0644\u064A';
  18452. t['\uFC45'] = '\u0645\u062C';
  18453. t['\uFC46'] = '\u0645\u062D';
  18454. t['\uFC47'] = '\u0645\u062E';
  18455. t['\uFC48'] = '\u0645\u0645';
  18456. t['\uFC49'] = '\u0645\u0649';
  18457. t['\uFC4A'] = '\u0645\u064A';
  18458. t['\uFC4B'] = '\u0646\u062C';
  18459. t['\uFC4C'] = '\u0646\u062D';
  18460. t['\uFC4D'] = '\u0646\u062E';
  18461. t['\uFC4E'] = '\u0646\u0645';
  18462. t['\uFC4F'] = '\u0646\u0649';
  18463. t['\uFC50'] = '\u0646\u064A';
  18464. t['\uFC51'] = '\u0647\u062C';
  18465. t['\uFC52'] = '\u0647\u0645';
  18466. t['\uFC53'] = '\u0647\u0649';
  18467. t['\uFC54'] = '\u0647\u064A';
  18468. t['\uFC55'] = '\u064A\u062C';
  18469. t['\uFC56'] = '\u064A\u062D';
  18470. t['\uFC57'] = '\u064A\u062E';
  18471. t['\uFC58'] = '\u064A\u0645';
  18472. t['\uFC59'] = '\u064A\u0649';
  18473. t['\uFC5A'] = '\u064A\u064A';
  18474. t['\uFC5B'] = '\u0630\u0670';
  18475. t['\uFC5C'] = '\u0631\u0670';
  18476. t['\uFC5D'] = '\u0649\u0670';
  18477. t['\uFC5E'] = '\u0020\u064C\u0651';
  18478. t['\uFC5F'] = '\u0020\u064D\u0651';
  18479. t['\uFC60'] = '\u0020\u064E\u0651';
  18480. t['\uFC61'] = '\u0020\u064F\u0651';
  18481. t['\uFC62'] = '\u0020\u0650\u0651';
  18482. t['\uFC63'] = '\u0020\u0651\u0670';
  18483. t['\uFC64'] = '\u0626\u0631';
  18484. t['\uFC65'] = '\u0626\u0632';
  18485. t['\uFC66'] = '\u0626\u0645';
  18486. t['\uFC67'] = '\u0626\u0646';
  18487. t['\uFC68'] = '\u0626\u0649';
  18488. t['\uFC69'] = '\u0626\u064A';
  18489. t['\uFC6A'] = '\u0628\u0631';
  18490. t['\uFC6B'] = '\u0628\u0632';
  18491. t['\uFC6C'] = '\u0628\u0645';
  18492. t['\uFC6D'] = '\u0628\u0646';
  18493. t['\uFC6E'] = '\u0628\u0649';
  18494. t['\uFC6F'] = '\u0628\u064A';
  18495. t['\uFC70'] = '\u062A\u0631';
  18496. t['\uFC71'] = '\u062A\u0632';
  18497. t['\uFC72'] = '\u062A\u0645';
  18498. t['\uFC73'] = '\u062A\u0646';
  18499. t['\uFC74'] = '\u062A\u0649';
  18500. t['\uFC75'] = '\u062A\u064A';
  18501. t['\uFC76'] = '\u062B\u0631';
  18502. t['\uFC77'] = '\u062B\u0632';
  18503. t['\uFC78'] = '\u062B\u0645';
  18504. t['\uFC79'] = '\u062B\u0646';
  18505. t['\uFC7A'] = '\u062B\u0649';
  18506. t['\uFC7B'] = '\u062B\u064A';
  18507. t['\uFC7C'] = '\u0641\u0649';
  18508. t['\uFC7D'] = '\u0641\u064A';
  18509. t['\uFC7E'] = '\u0642\u0649';
  18510. t['\uFC7F'] = '\u0642\u064A';
  18511. t['\uFC80'] = '\u0643\u0627';
  18512. t['\uFC81'] = '\u0643\u0644';
  18513. t['\uFC82'] = '\u0643\u0645';
  18514. t['\uFC83'] = '\u0643\u0649';
  18515. t['\uFC84'] = '\u0643\u064A';
  18516. t['\uFC85'] = '\u0644\u0645';
  18517. t['\uFC86'] = '\u0644\u0649';
  18518. t['\uFC87'] = '\u0644\u064A';
  18519. t['\uFC88'] = '\u0645\u0627';
  18520. t['\uFC89'] = '\u0645\u0645';
  18521. t['\uFC8A'] = '\u0646\u0631';
  18522. t['\uFC8B'] = '\u0646\u0632';
  18523. t['\uFC8C'] = '\u0646\u0645';
  18524. t['\uFC8D'] = '\u0646\u0646';
  18525. t['\uFC8E'] = '\u0646\u0649';
  18526. t['\uFC8F'] = '\u0646\u064A';
  18527. t['\uFC90'] = '\u0649\u0670';
  18528. t['\uFC91'] = '\u064A\u0631';
  18529. t['\uFC92'] = '\u064A\u0632';
  18530. t['\uFC93'] = '\u064A\u0645';
  18531. t['\uFC94'] = '\u064A\u0646';
  18532. t['\uFC95'] = '\u064A\u0649';
  18533. t['\uFC96'] = '\u064A\u064A';
  18534. t['\uFC97'] = '\u0626\u062C';
  18535. t['\uFC98'] = '\u0626\u062D';
  18536. t['\uFC99'] = '\u0626\u062E';
  18537. t['\uFC9A'] = '\u0626\u0645';
  18538. t['\uFC9B'] = '\u0626\u0647';
  18539. t['\uFC9C'] = '\u0628\u062C';
  18540. t['\uFC9D'] = '\u0628\u062D';
  18541. t['\uFC9E'] = '\u0628\u062E';
  18542. t['\uFC9F'] = '\u0628\u0645';
  18543. t['\uFCA0'] = '\u0628\u0647';
  18544. t['\uFCA1'] = '\u062A\u062C';
  18545. t['\uFCA2'] = '\u062A\u062D';
  18546. t['\uFCA3'] = '\u062A\u062E';
  18547. t['\uFCA4'] = '\u062A\u0645';
  18548. t['\uFCA5'] = '\u062A\u0647';
  18549. t['\uFCA6'] = '\u062B\u0645';
  18550. t['\uFCA7'] = '\u062C\u062D';
  18551. t['\uFCA8'] = '\u062C\u0645';
  18552. t['\uFCA9'] = '\u062D\u062C';
  18553. t['\uFCAA'] = '\u062D\u0645';
  18554. t['\uFCAB'] = '\u062E\u062C';
  18555. t['\uFCAC'] = '\u062E\u0645';
  18556. t['\uFCAD'] = '\u0633\u062C';
  18557. t['\uFCAE'] = '\u0633\u062D';
  18558. t['\uFCAF'] = '\u0633\u062E';
  18559. t['\uFCB0'] = '\u0633\u0645';
  18560. t['\uFCB1'] = '\u0635\u062D';
  18561. t['\uFCB2'] = '\u0635\u062E';
  18562. t['\uFCB3'] = '\u0635\u0645';
  18563. t['\uFCB4'] = '\u0636\u062C';
  18564. t['\uFCB5'] = '\u0636\u062D';
  18565. t['\uFCB6'] = '\u0636\u062E';
  18566. t['\uFCB7'] = '\u0636\u0645';
  18567. t['\uFCB8'] = '\u0637\u062D';
  18568. t['\uFCB9'] = '\u0638\u0645';
  18569. t['\uFCBA'] = '\u0639\u062C';
  18570. t['\uFCBB'] = '\u0639\u0645';
  18571. t['\uFCBC'] = '\u063A\u062C';
  18572. t['\uFCBD'] = '\u063A\u0645';
  18573. t['\uFCBE'] = '\u0641\u062C';
  18574. t['\uFCBF'] = '\u0641\u062D';
  18575. t['\uFCC0'] = '\u0641\u062E';
  18576. t['\uFCC1'] = '\u0641\u0645';
  18577. t['\uFCC2'] = '\u0642\u062D';
  18578. t['\uFCC3'] = '\u0642\u0645';
  18579. t['\uFCC4'] = '\u0643\u062C';
  18580. t['\uFCC5'] = '\u0643\u062D';
  18581. t['\uFCC6'] = '\u0643\u062E';
  18582. t['\uFCC7'] = '\u0643\u0644';
  18583. t['\uFCC8'] = '\u0643\u0645';
  18584. t['\uFCC9'] = '\u0644\u062C';
  18585. t['\uFCCA'] = '\u0644\u062D';
  18586. t['\uFCCB'] = '\u0644\u062E';
  18587. t['\uFCCC'] = '\u0644\u0645';
  18588. t['\uFCCD'] = '\u0644\u0647';
  18589. t['\uFCCE'] = '\u0645\u062C';
  18590. t['\uFCCF'] = '\u0645\u062D';
  18591. t['\uFCD0'] = '\u0645\u062E';
  18592. t['\uFCD1'] = '\u0645\u0645';
  18593. t['\uFCD2'] = '\u0646\u062C';
  18594. t['\uFCD3'] = '\u0646\u062D';
  18595. t['\uFCD4'] = '\u0646\u062E';
  18596. t['\uFCD5'] = '\u0646\u0645';
  18597. t['\uFCD6'] = '\u0646\u0647';
  18598. t['\uFCD7'] = '\u0647\u062C';
  18599. t['\uFCD8'] = '\u0647\u0645';
  18600. t['\uFCD9'] = '\u0647\u0670';
  18601. t['\uFCDA'] = '\u064A\u062C';
  18602. t['\uFCDB'] = '\u064A\u062D';
  18603. t['\uFCDC'] = '\u064A\u062E';
  18604. t['\uFCDD'] = '\u064A\u0645';
  18605. t['\uFCDE'] = '\u064A\u0647';
  18606. t['\uFCDF'] = '\u0626\u0645';
  18607. t['\uFCE0'] = '\u0626\u0647';
  18608. t['\uFCE1'] = '\u0628\u0645';
  18609. t['\uFCE2'] = '\u0628\u0647';
  18610. t['\uFCE3'] = '\u062A\u0645';
  18611. t['\uFCE4'] = '\u062A\u0647';
  18612. t['\uFCE5'] = '\u062B\u0645';
  18613. t['\uFCE6'] = '\u062B\u0647';
  18614. t['\uFCE7'] = '\u0633\u0645';
  18615. t['\uFCE8'] = '\u0633\u0647';
  18616. t['\uFCE9'] = '\u0634\u0645';
  18617. t['\uFCEA'] = '\u0634\u0647';
  18618. t['\uFCEB'] = '\u0643\u0644';
  18619. t['\uFCEC'] = '\u0643\u0645';
  18620. t['\uFCED'] = '\u0644\u0645';
  18621. t['\uFCEE'] = '\u0646\u0645';
  18622. t['\uFCEF'] = '\u0646\u0647';
  18623. t['\uFCF0'] = '\u064A\u0645';
  18624. t['\uFCF1'] = '\u064A\u0647';
  18625. t['\uFCF2'] = '\u0640\u064E\u0651';
  18626. t['\uFCF3'] = '\u0640\u064F\u0651';
  18627. t['\uFCF4'] = '\u0640\u0650\u0651';
  18628. t['\uFCF5'] = '\u0637\u0649';
  18629. t['\uFCF6'] = '\u0637\u064A';
  18630. t['\uFCF7'] = '\u0639\u0649';
  18631. t['\uFCF8'] = '\u0639\u064A';
  18632. t['\uFCF9'] = '\u063A\u0649';
  18633. t['\uFCFA'] = '\u063A\u064A';
  18634. t['\uFCFB'] = '\u0633\u0649';
  18635. t['\uFCFC'] = '\u0633\u064A';
  18636. t['\uFCFD'] = '\u0634\u0649';
  18637. t['\uFCFE'] = '\u0634\u064A';
  18638. t['\uFCFF'] = '\u062D\u0649';
  18639. t['\uFD00'] = '\u062D\u064A';
  18640. t['\uFD01'] = '\u062C\u0649';
  18641. t['\uFD02'] = '\u062C\u064A';
  18642. t['\uFD03'] = '\u062E\u0649';
  18643. t['\uFD04'] = '\u062E\u064A';
  18644. t['\uFD05'] = '\u0635\u0649';
  18645. t['\uFD06'] = '\u0635\u064A';
  18646. t['\uFD07'] = '\u0636\u0649';
  18647. t['\uFD08'] = '\u0636\u064A';
  18648. t['\uFD09'] = '\u0634\u062C';
  18649. t['\uFD0A'] = '\u0634\u062D';
  18650. t['\uFD0B'] = '\u0634\u062E';
  18651. t['\uFD0C'] = '\u0634\u0645';
  18652. t['\uFD0D'] = '\u0634\u0631';
  18653. t['\uFD0E'] = '\u0633\u0631';
  18654. t['\uFD0F'] = '\u0635\u0631';
  18655. t['\uFD10'] = '\u0636\u0631';
  18656. t['\uFD11'] = '\u0637\u0649';
  18657. t['\uFD12'] = '\u0637\u064A';
  18658. t['\uFD13'] = '\u0639\u0649';
  18659. t['\uFD14'] = '\u0639\u064A';
  18660. t['\uFD15'] = '\u063A\u0649';
  18661. t['\uFD16'] = '\u063A\u064A';
  18662. t['\uFD17'] = '\u0633\u0649';
  18663. t['\uFD18'] = '\u0633\u064A';
  18664. t['\uFD19'] = '\u0634\u0649';
  18665. t['\uFD1A'] = '\u0634\u064A';
  18666. t['\uFD1B'] = '\u062D\u0649';
  18667. t['\uFD1C'] = '\u062D\u064A';
  18668. t['\uFD1D'] = '\u062C\u0649';
  18669. t['\uFD1E'] = '\u062C\u064A';
  18670. t['\uFD1F'] = '\u062E\u0649';
  18671. t['\uFD20'] = '\u062E\u064A';
  18672. t['\uFD21'] = '\u0635\u0649';
  18673. t['\uFD22'] = '\u0635\u064A';
  18674. t['\uFD23'] = '\u0636\u0649';
  18675. t['\uFD24'] = '\u0636\u064A';
  18676. t['\uFD25'] = '\u0634\u062C';
  18677. t['\uFD26'] = '\u0634\u062D';
  18678. t['\uFD27'] = '\u0634\u062E';
  18679. t['\uFD28'] = '\u0634\u0645';
  18680. t['\uFD29'] = '\u0634\u0631';
  18681. t['\uFD2A'] = '\u0633\u0631';
  18682. t['\uFD2B'] = '\u0635\u0631';
  18683. t['\uFD2C'] = '\u0636\u0631';
  18684. t['\uFD2D'] = '\u0634\u062C';
  18685. t['\uFD2E'] = '\u0634\u062D';
  18686. t['\uFD2F'] = '\u0634\u062E';
  18687. t['\uFD30'] = '\u0634\u0645';
  18688. t['\uFD31'] = '\u0633\u0647';
  18689. t['\uFD32'] = '\u0634\u0647';
  18690. t['\uFD33'] = '\u0637\u0645';
  18691. t['\uFD34'] = '\u0633\u062C';
  18692. t['\uFD35'] = '\u0633\u062D';
  18693. t['\uFD36'] = '\u0633\u062E';
  18694. t['\uFD37'] = '\u0634\u062C';
  18695. t['\uFD38'] = '\u0634\u062D';
  18696. t['\uFD39'] = '\u0634\u062E';
  18697. t['\uFD3A'] = '\u0637\u0645';
  18698. t['\uFD3B'] = '\u0638\u0645';
  18699. t['\uFD3C'] = '\u0627\u064B';
  18700. t['\uFD3D'] = '\u0627\u064B';
  18701. t['\uFD50'] = '\u062A\u062C\u0645';
  18702. t['\uFD51'] = '\u062A\u062D\u062C';
  18703. t['\uFD52'] = '\u062A\u062D\u062C';
  18704. t['\uFD53'] = '\u062A\u062D\u0645';
  18705. t['\uFD54'] = '\u062A\u062E\u0645';
  18706. t['\uFD55'] = '\u062A\u0645\u062C';
  18707. t['\uFD56'] = '\u062A\u0645\u062D';
  18708. t['\uFD57'] = '\u062A\u0645\u062E';
  18709. t['\uFD58'] = '\u062C\u0645\u062D';
  18710. t['\uFD59'] = '\u062C\u0645\u062D';
  18711. t['\uFD5A'] = '\u062D\u0645\u064A';
  18712. t['\uFD5B'] = '\u062D\u0645\u0649';
  18713. t['\uFD5C'] = '\u0633\u062D\u062C';
  18714. t['\uFD5D'] = '\u0633\u062C\u062D';
  18715. t['\uFD5E'] = '\u0633\u062C\u0649';
  18716. t['\uFD5F'] = '\u0633\u0645\u062D';
  18717. t['\uFD60'] = '\u0633\u0645\u062D';
  18718. t['\uFD61'] = '\u0633\u0645\u062C';
  18719. t['\uFD62'] = '\u0633\u0645\u0645';
  18720. t['\uFD63'] = '\u0633\u0645\u0645';
  18721. t['\uFD64'] = '\u0635\u062D\u062D';
  18722. t['\uFD65'] = '\u0635\u062D\u062D';
  18723. t['\uFD66'] = '\u0635\u0645\u0645';
  18724. t['\uFD67'] = '\u0634\u062D\u0645';
  18725. t['\uFD68'] = '\u0634\u062D\u0645';
  18726. t['\uFD69'] = '\u0634\u062C\u064A';
  18727. t['\uFD6A'] = '\u0634\u0645\u062E';
  18728. t['\uFD6B'] = '\u0634\u0645\u062E';
  18729. t['\uFD6C'] = '\u0634\u0645\u0645';
  18730. t['\uFD6D'] = '\u0634\u0645\u0645';
  18731. t['\uFD6E'] = '\u0636\u062D\u0649';
  18732. t['\uFD6F'] = '\u0636\u062E\u0645';
  18733. t['\uFD70'] = '\u0636\u062E\u0645';
  18734. t['\uFD71'] = '\u0637\u0645\u062D';
  18735. t['\uFD72'] = '\u0637\u0645\u062D';
  18736. t['\uFD73'] = '\u0637\u0645\u0645';
  18737. t['\uFD74'] = '\u0637\u0645\u064A';
  18738. t['\uFD75'] = '\u0639\u062C\u0645';
  18739. t['\uFD76'] = '\u0639\u0645\u0645';
  18740. t['\uFD77'] = '\u0639\u0645\u0645';
  18741. t['\uFD78'] = '\u0639\u0645\u0649';
  18742. t['\uFD79'] = '\u063A\u0645\u0645';
  18743. t['\uFD7A'] = '\u063A\u0645\u064A';
  18744. t['\uFD7B'] = '\u063A\u0645\u0649';
  18745. t['\uFD7C'] = '\u0641\u062E\u0645';
  18746. t['\uFD7D'] = '\u0641\u062E\u0645';
  18747. t['\uFD7E'] = '\u0642\u0645\u062D';
  18748. t['\uFD7F'] = '\u0642\u0645\u0645';
  18749. t['\uFD80'] = '\u0644\u062D\u0645';
  18750. t['\uFD81'] = '\u0644\u062D\u064A';
  18751. t['\uFD82'] = '\u0644\u062D\u0649';
  18752. t['\uFD83'] = '\u0644\u062C\u062C';
  18753. t['\uFD84'] = '\u0644\u062C\u062C';
  18754. t['\uFD85'] = '\u0644\u062E\u0645';
  18755. t['\uFD86'] = '\u0644\u062E\u0645';
  18756. t['\uFD87'] = '\u0644\u0645\u062D';
  18757. t['\uFD88'] = '\u0644\u0645\u062D';
  18758. t['\uFD89'] = '\u0645\u062D\u062C';
  18759. t['\uFD8A'] = '\u0645\u062D\u0645';
  18760. t['\uFD8B'] = '\u0645\u062D\u064A';
  18761. t['\uFD8C'] = '\u0645\u062C\u062D';
  18762. t['\uFD8D'] = '\u0645\u062C\u0645';
  18763. t['\uFD8E'] = '\u0645\u062E\u062C';
  18764. t['\uFD8F'] = '\u0645\u062E\u0645';
  18765. t['\uFD92'] = '\u0645\u062C\u062E';
  18766. t['\uFD93'] = '\u0647\u0645\u062C';
  18767. t['\uFD94'] = '\u0647\u0645\u0645';
  18768. t['\uFD95'] = '\u0646\u062D\u0645';
  18769. t['\uFD96'] = '\u0646\u062D\u0649';
  18770. t['\uFD97'] = '\u0646\u062C\u0645';
  18771. t['\uFD98'] = '\u0646\u062C\u0645';
  18772. t['\uFD99'] = '\u0646\u062C\u0649';
  18773. t['\uFD9A'] = '\u0646\u0645\u064A';
  18774. t['\uFD9B'] = '\u0646\u0645\u0649';
  18775. t['\uFD9C'] = '\u064A\u0645\u0645';
  18776. t['\uFD9D'] = '\u064A\u0645\u0645';
  18777. t['\uFD9E'] = '\u0628\u062E\u064A';
  18778. t['\uFD9F'] = '\u062A\u062C\u064A';
  18779. t['\uFDA0'] = '\u062A\u062C\u0649';
  18780. t['\uFDA1'] = '\u062A\u062E\u064A';
  18781. t['\uFDA2'] = '\u062A\u062E\u0649';
  18782. t['\uFDA3'] = '\u062A\u0645\u064A';
  18783. t['\uFDA4'] = '\u062A\u0645\u0649';
  18784. t['\uFDA5'] = '\u062C\u0645\u064A';
  18785. t['\uFDA6'] = '\u062C\u062D\u0649';
  18786. t['\uFDA7'] = '\u062C\u0645\u0649';
  18787. t['\uFDA8'] = '\u0633\u062E\u0649';
  18788. t['\uFDA9'] = '\u0635\u062D\u064A';
  18789. t['\uFDAA'] = '\u0634\u062D\u064A';
  18790. t['\uFDAB'] = '\u0636\u062D\u064A';
  18791. t['\uFDAC'] = '\u0644\u062C\u064A';
  18792. t['\uFDAD'] = '\u0644\u0645\u064A';
  18793. t['\uFDAE'] = '\u064A\u062D\u064A';
  18794. t['\uFDAF'] = '\u064A\u062C\u064A';
  18795. t['\uFDB0'] = '\u064A\u0645\u064A';
  18796. t['\uFDB1'] = '\u0645\u0645\u064A';
  18797. t['\uFDB2'] = '\u0642\u0645\u064A';
  18798. t['\uFDB3'] = '\u0646\u062D\u064A';
  18799. t['\uFDB4'] = '\u0642\u0645\u062D';
  18800. t['\uFDB5'] = '\u0644\u062D\u0645';
  18801. t['\uFDB6'] = '\u0639\u0645\u064A';
  18802. t['\uFDB7'] = '\u0643\u0645\u064A';
  18803. t['\uFDB8'] = '\u0646\u062C\u062D';
  18804. t['\uFDB9'] = '\u0645\u062E\u064A';
  18805. t['\uFDBA'] = '\u0644\u062C\u0645';
  18806. t['\uFDBB'] = '\u0643\u0645\u0645';
  18807. t['\uFDBC'] = '\u0644\u062C\u0645';
  18808. t['\uFDBD'] = '\u0646\u062C\u062D';
  18809. t['\uFDBE'] = '\u062C\u062D\u064A';
  18810. t['\uFDBF'] = '\u062D\u062C\u064A';
  18811. t['\uFDC0'] = '\u0645\u062C\u064A';
  18812. t['\uFDC1'] = '\u0641\u0645\u064A';
  18813. t['\uFDC2'] = '\u0628\u062D\u064A';
  18814. t['\uFDC3'] = '\u0643\u0645\u0645';
  18815. t['\uFDC4'] = '\u0639\u062C\u0645';
  18816. t['\uFDC5'] = '\u0635\u0645\u0645';
  18817. t['\uFDC6'] = '\u0633\u062E\u064A';
  18818. t['\uFDC7'] = '\u0646\u062C\u064A';
  18819. t['\uFE49'] = '\u203E';
  18820. t['\uFE4A'] = '\u203E';
  18821. t['\uFE4B'] = '\u203E';
  18822. t['\uFE4C'] = '\u203E';
  18823. t['\uFE4D'] = '\u005F';
  18824. t['\uFE4E'] = '\u005F';
  18825. t['\uFE4F'] = '\u005F';
  18826. t['\uFE80'] = '\u0621';
  18827. t['\uFE81'] = '\u0622';
  18828. t['\uFE82'] = '\u0622';
  18829. t['\uFE83'] = '\u0623';
  18830. t['\uFE84'] = '\u0623';
  18831. t['\uFE85'] = '\u0624';
  18832. t['\uFE86'] = '\u0624';
  18833. t['\uFE87'] = '\u0625';
  18834. t['\uFE88'] = '\u0625';
  18835. t['\uFE89'] = '\u0626';
  18836. t['\uFE8A'] = '\u0626';
  18837. t['\uFE8B'] = '\u0626';
  18838. t['\uFE8C'] = '\u0626';
  18839. t['\uFE8D'] = '\u0627';
  18840. t['\uFE8E'] = '\u0627';
  18841. t['\uFE8F'] = '\u0628';
  18842. t['\uFE90'] = '\u0628';
  18843. t['\uFE91'] = '\u0628';
  18844. t['\uFE92'] = '\u0628';
  18845. t['\uFE93'] = '\u0629';
  18846. t['\uFE94'] = '\u0629';
  18847. t['\uFE95'] = '\u062A';
  18848. t['\uFE96'] = '\u062A';
  18849. t['\uFE97'] = '\u062A';
  18850. t['\uFE98'] = '\u062A';
  18851. t['\uFE99'] = '\u062B';
  18852. t['\uFE9A'] = '\u062B';
  18853. t['\uFE9B'] = '\u062B';
  18854. t['\uFE9C'] = '\u062B';
  18855. t['\uFE9D'] = '\u062C';
  18856. t['\uFE9E'] = '\u062C';
  18857. t['\uFE9F'] = '\u062C';
  18858. t['\uFEA0'] = '\u062C';
  18859. t['\uFEA1'] = '\u062D';
  18860. t['\uFEA2'] = '\u062D';
  18861. t['\uFEA3'] = '\u062D';
  18862. t['\uFEA4'] = '\u062D';
  18863. t['\uFEA5'] = '\u062E';
  18864. t['\uFEA6'] = '\u062E';
  18865. t['\uFEA7'] = '\u062E';
  18866. t['\uFEA8'] = '\u062E';
  18867. t['\uFEA9'] = '\u062F';
  18868. t['\uFEAA'] = '\u062F';
  18869. t['\uFEAB'] = '\u0630';
  18870. t['\uFEAC'] = '\u0630';
  18871. t['\uFEAD'] = '\u0631';
  18872. t['\uFEAE'] = '\u0631';
  18873. t['\uFEAF'] = '\u0632';
  18874. t['\uFEB0'] = '\u0632';
  18875. t['\uFEB1'] = '\u0633';
  18876. t['\uFEB2'] = '\u0633';
  18877. t['\uFEB3'] = '\u0633';
  18878. t['\uFEB4'] = '\u0633';
  18879. t['\uFEB5'] = '\u0634';
  18880. t['\uFEB6'] = '\u0634';
  18881. t['\uFEB7'] = '\u0634';
  18882. t['\uFEB8'] = '\u0634';
  18883. t['\uFEB9'] = '\u0635';
  18884. t['\uFEBA'] = '\u0635';
  18885. t['\uFEBB'] = '\u0635';
  18886. t['\uFEBC'] = '\u0635';
  18887. t['\uFEBD'] = '\u0636';
  18888. t['\uFEBE'] = '\u0636';
  18889. t['\uFEBF'] = '\u0636';
  18890. t['\uFEC0'] = '\u0636';
  18891. t['\uFEC1'] = '\u0637';
  18892. t['\uFEC2'] = '\u0637';
  18893. t['\uFEC3'] = '\u0637';
  18894. t['\uFEC4'] = '\u0637';
  18895. t['\uFEC5'] = '\u0638';
  18896. t['\uFEC6'] = '\u0638';
  18897. t['\uFEC7'] = '\u0638';
  18898. t['\uFEC8'] = '\u0638';
  18899. t['\uFEC9'] = '\u0639';
  18900. t['\uFECA'] = '\u0639';
  18901. t['\uFECB'] = '\u0639';
  18902. t['\uFECC'] = '\u0639';
  18903. t['\uFECD'] = '\u063A';
  18904. t['\uFECE'] = '\u063A';
  18905. t['\uFECF'] = '\u063A';
  18906. t['\uFED0'] = '\u063A';
  18907. t['\uFED1'] = '\u0641';
  18908. t['\uFED2'] = '\u0641';
  18909. t['\uFED3'] = '\u0641';
  18910. t['\uFED4'] = '\u0641';
  18911. t['\uFED5'] = '\u0642';
  18912. t['\uFED6'] = '\u0642';
  18913. t['\uFED7'] = '\u0642';
  18914. t['\uFED8'] = '\u0642';
  18915. t['\uFED9'] = '\u0643';
  18916. t['\uFEDA'] = '\u0643';
  18917. t['\uFEDB'] = '\u0643';
  18918. t['\uFEDC'] = '\u0643';
  18919. t['\uFEDD'] = '\u0644';
  18920. t['\uFEDE'] = '\u0644';
  18921. t['\uFEDF'] = '\u0644';
  18922. t['\uFEE0'] = '\u0644';
  18923. t['\uFEE1'] = '\u0645';
  18924. t['\uFEE2'] = '\u0645';
  18925. t['\uFEE3'] = '\u0645';
  18926. t['\uFEE4'] = '\u0645';
  18927. t['\uFEE5'] = '\u0646';
  18928. t['\uFEE6'] = '\u0646';
  18929. t['\uFEE7'] = '\u0646';
  18930. t['\uFEE8'] = '\u0646';
  18931. t['\uFEE9'] = '\u0647';
  18932. t['\uFEEA'] = '\u0647';
  18933. t['\uFEEB'] = '\u0647';
  18934. t['\uFEEC'] = '\u0647';
  18935. t['\uFEED'] = '\u0648';
  18936. t['\uFEEE'] = '\u0648';
  18937. t['\uFEEF'] = '\u0649';
  18938. t['\uFEF0'] = '\u0649';
  18939. t['\uFEF1'] = '\u064A';
  18940. t['\uFEF2'] = '\u064A';
  18941. t['\uFEF3'] = '\u064A';
  18942. t['\uFEF4'] = '\u064A';
  18943. t['\uFEF5'] = '\u0644\u0622';
  18944. t['\uFEF6'] = '\u0644\u0622';
  18945. t['\uFEF7'] = '\u0644\u0623';
  18946. t['\uFEF8'] = '\u0644\u0623';
  18947. t['\uFEF9'] = '\u0644\u0625';
  18948. t['\uFEFA'] = '\u0644\u0625';
  18949. t['\uFEFB'] = '\u0644\u0627';
  18950. t['\uFEFC'] = '\u0644\u0627';
  18951. });
  18952. function reverseIfRtl(chars) {
  18953. var charsLength = chars.length;
  18954. //reverse an arabic ligature
  18955. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18956. return chars;
  18957. }
  18958. var s = '';
  18959. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18960. s += chars[ii];
  18961. }
  18962. return s;
  18963. }
  18964. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18965. exports.reverseIfRtl = reverseIfRtl;
  18966. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18967. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18968. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18969. }));
  18970. (function (root, factory) {
  18971. {
  18972. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  18973. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  18974. root.pdfjsCoreJpx);
  18975. }
  18976. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  18977. coreJpx) {
  18978. var Util = sharedUtil.Util;
  18979. var error = sharedUtil.error;
  18980. var info = sharedUtil.info;
  18981. var isInt = sharedUtil.isInt;
  18982. var isArray = sharedUtil.isArray;
  18983. var createObjectURL = sharedUtil.createObjectURL;
  18984. var shadow = sharedUtil.shadow;
  18985. var warn = sharedUtil.warn;
  18986. var isSpace = sharedUtil.isSpace;
  18987. var Dict = corePrimitives.Dict;
  18988. var isDict = corePrimitives.isDict;
  18989. var Jbig2Image = coreJbig2.Jbig2Image;
  18990. var JpegImage = coreJpg.JpegImage;
  18991. var JpxImage = coreJpx.JpxImage;
  18992. var Stream = (function StreamClosure() {
  18993. function Stream(arrayBuffer, start, length, dict) {
  18994. this.bytes = (arrayBuffer instanceof Uint8Array ?
  18995. arrayBuffer : new Uint8Array(arrayBuffer));
  18996. this.start = start || 0;
  18997. this.pos = this.start;
  18998. this.end = (start + length) || this.bytes.length;
  18999. this.dict = dict;
  19000. }
  19001. // required methods for a stream. if a particular stream does not
  19002. // implement these, an error should be thrown
  19003. Stream.prototype = {
  19004. get length() {
  19005. return this.end - this.start;
  19006. },
  19007. get isEmpty() {
  19008. return this.length === 0;
  19009. },
  19010. getByte: function Stream_getByte() {
  19011. if (this.pos >= this.end) {
  19012. return -1;
  19013. }
  19014. return this.bytes[this.pos++];
  19015. },
  19016. getUint16: function Stream_getUint16() {
  19017. var b0 = this.getByte();
  19018. var b1 = this.getByte();
  19019. if (b0 === -1 || b1 === -1) {
  19020. return -1;
  19021. }
  19022. return (b0 << 8) + b1;
  19023. },
  19024. getInt32: function Stream_getInt32() {
  19025. var b0 = this.getByte();
  19026. var b1 = this.getByte();
  19027. var b2 = this.getByte();
  19028. var b3 = this.getByte();
  19029. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19030. },
  19031. // returns subarray of original buffer
  19032. // should only be read
  19033. getBytes: function Stream_getBytes(length) {
  19034. var bytes = this.bytes;
  19035. var pos = this.pos;
  19036. var strEnd = this.end;
  19037. if (!length) {
  19038. return bytes.subarray(pos, strEnd);
  19039. }
  19040. var end = pos + length;
  19041. if (end > strEnd) {
  19042. end = strEnd;
  19043. }
  19044. this.pos = end;
  19045. return bytes.subarray(pos, end);
  19046. },
  19047. peekByte: function Stream_peekByte() {
  19048. var peekedByte = this.getByte();
  19049. this.pos--;
  19050. return peekedByte;
  19051. },
  19052. peekBytes: function Stream_peekBytes(length) {
  19053. var bytes = this.getBytes(length);
  19054. this.pos -= bytes.length;
  19055. return bytes;
  19056. },
  19057. skip: function Stream_skip(n) {
  19058. if (!n) {
  19059. n = 1;
  19060. }
  19061. this.pos += n;
  19062. },
  19063. reset: function Stream_reset() {
  19064. this.pos = this.start;
  19065. },
  19066. moveStart: function Stream_moveStart() {
  19067. this.start = this.pos;
  19068. },
  19069. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  19070. return new Stream(this.bytes.buffer, start, length, dict);
  19071. },
  19072. isStream: true
  19073. };
  19074. return Stream;
  19075. })();
  19076. var StringStream = (function StringStreamClosure() {
  19077. function StringStream(str) {
  19078. var length = str.length;
  19079. var bytes = new Uint8Array(length);
  19080. for (var n = 0; n < length; ++n) {
  19081. bytes[n] = str.charCodeAt(n);
  19082. }
  19083. Stream.call(this, bytes);
  19084. }
  19085. StringStream.prototype = Stream.prototype;
  19086. return StringStream;
  19087. })();
  19088. // super class for the decoding streams
  19089. var DecodeStream = (function DecodeStreamClosure() {
  19090. // Lots of DecodeStreams are created whose buffers are never used. For these
  19091. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  19092. // having special cases that would be required if we used |null| for an empty
  19093. // buffer.
  19094. var emptyBuffer = new Uint8Array(0);
  19095. function DecodeStream(maybeMinBufferLength) {
  19096. this.pos = 0;
  19097. this.bufferLength = 0;
  19098. this.eof = false;
  19099. this.buffer = emptyBuffer;
  19100. this.minBufferLength = 512;
  19101. if (maybeMinBufferLength) {
  19102. // Compute the first power of two that is as big as maybeMinBufferLength.
  19103. while (this.minBufferLength < maybeMinBufferLength) {
  19104. this.minBufferLength *= 2;
  19105. }
  19106. }
  19107. }
  19108. DecodeStream.prototype = {
  19109. get isEmpty() {
  19110. while (!this.eof && this.bufferLength === 0) {
  19111. this.readBlock();
  19112. }
  19113. return this.bufferLength === 0;
  19114. },
  19115. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  19116. var buffer = this.buffer;
  19117. if (requested <= buffer.byteLength) {
  19118. return buffer;
  19119. }
  19120. var size = this.minBufferLength;
  19121. while (size < requested) {
  19122. size *= 2;
  19123. }
  19124. var buffer2 = new Uint8Array(size);
  19125. buffer2.set(buffer);
  19126. return (this.buffer = buffer2);
  19127. },
  19128. getByte: function DecodeStream_getByte() {
  19129. var pos = this.pos;
  19130. while (this.bufferLength <= pos) {
  19131. if (this.eof) {
  19132. return -1;
  19133. }
  19134. this.readBlock();
  19135. }
  19136. return this.buffer[this.pos++];
  19137. },
  19138. getUint16: function DecodeStream_getUint16() {
  19139. var b0 = this.getByte();
  19140. var b1 = this.getByte();
  19141. if (b0 === -1 || b1 === -1) {
  19142. return -1;
  19143. }
  19144. return (b0 << 8) + b1;
  19145. },
  19146. getInt32: function DecodeStream_getInt32() {
  19147. var b0 = this.getByte();
  19148. var b1 = this.getByte();
  19149. var b2 = this.getByte();
  19150. var b3 = this.getByte();
  19151. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19152. },
  19153. getBytes: function DecodeStream_getBytes(length) {
  19154. var end, pos = this.pos;
  19155. if (length) {
  19156. this.ensureBuffer(pos + length);
  19157. end = pos + length;
  19158. while (!this.eof && this.bufferLength < end) {
  19159. this.readBlock();
  19160. }
  19161. var bufEnd = this.bufferLength;
  19162. if (end > bufEnd) {
  19163. end = bufEnd;
  19164. }
  19165. } else {
  19166. while (!this.eof) {
  19167. this.readBlock();
  19168. }
  19169. end = this.bufferLength;
  19170. }
  19171. this.pos = end;
  19172. return this.buffer.subarray(pos, end);
  19173. },
  19174. peekByte: function DecodeStream_peekByte() {
  19175. var peekedByte = this.getByte();
  19176. this.pos--;
  19177. return peekedByte;
  19178. },
  19179. peekBytes: function DecodeStream_peekBytes(length) {
  19180. var bytes = this.getBytes(length);
  19181. this.pos -= bytes.length;
  19182. return bytes;
  19183. },
  19184. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  19185. var end = start + length;
  19186. while (this.bufferLength <= end && !this.eof) {
  19187. this.readBlock();
  19188. }
  19189. return new Stream(this.buffer, start, length, dict);
  19190. },
  19191. skip: function DecodeStream_skip(n) {
  19192. if (!n) {
  19193. n = 1;
  19194. }
  19195. this.pos += n;
  19196. },
  19197. reset: function DecodeStream_reset() {
  19198. this.pos = 0;
  19199. },
  19200. getBaseStreams: function DecodeStream_getBaseStreams() {
  19201. if (this.str && this.str.getBaseStreams) {
  19202. return this.str.getBaseStreams();
  19203. }
  19204. return [];
  19205. }
  19206. };
  19207. return DecodeStream;
  19208. })();
  19209. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  19210. function StreamsSequenceStream(streams) {
  19211. this.streams = streams;
  19212. DecodeStream.call(this, /* maybeLength = */ null);
  19213. }
  19214. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  19215. StreamsSequenceStream.prototype.readBlock =
  19216. function streamSequenceStreamReadBlock() {
  19217. var streams = this.streams;
  19218. if (streams.length === 0) {
  19219. this.eof = true;
  19220. return;
  19221. }
  19222. var stream = streams.shift();
  19223. var chunk = stream.getBytes();
  19224. var bufferLength = this.bufferLength;
  19225. var newLength = bufferLength + chunk.length;
  19226. var buffer = this.ensureBuffer(newLength);
  19227. buffer.set(chunk, bufferLength);
  19228. this.bufferLength = newLength;
  19229. };
  19230. StreamsSequenceStream.prototype.getBaseStreams =
  19231. function StreamsSequenceStream_getBaseStreams() {
  19232. var baseStreams = [];
  19233. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  19234. var stream = this.streams[i];
  19235. if (stream.getBaseStreams) {
  19236. Util.appendToArray(baseStreams, stream.getBaseStreams());
  19237. }
  19238. }
  19239. return baseStreams;
  19240. };
  19241. return StreamsSequenceStream;
  19242. })();
  19243. var FlateStream = (function FlateStreamClosure() {
  19244. var codeLenCodeMap = new Int32Array([
  19245. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  19246. ]);
  19247. var lengthDecode = new Int32Array([
  19248. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  19249. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  19250. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  19251. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  19252. ]);
  19253. var distDecode = new Int32Array([
  19254. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  19255. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  19256. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  19257. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  19258. ]);
  19259. var fixedLitCodeTab = [new Int32Array([
  19260. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  19261. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  19262. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  19263. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  19264. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  19265. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  19266. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  19267. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  19268. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  19269. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  19270. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  19271. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  19272. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  19273. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  19274. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  19275. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  19276. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  19277. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  19278. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  19279. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  19280. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  19281. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  19282. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  19283. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  19284. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  19285. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  19286. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  19287. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  19288. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  19289. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  19290. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  19291. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  19292. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  19293. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  19294. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  19295. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  19296. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  19297. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  19298. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  19299. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  19300. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  19301. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  19302. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  19303. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  19304. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  19305. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  19306. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  19307. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  19308. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  19309. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  19310. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  19311. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  19312. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  19313. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  19314. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  19315. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  19316. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  19317. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  19318. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  19319. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  19320. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  19321. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  19322. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  19323. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  19324. ]), 9];
  19325. var fixedDistCodeTab = [new Int32Array([
  19326. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  19327. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  19328. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  19329. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  19330. ]), 5];
  19331. function FlateStream(str, maybeLength) {
  19332. this.str = str;
  19333. this.dict = str.dict;
  19334. var cmf = str.getByte();
  19335. var flg = str.getByte();
  19336. if (cmf === -1 || flg === -1) {
  19337. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  19338. }
  19339. if ((cmf & 0x0f) !== 0x08) {
  19340. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  19341. }
  19342. if ((((cmf << 8) + flg) % 31) !== 0) {
  19343. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  19344. }
  19345. if (flg & 0x20) {
  19346. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  19347. }
  19348. this.codeSize = 0;
  19349. this.codeBuf = 0;
  19350. DecodeStream.call(this, maybeLength);
  19351. }
  19352. FlateStream.prototype = Object.create(DecodeStream.prototype);
  19353. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  19354. var str = this.str;
  19355. var codeSize = this.codeSize;
  19356. var codeBuf = this.codeBuf;
  19357. var b;
  19358. while (codeSize < bits) {
  19359. if ((b = str.getByte()) === -1) {
  19360. error('Bad encoding in flate stream');
  19361. }
  19362. codeBuf |= b << codeSize;
  19363. codeSize += 8;
  19364. }
  19365. b = codeBuf & ((1 << bits) - 1);
  19366. this.codeBuf = codeBuf >> bits;
  19367. this.codeSize = codeSize -= bits;
  19368. return b;
  19369. };
  19370. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  19371. var str = this.str;
  19372. var codes = table[0];
  19373. var maxLen = table[1];
  19374. var codeSize = this.codeSize;
  19375. var codeBuf = this.codeBuf;
  19376. var b;
  19377. while (codeSize < maxLen) {
  19378. if ((b = str.getByte()) === -1) {
  19379. // premature end of stream. code might however still be valid.
  19380. // codeSize < codeLen check below guards against incomplete codeVal.
  19381. break;
  19382. }
  19383. codeBuf |= (b << codeSize);
  19384. codeSize += 8;
  19385. }
  19386. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  19387. var codeLen = code >> 16;
  19388. var codeVal = code & 0xffff;
  19389. if (codeLen < 1 || codeSize < codeLen) {
  19390. error('Bad encoding in flate stream');
  19391. }
  19392. this.codeBuf = (codeBuf >> codeLen);
  19393. this.codeSize = (codeSize - codeLen);
  19394. return codeVal;
  19395. };
  19396. FlateStream.prototype.generateHuffmanTable =
  19397. function flateStreamGenerateHuffmanTable(lengths) {
  19398. var n = lengths.length;
  19399. // find max code length
  19400. var maxLen = 0;
  19401. var i;
  19402. for (i = 0; i < n; ++i) {
  19403. if (lengths[i] > maxLen) {
  19404. maxLen = lengths[i];
  19405. }
  19406. }
  19407. // build the table
  19408. var size = 1 << maxLen;
  19409. var codes = new Int32Array(size);
  19410. for (var len = 1, code = 0, skip = 2;
  19411. len <= maxLen;
  19412. ++len, code <<= 1, skip <<= 1) {
  19413. for (var val = 0; val < n; ++val) {
  19414. if (lengths[val] === len) {
  19415. // bit-reverse the code
  19416. var code2 = 0;
  19417. var t = code;
  19418. for (i = 0; i < len; ++i) {
  19419. code2 = (code2 << 1) | (t & 1);
  19420. t >>= 1;
  19421. }
  19422. // fill the table entries
  19423. for (i = code2; i < size; i += skip) {
  19424. codes[i] = (len << 16) | val;
  19425. }
  19426. ++code;
  19427. }
  19428. }
  19429. }
  19430. return [codes, maxLen];
  19431. };
  19432. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  19433. var buffer, len;
  19434. var str = this.str;
  19435. // read block header
  19436. var hdr = this.getBits(3);
  19437. if (hdr & 1) {
  19438. this.eof = true;
  19439. }
  19440. hdr >>= 1;
  19441. if (hdr === 0) { // uncompressed block
  19442. var b;
  19443. if ((b = str.getByte()) === -1) {
  19444. error('Bad block header in flate stream');
  19445. }
  19446. var blockLen = b;
  19447. if ((b = str.getByte()) === -1) {
  19448. error('Bad block header in flate stream');
  19449. }
  19450. blockLen |= (b << 8);
  19451. if ((b = str.getByte()) === -1) {
  19452. error('Bad block header in flate stream');
  19453. }
  19454. var check = b;
  19455. if ((b = str.getByte()) === -1) {
  19456. error('Bad block header in flate stream');
  19457. }
  19458. check |= (b << 8);
  19459. if (check !== (~blockLen & 0xffff) &&
  19460. (blockLen !== 0 || check !== 0)) {
  19461. // Ignoring error for bad "empty" block (see issue 1277)
  19462. error('Bad uncompressed block length in flate stream');
  19463. }
  19464. this.codeBuf = 0;
  19465. this.codeSize = 0;
  19466. var bufferLength = this.bufferLength;
  19467. buffer = this.ensureBuffer(bufferLength + blockLen);
  19468. var end = bufferLength + blockLen;
  19469. this.bufferLength = end;
  19470. if (blockLen === 0) {
  19471. if (str.peekByte() === -1) {
  19472. this.eof = true;
  19473. }
  19474. } else {
  19475. for (var n = bufferLength; n < end; ++n) {
  19476. if ((b = str.getByte()) === -1) {
  19477. this.eof = true;
  19478. break;
  19479. }
  19480. buffer[n] = b;
  19481. }
  19482. }
  19483. return;
  19484. }
  19485. var litCodeTable;
  19486. var distCodeTable;
  19487. if (hdr === 1) { // compressed block, fixed codes
  19488. litCodeTable = fixedLitCodeTab;
  19489. distCodeTable = fixedDistCodeTab;
  19490. } else if (hdr === 2) { // compressed block, dynamic codes
  19491. var numLitCodes = this.getBits(5) + 257;
  19492. var numDistCodes = this.getBits(5) + 1;
  19493. var numCodeLenCodes = this.getBits(4) + 4;
  19494. // build the code lengths code table
  19495. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  19496. var i;
  19497. for (i = 0; i < numCodeLenCodes; ++i) {
  19498. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  19499. }
  19500. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  19501. // build the literal and distance code tables
  19502. len = 0;
  19503. i = 0;
  19504. var codes = numLitCodes + numDistCodes;
  19505. var codeLengths = new Uint8Array(codes);
  19506. var bitsLength, bitsOffset, what;
  19507. while (i < codes) {
  19508. var code = this.getCode(codeLenCodeTab);
  19509. if (code === 16) {
  19510. bitsLength = 2; bitsOffset = 3; what = len;
  19511. } else if (code === 17) {
  19512. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  19513. } else if (code === 18) {
  19514. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  19515. } else {
  19516. codeLengths[i++] = len = code;
  19517. continue;
  19518. }
  19519. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  19520. while (repeatLength-- > 0) {
  19521. codeLengths[i++] = what;
  19522. }
  19523. }
  19524. litCodeTable =
  19525. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  19526. distCodeTable =
  19527. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  19528. } else {
  19529. error('Unknown block type in flate stream');
  19530. }
  19531. buffer = this.buffer;
  19532. var limit = buffer ? buffer.length : 0;
  19533. var pos = this.bufferLength;
  19534. while (true) {
  19535. var code1 = this.getCode(litCodeTable);
  19536. if (code1 < 256) {
  19537. if (pos + 1 >= limit) {
  19538. buffer = this.ensureBuffer(pos + 1);
  19539. limit = buffer.length;
  19540. }
  19541. buffer[pos++] = code1;
  19542. continue;
  19543. }
  19544. if (code1 === 256) {
  19545. this.bufferLength = pos;
  19546. return;
  19547. }
  19548. code1 -= 257;
  19549. code1 = lengthDecode[code1];
  19550. var code2 = code1 >> 16;
  19551. if (code2 > 0) {
  19552. code2 = this.getBits(code2);
  19553. }
  19554. len = (code1 & 0xffff) + code2;
  19555. code1 = this.getCode(distCodeTable);
  19556. code1 = distDecode[code1];
  19557. code2 = code1 >> 16;
  19558. if (code2 > 0) {
  19559. code2 = this.getBits(code2);
  19560. }
  19561. var dist = (code1 & 0xffff) + code2;
  19562. if (pos + len >= limit) {
  19563. buffer = this.ensureBuffer(pos + len);
  19564. limit = buffer.length;
  19565. }
  19566. for (var k = 0; k < len; ++k, ++pos) {
  19567. buffer[pos] = buffer[pos - dist];
  19568. }
  19569. }
  19570. };
  19571. return FlateStream;
  19572. })();
  19573. var PredictorStream = (function PredictorStreamClosure() {
  19574. function PredictorStream(str, maybeLength, params) {
  19575. if (!isDict(params)) {
  19576. return str; // no prediction
  19577. }
  19578. var predictor = this.predictor = params.get('Predictor') || 1;
  19579. if (predictor <= 1) {
  19580. return str; // no prediction
  19581. }
  19582. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  19583. error('Unsupported predictor: ' + predictor);
  19584. }
  19585. if (predictor === 2) {
  19586. this.readBlock = this.readBlockTiff;
  19587. } else {
  19588. this.readBlock = this.readBlockPng;
  19589. }
  19590. this.str = str;
  19591. this.dict = str.dict;
  19592. var colors = this.colors = params.get('Colors') || 1;
  19593. var bits = this.bits = params.get('BitsPerComponent') || 8;
  19594. var columns = this.columns = params.get('Columns') || 1;
  19595. this.pixBytes = (colors * bits + 7) >> 3;
  19596. this.rowBytes = (columns * colors * bits + 7) >> 3;
  19597. DecodeStream.call(this, maybeLength);
  19598. return this;
  19599. }
  19600. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  19601. PredictorStream.prototype.readBlockTiff =
  19602. function predictorStreamReadBlockTiff() {
  19603. var rowBytes = this.rowBytes;
  19604. var bufferLength = this.bufferLength;
  19605. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19606. var bits = this.bits;
  19607. var colors = this.colors;
  19608. var rawBytes = this.str.getBytes(rowBytes);
  19609. this.eof = !rawBytes.length;
  19610. if (this.eof) {
  19611. return;
  19612. }
  19613. var inbuf = 0, outbuf = 0;
  19614. var inbits = 0, outbits = 0;
  19615. var pos = bufferLength;
  19616. var i;
  19617. if (bits === 1) {
  19618. for (i = 0; i < rowBytes; ++i) {
  19619. var c = rawBytes[i];
  19620. inbuf = (inbuf << 8) | c;
  19621. // bitwise addition is exclusive or
  19622. // first shift inbuf and then add
  19623. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  19624. // truncate inbuf (assumes colors < 16)
  19625. inbuf &= 0xFFFF;
  19626. }
  19627. } else if (bits === 8) {
  19628. for (i = 0; i < colors; ++i) {
  19629. buffer[pos++] = rawBytes[i];
  19630. }
  19631. for (; i < rowBytes; ++i) {
  19632. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  19633. pos++;
  19634. }
  19635. } else {
  19636. var compArray = new Uint8Array(colors + 1);
  19637. var bitMask = (1 << bits) - 1;
  19638. var j = 0, k = bufferLength;
  19639. var columns = this.columns;
  19640. for (i = 0; i < columns; ++i) {
  19641. for (var kk = 0; kk < colors; ++kk) {
  19642. if (inbits < bits) {
  19643. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  19644. inbits += 8;
  19645. }
  19646. compArray[kk] = (compArray[kk] +
  19647. (inbuf >> (inbits - bits))) & bitMask;
  19648. inbits -= bits;
  19649. outbuf = (outbuf << bits) | compArray[kk];
  19650. outbits += bits;
  19651. if (outbits >= 8) {
  19652. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  19653. outbits -= 8;
  19654. }
  19655. }
  19656. }
  19657. if (outbits > 0) {
  19658. buffer[k++] = (outbuf << (8 - outbits)) +
  19659. (inbuf & ((1 << (8 - outbits)) - 1));
  19660. }
  19661. }
  19662. this.bufferLength += rowBytes;
  19663. };
  19664. PredictorStream.prototype.readBlockPng =
  19665. function predictorStreamReadBlockPng() {
  19666. var rowBytes = this.rowBytes;
  19667. var pixBytes = this.pixBytes;
  19668. var predictor = this.str.getByte();
  19669. var rawBytes = this.str.getBytes(rowBytes);
  19670. this.eof = !rawBytes.length;
  19671. if (this.eof) {
  19672. return;
  19673. }
  19674. var bufferLength = this.bufferLength;
  19675. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19676. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  19677. if (prevRow.length === 0) {
  19678. prevRow = new Uint8Array(rowBytes);
  19679. }
  19680. var i, j = bufferLength, up, c;
  19681. switch (predictor) {
  19682. case 0:
  19683. for (i = 0; i < rowBytes; ++i) {
  19684. buffer[j++] = rawBytes[i];
  19685. }
  19686. break;
  19687. case 1:
  19688. for (i = 0; i < pixBytes; ++i) {
  19689. buffer[j++] = rawBytes[i];
  19690. }
  19691. for (; i < rowBytes; ++i) {
  19692. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  19693. j++;
  19694. }
  19695. break;
  19696. case 2:
  19697. for (i = 0; i < rowBytes; ++i) {
  19698. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  19699. }
  19700. break;
  19701. case 3:
  19702. for (i = 0; i < pixBytes; ++i) {
  19703. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  19704. }
  19705. for (; i < rowBytes; ++i) {
  19706. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  19707. rawBytes[i]) & 0xFF;
  19708. j++;
  19709. }
  19710. break;
  19711. case 4:
  19712. // we need to save the up left pixels values. the simplest way
  19713. // is to create a new buffer
  19714. for (i = 0; i < pixBytes; ++i) {
  19715. up = prevRow[i];
  19716. c = rawBytes[i];
  19717. buffer[j++] = up + c;
  19718. }
  19719. for (; i < rowBytes; ++i) {
  19720. up = prevRow[i];
  19721. var upLeft = prevRow[i - pixBytes];
  19722. var left = buffer[j - pixBytes];
  19723. var p = left + up - upLeft;
  19724. var pa = p - left;
  19725. if (pa < 0) {
  19726. pa = -pa;
  19727. }
  19728. var pb = p - up;
  19729. if (pb < 0) {
  19730. pb = -pb;
  19731. }
  19732. var pc = p - upLeft;
  19733. if (pc < 0) {
  19734. pc = -pc;
  19735. }
  19736. c = rawBytes[i];
  19737. if (pa <= pb && pa <= pc) {
  19738. buffer[j++] = left + c;
  19739. } else if (pb <= pc) {
  19740. buffer[j++] = up + c;
  19741. } else {
  19742. buffer[j++] = upLeft + c;
  19743. }
  19744. }
  19745. break;
  19746. default:
  19747. error('Unsupported predictor: ' + predictor);
  19748. }
  19749. this.bufferLength += rowBytes;
  19750. };
  19751. return PredictorStream;
  19752. })();
  19753. /**
  19754. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  19755. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  19756. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  19757. * a library to decode these images and the stream behaves like all the other
  19758. * DecodeStreams.
  19759. */
  19760. var JpegStream = (function JpegStreamClosure() {
  19761. function JpegStream(stream, maybeLength, dict) {
  19762. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  19763. // Note: this seems to mainly affect inline images.
  19764. var ch;
  19765. while ((ch = stream.getByte()) !== -1) {
  19766. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  19767. stream.skip(-1); // Reset the stream position to the SOI.
  19768. break;
  19769. }
  19770. }
  19771. this.stream = stream;
  19772. this.maybeLength = maybeLength;
  19773. this.dict = dict;
  19774. DecodeStream.call(this, maybeLength);
  19775. }
  19776. JpegStream.prototype = Object.create(DecodeStream.prototype);
  19777. Object.defineProperty(JpegStream.prototype, 'bytes', {
  19778. get: function JpegStream_bytes() {
  19779. // If this.maybeLength is null, we'll get the entire stream.
  19780. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19781. },
  19782. configurable: true
  19783. });
  19784. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  19785. if (this.bufferLength) {
  19786. return;
  19787. }
  19788. var jpegImage = new JpegImage();
  19789. // Checking if values need to be transformed before conversion.
  19790. var decodeArr = this.dict.getArray('Decode', 'D');
  19791. if (this.forceRGB && isArray(decodeArr)) {
  19792. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  19793. var decodeArrLength = decodeArr.length;
  19794. var transform = new Int32Array(decodeArrLength);
  19795. var transformNeeded = false;
  19796. var maxValue = (1 << bitsPerComponent) - 1;
  19797. for (var i = 0; i < decodeArrLength; i += 2) {
  19798. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  19799. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  19800. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  19801. transformNeeded = true;
  19802. }
  19803. }
  19804. if (transformNeeded) {
  19805. jpegImage.decodeTransform = transform;
  19806. }
  19807. }
  19808. // Fetching the 'ColorTransform' entry, if it exists.
  19809. var decodeParams = this.dict.get('DecodeParms', 'DP');
  19810. if (isDict(decodeParams)) {
  19811. var colorTransform = decodeParams.get('ColorTransform');
  19812. if (isInt(colorTransform)) {
  19813. jpegImage.colorTransform = colorTransform;
  19814. }
  19815. }
  19816. jpegImage.parse(this.bytes);
  19817. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  19818. this.forceRGB);
  19819. this.buffer = data;
  19820. this.bufferLength = data.length;
  19821. this.eof = true;
  19822. };
  19823. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  19824. this.ensureBuffer();
  19825. return this.buffer;
  19826. };
  19827. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  19828. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  19829. };
  19830. return JpegStream;
  19831. })();
  19832. /**
  19833. * For JPEG 2000's we use a library to decode these images and
  19834. * the stream behaves like all the other DecodeStreams.
  19835. */
  19836. var JpxStream = (function JpxStreamClosure() {
  19837. function JpxStream(stream, maybeLength, dict) {
  19838. this.stream = stream;
  19839. this.maybeLength = maybeLength;
  19840. this.dict = dict;
  19841. DecodeStream.call(this, maybeLength);
  19842. }
  19843. JpxStream.prototype = Object.create(DecodeStream.prototype);
  19844. Object.defineProperty(JpxStream.prototype, 'bytes', {
  19845. get: function JpxStream_bytes() {
  19846. // If this.maybeLength is null, we'll get the entire stream.
  19847. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19848. },
  19849. configurable: true
  19850. });
  19851. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  19852. if (this.bufferLength) {
  19853. return;
  19854. }
  19855. var jpxImage = new JpxImage();
  19856. jpxImage.parse(this.bytes);
  19857. var width = jpxImage.width;
  19858. var height = jpxImage.height;
  19859. var componentsCount = jpxImage.componentsCount;
  19860. var tileCount = jpxImage.tiles.length;
  19861. if (tileCount === 1) {
  19862. this.buffer = jpxImage.tiles[0].items;
  19863. } else {
  19864. var data = new Uint8Array(width * height * componentsCount);
  19865. for (var k = 0; k < tileCount; k++) {
  19866. var tileComponents = jpxImage.tiles[k];
  19867. var tileWidth = tileComponents.width;
  19868. var tileHeight = tileComponents.height;
  19869. var tileLeft = tileComponents.left;
  19870. var tileTop = tileComponents.top;
  19871. var src = tileComponents.items;
  19872. var srcPosition = 0;
  19873. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19874. var imgRowSize = width * componentsCount;
  19875. var tileRowSize = tileWidth * componentsCount;
  19876. for (var j = 0; j < tileHeight; j++) {
  19877. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19878. data.set(rowBytes, dataPosition);
  19879. srcPosition += tileRowSize;
  19880. dataPosition += imgRowSize;
  19881. }
  19882. }
  19883. this.buffer = data;
  19884. }
  19885. this.bufferLength = this.buffer.length;
  19886. this.eof = true;
  19887. };
  19888. return JpxStream;
  19889. })();
  19890. /**
  19891. * For JBIG2's we use a library to decode these images and
  19892. * the stream behaves like all the other DecodeStreams.
  19893. */
  19894. var Jbig2Stream = (function Jbig2StreamClosure() {
  19895. function Jbig2Stream(stream, maybeLength, dict) {
  19896. this.stream = stream;
  19897. this.maybeLength = maybeLength;
  19898. this.dict = dict;
  19899. DecodeStream.call(this, maybeLength);
  19900. }
  19901. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  19902. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  19903. get: function Jbig2Stream_bytes() {
  19904. // If this.maybeLength is null, we'll get the entire stream.
  19905. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19906. },
  19907. configurable: true
  19908. });
  19909. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  19910. if (this.bufferLength) {
  19911. return;
  19912. }
  19913. var jbig2Image = new Jbig2Image();
  19914. var chunks = [];
  19915. var decodeParams = this.dict.getArray('DecodeParms', 'DP');
  19916. // According to the PDF specification, DecodeParms can be either
  19917. // a dictionary, or an array whose elements are dictionaries.
  19918. if (isArray(decodeParams)) {
  19919. if (decodeParams.length > 1) {
  19920. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  19921. 'not supported.');
  19922. }
  19923. decodeParams = decodeParams[0];
  19924. }
  19925. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  19926. var globalsStream = decodeParams.get('JBIG2Globals');
  19927. var globals = globalsStream.getBytes();
  19928. chunks.push({data: globals, start: 0, end: globals.length});
  19929. }
  19930. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  19931. var data = jbig2Image.parseChunks(chunks);
  19932. var dataLength = data.length;
  19933. // JBIG2 had black as 1 and white as 0, inverting the colors
  19934. for (var i = 0; i < dataLength; i++) {
  19935. data[i] ^= 0xFF;
  19936. }
  19937. this.buffer = data;
  19938. this.bufferLength = dataLength;
  19939. this.eof = true;
  19940. };
  19941. return Jbig2Stream;
  19942. })();
  19943. var DecryptStream = (function DecryptStreamClosure() {
  19944. function DecryptStream(str, maybeLength, decrypt) {
  19945. this.str = str;
  19946. this.dict = str.dict;
  19947. this.decrypt = decrypt;
  19948. this.nextChunk = null;
  19949. this.initialized = false;
  19950. DecodeStream.call(this, maybeLength);
  19951. }
  19952. var chunkSize = 512;
  19953. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  19954. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  19955. var chunk;
  19956. if (this.initialized) {
  19957. chunk = this.nextChunk;
  19958. } else {
  19959. chunk = this.str.getBytes(chunkSize);
  19960. this.initialized = true;
  19961. }
  19962. if (!chunk || chunk.length === 0) {
  19963. this.eof = true;
  19964. return;
  19965. }
  19966. this.nextChunk = this.str.getBytes(chunkSize);
  19967. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  19968. var decrypt = this.decrypt;
  19969. chunk = decrypt(chunk, !hasMoreData);
  19970. var bufferLength = this.bufferLength;
  19971. var i, n = chunk.length;
  19972. var buffer = this.ensureBuffer(bufferLength + n);
  19973. for (i = 0; i < n; i++) {
  19974. buffer[bufferLength++] = chunk[i];
  19975. }
  19976. this.bufferLength = bufferLength;
  19977. };
  19978. return DecryptStream;
  19979. })();
  19980. var Ascii85Stream = (function Ascii85StreamClosure() {
  19981. function Ascii85Stream(str, maybeLength) {
  19982. this.str = str;
  19983. this.dict = str.dict;
  19984. this.input = new Uint8Array(5);
  19985. // Most streams increase in size when decoded, but Ascii85 streams
  19986. // typically shrink by ~20%.
  19987. if (maybeLength) {
  19988. maybeLength = 0.8 * maybeLength;
  19989. }
  19990. DecodeStream.call(this, maybeLength);
  19991. }
  19992. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  19993. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  19994. var TILDA_CHAR = 0x7E; // '~'
  19995. var Z_LOWER_CHAR = 0x7A; // 'z'
  19996. var EOF = -1;
  19997. var str = this.str;
  19998. var c = str.getByte();
  19999. while (isSpace(c)) {
  20000. c = str.getByte();
  20001. }
  20002. if (c === EOF || c === TILDA_CHAR) {
  20003. this.eof = true;
  20004. return;
  20005. }
  20006. var bufferLength = this.bufferLength, buffer;
  20007. var i;
  20008. // special code for z
  20009. if (c === Z_LOWER_CHAR) {
  20010. buffer = this.ensureBuffer(bufferLength + 4);
  20011. for (i = 0; i < 4; ++i) {
  20012. buffer[bufferLength + i] = 0;
  20013. }
  20014. this.bufferLength += 4;
  20015. } else {
  20016. var input = this.input;
  20017. input[0] = c;
  20018. for (i = 1; i < 5; ++i) {
  20019. c = str.getByte();
  20020. while (isSpace(c)) {
  20021. c = str.getByte();
  20022. }
  20023. input[i] = c;
  20024. if (c === EOF || c === TILDA_CHAR) {
  20025. break;
  20026. }
  20027. }
  20028. buffer = this.ensureBuffer(bufferLength + i - 1);
  20029. this.bufferLength += i - 1;
  20030. // partial ending;
  20031. if (i < 5) {
  20032. for (; i < 5; ++i) {
  20033. input[i] = 0x21 + 84;
  20034. }
  20035. this.eof = true;
  20036. }
  20037. var t = 0;
  20038. for (i = 0; i < 5; ++i) {
  20039. t = t * 85 + (input[i] - 0x21);
  20040. }
  20041. for (i = 3; i >= 0; --i) {
  20042. buffer[bufferLength + i] = t & 0xFF;
  20043. t >>= 8;
  20044. }
  20045. }
  20046. };
  20047. return Ascii85Stream;
  20048. })();
  20049. var AsciiHexStream = (function AsciiHexStreamClosure() {
  20050. function AsciiHexStream(str, maybeLength) {
  20051. this.str = str;
  20052. this.dict = str.dict;
  20053. this.firstDigit = -1;
  20054. // Most streams increase in size when decoded, but AsciiHex streams shrink
  20055. // by 50%.
  20056. if (maybeLength) {
  20057. maybeLength = 0.5 * maybeLength;
  20058. }
  20059. DecodeStream.call(this, maybeLength);
  20060. }
  20061. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  20062. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  20063. var UPSTREAM_BLOCK_SIZE = 8000;
  20064. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  20065. if (!bytes.length) {
  20066. this.eof = true;
  20067. return;
  20068. }
  20069. var maxDecodeLength = (bytes.length + 1) >> 1;
  20070. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  20071. var bufferLength = this.bufferLength;
  20072. var firstDigit = this.firstDigit;
  20073. for (var i = 0, ii = bytes.length; i < ii; i++) {
  20074. var ch = bytes[i], digit;
  20075. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20076. digit = ch & 0x0F;
  20077. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20078. // 'A'-'Z', 'a'-'z'
  20079. digit = (ch & 0x0F) + 9;
  20080. } else if (ch === 0x3E) { // '>'
  20081. this.eof = true;
  20082. break;
  20083. } else { // probably whitespace
  20084. continue; // ignoring
  20085. }
  20086. if (firstDigit < 0) {
  20087. firstDigit = digit;
  20088. } else {
  20089. buffer[bufferLength++] = (firstDigit << 4) | digit;
  20090. firstDigit = -1;
  20091. }
  20092. }
  20093. if (firstDigit >= 0 && this.eof) {
  20094. // incomplete byte
  20095. buffer[bufferLength++] = (firstDigit << 4);
  20096. firstDigit = -1;
  20097. }
  20098. this.firstDigit = firstDigit;
  20099. this.bufferLength = bufferLength;
  20100. };
  20101. return AsciiHexStream;
  20102. })();
  20103. var RunLengthStream = (function RunLengthStreamClosure() {
  20104. function RunLengthStream(str, maybeLength) {
  20105. this.str = str;
  20106. this.dict = str.dict;
  20107. DecodeStream.call(this, maybeLength);
  20108. }
  20109. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  20110. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  20111. // The repeatHeader has following format. The first byte defines type of run
  20112. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  20113. // (in addition to the second byte from the header), n = 129 through 255 -
  20114. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  20115. var repeatHeader = this.str.getBytes(2);
  20116. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  20117. this.eof = true;
  20118. return;
  20119. }
  20120. var buffer;
  20121. var bufferLength = this.bufferLength;
  20122. var n = repeatHeader[0];
  20123. if (n < 128) {
  20124. // copy n bytes
  20125. buffer = this.ensureBuffer(bufferLength + n + 1);
  20126. buffer[bufferLength++] = repeatHeader[1];
  20127. if (n > 0) {
  20128. var source = this.str.getBytes(n);
  20129. buffer.set(source, bufferLength);
  20130. bufferLength += n;
  20131. }
  20132. } else {
  20133. n = 257 - n;
  20134. var b = repeatHeader[1];
  20135. buffer = this.ensureBuffer(bufferLength + n + 1);
  20136. for (var i = 0; i < n; i++) {
  20137. buffer[bufferLength++] = b;
  20138. }
  20139. }
  20140. this.bufferLength = bufferLength;
  20141. };
  20142. return RunLengthStream;
  20143. })();
  20144. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  20145. var ccittEOL = -2;
  20146. var ccittEOF = -1;
  20147. var twoDimPass = 0;
  20148. var twoDimHoriz = 1;
  20149. var twoDimVert0 = 2;
  20150. var twoDimVertR1 = 3;
  20151. var twoDimVertL1 = 4;
  20152. var twoDimVertR2 = 5;
  20153. var twoDimVertL2 = 6;
  20154. var twoDimVertR3 = 7;
  20155. var twoDimVertL3 = 8;
  20156. var twoDimTable = [
  20157. [-1, -1], [-1, -1], // 000000x
  20158. [7, twoDimVertL3], // 0000010
  20159. [7, twoDimVertR3], // 0000011
  20160. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  20161. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  20162. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  20163. [4, twoDimPass], [4, twoDimPass],
  20164. [4, twoDimPass], [4, twoDimPass],
  20165. [4, twoDimPass], [4, twoDimPass],
  20166. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  20167. [3, twoDimHoriz], [3, twoDimHoriz],
  20168. [3, twoDimHoriz], [3, twoDimHoriz],
  20169. [3, twoDimHoriz], [3, twoDimHoriz],
  20170. [3, twoDimHoriz], [3, twoDimHoriz],
  20171. [3, twoDimHoriz], [3, twoDimHoriz],
  20172. [3, twoDimHoriz], [3, twoDimHoriz],
  20173. [3, twoDimHoriz], [3, twoDimHoriz],
  20174. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  20175. [3, twoDimVertL1], [3, twoDimVertL1],
  20176. [3, twoDimVertL1], [3, twoDimVertL1],
  20177. [3, twoDimVertL1], [3, twoDimVertL1],
  20178. [3, twoDimVertL1], [3, twoDimVertL1],
  20179. [3, twoDimVertL1], [3, twoDimVertL1],
  20180. [3, twoDimVertL1], [3, twoDimVertL1],
  20181. [3, twoDimVertL1], [3, twoDimVertL1],
  20182. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  20183. [3, twoDimVertR1], [3, twoDimVertR1],
  20184. [3, twoDimVertR1], [3, twoDimVertR1],
  20185. [3, twoDimVertR1], [3, twoDimVertR1],
  20186. [3, twoDimVertR1], [3, twoDimVertR1],
  20187. [3, twoDimVertR1], [3, twoDimVertR1],
  20188. [3, twoDimVertR1], [3, twoDimVertR1],
  20189. [3, twoDimVertR1], [3, twoDimVertR1],
  20190. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  20191. [1, twoDimVert0], [1, twoDimVert0],
  20192. [1, twoDimVert0], [1, twoDimVert0],
  20193. [1, twoDimVert0], [1, twoDimVert0],
  20194. [1, twoDimVert0], [1, twoDimVert0],
  20195. [1, twoDimVert0], [1, twoDimVert0],
  20196. [1, twoDimVert0], [1, twoDimVert0],
  20197. [1, twoDimVert0], [1, twoDimVert0],
  20198. [1, twoDimVert0], [1, twoDimVert0],
  20199. [1, twoDimVert0], [1, twoDimVert0],
  20200. [1, twoDimVert0], [1, twoDimVert0],
  20201. [1, twoDimVert0], [1, twoDimVert0],
  20202. [1, twoDimVert0], [1, twoDimVert0],
  20203. [1, twoDimVert0], [1, twoDimVert0],
  20204. [1, twoDimVert0], [1, twoDimVert0],
  20205. [1, twoDimVert0], [1, twoDimVert0],
  20206. [1, twoDimVert0], [1, twoDimVert0],
  20207. [1, twoDimVert0], [1, twoDimVert0],
  20208. [1, twoDimVert0], [1, twoDimVert0],
  20209. [1, twoDimVert0], [1, twoDimVert0],
  20210. [1, twoDimVert0], [1, twoDimVert0],
  20211. [1, twoDimVert0], [1, twoDimVert0],
  20212. [1, twoDimVert0], [1, twoDimVert0],
  20213. [1, twoDimVert0], [1, twoDimVert0],
  20214. [1, twoDimVert0], [1, twoDimVert0],
  20215. [1, twoDimVert0], [1, twoDimVert0],
  20216. [1, twoDimVert0], [1, twoDimVert0],
  20217. [1, twoDimVert0], [1, twoDimVert0],
  20218. [1, twoDimVert0], [1, twoDimVert0],
  20219. [1, twoDimVert0], [1, twoDimVert0],
  20220. [1, twoDimVert0], [1, twoDimVert0],
  20221. [1, twoDimVert0], [1, twoDimVert0]
  20222. ];
  20223. var whiteTable1 = [
  20224. [-1, -1], // 00000
  20225. [12, ccittEOL], // 00001
  20226. [-1, -1], [-1, -1], // 0001x
  20227. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  20228. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  20229. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  20230. [11, 1792], [11, 1792], // 1000x
  20231. [12, 1984], // 10010
  20232. [12, 2048], // 10011
  20233. [12, 2112], // 10100
  20234. [12, 2176], // 10101
  20235. [12, 2240], // 10110
  20236. [12, 2304], // 10111
  20237. [11, 1856], [11, 1856], // 1100x
  20238. [11, 1920], [11, 1920], // 1101x
  20239. [12, 2368], // 11100
  20240. [12, 2432], // 11101
  20241. [12, 2496], // 11110
  20242. [12, 2560] // 11111
  20243. ];
  20244. var whiteTable2 = [
  20245. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  20246. [8, 29], [8, 29], // 00000010x
  20247. [8, 30], [8, 30], // 00000011x
  20248. [8, 45], [8, 45], // 00000100x
  20249. [8, 46], [8, 46], // 00000101x
  20250. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  20251. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  20252. [8, 47], [8, 47], // 00001010x
  20253. [8, 48], [8, 48], // 00001011x
  20254. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  20255. [6, 13], [6, 13], [6, 13], [6, 13],
  20256. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  20257. [8, 33], [8, 33], // 00010010x
  20258. [8, 34], [8, 34], // 00010011x
  20259. [8, 35], [8, 35], // 00010100x
  20260. [8, 36], [8, 36], // 00010101x
  20261. [8, 37], [8, 37], // 00010110x
  20262. [8, 38], [8, 38], // 00010111x
  20263. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  20264. [8, 31], [8, 31], // 00011010x
  20265. [8, 32], [8, 32], // 00011011x
  20266. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  20267. [6, 1], [6, 1], [6, 1], [6, 1],
  20268. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  20269. [6, 12], [6, 12], [6, 12], [6, 12],
  20270. [8, 53], [8, 53], // 00100100x
  20271. [8, 54], [8, 54], // 00100101x
  20272. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  20273. [8, 39], [8, 39], // 00101000x
  20274. [8, 40], [8, 40], // 00101001x
  20275. [8, 41], [8, 41], // 00101010x
  20276. [8, 42], [8, 42], // 00101011x
  20277. [8, 43], [8, 43], // 00101100x
  20278. [8, 44], [8, 44], // 00101101x
  20279. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  20280. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  20281. [8, 61], [8, 61], // 00110010x
  20282. [8, 62], [8, 62], // 00110011x
  20283. [8, 63], [8, 63], // 00110100x
  20284. [8, 0], [8, 0], // 00110101x
  20285. [8, 320], [8, 320], // 00110110x
  20286. [8, 384], [8, 384], // 00110111x
  20287. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  20288. [5, 10], [5, 10], [5, 10], [5, 10],
  20289. [5, 10], [5, 10], [5, 10], [5, 10],
  20290. [5, 10], [5, 10], [5, 10], [5, 10],
  20291. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  20292. [5, 11], [5, 11], [5, 11], [5, 11],
  20293. [5, 11], [5, 11], [5, 11], [5, 11],
  20294. [5, 11], [5, 11], [5, 11], [5, 11],
  20295. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  20296. [8, 59], [8, 59], // 01001010x
  20297. [8, 60], [8, 60], // 01001011x
  20298. [9, 1472], // 010011000
  20299. [9, 1536], // 010011001
  20300. [9, 1600], // 010011010
  20301. [9, 1728], // 010011011
  20302. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  20303. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  20304. [8, 49], [8, 49], // 01010010x
  20305. [8, 50], [8, 50], // 01010011x
  20306. [8, 51], [8, 51], // 01010100x
  20307. [8, 52], [8, 52], // 01010101x
  20308. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  20309. [8, 55], [8, 55], // 01011000x
  20310. [8, 56], [8, 56], // 01011001x
  20311. [8, 57], [8, 57], // 01011010x
  20312. [8, 58], [8, 58], // 01011011x
  20313. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  20314. [6, 192], [6, 192], [6, 192], [6, 192],
  20315. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  20316. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  20317. [8, 448], [8, 448], // 01100100x
  20318. [8, 512], [8, 512], // 01100101x
  20319. [9, 704], // 011001100
  20320. [9, 768], // 011001101
  20321. [8, 640], [8, 640], // 01100111x
  20322. [8, 576], [8, 576], // 01101000x
  20323. [9, 832], // 011010010
  20324. [9, 896], // 011010011
  20325. [9, 960], // 011010100
  20326. [9, 1024], // 011010101
  20327. [9, 1088], // 011010110
  20328. [9, 1152], // 011010111
  20329. [9, 1216], // 011011000
  20330. [9, 1280], // 011011001
  20331. [9, 1344], // 011011010
  20332. [9, 1408], // 011011011
  20333. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  20334. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  20335. [4, 2], [4, 2], [4, 2], [4, 2],
  20336. [4, 2], [4, 2], [4, 2], [4, 2],
  20337. [4, 2], [4, 2], [4, 2], [4, 2],
  20338. [4, 2], [4, 2], [4, 2], [4, 2],
  20339. [4, 2], [4, 2], [4, 2], [4, 2],
  20340. [4, 2], [4, 2], [4, 2], [4, 2],
  20341. [4, 2], [4, 2], [4, 2], [4, 2],
  20342. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  20343. [4, 3], [4, 3], [4, 3], [4, 3],
  20344. [4, 3], [4, 3], [4, 3], [4, 3],
  20345. [4, 3], [4, 3], [4, 3], [4, 3],
  20346. [4, 3], [4, 3], [4, 3], [4, 3],
  20347. [4, 3], [4, 3], [4, 3], [4, 3],
  20348. [4, 3], [4, 3], [4, 3], [4, 3],
  20349. [4, 3], [4, 3], [4, 3], [4, 3],
  20350. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  20351. [5, 128], [5, 128], [5, 128], [5, 128],
  20352. [5, 128], [5, 128], [5, 128], [5, 128],
  20353. [5, 128], [5, 128], [5, 128], [5, 128],
  20354. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  20355. [5, 8], [5, 8], [5, 8], [5, 8],
  20356. [5, 8], [5, 8], [5, 8], [5, 8],
  20357. [5, 8], [5, 8], [5, 8], [5, 8],
  20358. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  20359. [5, 9], [5, 9], [5, 9], [5, 9],
  20360. [5, 9], [5, 9], [5, 9], [5, 9],
  20361. [5, 9], [5, 9], [5, 9], [5, 9],
  20362. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  20363. [6, 16], [6, 16], [6, 16], [6, 16],
  20364. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  20365. [6, 17], [6, 17], [6, 17], [6, 17],
  20366. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  20367. [4, 4], [4, 4], [4, 4], [4, 4],
  20368. [4, 4], [4, 4], [4, 4], [4, 4],
  20369. [4, 4], [4, 4], [4, 4], [4, 4],
  20370. [4, 4], [4, 4], [4, 4], [4, 4],
  20371. [4, 4], [4, 4], [4, 4], [4, 4],
  20372. [4, 4], [4, 4], [4, 4], [4, 4],
  20373. [4, 4], [4, 4], [4, 4], [4, 4],
  20374. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  20375. [4, 5], [4, 5], [4, 5], [4, 5],
  20376. [4, 5], [4, 5], [4, 5], [4, 5],
  20377. [4, 5], [4, 5], [4, 5], [4, 5],
  20378. [4, 5], [4, 5], [4, 5], [4, 5],
  20379. [4, 5], [4, 5], [4, 5], [4, 5],
  20380. [4, 5], [4, 5], [4, 5], [4, 5],
  20381. [4, 5], [4, 5], [4, 5], [4, 5],
  20382. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  20383. [6, 14], [6, 14], [6, 14], [6, 14],
  20384. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  20385. [6, 15], [6, 15], [6, 15], [6, 15],
  20386. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  20387. [5, 64], [5, 64], [5, 64], [5, 64],
  20388. [5, 64], [5, 64], [5, 64], [5, 64],
  20389. [5, 64], [5, 64], [5, 64], [5, 64],
  20390. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  20391. [4, 6], [4, 6], [4, 6], [4, 6],
  20392. [4, 6], [4, 6], [4, 6], [4, 6],
  20393. [4, 6], [4, 6], [4, 6], [4, 6],
  20394. [4, 6], [4, 6], [4, 6], [4, 6],
  20395. [4, 6], [4, 6], [4, 6], [4, 6],
  20396. [4, 6], [4, 6], [4, 6], [4, 6],
  20397. [4, 6], [4, 6], [4, 6], [4, 6],
  20398. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  20399. [4, 7], [4, 7], [4, 7], [4, 7],
  20400. [4, 7], [4, 7], [4, 7], [4, 7],
  20401. [4, 7], [4, 7], [4, 7], [4, 7],
  20402. [4, 7], [4, 7], [4, 7], [4, 7],
  20403. [4, 7], [4, 7], [4, 7], [4, 7],
  20404. [4, 7], [4, 7], [4, 7], [4, 7],
  20405. [4, 7], [4, 7], [4, 7], [4, 7]
  20406. ];
  20407. var blackTable1 = [
  20408. [-1, -1], [-1, -1], // 000000000000x
  20409. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  20410. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  20411. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  20412. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  20413. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  20414. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  20415. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  20416. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  20417. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  20418. [12, 1984], [12, 1984], // 000000010010x
  20419. [12, 2048], [12, 2048], // 000000010011x
  20420. [12, 2112], [12, 2112], // 000000010100x
  20421. [12, 2176], [12, 2176], // 000000010101x
  20422. [12, 2240], [12, 2240], // 000000010110x
  20423. [12, 2304], [12, 2304], // 000000010111x
  20424. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  20425. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  20426. [12, 2368], [12, 2368], // 000000011100x
  20427. [12, 2432], [12, 2432], // 000000011101x
  20428. [12, 2496], [12, 2496], // 000000011110x
  20429. [12, 2560], [12, 2560], // 000000011111x
  20430. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  20431. [10, 18], [10, 18], [10, 18], [10, 18],
  20432. [12, 52], [12, 52], // 000000100100x
  20433. [13, 640], // 0000001001010
  20434. [13, 704], // 0000001001011
  20435. [13, 768], // 0000001001100
  20436. [13, 832], // 0000001001101
  20437. [12, 55], [12, 55], // 000000100111x
  20438. [12, 56], [12, 56], // 000000101000x
  20439. [13, 1280], // 0000001010010
  20440. [13, 1344], // 0000001010011
  20441. [13, 1408], // 0000001010100
  20442. [13, 1472], // 0000001010101
  20443. [12, 59], [12, 59], // 000000101011x
  20444. [12, 60], [12, 60], // 000000101100x
  20445. [13, 1536], // 0000001011010
  20446. [13, 1600], // 0000001011011
  20447. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  20448. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  20449. [13, 1664], // 0000001100100
  20450. [13, 1728], // 0000001100101
  20451. [12, 320], [12, 320], // 000000110011x
  20452. [12, 384], [12, 384], // 000000110100x
  20453. [12, 448], [12, 448], // 000000110101x
  20454. [13, 512], // 0000001101100
  20455. [13, 576], // 0000001101101
  20456. [12, 53], [12, 53], // 000000110111x
  20457. [12, 54], [12, 54], // 000000111000x
  20458. [13, 896], // 0000001110010
  20459. [13, 960], // 0000001110011
  20460. [13, 1024], // 0000001110100
  20461. [13, 1088], // 0000001110101
  20462. [13, 1152], // 0000001110110
  20463. [13, 1216], // 0000001110111
  20464. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  20465. [10, 64], [10, 64], [10, 64], [10, 64]
  20466. ];
  20467. var blackTable2 = [
  20468. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  20469. [8, 13], [8, 13], [8, 13], [8, 13],
  20470. [8, 13], [8, 13], [8, 13], [8, 13],
  20471. [8, 13], [8, 13], [8, 13], [8, 13],
  20472. [11, 23], [11, 23], // 00000101000x
  20473. [12, 50], // 000001010010
  20474. [12, 51], // 000001010011
  20475. [12, 44], // 000001010100
  20476. [12, 45], // 000001010101
  20477. [12, 46], // 000001010110
  20478. [12, 47], // 000001010111
  20479. [12, 57], // 000001011000
  20480. [12, 58], // 000001011001
  20481. [12, 61], // 000001011010
  20482. [12, 256], // 000001011011
  20483. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  20484. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  20485. [12, 48], // 000001100100
  20486. [12, 49], // 000001100101
  20487. [12, 62], // 000001100110
  20488. [12, 63], // 000001100111
  20489. [12, 30], // 000001101000
  20490. [12, 31], // 000001101001
  20491. [12, 32], // 000001101010
  20492. [12, 33], // 000001101011
  20493. [12, 40], // 000001101100
  20494. [12, 41], // 000001101101
  20495. [11, 22], [11, 22], // 00000110111x
  20496. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  20497. [8, 14], [8, 14], [8, 14], [8, 14],
  20498. [8, 14], [8, 14], [8, 14], [8, 14],
  20499. [8, 14], [8, 14], [8, 14], [8, 14],
  20500. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  20501. [7, 10], [7, 10], [7, 10], [7, 10],
  20502. [7, 10], [7, 10], [7, 10], [7, 10],
  20503. [7, 10], [7, 10], [7, 10], [7, 10],
  20504. [7, 10], [7, 10], [7, 10], [7, 10],
  20505. [7, 10], [7, 10], [7, 10], [7, 10],
  20506. [7, 10], [7, 10], [7, 10], [7, 10],
  20507. [7, 10], [7, 10], [7, 10], [7, 10],
  20508. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  20509. [7, 11], [7, 11], [7, 11], [7, 11],
  20510. [7, 11], [7, 11], [7, 11], [7, 11],
  20511. [7, 11], [7, 11], [7, 11], [7, 11],
  20512. [7, 11], [7, 11], [7, 11], [7, 11],
  20513. [7, 11], [7, 11], [7, 11], [7, 11],
  20514. [7, 11], [7, 11], [7, 11], [7, 11],
  20515. [7, 11], [7, 11], [7, 11], [7, 11],
  20516. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  20517. [9, 15], [9, 15], [9, 15], [9, 15],
  20518. [12, 128], // 000011001000
  20519. [12, 192], // 000011001001
  20520. [12, 26], // 000011001010
  20521. [12, 27], // 000011001011
  20522. [12, 28], // 000011001100
  20523. [12, 29], // 000011001101
  20524. [11, 19], [11, 19], // 00001100111x
  20525. [11, 20], [11, 20], // 00001101000x
  20526. [12, 34], // 000011010010
  20527. [12, 35], // 000011010011
  20528. [12, 36], // 000011010100
  20529. [12, 37], // 000011010101
  20530. [12, 38], // 000011010110
  20531. [12, 39], // 000011010111
  20532. [11, 21], [11, 21], // 00001101100x
  20533. [12, 42], // 000011011010
  20534. [12, 43], // 000011011011
  20535. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  20536. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  20537. [7, 12], [7, 12], [7, 12], [7, 12],
  20538. [7, 12], [7, 12], [7, 12], [7, 12],
  20539. [7, 12], [7, 12], [7, 12], [7, 12],
  20540. [7, 12], [7, 12], [7, 12], [7, 12],
  20541. [7, 12], [7, 12], [7, 12], [7, 12],
  20542. [7, 12], [7, 12], [7, 12], [7, 12],
  20543. [7, 12], [7, 12], [7, 12], [7, 12]
  20544. ];
  20545. var blackTable3 = [
  20546. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  20547. [6, 9], // 000100
  20548. [6, 8], // 000101
  20549. [5, 7], [5, 7], // 00011x
  20550. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  20551. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  20552. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  20553. [3, 1], [3, 1], [3, 1], [3, 1],
  20554. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  20555. [3, 4], [3, 4], [3, 4], [3, 4],
  20556. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  20557. [2, 3], [2, 3], [2, 3], [2, 3],
  20558. [2, 3], [2, 3], [2, 3], [2, 3],
  20559. [2, 3], [2, 3], [2, 3], [2, 3],
  20560. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  20561. [2, 2], [2, 2], [2, 2], [2, 2],
  20562. [2, 2], [2, 2], [2, 2], [2, 2],
  20563. [2, 2], [2, 2], [2, 2], [2, 2]
  20564. ];
  20565. function CCITTFaxStream(str, maybeLength, params) {
  20566. this.str = str;
  20567. this.dict = str.dict;
  20568. params = params || Dict.empty;
  20569. this.encoding = params.get('K') || 0;
  20570. this.eoline = params.get('EndOfLine') || false;
  20571. this.byteAlign = params.get('EncodedByteAlign') || false;
  20572. this.columns = params.get('Columns') || 1728;
  20573. this.rows = params.get('Rows') || 0;
  20574. var eoblock = params.get('EndOfBlock');
  20575. if (eoblock === null || eoblock === undefined) {
  20576. eoblock = true;
  20577. }
  20578. this.eoblock = eoblock;
  20579. this.black = params.get('BlackIs1') || false;
  20580. this.codingLine = new Uint32Array(this.columns + 1);
  20581. this.refLine = new Uint32Array(this.columns + 2);
  20582. this.codingLine[0] = this.columns;
  20583. this.codingPos = 0;
  20584. this.row = 0;
  20585. this.nextLine2D = this.encoding < 0;
  20586. this.inputBits = 0;
  20587. this.inputBuf = 0;
  20588. this.outputBits = 0;
  20589. var code1;
  20590. while ((code1 = this.lookBits(12)) === 0) {
  20591. this.eatBits(1);
  20592. }
  20593. if (code1 === 1) {
  20594. this.eatBits(12);
  20595. }
  20596. if (this.encoding > 0) {
  20597. this.nextLine2D = !this.lookBits(1);
  20598. this.eatBits(1);
  20599. }
  20600. DecodeStream.call(this, maybeLength);
  20601. }
  20602. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  20603. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  20604. while (!this.eof) {
  20605. var c = this.lookChar();
  20606. this.ensureBuffer(this.bufferLength + 1);
  20607. this.buffer[this.bufferLength++] = c;
  20608. }
  20609. };
  20610. CCITTFaxStream.prototype.addPixels =
  20611. function ccittFaxStreamAddPixels(a1, blackPixels) {
  20612. var codingLine = this.codingLine;
  20613. var codingPos = this.codingPos;
  20614. if (a1 > codingLine[codingPos]) {
  20615. if (a1 > this.columns) {
  20616. info('row is wrong length');
  20617. this.err = true;
  20618. a1 = this.columns;
  20619. }
  20620. if ((codingPos & 1) ^ blackPixels) {
  20621. ++codingPos;
  20622. }
  20623. codingLine[codingPos] = a1;
  20624. }
  20625. this.codingPos = codingPos;
  20626. };
  20627. CCITTFaxStream.prototype.addPixelsNeg =
  20628. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  20629. var codingLine = this.codingLine;
  20630. var codingPos = this.codingPos;
  20631. if (a1 > codingLine[codingPos]) {
  20632. if (a1 > this.columns) {
  20633. info('row is wrong length');
  20634. this.err = true;
  20635. a1 = this.columns;
  20636. }
  20637. if ((codingPos & 1) ^ blackPixels) {
  20638. ++codingPos;
  20639. }
  20640. codingLine[codingPos] = a1;
  20641. } else if (a1 < codingLine[codingPos]) {
  20642. if (a1 < 0) {
  20643. info('invalid code');
  20644. this.err = true;
  20645. a1 = 0;
  20646. }
  20647. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  20648. --codingPos;
  20649. }
  20650. codingLine[codingPos] = a1;
  20651. }
  20652. this.codingPos = codingPos;
  20653. };
  20654. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  20655. var refLine = this.refLine;
  20656. var codingLine = this.codingLine;
  20657. var columns = this.columns;
  20658. var refPos, blackPixels, bits, i;
  20659. if (this.outputBits === 0) {
  20660. if (this.eof) {
  20661. return null;
  20662. }
  20663. this.err = false;
  20664. var code1, code2, code3;
  20665. if (this.nextLine2D) {
  20666. for (i = 0; codingLine[i] < columns; ++i) {
  20667. refLine[i] = codingLine[i];
  20668. }
  20669. refLine[i++] = columns;
  20670. refLine[i] = columns;
  20671. codingLine[0] = 0;
  20672. this.codingPos = 0;
  20673. refPos = 0;
  20674. blackPixels = 0;
  20675. while (codingLine[this.codingPos] < columns) {
  20676. code1 = this.getTwoDimCode();
  20677. switch (code1) {
  20678. case twoDimPass:
  20679. this.addPixels(refLine[refPos + 1], blackPixels);
  20680. if (refLine[refPos + 1] < columns) {
  20681. refPos += 2;
  20682. }
  20683. break;
  20684. case twoDimHoriz:
  20685. code1 = code2 = 0;
  20686. if (blackPixels) {
  20687. do {
  20688. code1 += (code3 = this.getBlackCode());
  20689. } while (code3 >= 64);
  20690. do {
  20691. code2 += (code3 = this.getWhiteCode());
  20692. } while (code3 >= 64);
  20693. } else {
  20694. do {
  20695. code1 += (code3 = this.getWhiteCode());
  20696. } while (code3 >= 64);
  20697. do {
  20698. code2 += (code3 = this.getBlackCode());
  20699. } while (code3 >= 64);
  20700. }
  20701. this.addPixels(codingLine[this.codingPos] +
  20702. code1, blackPixels);
  20703. if (codingLine[this.codingPos] < columns) {
  20704. this.addPixels(codingLine[this.codingPos] + code2,
  20705. blackPixels ^ 1);
  20706. }
  20707. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20708. refLine[refPos] < columns) {
  20709. refPos += 2;
  20710. }
  20711. break;
  20712. case twoDimVertR3:
  20713. this.addPixels(refLine[refPos] + 3, blackPixels);
  20714. blackPixels ^= 1;
  20715. if (codingLine[this.codingPos] < columns) {
  20716. ++refPos;
  20717. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20718. refLine[refPos] < columns) {
  20719. refPos += 2;
  20720. }
  20721. }
  20722. break;
  20723. case twoDimVertR2:
  20724. this.addPixels(refLine[refPos] + 2, blackPixels);
  20725. blackPixels ^= 1;
  20726. if (codingLine[this.codingPos] < columns) {
  20727. ++refPos;
  20728. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20729. refLine[refPos] < columns) {
  20730. refPos += 2;
  20731. }
  20732. }
  20733. break;
  20734. case twoDimVertR1:
  20735. this.addPixels(refLine[refPos] + 1, blackPixels);
  20736. blackPixels ^= 1;
  20737. if (codingLine[this.codingPos] < columns) {
  20738. ++refPos;
  20739. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20740. refLine[refPos] < columns) {
  20741. refPos += 2;
  20742. }
  20743. }
  20744. break;
  20745. case twoDimVert0:
  20746. this.addPixels(refLine[refPos], blackPixels);
  20747. blackPixels ^= 1;
  20748. if (codingLine[this.codingPos] < columns) {
  20749. ++refPos;
  20750. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20751. refLine[refPos] < columns) {
  20752. refPos += 2;
  20753. }
  20754. }
  20755. break;
  20756. case twoDimVertL3:
  20757. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  20758. blackPixels ^= 1;
  20759. if (codingLine[this.codingPos] < columns) {
  20760. if (refPos > 0) {
  20761. --refPos;
  20762. } else {
  20763. ++refPos;
  20764. }
  20765. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20766. refLine[refPos] < columns) {
  20767. refPos += 2;
  20768. }
  20769. }
  20770. break;
  20771. case twoDimVertL2:
  20772. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  20773. blackPixels ^= 1;
  20774. if (codingLine[this.codingPos] < columns) {
  20775. if (refPos > 0) {
  20776. --refPos;
  20777. } else {
  20778. ++refPos;
  20779. }
  20780. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20781. refLine[refPos] < columns) {
  20782. refPos += 2;
  20783. }
  20784. }
  20785. break;
  20786. case twoDimVertL1:
  20787. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  20788. blackPixels ^= 1;
  20789. if (codingLine[this.codingPos] < columns) {
  20790. if (refPos > 0) {
  20791. --refPos;
  20792. } else {
  20793. ++refPos;
  20794. }
  20795. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20796. refLine[refPos] < columns) {
  20797. refPos += 2;
  20798. }
  20799. }
  20800. break;
  20801. case ccittEOF:
  20802. this.addPixels(columns, 0);
  20803. this.eof = true;
  20804. break;
  20805. default:
  20806. info('bad 2d code');
  20807. this.addPixels(columns, 0);
  20808. this.err = true;
  20809. }
  20810. }
  20811. } else {
  20812. codingLine[0] = 0;
  20813. this.codingPos = 0;
  20814. blackPixels = 0;
  20815. while (codingLine[this.codingPos] < columns) {
  20816. code1 = 0;
  20817. if (blackPixels) {
  20818. do {
  20819. code1 += (code3 = this.getBlackCode());
  20820. } while (code3 >= 64);
  20821. } else {
  20822. do {
  20823. code1 += (code3 = this.getWhiteCode());
  20824. } while (code3 >= 64);
  20825. }
  20826. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  20827. blackPixels ^= 1;
  20828. }
  20829. }
  20830. var gotEOL = false;
  20831. if (this.byteAlign) {
  20832. this.inputBits &= ~7;
  20833. }
  20834. if (!this.eoblock && this.row === this.rows - 1) {
  20835. this.eof = true;
  20836. } else {
  20837. code1 = this.lookBits(12);
  20838. if (this.eoline) {
  20839. while (code1 !== ccittEOF && code1 !== 1) {
  20840. this.eatBits(1);
  20841. code1 = this.lookBits(12);
  20842. }
  20843. } else {
  20844. while (code1 === 0) {
  20845. this.eatBits(1);
  20846. code1 = this.lookBits(12);
  20847. }
  20848. }
  20849. if (code1 === 1) {
  20850. this.eatBits(12);
  20851. gotEOL = true;
  20852. } else if (code1 === ccittEOF) {
  20853. this.eof = true;
  20854. }
  20855. }
  20856. if (!this.eof && this.encoding > 0) {
  20857. this.nextLine2D = !this.lookBits(1);
  20858. this.eatBits(1);
  20859. }
  20860. if (this.eoblock && gotEOL && this.byteAlign) {
  20861. code1 = this.lookBits(12);
  20862. if (code1 === 1) {
  20863. this.eatBits(12);
  20864. if (this.encoding > 0) {
  20865. this.lookBits(1);
  20866. this.eatBits(1);
  20867. }
  20868. if (this.encoding >= 0) {
  20869. for (i = 0; i < 4; ++i) {
  20870. code1 = this.lookBits(12);
  20871. if (code1 !== 1) {
  20872. info('bad rtc code: ' + code1);
  20873. }
  20874. this.eatBits(12);
  20875. if (this.encoding > 0) {
  20876. this.lookBits(1);
  20877. this.eatBits(1);
  20878. }
  20879. }
  20880. }
  20881. this.eof = true;
  20882. }
  20883. } else if (this.err && this.eoline) {
  20884. while (true) {
  20885. code1 = this.lookBits(13);
  20886. if (code1 === ccittEOF) {
  20887. this.eof = true;
  20888. return null;
  20889. }
  20890. if ((code1 >> 1) === 1) {
  20891. break;
  20892. }
  20893. this.eatBits(1);
  20894. }
  20895. this.eatBits(12);
  20896. if (this.encoding > 0) {
  20897. this.eatBits(1);
  20898. this.nextLine2D = !(code1 & 1);
  20899. }
  20900. }
  20901. if (codingLine[0] > 0) {
  20902. this.outputBits = codingLine[this.codingPos = 0];
  20903. } else {
  20904. this.outputBits = codingLine[this.codingPos = 1];
  20905. }
  20906. this.row++;
  20907. }
  20908. var c;
  20909. if (this.outputBits >= 8) {
  20910. c = (this.codingPos & 1) ? 0 : 0xFF;
  20911. this.outputBits -= 8;
  20912. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  20913. this.codingPos++;
  20914. this.outputBits = (codingLine[this.codingPos] -
  20915. codingLine[this.codingPos - 1]);
  20916. }
  20917. } else {
  20918. bits = 8;
  20919. c = 0;
  20920. do {
  20921. if (this.outputBits > bits) {
  20922. c <<= bits;
  20923. if (!(this.codingPos & 1)) {
  20924. c |= 0xFF >> (8 - bits);
  20925. }
  20926. this.outputBits -= bits;
  20927. bits = 0;
  20928. } else {
  20929. c <<= this.outputBits;
  20930. if (!(this.codingPos & 1)) {
  20931. c |= 0xFF >> (8 - this.outputBits);
  20932. }
  20933. bits -= this.outputBits;
  20934. this.outputBits = 0;
  20935. if (codingLine[this.codingPos] < columns) {
  20936. this.codingPos++;
  20937. this.outputBits = (codingLine[this.codingPos] -
  20938. codingLine[this.codingPos - 1]);
  20939. } else if (bits > 0) {
  20940. c <<= bits;
  20941. bits = 0;
  20942. }
  20943. }
  20944. } while (bits);
  20945. }
  20946. if (this.black) {
  20947. c ^= 0xFF;
  20948. }
  20949. return c;
  20950. };
  20951. // This functions returns the code found from the table.
  20952. // The start and end parameters set the boundaries for searching the table.
  20953. // The limit parameter is optional. Function returns an array with three
  20954. // values. The first array element indicates whether a valid code is being
  20955. // returned. The second array element is the actual code. The third array
  20956. // element indicates whether EOF was reached.
  20957. CCITTFaxStream.prototype.findTableCode =
  20958. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  20959. var limitValue = limit || 0;
  20960. for (var i = start; i <= end; ++i) {
  20961. var code = this.lookBits(i);
  20962. if (code === ccittEOF) {
  20963. return [true, 1, false];
  20964. }
  20965. if (i < end) {
  20966. code <<= end - i;
  20967. }
  20968. if (!limitValue || code >= limitValue) {
  20969. var p = table[code - limitValue];
  20970. if (p[0] === i) {
  20971. this.eatBits(i);
  20972. return [true, p[1], true];
  20973. }
  20974. }
  20975. }
  20976. return [false, 0, false];
  20977. };
  20978. CCITTFaxStream.prototype.getTwoDimCode =
  20979. function ccittFaxStreamGetTwoDimCode() {
  20980. var code = 0;
  20981. var p;
  20982. if (this.eoblock) {
  20983. code = this.lookBits(7);
  20984. p = twoDimTable[code];
  20985. if (p && p[0] > 0) {
  20986. this.eatBits(p[0]);
  20987. return p[1];
  20988. }
  20989. } else {
  20990. var result = this.findTableCode(1, 7, twoDimTable);
  20991. if (result[0] && result[2]) {
  20992. return result[1];
  20993. }
  20994. }
  20995. info('Bad two dim code');
  20996. return ccittEOF;
  20997. };
  20998. CCITTFaxStream.prototype.getWhiteCode =
  20999. function ccittFaxStreamGetWhiteCode() {
  21000. var code = 0;
  21001. var p;
  21002. if (this.eoblock) {
  21003. code = this.lookBits(12);
  21004. if (code === ccittEOF) {
  21005. return 1;
  21006. }
  21007. if ((code >> 5) === 0) {
  21008. p = whiteTable1[code];
  21009. } else {
  21010. p = whiteTable2[code >> 3];
  21011. }
  21012. if (p[0] > 0) {
  21013. this.eatBits(p[0]);
  21014. return p[1];
  21015. }
  21016. } else {
  21017. var result = this.findTableCode(1, 9, whiteTable2);
  21018. if (result[0]) {
  21019. return result[1];
  21020. }
  21021. result = this.findTableCode(11, 12, whiteTable1);
  21022. if (result[0]) {
  21023. return result[1];
  21024. }
  21025. }
  21026. info('bad white code');
  21027. this.eatBits(1);
  21028. return 1;
  21029. };
  21030. CCITTFaxStream.prototype.getBlackCode =
  21031. function ccittFaxStreamGetBlackCode() {
  21032. var code, p;
  21033. if (this.eoblock) {
  21034. code = this.lookBits(13);
  21035. if (code === ccittEOF) {
  21036. return 1;
  21037. }
  21038. if ((code >> 7) === 0) {
  21039. p = blackTable1[code];
  21040. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  21041. p = blackTable2[(code >> 1) - 64];
  21042. } else {
  21043. p = blackTable3[code >> 7];
  21044. }
  21045. if (p[0] > 0) {
  21046. this.eatBits(p[0]);
  21047. return p[1];
  21048. }
  21049. } else {
  21050. var result = this.findTableCode(2, 6, blackTable3);
  21051. if (result[0]) {
  21052. return result[1];
  21053. }
  21054. result = this.findTableCode(7, 12, blackTable2, 64);
  21055. if (result[0]) {
  21056. return result[1];
  21057. }
  21058. result = this.findTableCode(10, 13, blackTable1);
  21059. if (result[0]) {
  21060. return result[1];
  21061. }
  21062. }
  21063. info('bad black code');
  21064. this.eatBits(1);
  21065. return 1;
  21066. };
  21067. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  21068. var c;
  21069. while (this.inputBits < n) {
  21070. if ((c = this.str.getByte()) === -1) {
  21071. if (this.inputBits === 0) {
  21072. return ccittEOF;
  21073. }
  21074. return ((this.inputBuf << (n - this.inputBits)) &
  21075. (0xFFFF >> (16 - n)));
  21076. }
  21077. this.inputBuf = (this.inputBuf << 8) | c;
  21078. this.inputBits += 8;
  21079. }
  21080. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  21081. };
  21082. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  21083. if ((this.inputBits -= n) < 0) {
  21084. this.inputBits = 0;
  21085. }
  21086. };
  21087. return CCITTFaxStream;
  21088. })();
  21089. var LZWStream = (function LZWStreamClosure() {
  21090. function LZWStream(str, maybeLength, earlyChange) {
  21091. this.str = str;
  21092. this.dict = str.dict;
  21093. this.cachedData = 0;
  21094. this.bitsCached = 0;
  21095. var maxLzwDictionarySize = 4096;
  21096. var lzwState = {
  21097. earlyChange: earlyChange,
  21098. codeLength: 9,
  21099. nextCode: 258,
  21100. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  21101. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  21102. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  21103. currentSequence: new Uint8Array(maxLzwDictionarySize),
  21104. currentSequenceLength: 0
  21105. };
  21106. for (var i = 0; i < 256; ++i) {
  21107. lzwState.dictionaryValues[i] = i;
  21108. lzwState.dictionaryLengths[i] = 1;
  21109. }
  21110. this.lzwState = lzwState;
  21111. DecodeStream.call(this, maybeLength);
  21112. }
  21113. LZWStream.prototype = Object.create(DecodeStream.prototype);
  21114. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  21115. var bitsCached = this.bitsCached;
  21116. var cachedData = this.cachedData;
  21117. while (bitsCached < n) {
  21118. var c = this.str.getByte();
  21119. if (c === -1) {
  21120. this.eof = true;
  21121. return null;
  21122. }
  21123. cachedData = (cachedData << 8) | c;
  21124. bitsCached += 8;
  21125. }
  21126. this.bitsCached = (bitsCached -= n);
  21127. this.cachedData = cachedData;
  21128. this.lastCode = null;
  21129. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  21130. };
  21131. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  21132. var blockSize = 512;
  21133. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  21134. var i, j, q;
  21135. var lzwState = this.lzwState;
  21136. if (!lzwState) {
  21137. return; // eof was found
  21138. }
  21139. var earlyChange = lzwState.earlyChange;
  21140. var nextCode = lzwState.nextCode;
  21141. var dictionaryValues = lzwState.dictionaryValues;
  21142. var dictionaryLengths = lzwState.dictionaryLengths;
  21143. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  21144. var codeLength = lzwState.codeLength;
  21145. var prevCode = lzwState.prevCode;
  21146. var currentSequence = lzwState.currentSequence;
  21147. var currentSequenceLength = lzwState.currentSequenceLength;
  21148. var decodedLength = 0;
  21149. var currentBufferLength = this.bufferLength;
  21150. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21151. for (i = 0; i < blockSize; i++) {
  21152. var code = this.readBits(codeLength);
  21153. var hasPrev = currentSequenceLength > 0;
  21154. if (code < 256) {
  21155. currentSequence[0] = code;
  21156. currentSequenceLength = 1;
  21157. } else if (code >= 258) {
  21158. if (code < nextCode) {
  21159. currentSequenceLength = dictionaryLengths[code];
  21160. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  21161. currentSequence[j] = dictionaryValues[q];
  21162. q = dictionaryPrevCodes[q];
  21163. }
  21164. } else {
  21165. currentSequence[currentSequenceLength++] = currentSequence[0];
  21166. }
  21167. } else if (code === 256) {
  21168. codeLength = 9;
  21169. nextCode = 258;
  21170. currentSequenceLength = 0;
  21171. continue;
  21172. } else {
  21173. this.eof = true;
  21174. delete this.lzwState;
  21175. break;
  21176. }
  21177. if (hasPrev) {
  21178. dictionaryPrevCodes[nextCode] = prevCode;
  21179. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  21180. dictionaryValues[nextCode] = currentSequence[0];
  21181. nextCode++;
  21182. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  21183. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  21184. 0.6931471805599453 + 1, 12) | 0;
  21185. }
  21186. prevCode = code;
  21187. decodedLength += currentSequenceLength;
  21188. if (estimatedDecodedSize < decodedLength) {
  21189. do {
  21190. estimatedDecodedSize += decodedSizeDelta;
  21191. } while (estimatedDecodedSize < decodedLength);
  21192. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21193. }
  21194. for (j = 0; j < currentSequenceLength; j++) {
  21195. buffer[currentBufferLength++] = currentSequence[j];
  21196. }
  21197. }
  21198. lzwState.nextCode = nextCode;
  21199. lzwState.codeLength = codeLength;
  21200. lzwState.prevCode = prevCode;
  21201. lzwState.currentSequenceLength = currentSequenceLength;
  21202. this.bufferLength = currentBufferLength;
  21203. };
  21204. return LZWStream;
  21205. })();
  21206. var NullStream = (function NullStreamClosure() {
  21207. function NullStream() {
  21208. Stream.call(this, new Uint8Array(0));
  21209. }
  21210. NullStream.prototype = Stream.prototype;
  21211. return NullStream;
  21212. })();
  21213. exports.Ascii85Stream = Ascii85Stream;
  21214. exports.AsciiHexStream = AsciiHexStream;
  21215. exports.CCITTFaxStream = CCITTFaxStream;
  21216. exports.DecryptStream = DecryptStream;
  21217. exports.DecodeStream = DecodeStream;
  21218. exports.FlateStream = FlateStream;
  21219. exports.Jbig2Stream = Jbig2Stream;
  21220. exports.JpegStream = JpegStream;
  21221. exports.JpxStream = JpxStream;
  21222. exports.NullStream = NullStream;
  21223. exports.PredictorStream = PredictorStream;
  21224. exports.RunLengthStream = RunLengthStream;
  21225. exports.Stream = Stream;
  21226. exports.StreamsSequenceStream = StreamsSequenceStream;
  21227. exports.StringStream = StringStream;
  21228. exports.LZWStream = LZWStream;
  21229. }));
  21230. (function (root, factory) {
  21231. {
  21232. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  21233. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  21234. }
  21235. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  21236. var PasswordException = sharedUtil.PasswordException;
  21237. var PasswordResponses = sharedUtil.PasswordResponses;
  21238. var bytesToString = sharedUtil.bytesToString;
  21239. var error = sharedUtil.error;
  21240. var isInt = sharedUtil.isInt;
  21241. var stringToBytes = sharedUtil.stringToBytes;
  21242. var utf8StringToString = sharedUtil.utf8StringToString;
  21243. var warn = sharedUtil.warn;
  21244. var Name = corePrimitives.Name;
  21245. var isName = corePrimitives.isName;
  21246. var isDict = corePrimitives.isDict;
  21247. var DecryptStream = coreStream.DecryptStream;
  21248. var ARCFourCipher = (function ARCFourCipherClosure() {
  21249. function ARCFourCipher(key) {
  21250. this.a = 0;
  21251. this.b = 0;
  21252. var s = new Uint8Array(256);
  21253. var i, j = 0, tmp, keyLength = key.length;
  21254. for (i = 0; i < 256; ++i) {
  21255. s[i] = i;
  21256. }
  21257. for (i = 0; i < 256; ++i) {
  21258. tmp = s[i];
  21259. j = (j + tmp + key[i % keyLength]) & 0xFF;
  21260. s[i] = s[j];
  21261. s[j] = tmp;
  21262. }
  21263. this.s = s;
  21264. }
  21265. ARCFourCipher.prototype = {
  21266. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  21267. var i, n = data.length, tmp, tmp2;
  21268. var a = this.a, b = this.b, s = this.s;
  21269. var output = new Uint8Array(n);
  21270. for (i = 0; i < n; ++i) {
  21271. a = (a + 1) & 0xFF;
  21272. tmp = s[a];
  21273. b = (b + tmp) & 0xFF;
  21274. tmp2 = s[b];
  21275. s[a] = tmp2;
  21276. s[b] = tmp;
  21277. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  21278. }
  21279. this.a = a;
  21280. this.b = b;
  21281. return output;
  21282. }
  21283. };
  21284. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  21285. return ARCFourCipher;
  21286. })();
  21287. var calculateMD5 = (function calculateMD5Closure() {
  21288. var r = new Uint8Array([
  21289. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  21290. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  21291. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  21292. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  21293. var k = new Int32Array([
  21294. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  21295. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  21296. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  21297. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  21298. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  21299. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  21300. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  21301. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  21302. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  21303. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  21304. -145523070, -1120210379, 718787259, -343485551]);
  21305. function hash(data, offset, length) {
  21306. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  21307. // pre-processing
  21308. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  21309. var padded = new Uint8Array(paddedLength);
  21310. var i, j, n;
  21311. for (i = 0; i < length; ++i) {
  21312. padded[i] = data[offset++];
  21313. }
  21314. padded[i++] = 0x80;
  21315. n = paddedLength - 8;
  21316. while (i < n) {
  21317. padded[i++] = 0;
  21318. }
  21319. padded[i++] = (length << 3) & 0xFF;
  21320. padded[i++] = (length >> 5) & 0xFF;
  21321. padded[i++] = (length >> 13) & 0xFF;
  21322. padded[i++] = (length >> 21) & 0xFF;
  21323. padded[i++] = (length >>> 29) & 0xFF;
  21324. padded[i++] = 0;
  21325. padded[i++] = 0;
  21326. padded[i++] = 0;
  21327. var w = new Int32Array(16);
  21328. for (i = 0; i < paddedLength;) {
  21329. for (j = 0; j < 16; ++j, i += 4) {
  21330. w[j] = (padded[i] | (padded[i + 1] << 8) |
  21331. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  21332. }
  21333. var a = h0, b = h1, c = h2, d = h3, f, g;
  21334. for (j = 0; j < 64; ++j) {
  21335. if (j < 16) {
  21336. f = (b & c) | ((~b) & d);
  21337. g = j;
  21338. } else if (j < 32) {
  21339. f = (d & b) | ((~d) & c);
  21340. g = (5 * j + 1) & 15;
  21341. } else if (j < 48) {
  21342. f = b ^ c ^ d;
  21343. g = (3 * j + 5) & 15;
  21344. } else {
  21345. f = c ^ (b | (~d));
  21346. g = (7 * j) & 15;
  21347. }
  21348. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  21349. d = c;
  21350. c = b;
  21351. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  21352. a = tmp;
  21353. }
  21354. h0 = (h0 + a) | 0;
  21355. h1 = (h1 + b) | 0;
  21356. h2 = (h2 + c) | 0;
  21357. h3 = (h3 + d) | 0;
  21358. }
  21359. return new Uint8Array([
  21360. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  21361. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  21362. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  21363. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  21364. ]);
  21365. }
  21366. return hash;
  21367. })();
  21368. var Word64 = (function Word64Closure() {
  21369. function Word64(highInteger, lowInteger) {
  21370. this.high = highInteger | 0;
  21371. this.low = lowInteger | 0;
  21372. }
  21373. Word64.prototype = {
  21374. and: function Word64_and(word) {
  21375. this.high &= word.high;
  21376. this.low &= word.low;
  21377. },
  21378. xor: function Word64_xor(word) {
  21379. this.high ^= word.high;
  21380. this.low ^= word.low;
  21381. },
  21382. or: function Word64_or(word) {
  21383. this.high |= word.high;
  21384. this.low |= word.low;
  21385. },
  21386. shiftRight: function Word64_shiftRight(places) {
  21387. if (places >= 32) {
  21388. this.low = (this.high >>> (places - 32)) | 0;
  21389. this.high = 0;
  21390. } else {
  21391. this.low = (this.low >>> places) | (this.high << (32 - places));
  21392. this.high = (this.high >>> places) | 0;
  21393. }
  21394. },
  21395. shiftLeft: function Word64_shiftLeft(places) {
  21396. if (places >= 32) {
  21397. this.high = this.low << (places - 32);
  21398. this.low = 0;
  21399. } else {
  21400. this.high = (this.high << places) | (this.low >>> (32 - places));
  21401. this.low = this.low << places;
  21402. }
  21403. },
  21404. rotateRight: function Word64_rotateRight(places) {
  21405. var low, high;
  21406. if (places & 32) {
  21407. high = this.low;
  21408. low = this.high;
  21409. } else {
  21410. low = this.low;
  21411. high = this.high;
  21412. }
  21413. places &= 31;
  21414. this.low = (low >>> places) | (high << (32 - places));
  21415. this.high = (high >>> places) | (low << (32 - places));
  21416. },
  21417. not: function Word64_not() {
  21418. this.high = ~this.high;
  21419. this.low = ~this.low;
  21420. },
  21421. add: function Word64_add(word) {
  21422. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  21423. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  21424. if (lowAdd > 0xFFFFFFFF) {
  21425. highAdd += 1;
  21426. }
  21427. this.low = lowAdd | 0;
  21428. this.high = highAdd | 0;
  21429. },
  21430. copyTo: function Word64_copyTo(bytes, offset) {
  21431. bytes[offset] = (this.high >>> 24) & 0xFF;
  21432. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  21433. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  21434. bytes[offset + 3] = this.high & 0xFF;
  21435. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  21436. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  21437. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  21438. bytes[offset + 7] = this.low & 0xFF;
  21439. },
  21440. assign: function Word64_assign(word) {
  21441. this.high = word.high;
  21442. this.low = word.low;
  21443. }
  21444. };
  21445. return Word64;
  21446. })();
  21447. var calculateSHA256 = (function calculateSHA256Closure() {
  21448. function rotr(x, n) {
  21449. return (x >>> n) | (x << 32 - n);
  21450. }
  21451. function ch(x, y, z) {
  21452. return (x & y) ^ (~x & z);
  21453. }
  21454. function maj(x, y, z) {
  21455. return (x & y) ^ (x & z) ^ (y & z);
  21456. }
  21457. function sigma(x) {
  21458. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  21459. }
  21460. function sigmaPrime(x) {
  21461. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  21462. }
  21463. function littleSigma(x) {
  21464. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  21465. }
  21466. function littleSigmaPrime(x) {
  21467. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  21468. }
  21469. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  21470. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  21471. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  21472. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  21473. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  21474. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  21475. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  21476. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  21477. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  21478. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  21479. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  21480. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  21481. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  21482. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  21483. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  21484. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  21485. function hash(data, offset, length) {
  21486. // initial hash values
  21487. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  21488. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  21489. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  21490. // pre-processing
  21491. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  21492. var padded = new Uint8Array(paddedLength);
  21493. var i, j, n;
  21494. for (i = 0; i < length; ++i) {
  21495. padded[i] = data[offset++];
  21496. }
  21497. padded[i++] = 0x80;
  21498. n = paddedLength - 8;
  21499. while (i < n) {
  21500. padded[i++] = 0;
  21501. }
  21502. padded[i++] = 0;
  21503. padded[i++] = 0;
  21504. padded[i++] = 0;
  21505. padded[i++] = (length >>> 29) & 0xFF;
  21506. padded[i++] = (length >> 21) & 0xFF;
  21507. padded[i++] = (length >> 13) & 0xFF;
  21508. padded[i++] = (length >> 5) & 0xFF;
  21509. padded[i++] = (length << 3) & 0xFF;
  21510. var w = new Uint32Array(64);
  21511. // for each 512 bit block
  21512. for (i = 0; i < paddedLength;) {
  21513. for (j = 0; j < 16; ++j) {
  21514. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  21515. (padded[i + 2] << 8) | (padded[i + 3]));
  21516. i += 4;
  21517. }
  21518. for (j = 16; j < 64; ++j) {
  21519. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  21520. littleSigma(w[j - 15]) + w[j - 16] | 0;
  21521. }
  21522. var a = h0, b = h1, c = h2, d = h3, e = h4,
  21523. f = h5, g = h6, h = h7, t1, t2;
  21524. for (j = 0; j < 64; ++j) {
  21525. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  21526. t2 = sigma(a) + maj(a, b, c);
  21527. h = g;
  21528. g = f;
  21529. f = e;
  21530. e = (d + t1) | 0;
  21531. d = c;
  21532. c = b;
  21533. b = a;
  21534. a = (t1 + t2) | 0;
  21535. }
  21536. h0 = (h0 + a) | 0;
  21537. h1 = (h1 + b) | 0;
  21538. h2 = (h2 + c) | 0;
  21539. h3 = (h3 + d) | 0;
  21540. h4 = (h4 + e) | 0;
  21541. h5 = (h5 + f) | 0;
  21542. h6 = (h6 + g) | 0;
  21543. h7 = (h7 + h) | 0;
  21544. }
  21545. return new Uint8Array([
  21546. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  21547. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  21548. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  21549. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  21550. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  21551. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  21552. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  21553. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  21554. ]);
  21555. }
  21556. return hash;
  21557. })();
  21558. var calculateSHA512 = (function calculateSHA512Closure() {
  21559. function ch(result, x, y, z, tmp) {
  21560. result.assign(x);
  21561. result.and(y);
  21562. tmp.assign(x);
  21563. tmp.not();
  21564. tmp.and(z);
  21565. result.xor(tmp);
  21566. }
  21567. function maj(result, x, y, z, tmp) {
  21568. result.assign(x);
  21569. result.and(y);
  21570. tmp.assign(x);
  21571. tmp.and(z);
  21572. result.xor(tmp);
  21573. tmp.assign(y);
  21574. tmp.and(z);
  21575. result.xor(tmp);
  21576. }
  21577. function sigma(result, x, tmp) {
  21578. result.assign(x);
  21579. result.rotateRight(28);
  21580. tmp.assign(x);
  21581. tmp.rotateRight(34);
  21582. result.xor(tmp);
  21583. tmp.assign(x);
  21584. tmp.rotateRight(39);
  21585. result.xor(tmp);
  21586. }
  21587. function sigmaPrime(result, x, tmp) {
  21588. result.assign(x);
  21589. result.rotateRight(14);
  21590. tmp.assign(x);
  21591. tmp.rotateRight(18);
  21592. result.xor(tmp);
  21593. tmp.assign(x);
  21594. tmp.rotateRight(41);
  21595. result.xor(tmp);
  21596. }
  21597. function littleSigma(result, x, tmp) {
  21598. result.assign(x);
  21599. result.rotateRight(1);
  21600. tmp.assign(x);
  21601. tmp.rotateRight(8);
  21602. result.xor(tmp);
  21603. tmp.assign(x);
  21604. tmp.shiftRight(7);
  21605. result.xor(tmp);
  21606. }
  21607. function littleSigmaPrime(result, x, tmp) {
  21608. result.assign(x);
  21609. result.rotateRight(19);
  21610. tmp.assign(x);
  21611. tmp.rotateRight(61);
  21612. result.xor(tmp);
  21613. tmp.assign(x);
  21614. tmp.shiftRight(6);
  21615. result.xor(tmp);
  21616. }
  21617. var k = [
  21618. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  21619. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  21620. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  21621. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  21622. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  21623. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  21624. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  21625. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  21626. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  21627. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  21628. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  21629. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  21630. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  21631. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  21632. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  21633. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  21634. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  21635. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  21636. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  21637. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  21638. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  21639. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  21640. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  21641. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  21642. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  21643. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  21644. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  21645. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  21646. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  21647. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  21648. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  21649. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  21650. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  21651. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  21652. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  21653. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  21654. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  21655. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  21656. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  21657. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  21658. function hash(data, offset, length, mode384) {
  21659. mode384 = !!mode384;
  21660. // initial hash values
  21661. var h0, h1, h2, h3, h4, h5, h6, h7;
  21662. if (!mode384) {
  21663. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  21664. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  21665. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  21666. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  21667. h4 = new Word64(0x510e527f, 0xade682d1);
  21668. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  21669. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  21670. h7 = new Word64(0x5be0cd19, 0x137e2179);
  21671. }
  21672. else {
  21673. // SHA384 is exactly the same
  21674. // except with different starting values and a trimmed result
  21675. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  21676. h1 = new Word64(0x629a292a, 0x367cd507);
  21677. h2 = new Word64(0x9159015a, 0x3070dd17);
  21678. h3 = new Word64(0x152fecd8, 0xf70e5939);
  21679. h4 = new Word64(0x67332667, 0xffc00b31);
  21680. h5 = new Word64(0x8eb44a87, 0x68581511);
  21681. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  21682. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  21683. }
  21684. // pre-processing
  21685. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  21686. var padded = new Uint8Array(paddedLength);
  21687. var i, j, n;
  21688. for (i = 0; i < length; ++i) {
  21689. padded[i] = data[offset++];
  21690. }
  21691. padded[i++] = 0x80;
  21692. n = paddedLength - 16;
  21693. while (i < n) {
  21694. padded[i++] = 0;
  21695. }
  21696. padded[i++] = 0;
  21697. padded[i++] = 0;
  21698. padded[i++] = 0;
  21699. padded[i++] = 0;
  21700. padded[i++] = 0;
  21701. padded[i++] = 0;
  21702. padded[i++] = 0;
  21703. padded[i++] = 0;
  21704. padded[i++] = 0;
  21705. padded[i++] = 0;
  21706. padded[i++] = 0;
  21707. padded[i++] = (length >>> 29) & 0xFF;
  21708. padded[i++] = (length >> 21) & 0xFF;
  21709. padded[i++] = (length >> 13) & 0xFF;
  21710. padded[i++] = (length >> 5) & 0xFF;
  21711. padded[i++] = (length << 3) & 0xFF;
  21712. var w = new Array(80);
  21713. for (i = 0; i < 80; i++) {
  21714. w[i] = new Word64(0, 0);
  21715. }
  21716. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  21717. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  21718. var g = new Word64(0, 0), h = new Word64(0, 0);
  21719. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  21720. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  21721. // for each 1024 bit block
  21722. for (i = 0; i < paddedLength;) {
  21723. for (j = 0; j < 16; ++j) {
  21724. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  21725. (padded[i + 2] << 8) | (padded[i + 3]);
  21726. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  21727. (padded[i + 6]) << 8 | (padded[i + 7]);
  21728. i += 8;
  21729. }
  21730. for (j = 16; j < 80; ++j) {
  21731. tmp3 = w[j];
  21732. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  21733. tmp3.add(w[j - 7]);
  21734. littleSigma(tmp1, w[j - 15], tmp2);
  21735. tmp3.add(tmp1);
  21736. tmp3.add(w[j - 16]);
  21737. }
  21738. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  21739. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  21740. for (j = 0; j < 80; ++j) {
  21741. t1.assign(h);
  21742. sigmaPrime(tmp1, e, tmp2);
  21743. t1.add(tmp1);
  21744. ch(tmp1, e, f, g, tmp2);
  21745. t1.add(tmp1);
  21746. t1.add(k[j]);
  21747. t1.add(w[j]);
  21748. sigma(t2, a, tmp2);
  21749. maj(tmp1, a, b, c, tmp2);
  21750. t2.add(tmp1);
  21751. tmp3 = h;
  21752. h = g;
  21753. g = f;
  21754. f = e;
  21755. d.add(t1);
  21756. e = d;
  21757. d = c;
  21758. c = b;
  21759. b = a;
  21760. tmp3.assign(t1);
  21761. tmp3.add(t2);
  21762. a = tmp3;
  21763. }
  21764. h0.add(a);
  21765. h1.add(b);
  21766. h2.add(c);
  21767. h3.add(d);
  21768. h4.add(e);
  21769. h5.add(f);
  21770. h6.add(g);
  21771. h7.add(h);
  21772. }
  21773. var result;
  21774. if (!mode384) {
  21775. result = new Uint8Array(64);
  21776. h0.copyTo(result,0);
  21777. h1.copyTo(result,8);
  21778. h2.copyTo(result,16);
  21779. h3.copyTo(result,24);
  21780. h4.copyTo(result,32);
  21781. h5.copyTo(result,40);
  21782. h6.copyTo(result,48);
  21783. h7.copyTo(result,56);
  21784. }
  21785. else {
  21786. result = new Uint8Array(48);
  21787. h0.copyTo(result,0);
  21788. h1.copyTo(result,8);
  21789. h2.copyTo(result,16);
  21790. h3.copyTo(result,24);
  21791. h4.copyTo(result,32);
  21792. h5.copyTo(result,40);
  21793. }
  21794. return result;
  21795. }
  21796. return hash;
  21797. })();
  21798. var calculateSHA384 = (function calculateSHA384Closure() {
  21799. function hash(data, offset, length) {
  21800. return calculateSHA512(data, offset, length, true);
  21801. }
  21802. return hash;
  21803. })();
  21804. var NullCipher = (function NullCipherClosure() {
  21805. function NullCipher() {
  21806. }
  21807. NullCipher.prototype = {
  21808. decryptBlock: function NullCipher_decryptBlock(data) {
  21809. return data;
  21810. }
  21811. };
  21812. return NullCipher;
  21813. })();
  21814. var AES128Cipher = (function AES128CipherClosure() {
  21815. var rcon = new Uint8Array([
  21816. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21817. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21818. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21819. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21820. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  21821. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  21822. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  21823. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  21824. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  21825. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  21826. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  21827. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  21828. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  21829. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  21830. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  21831. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  21832. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  21833. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  21834. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  21835. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  21836. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  21837. 0x74, 0xe8, 0xcb, 0x8d]);
  21838. var s = new Uint8Array([
  21839. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  21840. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  21841. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  21842. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  21843. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  21844. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  21845. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  21846. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  21847. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  21848. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  21849. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  21850. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  21851. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  21852. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  21853. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  21854. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  21855. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  21856. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  21857. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  21858. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  21859. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  21860. 0xb0, 0x54, 0xbb, 0x16]);
  21861. var inv_s = new Uint8Array([
  21862. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  21863. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  21864. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  21865. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  21866. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  21867. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  21868. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  21869. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  21870. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  21871. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  21872. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  21873. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  21874. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  21875. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  21876. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  21877. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  21878. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  21879. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  21880. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  21881. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  21882. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  21883. 0x55, 0x21, 0x0c, 0x7d]);
  21884. var mixCol = new Uint8Array(256);
  21885. for (var i = 0; i < 256; i++) {
  21886. if (i < 128) {
  21887. mixCol[i] = i << 1;
  21888. } else {
  21889. mixCol[i] = (i << 1) ^ 0x1b;
  21890. }
  21891. }
  21892. var mix = new Uint32Array([
  21893. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  21894. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  21895. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  21896. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  21897. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  21898. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  21899. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  21900. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  21901. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  21902. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  21903. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  21904. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  21905. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  21906. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  21907. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  21908. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  21909. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  21910. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  21911. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  21912. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  21913. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  21914. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  21915. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  21916. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  21917. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  21918. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  21919. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  21920. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  21921. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  21922. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  21923. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  21924. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  21925. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  21926. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  21927. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  21928. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  21929. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  21930. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  21931. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  21932. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  21933. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  21934. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  21935. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  21936. function expandKey128(cipherKey) {
  21937. var b = 176, result = new Uint8Array(b);
  21938. result.set(cipherKey);
  21939. for (var j = 16, i = 1; j < b; ++i) {
  21940. // RotWord
  21941. var t1 = result[j - 3], t2 = result[j - 2],
  21942. t3 = result[j - 1], t4 = result[j - 4];
  21943. // SubWord
  21944. t1 = s[t1];
  21945. t2 = s[t2];
  21946. t3 = s[t3];
  21947. t4 = s[t4];
  21948. // Rcon
  21949. t1 = t1 ^ rcon[i];
  21950. for (var n = 0; n < 4; ++n) {
  21951. result[j] = (t1 ^= result[j - 16]);
  21952. j++;
  21953. result[j] = (t2 ^= result[j - 16]);
  21954. j++;
  21955. result[j] = (t3 ^= result[j - 16]);
  21956. j++;
  21957. result[j] = (t4 ^= result[j - 16]);
  21958. j++;
  21959. }
  21960. }
  21961. return result;
  21962. }
  21963. function decrypt128(input, key) {
  21964. var state = new Uint8Array(16);
  21965. state.set(input);
  21966. var i, j, k;
  21967. var t, u, v;
  21968. // AddRoundKey
  21969. for (j = 0, k = 160; j < 16; ++j, ++k) {
  21970. state[j] ^= key[k];
  21971. }
  21972. for (i = 9; i >= 1; --i) {
  21973. // InvShiftRows
  21974. t = state[13];
  21975. state[13] = state[9];
  21976. state[9] = state[5];
  21977. state[5] = state[1];
  21978. state[1] = t;
  21979. t = state[14];
  21980. u = state[10];
  21981. state[14] = state[6];
  21982. state[10] = state[2];
  21983. state[6] = t;
  21984. state[2] = u;
  21985. t = state[15];
  21986. u = state[11];
  21987. v = state[7];
  21988. state[15] = state[3];
  21989. state[11] = t;
  21990. state[7] = u;
  21991. state[3] = v;
  21992. // InvSubBytes
  21993. for (j = 0; j < 16; ++j) {
  21994. state[j] = inv_s[state[j]];
  21995. }
  21996. // AddRoundKey
  21997. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21998. state[j] ^= key[k];
  21999. }
  22000. // InvMixColumns
  22001. for (j = 0; j < 16; j += 4) {
  22002. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22003. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22004. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22005. (s3 >>> 24) ^ (s3 << 8));
  22006. state[j] = (t >>> 24) & 0xFF;
  22007. state[j + 1] = (t >> 16) & 0xFF;
  22008. state[j + 2] = (t >> 8) & 0xFF;
  22009. state[j + 3] = t & 0xFF;
  22010. }
  22011. }
  22012. // InvShiftRows
  22013. t = state[13];
  22014. state[13] = state[9];
  22015. state[9] = state[5];
  22016. state[5] = state[1];
  22017. state[1] = t;
  22018. t = state[14];
  22019. u = state[10];
  22020. state[14] = state[6];
  22021. state[10] = state[2];
  22022. state[6] = t;
  22023. state[2] = u;
  22024. t = state[15];
  22025. u = state[11];
  22026. v = state[7];
  22027. state[15] = state[3];
  22028. state[11] = t;
  22029. state[7] = u;
  22030. state[3] = v;
  22031. for (j = 0; j < 16; ++j) {
  22032. // InvSubBytes
  22033. state[j] = inv_s[state[j]];
  22034. // AddRoundKey
  22035. state[j] ^= key[j];
  22036. }
  22037. return state;
  22038. }
  22039. function encrypt128(input, key) {
  22040. var t, u, v, k;
  22041. var state = new Uint8Array(16);
  22042. state.set(input);
  22043. for (j = 0; j < 16; ++j) {
  22044. // AddRoundKey
  22045. state[j] ^= key[j];
  22046. }
  22047. for (i = 1; i < 10; i++) {
  22048. //SubBytes
  22049. for (j = 0; j < 16; ++j) {
  22050. state[j] = s[state[j]];
  22051. }
  22052. //ShiftRows
  22053. v = state[1];
  22054. state[1] = state[5];
  22055. state[5] = state[9];
  22056. state[9] = state[13];
  22057. state[13] = v;
  22058. v = state[2];
  22059. u = state[6];
  22060. state[2] = state[10];
  22061. state[6] = state[14];
  22062. state[10] = v;
  22063. state[14] = u;
  22064. v = state[3];
  22065. u = state[7];
  22066. t = state[11];
  22067. state[3] = state[15];
  22068. state[7] = v;
  22069. state[11] = u;
  22070. state[15] = t;
  22071. //MixColumns
  22072. for (var j = 0; j < 16; j += 4) {
  22073. var s0 = state[j + 0], s1 = state[j + 1];
  22074. var s2 = state[j + 2], s3 = state[j + 3];
  22075. t = s0 ^ s1 ^ s2 ^ s3;
  22076. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22077. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22078. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22079. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22080. }
  22081. //AddRoundKey
  22082. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22083. state[j] ^= key[k];
  22084. }
  22085. }
  22086. //SubBytes
  22087. for (j = 0; j < 16; ++j) {
  22088. state[j] = s[state[j]];
  22089. }
  22090. //ShiftRows
  22091. v = state[1];
  22092. state[1] = state[5];
  22093. state[5] = state[9];
  22094. state[9] = state[13];
  22095. state[13] = v;
  22096. v = state[2];
  22097. u = state[6];
  22098. state[2] = state[10];
  22099. state[6] = state[14];
  22100. state[10] = v;
  22101. state[14] = u;
  22102. v = state[3];
  22103. u = state[7];
  22104. t = state[11];
  22105. state[3] = state[15];
  22106. state[7] = v;
  22107. state[11] = u;
  22108. state[15] = t;
  22109. //AddRoundKey
  22110. for (j = 0, k = 160; j < 16; ++j, ++k) {
  22111. state[j] ^= key[k];
  22112. }
  22113. return state;
  22114. }
  22115. function AES128Cipher(key) {
  22116. this.key = expandKey128(key);
  22117. this.buffer = new Uint8Array(16);
  22118. this.bufferPosition = 0;
  22119. }
  22120. function decryptBlock2(data, finalize) {
  22121. var i, j, ii, sourceLength = data.length,
  22122. buffer = this.buffer, bufferLength = this.bufferPosition,
  22123. result = [], iv = this.iv;
  22124. for (i = 0; i < sourceLength; ++i) {
  22125. buffer[bufferLength] = data[i];
  22126. ++bufferLength;
  22127. if (bufferLength < 16) {
  22128. continue;
  22129. }
  22130. // buffer is full, decrypting
  22131. var plain = decrypt128(buffer, this.key);
  22132. // xor-ing the IV vector to get plain text
  22133. for (j = 0; j < 16; ++j) {
  22134. plain[j] ^= iv[j];
  22135. }
  22136. iv = buffer;
  22137. result.push(plain);
  22138. buffer = new Uint8Array(16);
  22139. bufferLength = 0;
  22140. }
  22141. // saving incomplete buffer
  22142. this.buffer = buffer;
  22143. this.bufferLength = bufferLength;
  22144. this.iv = iv;
  22145. if (result.length === 0) {
  22146. return new Uint8Array([]);
  22147. }
  22148. // combining plain text blocks into one
  22149. var outputLength = 16 * result.length;
  22150. if (finalize) {
  22151. // undo a padding that is described in RFC 2898
  22152. var lastBlock = result[result.length - 1];
  22153. var psLen = lastBlock[15];
  22154. if (psLen <= 16) {
  22155. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22156. if (lastBlock[i] !== psLen) {
  22157. // Invalid padding, assume that the block has no padding.
  22158. psLen = 0;
  22159. break;
  22160. }
  22161. }
  22162. outputLength -= psLen;
  22163. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22164. }
  22165. }
  22166. var output = new Uint8Array(outputLength);
  22167. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22168. output.set(result[i], j);
  22169. }
  22170. return output;
  22171. }
  22172. AES128Cipher.prototype = {
  22173. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  22174. var i, sourceLength = data.length;
  22175. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22176. // waiting for IV values -- they are at the start of the stream
  22177. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  22178. buffer[bufferLength] = data[i];
  22179. }
  22180. if (bufferLength < 16) {
  22181. // need more data
  22182. this.bufferLength = bufferLength;
  22183. return new Uint8Array([]);
  22184. }
  22185. this.iv = buffer;
  22186. this.buffer = new Uint8Array(16);
  22187. this.bufferLength = 0;
  22188. // starting decryption
  22189. this.decryptBlock = decryptBlock2;
  22190. return this.decryptBlock(data.subarray(16), finalize);
  22191. },
  22192. encrypt: function AES128Cipher_encrypt(data, iv) {
  22193. var i, j, ii, sourceLength = data.length,
  22194. buffer = this.buffer, bufferLength = this.bufferPosition,
  22195. result = [];
  22196. if (!iv) {
  22197. iv = new Uint8Array(16);
  22198. }
  22199. for (i = 0; i < sourceLength; ++i) {
  22200. buffer[bufferLength] = data[i];
  22201. ++bufferLength;
  22202. if (bufferLength < 16) {
  22203. continue;
  22204. }
  22205. for (j = 0; j < 16; ++j) {
  22206. buffer[j] ^= iv[j];
  22207. }
  22208. // buffer is full, encrypting
  22209. var cipher = encrypt128(buffer, this.key);
  22210. iv = cipher;
  22211. result.push(cipher);
  22212. buffer = new Uint8Array(16);
  22213. bufferLength = 0;
  22214. }
  22215. // saving incomplete buffer
  22216. this.buffer = buffer;
  22217. this.bufferLength = bufferLength;
  22218. this.iv = iv;
  22219. if (result.length === 0) {
  22220. return new Uint8Array([]);
  22221. }
  22222. // combining plain text blocks into one
  22223. var outputLength = 16 * result.length;
  22224. var output = new Uint8Array(outputLength);
  22225. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22226. output.set(result[i], j);
  22227. }
  22228. return output;
  22229. }
  22230. };
  22231. return AES128Cipher;
  22232. })();
  22233. var AES256Cipher = (function AES256CipherClosure() {
  22234. var rcon = new Uint8Array([
  22235. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22236. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22237. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22238. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22239. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  22240. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  22241. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  22242. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  22243. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  22244. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  22245. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  22246. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  22247. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  22248. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  22249. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  22250. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  22251. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  22252. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  22253. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  22254. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  22255. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  22256. 0x74, 0xe8, 0xcb, 0x8d]);
  22257. var s = new Uint8Array([
  22258. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  22259. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  22260. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  22261. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  22262. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  22263. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  22264. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  22265. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  22266. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  22267. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  22268. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  22269. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  22270. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  22271. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  22272. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  22273. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  22274. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  22275. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  22276. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  22277. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  22278. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  22279. 0xb0, 0x54, 0xbb, 0x16]);
  22280. var inv_s = new Uint8Array([
  22281. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  22282. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  22283. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  22284. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  22285. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  22286. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  22287. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  22288. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  22289. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  22290. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  22291. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  22292. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  22293. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  22294. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  22295. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  22296. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  22297. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  22298. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  22299. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  22300. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  22301. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  22302. 0x55, 0x21, 0x0c, 0x7d]);
  22303. var mixCol = new Uint8Array(256);
  22304. for (var i = 0; i < 256; i++) {
  22305. if (i < 128) {
  22306. mixCol[i] = i << 1;
  22307. } else {
  22308. mixCol[i] = (i << 1) ^ 0x1b;
  22309. }
  22310. }
  22311. var mix = new Uint32Array([
  22312. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  22313. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  22314. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  22315. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  22316. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  22317. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  22318. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  22319. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  22320. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  22321. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  22322. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  22323. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  22324. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  22325. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  22326. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  22327. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  22328. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  22329. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  22330. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  22331. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  22332. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  22333. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  22334. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  22335. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  22336. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  22337. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  22338. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  22339. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  22340. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  22341. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  22342. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  22343. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  22344. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  22345. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  22346. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  22347. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  22348. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  22349. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  22350. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  22351. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  22352. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  22353. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  22354. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  22355. function expandKey256(cipherKey) {
  22356. var b = 240, result = new Uint8Array(b);
  22357. var r = 1;
  22358. result.set(cipherKey);
  22359. for (var j = 32, i = 1; j < b; ++i) {
  22360. if (j % 32 === 16) {
  22361. t1 = s[t1];
  22362. t2 = s[t2];
  22363. t3 = s[t3];
  22364. t4 = s[t4];
  22365. } else if (j % 32 === 0) {
  22366. // RotWord
  22367. var t1 = result[j - 3], t2 = result[j - 2],
  22368. t3 = result[j - 1], t4 = result[j - 4];
  22369. // SubWord
  22370. t1 = s[t1];
  22371. t2 = s[t2];
  22372. t3 = s[t3];
  22373. t4 = s[t4];
  22374. // Rcon
  22375. t1 = t1 ^ r;
  22376. if ((r <<= 1) >= 256) {
  22377. r = (r ^ 0x1b) & 0xFF;
  22378. }
  22379. }
  22380. for (var n = 0; n < 4; ++n) {
  22381. result[j] = (t1 ^= result[j - 32]);
  22382. j++;
  22383. result[j] = (t2 ^= result[j - 32]);
  22384. j++;
  22385. result[j] = (t3 ^= result[j - 32]);
  22386. j++;
  22387. result[j] = (t4 ^= result[j - 32]);
  22388. j++;
  22389. }
  22390. }
  22391. return result;
  22392. }
  22393. function decrypt256(input, key) {
  22394. var state = new Uint8Array(16);
  22395. state.set(input);
  22396. var i, j, k;
  22397. var t, u, v;
  22398. // AddRoundKey
  22399. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22400. state[j] ^= key[k];
  22401. }
  22402. for (i = 13; i >= 1; --i) {
  22403. // InvShiftRows
  22404. t = state[13];
  22405. state[13] = state[9];
  22406. state[9] = state[5];
  22407. state[5] = state[1];
  22408. state[1] = t;
  22409. t = state[14];
  22410. u = state[10];
  22411. state[14] = state[6];
  22412. state[10] = state[2];
  22413. state[6] = t;
  22414. state[2] = u;
  22415. t = state[15];
  22416. u = state[11];
  22417. v = state[7];
  22418. state[15] = state[3];
  22419. state[11] = t;
  22420. state[7] = u;
  22421. state[3] = v;
  22422. // InvSubBytes
  22423. for (j = 0; j < 16; ++j) {
  22424. state[j] = inv_s[state[j]];
  22425. }
  22426. // AddRoundKey
  22427. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22428. state[j] ^= key[k];
  22429. }
  22430. // InvMixColumns
  22431. for (j = 0; j < 16; j += 4) {
  22432. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  22433. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  22434. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  22435. (s3 >>> 24) ^ (s3 << 8));
  22436. state[j] = (t >>> 24) & 0xFF;
  22437. state[j + 1] = (t >> 16) & 0xFF;
  22438. state[j + 2] = (t >> 8) & 0xFF;
  22439. state[j + 3] = t & 0xFF;
  22440. }
  22441. }
  22442. // InvShiftRows
  22443. t = state[13];
  22444. state[13] = state[9];
  22445. state[9] = state[5];
  22446. state[5] = state[1];
  22447. state[1] = t;
  22448. t = state[14];
  22449. u = state[10];
  22450. state[14] = state[6];
  22451. state[10] = state[2];
  22452. state[6] = t;
  22453. state[2] = u;
  22454. t = state[15];
  22455. u = state[11];
  22456. v = state[7];
  22457. state[15] = state[3];
  22458. state[11] = t;
  22459. state[7] = u;
  22460. state[3] = v;
  22461. for (j = 0; j < 16; ++j) {
  22462. // InvSubBytes
  22463. state[j] = inv_s[state[j]];
  22464. // AddRoundKey
  22465. state[j] ^= key[j];
  22466. }
  22467. return state;
  22468. }
  22469. function encrypt256(input, key) {
  22470. var t, u, v, k;
  22471. var state = new Uint8Array(16);
  22472. state.set(input);
  22473. for (j = 0; j < 16; ++j) {
  22474. // AddRoundKey
  22475. state[j] ^= key[j];
  22476. }
  22477. for (i = 1; i < 14; i++) {
  22478. //SubBytes
  22479. for (j = 0; j < 16; ++j) {
  22480. state[j] = s[state[j]];
  22481. }
  22482. //ShiftRows
  22483. v = state[1];
  22484. state[1] = state[5];
  22485. state[5] = state[9];
  22486. state[9] = state[13];
  22487. state[13] = v;
  22488. v = state[2];
  22489. u = state[6];
  22490. state[2] = state[10];
  22491. state[6] = state[14];
  22492. state[10] = v;
  22493. state[14] = u;
  22494. v = state[3];
  22495. u = state[7];
  22496. t = state[11];
  22497. state[3] = state[15];
  22498. state[7] = v;
  22499. state[11] = u;
  22500. state[15] = t;
  22501. //MixColumns
  22502. for (var j = 0; j < 16; j += 4) {
  22503. var s0 = state[j + 0], s1 = state[j + 1];
  22504. var s2 = state[j + 2], s3 = state[j + 3];
  22505. t = s0 ^ s1 ^ s2 ^ s3;
  22506. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  22507. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  22508. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  22509. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  22510. }
  22511. //AddRoundKey
  22512. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  22513. state[j] ^= key[k];
  22514. }
  22515. }
  22516. //SubBytes
  22517. for (j = 0; j < 16; ++j) {
  22518. state[j] = s[state[j]];
  22519. }
  22520. //ShiftRows
  22521. v = state[1];
  22522. state[1] = state[5];
  22523. state[5] = state[9];
  22524. state[9] = state[13];
  22525. state[13] = v;
  22526. v = state[2];
  22527. u = state[6];
  22528. state[2] = state[10];
  22529. state[6] = state[14];
  22530. state[10] = v;
  22531. state[14] = u;
  22532. v = state[3];
  22533. u = state[7];
  22534. t = state[11];
  22535. state[3] = state[15];
  22536. state[7] = v;
  22537. state[11] = u;
  22538. state[15] = t;
  22539. //AddRoundKey
  22540. for (j = 0, k = 224; j < 16; ++j, ++k) {
  22541. state[j] ^= key[k];
  22542. }
  22543. return state;
  22544. }
  22545. function AES256Cipher(key) {
  22546. this.key = expandKey256(key);
  22547. this.buffer = new Uint8Array(16);
  22548. this.bufferPosition = 0;
  22549. }
  22550. function decryptBlock2(data, finalize) {
  22551. var i, j, ii, sourceLength = data.length,
  22552. buffer = this.buffer, bufferLength = this.bufferPosition,
  22553. result = [], iv = this.iv;
  22554. for (i = 0; i < sourceLength; ++i) {
  22555. buffer[bufferLength] = data[i];
  22556. ++bufferLength;
  22557. if (bufferLength < 16) {
  22558. continue;
  22559. }
  22560. // buffer is full, decrypting
  22561. var plain = decrypt256(buffer, this.key);
  22562. // xor-ing the IV vector to get plain text
  22563. for (j = 0; j < 16; ++j) {
  22564. plain[j] ^= iv[j];
  22565. }
  22566. iv = buffer;
  22567. result.push(plain);
  22568. buffer = new Uint8Array(16);
  22569. bufferLength = 0;
  22570. }
  22571. // saving incomplete buffer
  22572. this.buffer = buffer;
  22573. this.bufferLength = bufferLength;
  22574. this.iv = iv;
  22575. if (result.length === 0) {
  22576. return new Uint8Array([]);
  22577. }
  22578. // combining plain text blocks into one
  22579. var outputLength = 16 * result.length;
  22580. if (finalize) {
  22581. // undo a padding that is described in RFC 2898
  22582. var lastBlock = result[result.length - 1];
  22583. var psLen = lastBlock[15];
  22584. if (psLen <= 16) {
  22585. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  22586. if (lastBlock[i] !== psLen) {
  22587. // Invalid padding, assume that the block has no padding.
  22588. psLen = 0;
  22589. break;
  22590. }
  22591. }
  22592. outputLength -= psLen;
  22593. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  22594. }
  22595. }
  22596. var output = new Uint8Array(outputLength);
  22597. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22598. output.set(result[i], j);
  22599. }
  22600. return output;
  22601. }
  22602. AES256Cipher.prototype = {
  22603. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  22604. var i, sourceLength = data.length;
  22605. var buffer = this.buffer, bufferLength = this.bufferPosition;
  22606. // if not supplied an IV wait for IV values
  22607. // they are at the start of the stream
  22608. if (iv) {
  22609. this.iv = iv;
  22610. } else {
  22611. for (i = 0; bufferLength < 16 &&
  22612. i < sourceLength; ++i, ++bufferLength) {
  22613. buffer[bufferLength] = data[i];
  22614. }
  22615. if (bufferLength < 16) {
  22616. //need more data
  22617. this.bufferLength = bufferLength;
  22618. return new Uint8Array([]);
  22619. }
  22620. this.iv = buffer;
  22621. data = data.subarray(16);
  22622. }
  22623. this.buffer = new Uint8Array(16);
  22624. this.bufferLength = 0;
  22625. // starting decryption
  22626. this.decryptBlock = decryptBlock2;
  22627. return this.decryptBlock(data, finalize);
  22628. },
  22629. encrypt: function AES256Cipher_encrypt(data, iv) {
  22630. var i, j, ii, sourceLength = data.length,
  22631. buffer = this.buffer, bufferLength = this.bufferPosition,
  22632. result = [];
  22633. if (!iv) {
  22634. iv = new Uint8Array(16);
  22635. }
  22636. for (i = 0; i < sourceLength; ++i) {
  22637. buffer[bufferLength] = data[i];
  22638. ++bufferLength;
  22639. if (bufferLength < 16) {
  22640. continue;
  22641. }
  22642. for (j = 0; j < 16; ++j) {
  22643. buffer[j] ^= iv[j];
  22644. }
  22645. // buffer is full, encrypting
  22646. var cipher = encrypt256(buffer, this.key);
  22647. this.iv = cipher;
  22648. result.push(cipher);
  22649. buffer = new Uint8Array(16);
  22650. bufferLength = 0;
  22651. }
  22652. // saving incomplete buffer
  22653. this.buffer = buffer;
  22654. this.bufferLength = bufferLength;
  22655. this.iv = iv;
  22656. if (result.length === 0) {
  22657. return new Uint8Array([]);
  22658. }
  22659. // combining plain text blocks into one
  22660. var outputLength = 16 * result.length;
  22661. var output = new Uint8Array(outputLength);
  22662. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  22663. output.set(result[i], j);
  22664. }
  22665. return output;
  22666. }
  22667. };
  22668. return AES256Cipher;
  22669. })();
  22670. var PDF17 = (function PDF17Closure() {
  22671. function compareByteArrays(array1, array2) {
  22672. if (array1.length !== array2.length) {
  22673. return false;
  22674. }
  22675. for (var i = 0; i < array1.length; i++) {
  22676. if (array1[i] !== array2[i]) {
  22677. return false;
  22678. }
  22679. }
  22680. return true;
  22681. }
  22682. function PDF17() {
  22683. }
  22684. PDF17.prototype = {
  22685. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  22686. ownerValidationSalt,
  22687. userBytes,
  22688. ownerPassword) {
  22689. var hashData = new Uint8Array(password.length + 56);
  22690. hashData.set(password, 0);
  22691. hashData.set(ownerValidationSalt, password.length);
  22692. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22693. var result = calculateSHA256(hashData, 0, hashData.length);
  22694. return compareByteArrays(result, ownerPassword);
  22695. },
  22696. checkUserPassword: function PDF17_checkUserPassword(password,
  22697. userValidationSalt,
  22698. userPassword) {
  22699. var hashData = new Uint8Array(password.length + 8);
  22700. hashData.set(password, 0);
  22701. hashData.set(userValidationSalt, password.length);
  22702. var result = calculateSHA256(hashData, 0, hashData.length);
  22703. return compareByteArrays(result, userPassword);
  22704. },
  22705. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  22706. ownerEncryption) {
  22707. var hashData = new Uint8Array(password.length + 56);
  22708. hashData.set(password, 0);
  22709. hashData.set(ownerKeySalt, password.length);
  22710. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22711. var key = calculateSHA256(hashData, 0, hashData.length);
  22712. var cipher = new AES256Cipher(key);
  22713. return cipher.decryptBlock(ownerEncryption,
  22714. false,
  22715. new Uint8Array(16));
  22716. },
  22717. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  22718. userEncryption) {
  22719. var hashData = new Uint8Array(password.length + 8);
  22720. hashData.set(password, 0);
  22721. hashData.set(userKeySalt, password.length);
  22722. //key is the decryption key for the UE string
  22723. var key = calculateSHA256(hashData, 0, hashData.length);
  22724. var cipher = new AES256Cipher(key);
  22725. return cipher.decryptBlock(userEncryption,
  22726. false,
  22727. new Uint8Array(16));
  22728. }
  22729. };
  22730. return PDF17;
  22731. })();
  22732. var PDF20 = (function PDF20Closure() {
  22733. function concatArrays(array1, array2) {
  22734. var t = new Uint8Array(array1.length + array2.length);
  22735. t.set(array1, 0);
  22736. t.set(array2, array1.length);
  22737. return t;
  22738. }
  22739. function calculatePDF20Hash(password, input, userBytes) {
  22740. //This refers to Algorithm 2.B as defined in ISO 32000-2
  22741. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  22742. var e = [0];
  22743. var i = 0;
  22744. while (i < 64 || e[e.length - 1] > i - 32) {
  22745. var arrayLength = password.length + k.length + userBytes.length;
  22746. var k1 = new Uint8Array(arrayLength * 64);
  22747. var array = concatArrays(password, k);
  22748. array = concatArrays(array, userBytes);
  22749. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  22750. k1.set(array, pos);
  22751. }
  22752. //AES128 CBC NO PADDING with
  22753. //first 16 bytes of k as the key and the second 16 as the iv.
  22754. var cipher = new AES128Cipher(k.subarray(0, 16));
  22755. e = cipher.encrypt(k1, k.subarray(16, 32));
  22756. //Now we have to take the first 16 bytes of an unsigned
  22757. //big endian integer... and compute the remainder
  22758. //modulo 3.... That is a fairly large number and
  22759. //JavaScript isn't going to handle that well...
  22760. //So we're using a trick that allows us to perform
  22761. //modulo math byte by byte
  22762. var remainder = 0;
  22763. for (var z = 0; z < 16; z++) {
  22764. remainder *= (256 % 3);
  22765. remainder %= 3;
  22766. remainder += ((e[z] >>> 0) % 3);
  22767. remainder %= 3;
  22768. }
  22769. if (remainder === 0) {
  22770. k = calculateSHA256(e, 0, e.length);
  22771. }
  22772. else if (remainder === 1) {
  22773. k = calculateSHA384(e, 0, e.length);
  22774. }
  22775. else if (remainder === 2) {
  22776. k = calculateSHA512(e, 0, e.length);
  22777. }
  22778. i++;
  22779. }
  22780. return k.subarray(0, 32);
  22781. }
  22782. function PDF20() {
  22783. }
  22784. function compareByteArrays(array1, array2) {
  22785. if (array1.length !== array2.length) {
  22786. return false;
  22787. }
  22788. for (var i = 0; i < array1.length; i++) {
  22789. if (array1[i] !== array2[i]) {
  22790. return false;
  22791. }
  22792. }
  22793. return true;
  22794. }
  22795. PDF20.prototype = {
  22796. hash: function PDF20_hash(password, concatBytes, userBytes) {
  22797. return calculatePDF20Hash(password, concatBytes, userBytes);
  22798. },
  22799. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  22800. ownerValidationSalt,
  22801. userBytes,
  22802. ownerPassword) {
  22803. var hashData = new Uint8Array(password.length + 56);
  22804. hashData.set(password, 0);
  22805. hashData.set(ownerValidationSalt, password.length);
  22806. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  22807. var result = calculatePDF20Hash(password, hashData, userBytes);
  22808. return compareByteArrays(result, ownerPassword);
  22809. },
  22810. checkUserPassword: function PDF20_checkUserPassword(password,
  22811. userValidationSalt,
  22812. userPassword) {
  22813. var hashData = new Uint8Array(password.length + 8);
  22814. hashData.set(password, 0);
  22815. hashData.set(userValidationSalt, password.length);
  22816. var result = calculatePDF20Hash(password, hashData, []);
  22817. return compareByteArrays(result, userPassword);
  22818. },
  22819. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  22820. ownerEncryption) {
  22821. var hashData = new Uint8Array(password.length + 56);
  22822. hashData.set(password, 0);
  22823. hashData.set(ownerKeySalt, password.length);
  22824. hashData.set(userBytes, password.length + ownerKeySalt.length);
  22825. var key = calculatePDF20Hash(password, hashData, userBytes);
  22826. var cipher = new AES256Cipher(key);
  22827. return cipher.decryptBlock(ownerEncryption,
  22828. false,
  22829. new Uint8Array(16));
  22830. },
  22831. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  22832. userEncryption) {
  22833. var hashData = new Uint8Array(password.length + 8);
  22834. hashData.set(password, 0);
  22835. hashData.set(userKeySalt, password.length);
  22836. //key is the decryption key for the UE string
  22837. var key = calculatePDF20Hash(password, hashData, []);
  22838. var cipher = new AES256Cipher(key);
  22839. return cipher.decryptBlock(userEncryption,
  22840. false,
  22841. new Uint8Array(16));
  22842. }
  22843. };
  22844. return PDF20;
  22845. })();
  22846. var CipherTransform = (function CipherTransformClosure() {
  22847. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  22848. this.stringCipherConstructor = stringCipherConstructor;
  22849. this.streamCipherConstructor = streamCipherConstructor;
  22850. }
  22851. CipherTransform.prototype = {
  22852. createStream: function CipherTransform_createStream(stream, length) {
  22853. var cipher = new this.streamCipherConstructor();
  22854. return new DecryptStream(stream, length,
  22855. function cipherTransformDecryptStream(data, finalize) {
  22856. return cipher.decryptBlock(data, finalize);
  22857. }
  22858. );
  22859. },
  22860. decryptString: function CipherTransform_decryptString(s) {
  22861. var cipher = new this.stringCipherConstructor();
  22862. var data = stringToBytes(s);
  22863. data = cipher.decryptBlock(data, true);
  22864. return bytesToString(data);
  22865. }
  22866. };
  22867. return CipherTransform;
  22868. })();
  22869. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  22870. var defaultPasswordBytes = new Uint8Array([
  22871. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  22872. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  22873. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  22874. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  22875. function createEncryptionKey20(revision, password, ownerPassword,
  22876. ownerValidationSalt, ownerKeySalt, uBytes,
  22877. userPassword, userValidationSalt, userKeySalt,
  22878. ownerEncryption, userEncryption, perms) {
  22879. if (password) {
  22880. var passwordLength = Math.min(127, password.length);
  22881. password = password.subarray(0, passwordLength);
  22882. } else {
  22883. password = [];
  22884. }
  22885. var pdfAlgorithm;
  22886. if (revision === 6) {
  22887. pdfAlgorithm = new PDF20();
  22888. } else {
  22889. pdfAlgorithm = new PDF17();
  22890. }
  22891. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  22892. userPassword)) {
  22893. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  22894. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  22895. ownerValidationSalt,
  22896. uBytes,
  22897. ownerPassword)) {
  22898. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  22899. ownerEncryption);
  22900. }
  22901. return null;
  22902. }
  22903. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  22904. flags, revision, keyLength, encryptMetadata) {
  22905. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  22906. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  22907. if (password) {
  22908. n = Math.min(32, password.length);
  22909. for (; i < n; ++i) {
  22910. hashData[i] = password[i];
  22911. }
  22912. }
  22913. j = 0;
  22914. while (i < 32) {
  22915. hashData[i++] = defaultPasswordBytes[j++];
  22916. }
  22917. // as now the padded password in the hashData[0..i]
  22918. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  22919. hashData[i++] = ownerPassword[j];
  22920. }
  22921. hashData[i++] = flags & 0xFF;
  22922. hashData[i++] = (flags >> 8) & 0xFF;
  22923. hashData[i++] = (flags >> 16) & 0xFF;
  22924. hashData[i++] = (flags >>> 24) & 0xFF;
  22925. for (j = 0, n = fileId.length; j < n; ++j) {
  22926. hashData[i++] = fileId[j];
  22927. }
  22928. if (revision >= 4 && !encryptMetadata) {
  22929. hashData[i++] = 0xFF;
  22930. hashData[i++] = 0xFF;
  22931. hashData[i++] = 0xFF;
  22932. hashData[i++] = 0xFF;
  22933. }
  22934. var hash = calculateMD5(hashData, 0, i);
  22935. var keyLengthInBytes = keyLength >> 3;
  22936. if (revision >= 3) {
  22937. for (j = 0; j < 50; ++j) {
  22938. hash = calculateMD5(hash, 0, keyLengthInBytes);
  22939. }
  22940. }
  22941. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  22942. var cipher, checkData;
  22943. if (revision >= 3) {
  22944. for (i = 0; i < 32; ++i) {
  22945. hashData[i] = defaultPasswordBytes[i];
  22946. }
  22947. for (j = 0, n = fileId.length; j < n; ++j) {
  22948. hashData[i++] = fileId[j];
  22949. }
  22950. cipher = new ARCFourCipher(encryptionKey);
  22951. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  22952. n = encryptionKey.length;
  22953. var derivedKey = new Uint8Array(n), k;
  22954. for (j = 1; j <= 19; ++j) {
  22955. for (k = 0; k < n; ++k) {
  22956. derivedKey[k] = encryptionKey[k] ^ j;
  22957. }
  22958. cipher = new ARCFourCipher(derivedKey);
  22959. checkData = cipher.encryptBlock(checkData);
  22960. }
  22961. for (j = 0, n = checkData.length; j < n; ++j) {
  22962. if (userPassword[j] !== checkData[j]) {
  22963. return null;
  22964. }
  22965. }
  22966. } else {
  22967. cipher = new ARCFourCipher(encryptionKey);
  22968. checkData = cipher.encryptBlock(defaultPasswordBytes);
  22969. for (j = 0, n = checkData.length; j < n; ++j) {
  22970. if (userPassword[j] !== checkData[j]) {
  22971. return null;
  22972. }
  22973. }
  22974. }
  22975. return encryptionKey;
  22976. }
  22977. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  22978. var hashData = new Uint8Array(32), i = 0, j, n;
  22979. n = Math.min(32, password.length);
  22980. for (; i < n; ++i) {
  22981. hashData[i] = password[i];
  22982. }
  22983. j = 0;
  22984. while (i < 32) {
  22985. hashData[i++] = defaultPasswordBytes[j++];
  22986. }
  22987. var hash = calculateMD5(hashData, 0, i);
  22988. var keyLengthInBytes = keyLength >> 3;
  22989. if (revision >= 3) {
  22990. for (j = 0; j < 50; ++j) {
  22991. hash = calculateMD5(hash, 0, hash.length);
  22992. }
  22993. }
  22994. var cipher, userPassword;
  22995. if (revision >= 3) {
  22996. userPassword = ownerPassword;
  22997. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  22998. for (j = 19; j >= 0; j--) {
  22999. for (k = 0; k < keyLengthInBytes; ++k) {
  23000. derivedKey[k] = hash[k] ^ j;
  23001. }
  23002. cipher = new ARCFourCipher(derivedKey);
  23003. userPassword = cipher.encryptBlock(userPassword);
  23004. }
  23005. } else {
  23006. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  23007. userPassword = cipher.encryptBlock(ownerPassword);
  23008. }
  23009. return userPassword;
  23010. }
  23011. var identityName = Name.get('Identity');
  23012. function CipherTransformFactory(dict, fileId, password) {
  23013. var filter = dict.get('Filter');
  23014. if (!isName(filter, 'Standard')) {
  23015. error('unknown encryption method');
  23016. }
  23017. this.dict = dict;
  23018. var algorithm = dict.get('V');
  23019. if (!isInt(algorithm) ||
  23020. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  23021. algorithm !== 5)) {
  23022. error('unsupported encryption algorithm');
  23023. }
  23024. this.algorithm = algorithm;
  23025. var keyLength = dict.get('Length');
  23026. if (!keyLength) {
  23027. // Spec asks to rely on encryption dictionary's Length entry, however
  23028. // some PDFs don't have it. Trying to recover.
  23029. if (algorithm <= 3) {
  23030. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  23031. keyLength = 40;
  23032. } else {
  23033. // Trying to find default handler -- it usually has Length.
  23034. var cfDict = dict.get('CF');
  23035. var streamCryptoName = dict.get('StmF');
  23036. if (isDict(cfDict) && isName(streamCryptoName)) {
  23037. var handlerDict = cfDict.get(streamCryptoName.name);
  23038. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  23039. if (keyLength < 40) {
  23040. // Sometimes it's incorrect value of bits, generators specify bytes.
  23041. keyLength <<= 3;
  23042. }
  23043. }
  23044. }
  23045. }
  23046. if (!isInt(keyLength) ||
  23047. keyLength < 40 || (keyLength % 8) !== 0) {
  23048. error('invalid key length');
  23049. }
  23050. // prepare keys
  23051. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  23052. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  23053. var flags = dict.get('P');
  23054. var revision = dict.get('R');
  23055. // meaningful when V is 4 or 5
  23056. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  23057. dict.get('EncryptMetadata') !== false);
  23058. this.encryptMetadata = encryptMetadata;
  23059. var fileIdBytes = stringToBytes(fileId);
  23060. var passwordBytes;
  23061. if (password) {
  23062. if (revision === 6) {
  23063. try {
  23064. password = utf8StringToString(password);
  23065. } catch (ex) {
  23066. warn('CipherTransformFactory: ' +
  23067. 'Unable to convert UTF8 encoded password.');
  23068. }
  23069. }
  23070. passwordBytes = stringToBytes(password);
  23071. }
  23072. var encryptionKey;
  23073. if (algorithm !== 5) {
  23074. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  23075. ownerPassword, userPassword, flags,
  23076. revision, keyLength, encryptMetadata);
  23077. }
  23078. else {
  23079. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  23080. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  23081. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  23082. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  23083. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  23084. var ownerEncryption = stringToBytes(dict.get('OE'));
  23085. var userEncryption = stringToBytes(dict.get('UE'));
  23086. var perms = stringToBytes(dict.get('Perms'));
  23087. encryptionKey =
  23088. createEncryptionKey20(revision, passwordBytes,
  23089. ownerPassword, ownerValidationSalt,
  23090. ownerKeySalt, uBytes,
  23091. userPassword, userValidationSalt,
  23092. userKeySalt, ownerEncryption,
  23093. userEncryption, perms);
  23094. }
  23095. if (!encryptionKey && !password) {
  23096. throw new PasswordException('No password given',
  23097. PasswordResponses.NEED_PASSWORD);
  23098. } else if (!encryptionKey && password) {
  23099. // Attempting use the password as an owner password
  23100. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  23101. revision, keyLength);
  23102. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  23103. ownerPassword, userPassword, flags,
  23104. revision, keyLength, encryptMetadata);
  23105. }
  23106. if (!encryptionKey) {
  23107. throw new PasswordException('Incorrect Password',
  23108. PasswordResponses.INCORRECT_PASSWORD);
  23109. }
  23110. this.encryptionKey = encryptionKey;
  23111. if (algorithm >= 4) {
  23112. this.cf = dict.get('CF');
  23113. this.stmf = dict.get('StmF') || identityName;
  23114. this.strf = dict.get('StrF') || identityName;
  23115. this.eff = dict.get('EFF') || this.stmf;
  23116. }
  23117. }
  23118. function buildObjectKey(num, gen, encryptionKey, isAes) {
  23119. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  23120. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  23121. key[i] = encryptionKey[i];
  23122. }
  23123. key[i++] = num & 0xFF;
  23124. key[i++] = (num >> 8) & 0xFF;
  23125. key[i++] = (num >> 16) & 0xFF;
  23126. key[i++] = gen & 0xFF;
  23127. key[i++] = (gen >> 8) & 0xFF;
  23128. if (isAes) {
  23129. key[i++] = 0x73;
  23130. key[i++] = 0x41;
  23131. key[i++] = 0x6C;
  23132. key[i++] = 0x54;
  23133. }
  23134. var hash = calculateMD5(key, 0, i);
  23135. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  23136. }
  23137. function buildCipherConstructor(cf, name, num, gen, key) {
  23138. var cryptFilter = cf.get(name.name);
  23139. var cfm;
  23140. if (cryptFilter !== null && cryptFilter !== undefined) {
  23141. cfm = cryptFilter.get('CFM');
  23142. }
  23143. if (!cfm || cfm.name === 'None') {
  23144. return function cipherTransformFactoryBuildCipherConstructorNone() {
  23145. return new NullCipher();
  23146. };
  23147. }
  23148. if ('V2' === cfm.name) {
  23149. return function cipherTransformFactoryBuildCipherConstructorV2() {
  23150. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  23151. };
  23152. }
  23153. if ('AESV2' === cfm.name) {
  23154. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  23155. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  23156. };
  23157. }
  23158. if ('AESV3' === cfm.name) {
  23159. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  23160. return new AES256Cipher(key);
  23161. };
  23162. }
  23163. error('Unknown crypto method');
  23164. }
  23165. CipherTransformFactory.prototype = {
  23166. createCipherTransform:
  23167. function CipherTransformFactory_createCipherTransform(num, gen) {
  23168. if (this.algorithm === 4 || this.algorithm === 5) {
  23169. return new CipherTransform(
  23170. buildCipherConstructor(this.cf, this.stmf,
  23171. num, gen, this.encryptionKey),
  23172. buildCipherConstructor(this.cf, this.strf,
  23173. num, gen, this.encryptionKey));
  23174. }
  23175. // algorithms 1 and 2
  23176. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  23177. var cipherConstructor = function buildCipherCipherConstructor() {
  23178. return new ARCFourCipher(key);
  23179. };
  23180. return new CipherTransform(cipherConstructor, cipherConstructor);
  23181. }
  23182. };
  23183. return CipherTransformFactory;
  23184. })();
  23185. exports.AES128Cipher = AES128Cipher;
  23186. exports.AES256Cipher = AES256Cipher;
  23187. exports.ARCFourCipher = ARCFourCipher;
  23188. exports.CipherTransformFactory = CipherTransformFactory;
  23189. exports.PDF17 = PDF17;
  23190. exports.PDF20 = PDF20;
  23191. exports.calculateMD5 = calculateMD5;
  23192. exports.calculateSHA256 = calculateSHA256;
  23193. exports.calculateSHA384 = calculateSHA384;
  23194. exports.calculateSHA512 = calculateSHA512;
  23195. }));
  23196. (function (root, factory) {
  23197. {
  23198. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  23199. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  23200. root.pdfjsCoreCFFParser);
  23201. }
  23202. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  23203. coreEncodings, coreCFFParser) {
  23204. var Util = sharedUtil.Util;
  23205. var bytesToString = sharedUtil.bytesToString;
  23206. var error = sharedUtil.error;
  23207. var Stream = coreStream.Stream;
  23208. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  23209. var StandardEncoding = coreEncodings.StandardEncoding;
  23210. var CFFParser = coreCFFParser.CFFParser;
  23211. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23212. function getLong(data, offset) {
  23213. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23214. (data[offset + 2] << 8) | data[offset + 3];
  23215. }
  23216. function getUshort(data, offset) {
  23217. return (data[offset] << 8) | data[offset + 1];
  23218. }
  23219. function parseCmap(data, start, end) {
  23220. var offset = (getUshort(data, start + 2) === 1 ?
  23221. getLong(data, start + 8) : getLong(data, start + 16));
  23222. var format = getUshort(data, start + offset);
  23223. var length, ranges, p, i;
  23224. if (format === 4) {
  23225. length = getUshort(data, start + offset + 2);
  23226. var segCount = getUshort(data, start + offset + 6) >> 1;
  23227. p = start + offset + 14;
  23228. ranges = [];
  23229. for (i = 0; i < segCount; i++, p += 2) {
  23230. ranges[i] = {end: getUshort(data, p)};
  23231. }
  23232. p += 2;
  23233. for (i = 0; i < segCount; i++, p += 2) {
  23234. ranges[i].start = getUshort(data, p);
  23235. }
  23236. for (i = 0; i < segCount; i++, p += 2) {
  23237. ranges[i].idDelta = getUshort(data, p);
  23238. }
  23239. for (i = 0; i < segCount; i++, p += 2) {
  23240. var idOffset = getUshort(data, p);
  23241. if (idOffset === 0) {
  23242. continue;
  23243. }
  23244. ranges[i].ids = [];
  23245. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23246. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23247. idOffset += 2;
  23248. }
  23249. }
  23250. return ranges;
  23251. } else if (format === 12) {
  23252. length = getLong(data, start + offset + 4);
  23253. var groups = getLong(data, start + offset + 12);
  23254. p = start + offset + 16;
  23255. ranges = [];
  23256. for (i = 0; i < groups; i++) {
  23257. ranges.push({
  23258. start: getLong(data, p),
  23259. end: getLong(data, p + 4),
  23260. idDelta: getLong(data, p + 8) - getLong(data, p)
  23261. });
  23262. p += 12;
  23263. }
  23264. return ranges;
  23265. }
  23266. error('not supported cmap: ' + format);
  23267. }
  23268. function parseCff(data, start, end, seacAnalysisEnabled) {
  23269. var properties = {};
  23270. var parser = new CFFParser(new Stream(data, start, end - start),
  23271. properties, seacAnalysisEnabled);
  23272. var cff = parser.parse();
  23273. return {
  23274. glyphs: cff.charStrings.objects,
  23275. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23276. cff.topDict.privateDict.subrsIndex.objects),
  23277. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23278. };
  23279. }
  23280. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23281. var itemSize, itemDecode;
  23282. if (isGlyphLocationsLong) {
  23283. itemSize = 4;
  23284. itemDecode = function fontItemDecodeLong(data, offset) {
  23285. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23286. (data[offset + 2] << 8) | data[offset + 3];
  23287. };
  23288. } else {
  23289. itemSize = 2;
  23290. itemDecode = function fontItemDecode(data, offset) {
  23291. return (data[offset] << 9) | (data[offset + 1] << 1);
  23292. };
  23293. }
  23294. var glyphs = [];
  23295. var startOffset = itemDecode(loca, 0);
  23296. for (var j = itemSize; j < loca.length; j += itemSize) {
  23297. var endOffset = itemDecode(loca, j);
  23298. glyphs.push(glyf.subarray(startOffset, endOffset));
  23299. startOffset = endOffset;
  23300. }
  23301. return glyphs;
  23302. }
  23303. function lookupCmap(ranges, unicode) {
  23304. var code = unicode.charCodeAt(0), gid = 0;
  23305. var l = 0, r = ranges.length - 1;
  23306. while (l < r) {
  23307. var c = (l + r + 1) >> 1;
  23308. if (code < ranges[c].start) {
  23309. r = c - 1;
  23310. } else {
  23311. l = c;
  23312. }
  23313. }
  23314. if (ranges[l].start <= code && code <= ranges[l].end) {
  23315. gid = (ranges[l].idDelta + (ranges[l].ids ?
  23316. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23317. }
  23318. return {
  23319. charCode: code,
  23320. glyphId: gid,
  23321. };
  23322. }
  23323. function compileGlyf(code, cmds, font) {
  23324. function moveTo(x, y) {
  23325. cmds.push({cmd: 'moveTo', args: [x, y]});
  23326. }
  23327. function lineTo(x, y) {
  23328. cmds.push({cmd: 'lineTo', args: [x, y]});
  23329. }
  23330. function quadraticCurveTo(xa, ya, x, y) {
  23331. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  23332. }
  23333. var i = 0;
  23334. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23335. var flags;
  23336. var x = 0, y = 0;
  23337. i += 10;
  23338. if (numberOfContours < 0) {
  23339. // composite glyph
  23340. do {
  23341. flags = (code[i] << 8) | code[i + 1];
  23342. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23343. i += 4;
  23344. var arg1, arg2;
  23345. if ((flags & 0x01)) {
  23346. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23347. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23348. i += 4;
  23349. } else {
  23350. arg1 = code[i++]; arg2 = code[i++];
  23351. }
  23352. if ((flags & 0x02)) {
  23353. x = arg1;
  23354. y = arg2;
  23355. } else {
  23356. x = 0; y = 0; // TODO "they are points" ?
  23357. }
  23358. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23359. if ((flags & 0x08)) {
  23360. scaleX =
  23361. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23362. i += 2;
  23363. } else if ((flags & 0x40)) {
  23364. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23365. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23366. i += 4;
  23367. } else if ((flags & 0x80)) {
  23368. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23369. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23370. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23371. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23372. i += 8;
  23373. }
  23374. var subglyph = font.glyphs[glyphIndex];
  23375. if (subglyph) {
  23376. cmds.push({cmd: 'save'});
  23377. cmds.push({cmd: 'transform',
  23378. args: [scaleX, scale01, scale10, scaleY, x, y]});
  23379. compileGlyf(subglyph, cmds, font);
  23380. cmds.push({cmd: 'restore'});
  23381. }
  23382. } while ((flags & 0x20));
  23383. } else {
  23384. // simple glyph
  23385. var endPtsOfContours = [];
  23386. var j, jj;
  23387. for (j = 0; j < numberOfContours; j++) {
  23388. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23389. i += 2;
  23390. }
  23391. var instructionLength = (code[i] << 8) | code[i + 1];
  23392. i += 2 + instructionLength; // skipping the instructions
  23393. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23394. var points = [];
  23395. while (points.length < numberOfPoints) {
  23396. flags = code[i++];
  23397. var repeat = 1;
  23398. if ((flags & 0x08)) {
  23399. repeat += code[i++];
  23400. }
  23401. while (repeat-- > 0) {
  23402. points.push({flags: flags});
  23403. }
  23404. }
  23405. for (j = 0; j < numberOfPoints; j++) {
  23406. switch (points[j].flags & 0x12) {
  23407. case 0x00:
  23408. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23409. i += 2;
  23410. break;
  23411. case 0x02:
  23412. x -= code[i++];
  23413. break;
  23414. case 0x12:
  23415. x += code[i++];
  23416. break;
  23417. }
  23418. points[j].x = x;
  23419. }
  23420. for (j = 0; j < numberOfPoints; j++) {
  23421. switch (points[j].flags & 0x24) {
  23422. case 0x00:
  23423. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23424. i += 2;
  23425. break;
  23426. case 0x04:
  23427. y -= code[i++];
  23428. break;
  23429. case 0x24:
  23430. y += code[i++];
  23431. break;
  23432. }
  23433. points[j].y = y;
  23434. }
  23435. var startPoint = 0;
  23436. for (i = 0; i < numberOfContours; i++) {
  23437. var endPoint = endPtsOfContours[i];
  23438. // contours might have implicit points, which is located in the middle
  23439. // between two neighboring off-curve points
  23440. var contour = points.slice(startPoint, endPoint + 1);
  23441. if ((contour[0].flags & 1)) {
  23442. contour.push(contour[0]); // using start point at the contour end
  23443. } else if ((contour[contour.length - 1].flags & 1)) {
  23444. // first is off-curve point, trying to use one from the end
  23445. contour.unshift(contour[contour.length - 1]);
  23446. } else {
  23447. // start and end are off-curve points, creating implicit one
  23448. var p = {
  23449. flags: 1,
  23450. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23451. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23452. };
  23453. contour.unshift(p);
  23454. contour.push(p);
  23455. }
  23456. moveTo(contour[0].x, contour[0].y);
  23457. for (j = 1, jj = contour.length; j < jj; j++) {
  23458. if ((contour[j].flags & 1)) {
  23459. lineTo(contour[j].x, contour[j].y);
  23460. } else if ((contour[j + 1].flags & 1)){
  23461. quadraticCurveTo(contour[j].x, contour[j].y,
  23462. contour[j + 1].x, contour[j + 1].y);
  23463. j++;
  23464. } else {
  23465. quadraticCurveTo(contour[j].x, contour[j].y,
  23466. (contour[j].x + contour[j + 1].x) / 2,
  23467. (contour[j].y + contour[j + 1].y) / 2);
  23468. }
  23469. }
  23470. startPoint = endPoint + 1;
  23471. }
  23472. }
  23473. }
  23474. function compileCharString(code, cmds, font) {
  23475. var stack = [];
  23476. var x = 0, y = 0;
  23477. var stems = 0;
  23478. function moveTo(x, y) {
  23479. cmds.push({cmd: 'moveTo', args: [x, y]});
  23480. }
  23481. function lineTo(x, y) {
  23482. cmds.push({cmd: 'lineTo', args: [x, y]});
  23483. }
  23484. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23485. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  23486. }
  23487. function parse(code) {
  23488. var i = 0;
  23489. while (i < code.length) {
  23490. var stackClean = false;
  23491. var v = code[i++];
  23492. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23493. switch (v) {
  23494. case 1: // hstem
  23495. stems += stack.length >> 1;
  23496. stackClean = true;
  23497. break;
  23498. case 3: // vstem
  23499. stems += stack.length >> 1;
  23500. stackClean = true;
  23501. break;
  23502. case 4: // vmoveto
  23503. y += stack.pop();
  23504. moveTo(x, y);
  23505. stackClean = true;
  23506. break;
  23507. case 5: // rlineto
  23508. while (stack.length > 0) {
  23509. x += stack.shift();
  23510. y += stack.shift();
  23511. lineTo(x, y);
  23512. }
  23513. break;
  23514. case 6: // hlineto
  23515. while (stack.length > 0) {
  23516. x += stack.shift();
  23517. lineTo(x, y);
  23518. if (stack.length === 0) {
  23519. break;
  23520. }
  23521. y += stack.shift();
  23522. lineTo(x, y);
  23523. }
  23524. break;
  23525. case 7: // vlineto
  23526. while (stack.length > 0) {
  23527. y += stack.shift();
  23528. lineTo(x, y);
  23529. if (stack.length === 0) {
  23530. break;
  23531. }
  23532. x += stack.shift();
  23533. lineTo(x, y);
  23534. }
  23535. break;
  23536. case 8: // rrcurveto
  23537. while (stack.length > 0) {
  23538. xa = x + stack.shift(); ya = y + stack.shift();
  23539. xb = xa + stack.shift(); yb = ya + stack.shift();
  23540. x = xb + stack.shift(); y = yb + stack.shift();
  23541. bezierCurveTo(xa, ya, xb, yb, x, y);
  23542. }
  23543. break;
  23544. case 10: // callsubr
  23545. n = stack.pop() + font.subrsBias;
  23546. subrCode = font.subrs[n];
  23547. if (subrCode) {
  23548. parse(subrCode);
  23549. }
  23550. break;
  23551. case 11: // return
  23552. return;
  23553. case 12:
  23554. v = code[i++];
  23555. switch (v) {
  23556. case 34: // flex
  23557. xa = x + stack.shift();
  23558. xb = xa + stack.shift(); y1 = y + stack.shift();
  23559. x = xb + stack.shift();
  23560. bezierCurveTo(xa, y, xb, y1, x, y1);
  23561. xa = x + stack.shift();
  23562. xb = xa + stack.shift();
  23563. x = xb + stack.shift();
  23564. bezierCurveTo(xa, y1, xb, y, x, y);
  23565. break;
  23566. case 35: // flex
  23567. xa = x + stack.shift(); ya = y + stack.shift();
  23568. xb = xa + stack.shift(); yb = ya + stack.shift();
  23569. x = xb + stack.shift(); y = yb + stack.shift();
  23570. bezierCurveTo(xa, ya, xb, yb, x, y);
  23571. xa = x + stack.shift(); ya = y + stack.shift();
  23572. xb = xa + stack.shift(); yb = ya + stack.shift();
  23573. x = xb + stack.shift(); y = yb + stack.shift();
  23574. bezierCurveTo(xa, ya, xb, yb, x, y);
  23575. stack.pop(); // fd
  23576. break;
  23577. case 36: // hflex1
  23578. xa = x + stack.shift(); y1 = y + stack.shift();
  23579. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23580. x = xb + stack.shift();
  23581. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23582. xa = x + stack.shift();
  23583. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23584. x = xb + stack.shift();
  23585. bezierCurveTo(xa, y2, xb, y3, x, y);
  23586. break;
  23587. case 37: // flex1
  23588. var x0 = x, y0 = y;
  23589. xa = x + stack.shift(); ya = y + stack.shift();
  23590. xb = xa + stack.shift(); yb = ya + stack.shift();
  23591. x = xb + stack.shift(); y = yb + stack.shift();
  23592. bezierCurveTo(xa, ya, xb, yb, x, y);
  23593. xa = x + stack.shift(); ya = y + stack.shift();
  23594. xb = xa + stack.shift(); yb = ya + stack.shift();
  23595. x = xb; y = yb;
  23596. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23597. x += stack.shift();
  23598. } else {
  23599. y += stack.shift();
  23600. }
  23601. bezierCurveTo(xa, ya, xb, yb, x, y);
  23602. break;
  23603. default:
  23604. error('unknown operator: 12 ' + v);
  23605. }
  23606. break;
  23607. case 14: // endchar
  23608. if (stack.length >= 4) {
  23609. var achar = stack.pop();
  23610. var bchar = stack.pop();
  23611. y = stack.pop();
  23612. x = stack.pop();
  23613. cmds.push({cmd: 'save'});
  23614. cmds.push({cmd: 'translate', args: [x, y]});
  23615. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  23616. font.glyphNameMap[StandardEncoding[achar]]));
  23617. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23618. cmds.push({cmd: 'restore'});
  23619. cmap = lookupCmap(font.cmap, String.fromCharCode(
  23620. font.glyphNameMap[StandardEncoding[bchar]]));
  23621. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  23622. }
  23623. return;
  23624. case 18: // hstemhm
  23625. stems += stack.length >> 1;
  23626. stackClean = true;
  23627. break;
  23628. case 19: // hintmask
  23629. stems += stack.length >> 1;
  23630. i += (stems + 7) >> 3;
  23631. stackClean = true;
  23632. break;
  23633. case 20: // cntrmask
  23634. stems += stack.length >> 1;
  23635. i += (stems + 7) >> 3;
  23636. stackClean = true;
  23637. break;
  23638. case 21: // rmoveto
  23639. y += stack.pop();
  23640. x += stack.pop();
  23641. moveTo(x, y);
  23642. stackClean = true;
  23643. break;
  23644. case 22: // hmoveto
  23645. x += stack.pop();
  23646. moveTo(x, y);
  23647. stackClean = true;
  23648. break;
  23649. case 23: // vstemhm
  23650. stems += stack.length >> 1;
  23651. stackClean = true;
  23652. break;
  23653. case 24: // rcurveline
  23654. while (stack.length > 2) {
  23655. xa = x + stack.shift(); ya = y + stack.shift();
  23656. xb = xa + stack.shift(); yb = ya + stack.shift();
  23657. x = xb + stack.shift(); y = yb + stack.shift();
  23658. bezierCurveTo(xa, ya, xb, yb, x, y);
  23659. }
  23660. x += stack.shift();
  23661. y += stack.shift();
  23662. lineTo(x, y);
  23663. break;
  23664. case 25: // rlinecurve
  23665. while (stack.length > 6) {
  23666. x += stack.shift();
  23667. y += stack.shift();
  23668. lineTo(x, y);
  23669. }
  23670. xa = x + stack.shift(); ya = y + stack.shift();
  23671. xb = xa + stack.shift(); yb = ya + stack.shift();
  23672. x = xb + stack.shift(); y = yb + stack.shift();
  23673. bezierCurveTo(xa, ya, xb, yb, x, y);
  23674. break;
  23675. case 26: // vvcurveto
  23676. if (stack.length % 2) {
  23677. x += stack.shift();
  23678. }
  23679. while (stack.length > 0) {
  23680. xa = x; ya = y + stack.shift();
  23681. xb = xa + stack.shift(); yb = ya + stack.shift();
  23682. x = xb; y = yb + stack.shift();
  23683. bezierCurveTo(xa, ya, xb, yb, x, y);
  23684. }
  23685. break;
  23686. case 27: // hhcurveto
  23687. if (stack.length % 2) {
  23688. y += stack.shift();
  23689. }
  23690. while (stack.length > 0) {
  23691. xa = x + stack.shift(); ya = y;
  23692. xb = xa + stack.shift(); yb = ya + stack.shift();
  23693. x = xb + stack.shift(); y = yb;
  23694. bezierCurveTo(xa, ya, xb, yb, x, y);
  23695. }
  23696. break;
  23697. case 28:
  23698. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23699. i += 2;
  23700. break;
  23701. case 29: // callgsubr
  23702. n = stack.pop() + font.gsubrsBias;
  23703. subrCode = font.gsubrs[n];
  23704. if (subrCode) {
  23705. parse(subrCode);
  23706. }
  23707. break;
  23708. case 30: // vhcurveto
  23709. while (stack.length > 0) {
  23710. xa = x; ya = y + stack.shift();
  23711. xb = xa + stack.shift(); yb = ya + stack.shift();
  23712. x = xb + stack.shift();
  23713. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23714. bezierCurveTo(xa, ya, xb, yb, x, y);
  23715. if (stack.length === 0) {
  23716. break;
  23717. }
  23718. xa = x + stack.shift(); ya = y;
  23719. xb = xa + stack.shift(); yb = ya + stack.shift();
  23720. y = yb + stack.shift();
  23721. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23722. bezierCurveTo(xa, ya, xb, yb, x, y);
  23723. }
  23724. break;
  23725. case 31: // hvcurveto
  23726. while (stack.length > 0) {
  23727. xa = x + stack.shift(); ya = y;
  23728. xb = xa + stack.shift(); yb = ya + stack.shift();
  23729. y = yb + stack.shift();
  23730. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23731. bezierCurveTo(xa, ya, xb, yb, x, y);
  23732. if (stack.length === 0) {
  23733. break;
  23734. }
  23735. xa = x; ya = y + stack.shift();
  23736. xb = xa + stack.shift(); yb = ya + stack.shift();
  23737. x = xb + stack.shift();
  23738. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23739. bezierCurveTo(xa, ya, xb, yb, x, y);
  23740. }
  23741. break;
  23742. default:
  23743. if (v < 32) {
  23744. error('unknown operator: ' + v);
  23745. }
  23746. if (v < 247) {
  23747. stack.push(v - 139);
  23748. } else if (v < 251) {
  23749. stack.push((v - 247) * 256 + code[i++] + 108);
  23750. } else if (v < 255) {
  23751. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23752. } else {
  23753. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23754. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23755. i += 4;
  23756. }
  23757. break;
  23758. }
  23759. if (stackClean) {
  23760. stack.length = 0;
  23761. }
  23762. }
  23763. }
  23764. parse(code);
  23765. }
  23766. var noop = '';
  23767. function CompiledFont(fontMatrix) {
  23768. this.compiledGlyphs = Object.create(null);
  23769. this.compiledCharCodeToGlyphId = Object.create(null);
  23770. this.fontMatrix = fontMatrix;
  23771. }
  23772. CompiledFont.prototype = {
  23773. getPathJs: function (unicode) {
  23774. var cmap = lookupCmap(this.cmap, unicode);
  23775. var fn = this.compiledGlyphs[cmap.glyphId];
  23776. if (!fn) {
  23777. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  23778. this.compiledGlyphs[cmap.glyphId] = fn;
  23779. }
  23780. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  23781. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  23782. }
  23783. return fn;
  23784. },
  23785. compileGlyph: function (code) {
  23786. if (!code || code.length === 0 || code[0] === 14) {
  23787. return noop;
  23788. }
  23789. var cmds = [];
  23790. cmds.push({cmd: 'save'});
  23791. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  23792. cmds.push({cmd: 'scale', args: ['size', '-size']});
  23793. this.compileGlyphImpl(code, cmds);
  23794. cmds.push({cmd: 'restore'});
  23795. return cmds;
  23796. },
  23797. compileGlyphImpl: function () {
  23798. error('Children classes should implement this.');
  23799. },
  23800. hasBuiltPath: function (unicode) {
  23801. var cmap = lookupCmap(this.cmap, unicode);
  23802. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  23803. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  23804. }
  23805. };
  23806. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23807. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23808. CompiledFont.call(this, fontMatrix);
  23809. this.glyphs = glyphs;
  23810. this.cmap = cmap;
  23811. }
  23812. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23813. compileGlyphImpl: function (code, cmds) {
  23814. compileGlyf(code, cmds, this);
  23815. }
  23816. });
  23817. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23818. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23819. CompiledFont.call(this, fontMatrix);
  23820. this.glyphs = cffInfo.glyphs;
  23821. this.gsubrs = cffInfo.gsubrs || [];
  23822. this.subrs = cffInfo.subrs || [];
  23823. this.cmap = cmap;
  23824. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  23825. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23826. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23827. this.subrsBias = (this.subrs.length < 1240 ?
  23828. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23829. }
  23830. Util.inherit(Type2Compiled, CompiledFont, {
  23831. compileGlyphImpl: function (code, cmds) {
  23832. compileCharString(code, cmds, this);
  23833. }
  23834. });
  23835. return {
  23836. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  23837. var data = new Uint8Array(font.data);
  23838. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23839. var numTables = getUshort(data, 4);
  23840. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23841. var tag = bytesToString(data.subarray(p, p + 4));
  23842. var offset = getLong(data, p + 8);
  23843. var length = getLong(data, p + 12);
  23844. switch (tag) {
  23845. case 'cmap':
  23846. cmap = parseCmap(data, offset, offset + length);
  23847. break;
  23848. case 'glyf':
  23849. glyf = data.subarray(offset, offset + length);
  23850. break;
  23851. case 'loca':
  23852. loca = data.subarray(offset, offset + length);
  23853. break;
  23854. case 'head':
  23855. unitsPerEm = getUshort(data, offset + 18);
  23856. indexToLocFormat = getUshort(data, offset + 50);
  23857. break;
  23858. case 'CFF ':
  23859. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  23860. break;
  23861. }
  23862. }
  23863. if (glyf) {
  23864. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23865. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23866. return new TrueTypeCompiled(
  23867. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23868. } else {
  23869. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23870. }
  23871. }
  23872. };
  23873. })();
  23874. exports.FontRendererFactory = FontRendererFactory;
  23875. }));
  23876. (function (root, factory) {
  23877. {
  23878. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  23879. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23880. }
  23881. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23882. var MissingDataException = sharedUtil.MissingDataException;
  23883. var StreamType = sharedUtil.StreamType;
  23884. var assert = sharedUtil.assert;
  23885. var error = sharedUtil.error;
  23886. var info = sharedUtil.info;
  23887. var isArray = sharedUtil.isArray;
  23888. var isInt = sharedUtil.isInt;
  23889. var isNum = sharedUtil.isNum;
  23890. var isString = sharedUtil.isString;
  23891. var warn = sharedUtil.warn;
  23892. var Cmd = corePrimitives.Cmd;
  23893. var Dict = corePrimitives.Dict;
  23894. var Name = corePrimitives.Name;
  23895. var Ref = corePrimitives.Ref;
  23896. var isCmd = corePrimitives.isCmd;
  23897. var isDict = corePrimitives.isDict;
  23898. var isName = corePrimitives.isName;
  23899. var Ascii85Stream = coreStream.Ascii85Stream;
  23900. var AsciiHexStream = coreStream.AsciiHexStream;
  23901. var CCITTFaxStream = coreStream.CCITTFaxStream;
  23902. var FlateStream = coreStream.FlateStream;
  23903. var Jbig2Stream = coreStream.Jbig2Stream;
  23904. var JpegStream = coreStream.JpegStream;
  23905. var JpxStream = coreStream.JpxStream;
  23906. var LZWStream = coreStream.LZWStream;
  23907. var NullStream = coreStream.NullStream;
  23908. var PredictorStream = coreStream.PredictorStream;
  23909. var RunLengthStream = coreStream.RunLengthStream;
  23910. var EOF = {};
  23911. function isEOF(v) {
  23912. return (v === EOF);
  23913. }
  23914. var MAX_LENGTH_TO_CACHE = 1000;
  23915. var Parser = (function ParserClosure() {
  23916. function Parser(lexer, allowStreams, xref, recoveryMode) {
  23917. this.lexer = lexer;
  23918. this.allowStreams = allowStreams;
  23919. this.xref = xref;
  23920. this.recoveryMode = recoveryMode || false;
  23921. this.imageCache = Object.create(null);
  23922. this.refill();
  23923. }
  23924. Parser.prototype = {
  23925. refill: function Parser_refill() {
  23926. this.buf1 = this.lexer.getObj();
  23927. this.buf2 = this.lexer.getObj();
  23928. },
  23929. shift: function Parser_shift() {
  23930. if (isCmd(this.buf2, 'ID')) {
  23931. this.buf1 = this.buf2;
  23932. this.buf2 = null;
  23933. } else {
  23934. this.buf1 = this.buf2;
  23935. this.buf2 = this.lexer.getObj();
  23936. }
  23937. },
  23938. tryShift: function Parser_tryShift() {
  23939. try {
  23940. this.shift();
  23941. return true;
  23942. } catch (e) {
  23943. if (e instanceof MissingDataException) {
  23944. throw e;
  23945. }
  23946. // Upon failure, the caller should reset this.lexer.pos to a known good
  23947. // state and call this.shift() twice to reset the buffers.
  23948. return false;
  23949. }
  23950. },
  23951. getObj: function Parser_getObj(cipherTransform) {
  23952. var buf1 = this.buf1;
  23953. this.shift();
  23954. if (buf1 instanceof Cmd) {
  23955. switch (buf1.cmd) {
  23956. case 'BI': // inline image
  23957. return this.makeInlineImage(cipherTransform);
  23958. case '[': // array
  23959. var array = [];
  23960. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  23961. array.push(this.getObj(cipherTransform));
  23962. }
  23963. if (isEOF(this.buf1)) {
  23964. if (!this.recoveryMode) {
  23965. error('End of file inside array');
  23966. }
  23967. return array;
  23968. }
  23969. this.shift();
  23970. return array;
  23971. case '<<': // dictionary or stream
  23972. var dict = new Dict(this.xref);
  23973. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  23974. if (!isName(this.buf1)) {
  23975. info('Malformed dictionary: key must be a name object');
  23976. this.shift();
  23977. continue;
  23978. }
  23979. var key = this.buf1.name;
  23980. this.shift();
  23981. if (isEOF(this.buf1)) {
  23982. break;
  23983. }
  23984. dict.set(key, this.getObj(cipherTransform));
  23985. }
  23986. if (isEOF(this.buf1)) {
  23987. if (!this.recoveryMode) {
  23988. error('End of file inside dictionary');
  23989. }
  23990. return dict;
  23991. }
  23992. // Stream objects are not allowed inside content streams or
  23993. // object streams.
  23994. if (isCmd(this.buf2, 'stream')) {
  23995. return (this.allowStreams ?
  23996. this.makeStream(dict, cipherTransform) : dict);
  23997. }
  23998. this.shift();
  23999. return dict;
  24000. default: // simple object
  24001. return buf1;
  24002. }
  24003. }
  24004. if (isInt(buf1)) { // indirect reference or integer
  24005. var num = buf1;
  24006. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  24007. var ref = new Ref(num, this.buf1);
  24008. this.shift();
  24009. this.shift();
  24010. return ref;
  24011. }
  24012. return num;
  24013. }
  24014. if (isString(buf1)) { // string
  24015. var str = buf1;
  24016. if (cipherTransform) {
  24017. str = cipherTransform.decryptString(str);
  24018. }
  24019. return str;
  24020. }
  24021. // simple object
  24022. return buf1;
  24023. },
  24024. /**
  24025. * Find the end of the stream by searching for the /EI\s/.
  24026. * @returns {number} The inline stream length.
  24027. */
  24028. findDefaultInlineStreamEnd:
  24029. function Parser_findDefaultInlineStreamEnd(stream) {
  24030. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  24031. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  24032. while ((ch = stream.getByte()) !== -1) {
  24033. if (state === 0) {
  24034. state = (ch === E) ? 1 : 0;
  24035. } else if (state === 1) {
  24036. state = (ch === I) ? 2 : 0;
  24037. } else {
  24038. assert(state === 2);
  24039. if (ch === SPACE || ch === LF || ch === CR) {
  24040. // Let's check the next five bytes are ASCII... just be sure.
  24041. n = 5;
  24042. followingBytes = stream.peekBytes(n);
  24043. for (i = 0; i < n; i++) {
  24044. ch = followingBytes[i];
  24045. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  24046. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  24047. // it's binary stuff. Resetting the state.
  24048. state = 0;
  24049. break;
  24050. }
  24051. }
  24052. if (state === 2) {
  24053. break; // Finished!
  24054. }
  24055. } else {
  24056. state = 0;
  24057. }
  24058. }
  24059. }
  24060. return ((stream.pos - 4) - startPos);
  24061. },
  24062. /**
  24063. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  24064. * @returns {number} The inline stream length.
  24065. */
  24066. findDCTDecodeInlineStreamEnd:
  24067. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  24068. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  24069. while ((b = stream.getByte()) !== -1) {
  24070. if (b !== 0xFF) { // Not a valid marker.
  24071. continue;
  24072. }
  24073. switch (stream.getByte()) {
  24074. case 0x00: // Byte stuffing.
  24075. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  24076. break;
  24077. case 0xFF: // Fill byte.
  24078. // Avoid skipping a valid marker, resetting the stream position.
  24079. stream.skip(-1);
  24080. break;
  24081. case 0xD9: // EOI
  24082. foundEOI = true;
  24083. break;
  24084. case 0xC0: // SOF0
  24085. case 0xC1: // SOF1
  24086. case 0xC2: // SOF2
  24087. case 0xC3: // SOF3
  24088. case 0xC5: // SOF5
  24089. case 0xC6: // SOF6
  24090. case 0xC7: // SOF7
  24091. case 0xC9: // SOF9
  24092. case 0xCA: // SOF10
  24093. case 0xCB: // SOF11
  24094. case 0xCD: // SOF13
  24095. case 0xCE: // SOF14
  24096. case 0xCF: // SOF15
  24097. case 0xC4: // DHT
  24098. case 0xCC: // DAC
  24099. case 0xDA: // SOS
  24100. case 0xDB: // DQT
  24101. case 0xDC: // DNL
  24102. case 0xDD: // DRI
  24103. case 0xDE: // DHP
  24104. case 0xDF: // EXP
  24105. case 0xE0: // APP0
  24106. case 0xE1: // APP1
  24107. case 0xE2: // APP2
  24108. case 0xE3: // APP3
  24109. case 0xE4: // APP4
  24110. case 0xE5: // APP5
  24111. case 0xE6: // APP6
  24112. case 0xE7: // APP7
  24113. case 0xE8: // APP8
  24114. case 0xE9: // APP9
  24115. case 0xEA: // APP10
  24116. case 0xEB: // APP11
  24117. case 0xEC: // APP12
  24118. case 0xED: // APP13
  24119. case 0xEE: // APP14
  24120. case 0xEF: // APP15
  24121. case 0xFE: // COM
  24122. // The marker should be followed by the length of the segment.
  24123. markerLength = stream.getUint16();
  24124. if (markerLength > 2) {
  24125. // |markerLength| contains the byte length of the marker segment,
  24126. // including its own length (2 bytes) and excluding the marker.
  24127. stream.skip(markerLength - 2); // Jump to the next marker.
  24128. } else {
  24129. // The marker length is invalid, resetting the stream position.
  24130. stream.skip(-2);
  24131. }
  24132. break;
  24133. }
  24134. if (foundEOI) {
  24135. break;
  24136. }
  24137. }
  24138. length = stream.pos - startPos;
  24139. if (b === -1) {
  24140. warn('Inline DCTDecode image stream: ' +
  24141. 'EOI marker not found, searching for /EI/ instead.');
  24142. stream.skip(-length); // Reset the stream position.
  24143. return this.findDefaultInlineStreamEnd(stream);
  24144. }
  24145. this.inlineStreamSkipEI(stream);
  24146. return length;
  24147. },
  24148. /**
  24149. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  24150. * @returns {number} The inline stream length.
  24151. */
  24152. findASCII85DecodeInlineStreamEnd:
  24153. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  24154. var TILDE = 0x7E, GT = 0x3E;
  24155. var startPos = stream.pos, ch, length;
  24156. while ((ch = stream.getByte()) !== -1) {
  24157. if (ch === TILDE && stream.peekByte() === GT) {
  24158. stream.skip();
  24159. break;
  24160. }
  24161. }
  24162. length = stream.pos - startPos;
  24163. if (ch === -1) {
  24164. warn('Inline ASCII85Decode image stream: ' +
  24165. 'EOD marker not found, searching for /EI/ instead.');
  24166. stream.skip(-length); // Reset the stream position.
  24167. return this.findDefaultInlineStreamEnd(stream);
  24168. }
  24169. this.inlineStreamSkipEI(stream);
  24170. return length;
  24171. },
  24172. /**
  24173. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  24174. * @returns {number} The inline stream length.
  24175. */
  24176. findASCIIHexDecodeInlineStreamEnd:
  24177. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  24178. var GT = 0x3E;
  24179. var startPos = stream.pos, ch, length;
  24180. while ((ch = stream.getByte()) !== -1) {
  24181. if (ch === GT) {
  24182. break;
  24183. }
  24184. }
  24185. length = stream.pos - startPos;
  24186. if (ch === -1) {
  24187. warn('Inline ASCIIHexDecode image stream: ' +
  24188. 'EOD marker not found, searching for /EI/ instead.');
  24189. stream.skip(-length); // Reset the stream position.
  24190. return this.findDefaultInlineStreamEnd(stream);
  24191. }
  24192. this.inlineStreamSkipEI(stream);
  24193. return length;
  24194. },
  24195. /**
  24196. * Skip over the /EI/ for streams where we search for an EOD marker.
  24197. */
  24198. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  24199. var E = 0x45, I = 0x49;
  24200. var state = 0, ch;
  24201. while ((ch = stream.getByte()) !== -1) {
  24202. if (state === 0) {
  24203. state = (ch === E) ? 1 : 0;
  24204. } else if (state === 1) {
  24205. state = (ch === I) ? 2 : 0;
  24206. } else if (state === 2) {
  24207. break;
  24208. }
  24209. }
  24210. },
  24211. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  24212. var lexer = this.lexer;
  24213. var stream = lexer.stream;
  24214. // Parse dictionary.
  24215. var dict = new Dict(this.xref);
  24216. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  24217. if (!isName(this.buf1)) {
  24218. error('Dictionary key must be a name object');
  24219. }
  24220. var key = this.buf1.name;
  24221. this.shift();
  24222. if (isEOF(this.buf1)) {
  24223. break;
  24224. }
  24225. dict.set(key, this.getObj(cipherTransform));
  24226. }
  24227. // Extract the name of the first (i.e. the current) image filter.
  24228. var filter = dict.get('Filter', 'F'), filterName;
  24229. if (isName(filter)) {
  24230. filterName = filter.name;
  24231. } else if (isArray(filter) && isName(filter[0])) {
  24232. filterName = filter[0].name;
  24233. }
  24234. // Parse image stream.
  24235. var startPos = stream.pos, length, i, ii;
  24236. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  24237. length = this.findDCTDecodeInlineStreamEnd(stream);
  24238. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  24239. length = this.findASCII85DecodeInlineStreamEnd(stream);
  24240. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  24241. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  24242. } else {
  24243. length = this.findDefaultInlineStreamEnd(stream);
  24244. }
  24245. var imageStream = stream.makeSubStream(startPos, length, dict);
  24246. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  24247. // adler32 checksum.
  24248. var adler32;
  24249. if (length < MAX_LENGTH_TO_CACHE) {
  24250. var imageBytes = imageStream.getBytes();
  24251. imageStream.reset();
  24252. var a = 1;
  24253. var b = 0;
  24254. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  24255. // No modulo required in the loop if imageBytes.length < 5552.
  24256. a += imageBytes[i] & 0xff;
  24257. b += a;
  24258. }
  24259. adler32 = ((b % 65521) << 16) | (a % 65521);
  24260. if (this.imageCache.adler32 === adler32) {
  24261. this.buf2 = Cmd.get('EI');
  24262. this.shift();
  24263. this.imageCache[adler32].reset();
  24264. return this.imageCache[adler32];
  24265. }
  24266. }
  24267. if (cipherTransform) {
  24268. imageStream = cipherTransform.createStream(imageStream, length);
  24269. }
  24270. imageStream = this.filter(imageStream, dict, length);
  24271. imageStream.dict = dict;
  24272. if (adler32 !== undefined) {
  24273. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  24274. this.imageCache[adler32] = imageStream;
  24275. }
  24276. this.buf2 = Cmd.get('EI');
  24277. this.shift();
  24278. return imageStream;
  24279. },
  24280. makeStream: function Parser_makeStream(dict, cipherTransform) {
  24281. var lexer = this.lexer;
  24282. var stream = lexer.stream;
  24283. // get stream start position
  24284. lexer.skipToNextLine();
  24285. var pos = stream.pos - 1;
  24286. // get length
  24287. var length = dict.get('Length');
  24288. if (!isInt(length)) {
  24289. info('Bad ' + length + ' attribute in stream');
  24290. length = 0;
  24291. }
  24292. // skip over the stream data
  24293. stream.pos = pos + length;
  24294. lexer.nextChar();
  24295. // Shift '>>' and check whether the new object marks the end of the stream
  24296. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  24297. this.shift(); // 'stream'
  24298. } else {
  24299. // bad stream length, scanning for endstream
  24300. stream.pos = pos;
  24301. var SCAN_BLOCK_SIZE = 2048;
  24302. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  24303. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  24304. 0x61, 0x6D];
  24305. var skipped = 0, found = false, i, j;
  24306. while (stream.pos < stream.end) {
  24307. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  24308. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  24309. if (scanLength <= 0) {
  24310. break;
  24311. }
  24312. found = false;
  24313. i = 0;
  24314. while (i < scanLength) {
  24315. j = 0;
  24316. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  24317. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  24318. j++;
  24319. }
  24320. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  24321. found = true;
  24322. break;
  24323. }
  24324. i++;
  24325. }
  24326. if (found) {
  24327. skipped += i;
  24328. stream.pos += i;
  24329. break;
  24330. }
  24331. skipped += scanLength;
  24332. stream.pos += scanLength;
  24333. }
  24334. if (!found) {
  24335. error('Missing endstream');
  24336. }
  24337. length = skipped;
  24338. lexer.nextChar();
  24339. this.shift();
  24340. this.shift();
  24341. }
  24342. this.shift(); // 'endstream'
  24343. stream = stream.makeSubStream(pos, length, dict);
  24344. if (cipherTransform) {
  24345. stream = cipherTransform.createStream(stream, length);
  24346. }
  24347. stream = this.filter(stream, dict, length);
  24348. stream.dict = dict;
  24349. return stream;
  24350. },
  24351. filter: function Parser_filter(stream, dict, length) {
  24352. var filter = dict.get('Filter', 'F');
  24353. var params = dict.get('DecodeParms', 'DP');
  24354. if (isName(filter)) {
  24355. return this.makeFilter(stream, filter.name, length, params);
  24356. }
  24357. var maybeLength = length;
  24358. if (isArray(filter)) {
  24359. var filterArray = filter;
  24360. var paramsArray = params;
  24361. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  24362. filter = filterArray[i];
  24363. if (!isName(filter)) {
  24364. error('Bad filter name: ' + filter);
  24365. }
  24366. params = null;
  24367. if (isArray(paramsArray) && (i in paramsArray)) {
  24368. params = paramsArray[i];
  24369. }
  24370. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  24371. // after the first stream the length variable is invalid
  24372. maybeLength = null;
  24373. }
  24374. }
  24375. return stream;
  24376. },
  24377. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  24378. // Since the 'Length' entry in the stream dictionary can be completely
  24379. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  24380. // when we can be absolutely certain that it actually is empty.
  24381. if (maybeLength === 0) {
  24382. warn('Empty "' + name + '" stream.');
  24383. return new NullStream(stream);
  24384. }
  24385. try {
  24386. if (params && this.xref) {
  24387. params = this.xref.fetchIfRef(params);
  24388. }
  24389. var xrefStreamStats = this.xref.stats.streamTypes;
  24390. if (name === 'FlateDecode' || name === 'Fl') {
  24391. xrefStreamStats[StreamType.FLATE] = true;
  24392. if (params) {
  24393. return new PredictorStream(new FlateStream(stream, maybeLength),
  24394. maybeLength, params);
  24395. }
  24396. return new FlateStream(stream, maybeLength);
  24397. }
  24398. if (name === 'LZWDecode' || name === 'LZW') {
  24399. xrefStreamStats[StreamType.LZW] = true;
  24400. var earlyChange = 1;
  24401. if (params) {
  24402. if (params.has('EarlyChange')) {
  24403. earlyChange = params.get('EarlyChange');
  24404. }
  24405. return new PredictorStream(
  24406. new LZWStream(stream, maybeLength, earlyChange),
  24407. maybeLength, params);
  24408. }
  24409. return new LZWStream(stream, maybeLength, earlyChange);
  24410. }
  24411. if (name === 'DCTDecode' || name === 'DCT') {
  24412. xrefStreamStats[StreamType.DCT] = true;
  24413. return new JpegStream(stream, maybeLength, stream.dict);
  24414. }
  24415. if (name === 'JPXDecode' || name === 'JPX') {
  24416. xrefStreamStats[StreamType.JPX] = true;
  24417. return new JpxStream(stream, maybeLength, stream.dict);
  24418. }
  24419. if (name === 'ASCII85Decode' || name === 'A85') {
  24420. xrefStreamStats[StreamType.A85] = true;
  24421. return new Ascii85Stream(stream, maybeLength);
  24422. }
  24423. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  24424. xrefStreamStats[StreamType.AHX] = true;
  24425. return new AsciiHexStream(stream, maybeLength);
  24426. }
  24427. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  24428. xrefStreamStats[StreamType.CCF] = true;
  24429. return new CCITTFaxStream(stream, maybeLength, params);
  24430. }
  24431. if (name === 'RunLengthDecode' || name === 'RL') {
  24432. xrefStreamStats[StreamType.RL] = true;
  24433. return new RunLengthStream(stream, maybeLength);
  24434. }
  24435. if (name === 'JBIG2Decode') {
  24436. xrefStreamStats[StreamType.JBIG] = true;
  24437. return new Jbig2Stream(stream, maybeLength, stream.dict);
  24438. }
  24439. warn('filter "' + name + '" not supported yet');
  24440. return stream;
  24441. } catch (ex) {
  24442. if (ex instanceof MissingDataException) {
  24443. throw ex;
  24444. }
  24445. warn('Invalid stream: \"' + ex + '\"');
  24446. return new NullStream(stream);
  24447. }
  24448. }
  24449. };
  24450. return Parser;
  24451. })();
  24452. var Lexer = (function LexerClosure() {
  24453. function Lexer(stream, knownCommands) {
  24454. this.stream = stream;
  24455. this.nextChar();
  24456. // While lexing, we build up many strings one char at a time. Using += for
  24457. // this can result in lots of garbage strings. It's better to build an
  24458. // array of single-char strings and then join() them together at the end.
  24459. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  24460. // purpose uses less memory than using a new array for each string.
  24461. this.strBuf = [];
  24462. // The PDFs might have "glued" commands with other commands, operands or
  24463. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  24464. // commands and their prefixes. The prefixes are built the following way:
  24465. // if there a command that is a prefix of the other valid command or
  24466. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  24467. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  24468. // other commands or literals as a prefix. The knowCommands is optional.
  24469. this.knownCommands = knownCommands;
  24470. }
  24471. // A '1' in this array means the character is white space. A '1' or
  24472. // '2' means the character ends a name or command.
  24473. var specialChars = [
  24474. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  24475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  24476. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  24477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  24478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  24479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  24480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  24481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  24482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  24483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  24484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  24485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  24486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  24487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  24488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  24489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  24490. ];
  24491. function toHexDigit(ch) {
  24492. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  24493. return ch & 0x0F;
  24494. }
  24495. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  24496. // 'A'-'F', 'a'-'f'
  24497. return (ch & 0x0F) + 9;
  24498. }
  24499. return -1;
  24500. }
  24501. Lexer.prototype = {
  24502. nextChar: function Lexer_nextChar() {
  24503. return (this.currentChar = this.stream.getByte());
  24504. },
  24505. peekChar: function Lexer_peekChar() {
  24506. return this.stream.peekByte();
  24507. },
  24508. getNumber: function Lexer_getNumber() {
  24509. var ch = this.currentChar;
  24510. var eNotation = false;
  24511. var divideBy = 0; // different from 0 if it's a floating point value
  24512. var sign = 1;
  24513. if (ch === 0x2D) { // '-'
  24514. sign = -1;
  24515. ch = this.nextChar();
  24516. if (ch === 0x2D) { // '-'
  24517. // Ignore double negative (this is consistent with Adobe Reader).
  24518. ch = this.nextChar();
  24519. }
  24520. } else if (ch === 0x2B) { // '+'
  24521. ch = this.nextChar();
  24522. }
  24523. if (ch === 0x2E) { // '.'
  24524. divideBy = 10;
  24525. ch = this.nextChar();
  24526. }
  24527. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24528. error('Invalid number: ' + String.fromCharCode(ch));
  24529. return 0;
  24530. }
  24531. var baseValue = ch - 0x30; // '0'
  24532. var powerValue = 0;
  24533. var powerValueSign = 1;
  24534. while ((ch = this.nextChar()) >= 0) {
  24535. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  24536. var currentDigit = ch - 0x30; // '0'
  24537. if (eNotation) { // We are after an 'e' or 'E'
  24538. powerValue = powerValue * 10 + currentDigit;
  24539. } else {
  24540. if (divideBy !== 0) { // We are after a point
  24541. divideBy *= 10;
  24542. }
  24543. baseValue = baseValue * 10 + currentDigit;
  24544. }
  24545. } else if (ch === 0x2E) { // '.'
  24546. if (divideBy === 0) {
  24547. divideBy = 1;
  24548. } else {
  24549. // A number can have only one '.'
  24550. break;
  24551. }
  24552. } else if (ch === 0x2D) { // '-'
  24553. // ignore minus signs in the middle of numbers to match
  24554. // Adobe's behavior
  24555. warn('Badly formatted number');
  24556. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  24557. // 'E' can be either a scientific notation or the beginning of a new
  24558. // operator
  24559. ch = this.peekChar();
  24560. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  24561. powerValueSign = (ch === 0x2D) ? -1 : 1;
  24562. this.nextChar(); // Consume the sign character
  24563. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  24564. // The 'E' must be the beginning of a new operator
  24565. break;
  24566. }
  24567. eNotation = true;
  24568. } else {
  24569. // the last character doesn't belong to us
  24570. break;
  24571. }
  24572. }
  24573. if (divideBy !== 0) {
  24574. baseValue /= divideBy;
  24575. }
  24576. if (eNotation) {
  24577. baseValue *= Math.pow(10, powerValueSign * powerValue);
  24578. }
  24579. return sign * baseValue;
  24580. },
  24581. getString: function Lexer_getString() {
  24582. var numParen = 1;
  24583. var done = false;
  24584. var strBuf = this.strBuf;
  24585. strBuf.length = 0;
  24586. var ch = this.nextChar();
  24587. while (true) {
  24588. var charBuffered = false;
  24589. switch (ch | 0) {
  24590. case -1:
  24591. warn('Unterminated string');
  24592. done = true;
  24593. break;
  24594. case 0x28: // '('
  24595. ++numParen;
  24596. strBuf.push('(');
  24597. break;
  24598. case 0x29: // ')'
  24599. if (--numParen === 0) {
  24600. this.nextChar(); // consume strings ')'
  24601. done = true;
  24602. } else {
  24603. strBuf.push(')');
  24604. }
  24605. break;
  24606. case 0x5C: // '\\'
  24607. ch = this.nextChar();
  24608. switch (ch) {
  24609. case -1:
  24610. warn('Unterminated string');
  24611. done = true;
  24612. break;
  24613. case 0x6E: // 'n'
  24614. strBuf.push('\n');
  24615. break;
  24616. case 0x72: // 'r'
  24617. strBuf.push('\r');
  24618. break;
  24619. case 0x74: // 't'
  24620. strBuf.push('\t');
  24621. break;
  24622. case 0x62: // 'b'
  24623. strBuf.push('\b');
  24624. break;
  24625. case 0x66: // 'f'
  24626. strBuf.push('\f');
  24627. break;
  24628. case 0x5C: // '\'
  24629. case 0x28: // '('
  24630. case 0x29: // ')'
  24631. strBuf.push(String.fromCharCode(ch));
  24632. break;
  24633. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  24634. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  24635. var x = ch & 0x0F;
  24636. ch = this.nextChar();
  24637. charBuffered = true;
  24638. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24639. x = (x << 3) + (ch & 0x0F);
  24640. ch = this.nextChar();
  24641. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  24642. charBuffered = false;
  24643. x = (x << 3) + (ch & 0x0F);
  24644. }
  24645. }
  24646. strBuf.push(String.fromCharCode(x));
  24647. break;
  24648. case 0x0D: // CR
  24649. if (this.peekChar() === 0x0A) { // LF
  24650. this.nextChar();
  24651. }
  24652. break;
  24653. case 0x0A: // LF
  24654. break;
  24655. default:
  24656. strBuf.push(String.fromCharCode(ch));
  24657. break;
  24658. }
  24659. break;
  24660. default:
  24661. strBuf.push(String.fromCharCode(ch));
  24662. break;
  24663. }
  24664. if (done) {
  24665. break;
  24666. }
  24667. if (!charBuffered) {
  24668. ch = this.nextChar();
  24669. }
  24670. }
  24671. return strBuf.join('');
  24672. },
  24673. getName: function Lexer_getName() {
  24674. var ch, previousCh;
  24675. var strBuf = this.strBuf;
  24676. strBuf.length = 0;
  24677. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24678. if (ch === 0x23) { // '#'
  24679. ch = this.nextChar();
  24680. if (specialChars[ch]) {
  24681. warn('Lexer_getName: ' +
  24682. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  24683. strBuf.push('#');
  24684. break;
  24685. }
  24686. var x = toHexDigit(ch);
  24687. if (x !== -1) {
  24688. previousCh = ch;
  24689. ch = this.nextChar();
  24690. var x2 = toHexDigit(ch);
  24691. if (x2 === -1) {
  24692. warn('Lexer_getName: Illegal digit (' +
  24693. String.fromCharCode(ch) +') in hexadecimal number.');
  24694. strBuf.push('#', String.fromCharCode(previousCh));
  24695. if (specialChars[ch]) {
  24696. break;
  24697. }
  24698. strBuf.push(String.fromCharCode(ch));
  24699. continue;
  24700. }
  24701. strBuf.push(String.fromCharCode((x << 4) | x2));
  24702. } else {
  24703. strBuf.push('#', String.fromCharCode(ch));
  24704. }
  24705. } else {
  24706. strBuf.push(String.fromCharCode(ch));
  24707. }
  24708. }
  24709. if (strBuf.length > 127) {
  24710. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  24711. }
  24712. return Name.get(strBuf.join(''));
  24713. },
  24714. getHexString: function Lexer_getHexString() {
  24715. var strBuf = this.strBuf;
  24716. strBuf.length = 0;
  24717. var ch = this.currentChar;
  24718. var isFirstHex = true;
  24719. var firstDigit;
  24720. var secondDigit;
  24721. while (true) {
  24722. if (ch < 0) {
  24723. warn('Unterminated hex string');
  24724. break;
  24725. } else if (ch === 0x3E) { // '>'
  24726. this.nextChar();
  24727. break;
  24728. } else if (specialChars[ch] === 1) {
  24729. ch = this.nextChar();
  24730. continue;
  24731. } else {
  24732. if (isFirstHex) {
  24733. firstDigit = toHexDigit(ch);
  24734. if (firstDigit === -1) {
  24735. warn('Ignoring invalid character "' + ch + '" in hex string');
  24736. ch = this.nextChar();
  24737. continue;
  24738. }
  24739. } else {
  24740. secondDigit = toHexDigit(ch);
  24741. if (secondDigit === -1) {
  24742. warn('Ignoring invalid character "' + ch + '" in hex string');
  24743. ch = this.nextChar();
  24744. continue;
  24745. }
  24746. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  24747. }
  24748. isFirstHex = !isFirstHex;
  24749. ch = this.nextChar();
  24750. }
  24751. }
  24752. return strBuf.join('');
  24753. },
  24754. getObj: function Lexer_getObj() {
  24755. // skip whitespace and comments
  24756. var comment = false;
  24757. var ch = this.currentChar;
  24758. while (true) {
  24759. if (ch < 0) {
  24760. return EOF;
  24761. }
  24762. if (comment) {
  24763. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  24764. comment = false;
  24765. }
  24766. } else if (ch === 0x25) { // '%'
  24767. comment = true;
  24768. } else if (specialChars[ch] !== 1) {
  24769. break;
  24770. }
  24771. ch = this.nextChar();
  24772. }
  24773. // start reading token
  24774. switch (ch | 0) {
  24775. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24776. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24777. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24778. return this.getNumber();
  24779. case 0x28: // '('
  24780. return this.getString();
  24781. case 0x2F: // '/'
  24782. return this.getName();
  24783. // array punctuation
  24784. case 0x5B: // '['
  24785. this.nextChar();
  24786. return Cmd.get('[');
  24787. case 0x5D: // ']'
  24788. this.nextChar();
  24789. return Cmd.get(']');
  24790. // hex string or dict punctuation
  24791. case 0x3C: // '<'
  24792. ch = this.nextChar();
  24793. if (ch === 0x3C) {
  24794. // dict punctuation
  24795. this.nextChar();
  24796. return Cmd.get('<<');
  24797. }
  24798. return this.getHexString();
  24799. // dict punctuation
  24800. case 0x3E: // '>'
  24801. ch = this.nextChar();
  24802. if (ch === 0x3E) {
  24803. this.nextChar();
  24804. return Cmd.get('>>');
  24805. }
  24806. return Cmd.get('>');
  24807. case 0x7B: // '{'
  24808. this.nextChar();
  24809. return Cmd.get('{');
  24810. case 0x7D: // '}'
  24811. this.nextChar();
  24812. return Cmd.get('}');
  24813. case 0x29: // ')'
  24814. error('Illegal character: ' + ch);
  24815. break;
  24816. }
  24817. // command
  24818. var str = String.fromCharCode(ch);
  24819. var knownCommands = this.knownCommands;
  24820. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24821. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  24822. // stop if known command is found and next character does not make
  24823. // the str a command
  24824. var possibleCommand = str + String.fromCharCode(ch);
  24825. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  24826. break;
  24827. }
  24828. if (str.length === 128) {
  24829. error('Command token too long: ' + str.length);
  24830. }
  24831. str = possibleCommand;
  24832. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  24833. }
  24834. if (str === 'true') {
  24835. return true;
  24836. }
  24837. if (str === 'false') {
  24838. return false;
  24839. }
  24840. if (str === 'null') {
  24841. return null;
  24842. }
  24843. return Cmd.get(str);
  24844. },
  24845. skipToNextLine: function Lexer_skipToNextLine() {
  24846. var ch = this.currentChar;
  24847. while (ch >= 0) {
  24848. if (ch === 0x0D) { // CR
  24849. ch = this.nextChar();
  24850. if (ch === 0x0A) { // LF
  24851. this.nextChar();
  24852. }
  24853. break;
  24854. } else if (ch === 0x0A) { // LF
  24855. this.nextChar();
  24856. break;
  24857. }
  24858. ch = this.nextChar();
  24859. }
  24860. }
  24861. };
  24862. return Lexer;
  24863. })();
  24864. var Linearization = {
  24865. create: function LinearizationCreate(stream) {
  24866. function getInt(name, allowZeroValue) {
  24867. var obj = linDict.get(name);
  24868. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  24869. return obj;
  24870. }
  24871. throw new Error('The "' + name + '" parameter in the linearization ' +
  24872. 'dictionary is invalid.');
  24873. }
  24874. function getHints() {
  24875. var hints = linDict.get('H'), hintsLength, item;
  24876. if (isArray(hints) &&
  24877. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  24878. for (var index = 0; index < hintsLength; index++) {
  24879. if (!(isInt(item = hints[index]) && item > 0)) {
  24880. throw new Error('Hint (' + index +
  24881. ') in the linearization dictionary is invalid.');
  24882. }
  24883. }
  24884. return hints;
  24885. }
  24886. throw new Error('Hint array in the linearization dictionary is invalid.');
  24887. }
  24888. var parser = new Parser(new Lexer(stream), false, null);
  24889. var obj1 = parser.getObj();
  24890. var obj2 = parser.getObj();
  24891. var obj3 = parser.getObj();
  24892. var linDict = parser.getObj();
  24893. var obj, length;
  24894. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  24895. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  24896. return null; // No valid linearization dictionary found.
  24897. } else if ((length = getInt('L')) !== stream.length) {
  24898. throw new Error('The "L" parameter in the linearization dictionary ' +
  24899. 'does not equal the stream length.');
  24900. }
  24901. return {
  24902. length: length,
  24903. hints: getHints(),
  24904. objectNumberFirst: getInt('O'),
  24905. endFirst: getInt('E'),
  24906. numPages: getInt('N'),
  24907. mainXRefEntriesOffset: getInt('T'),
  24908. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  24909. };
  24910. }
  24911. };
  24912. exports.EOF = EOF;
  24913. exports.Lexer = Lexer;
  24914. exports.Linearization = Linearization;
  24915. exports.Parser = Parser;
  24916. exports.isEOF = isEOF;
  24917. }));
  24918. (function (root, factory) {
  24919. {
  24920. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  24921. root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  24922. }
  24923. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  24924. var warn = sharedUtil.warn;
  24925. var isSpace = sharedUtil.isSpace;
  24926. var Stream = coreStream.Stream;
  24927. var getEncoding = coreEncodings.getEncoding;
  24928. // Hinting is currently disabled due to unknown problems on windows
  24929. // in tracemonkey and various other pdfs with type1 fonts.
  24930. var HINTING_ENABLED = false;
  24931. /*
  24932. * CharStrings are encoded following the the CharString Encoding sequence
  24933. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  24934. * The value in a byte indicates a command, a number, or subsequent bytes
  24935. * that are to be interpreted in a special way.
  24936. *
  24937. * CharString Number Encoding:
  24938. * A CharString byte containing the values from 32 through 255 inclusive
  24939. * indicate an integer. These values are decoded in four ranges.
  24940. *
  24941. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  24942. * indicate the integer v - 139. Thus, the integer values from -107 through
  24943. * 107 inclusive may be encoded in single byte.
  24944. *
  24945. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  24946. * indicates an integer involving the next byte, w, according to the formula:
  24947. * [(v - 247) x 256] + w + 108
  24948. *
  24949. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  24950. * indicates an integer involving the next byte, w, according to the formula:
  24951. * -[(v - 251) * 256] - w - 108
  24952. *
  24953. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  24954. * are a two complement signed integer. The first of these bytes contains the
  24955. * highest order bits, the second byte contains the next higher order bits
  24956. * and the fourth byte contain the lowest order bits.
  24957. *
  24958. *
  24959. * CharString Command Encoding:
  24960. * CharStrings commands are encoded in 1 or 2 bytes.
  24961. *
  24962. * Single byte commands are encoded in 1 byte that contains a value between
  24963. * 0 and 31 inclusive.
  24964. * If a command byte contains the value 12, then the value in the next byte
  24965. * indicates a command. This "escape" mechanism allows many extra commands
  24966. * to be encoded and this encoding technique helps to minimize the length of
  24967. * the charStrings.
  24968. */
  24969. var Type1CharString = (function Type1CharStringClosure() {
  24970. var COMMAND_MAP = {
  24971. 'hstem': [1],
  24972. 'vstem': [3],
  24973. 'vmoveto': [4],
  24974. 'rlineto': [5],
  24975. 'hlineto': [6],
  24976. 'vlineto': [7],
  24977. 'rrcurveto': [8],
  24978. 'callsubr': [10],
  24979. 'flex': [12, 35],
  24980. 'drop' : [12, 18],
  24981. 'endchar': [14],
  24982. 'rmoveto': [21],
  24983. 'hmoveto': [22],
  24984. 'vhcurveto': [30],
  24985. 'hvcurveto': [31]
  24986. };
  24987. function Type1CharString() {
  24988. this.width = 0;
  24989. this.lsb = 0;
  24990. this.flexing = false;
  24991. this.output = [];
  24992. this.stack = [];
  24993. }
  24994. Type1CharString.prototype = {
  24995. convert: function Type1CharString_convert(encoded, subrs,
  24996. seacAnalysisEnabled) {
  24997. var count = encoded.length;
  24998. var error = false;
  24999. var wx, sbx, subrNumber;
  25000. for (var i = 0; i < count; i++) {
  25001. var value = encoded[i];
  25002. if (value < 32) {
  25003. if (value === 12) {
  25004. value = (value << 8) + encoded[++i];
  25005. }
  25006. switch (value) {
  25007. case 1: // hstem
  25008. if (!HINTING_ENABLED) {
  25009. this.stack = [];
  25010. break;
  25011. }
  25012. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25013. break;
  25014. case 3: // vstem
  25015. if (!HINTING_ENABLED) {
  25016. this.stack = [];
  25017. break;
  25018. }
  25019. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25020. break;
  25021. case 4: // vmoveto
  25022. if (this.flexing) {
  25023. if (this.stack.length < 1) {
  25024. error = true;
  25025. break;
  25026. }
  25027. // Add the dx for flex and but also swap the values so they are
  25028. // the right order.
  25029. var dy = this.stack.pop();
  25030. this.stack.push(0, dy);
  25031. break;
  25032. }
  25033. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  25034. break;
  25035. case 5: // rlineto
  25036. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  25037. break;
  25038. case 6: // hlineto
  25039. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  25040. break;
  25041. case 7: // vlineto
  25042. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  25043. break;
  25044. case 8: // rrcurveto
  25045. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  25046. break;
  25047. case 9: // closepath
  25048. // closepath is a Type1 command that does not take argument and is
  25049. // useless in Type2 and it can simply be ignored.
  25050. this.stack = [];
  25051. break;
  25052. case 10: // callsubr
  25053. if (this.stack.length < 1) {
  25054. error = true;
  25055. break;
  25056. }
  25057. subrNumber = this.stack.pop();
  25058. error = this.convert(subrs[subrNumber], subrs,
  25059. seacAnalysisEnabled);
  25060. break;
  25061. case 11: // return
  25062. return error;
  25063. case 13: // hsbw
  25064. if (this.stack.length < 2) {
  25065. error = true;
  25066. break;
  25067. }
  25068. // To convert to type2 we have to move the width value to the
  25069. // first part of the charstring and then use hmoveto with lsb.
  25070. wx = this.stack.pop();
  25071. sbx = this.stack.pop();
  25072. this.lsb = sbx;
  25073. this.width = wx;
  25074. this.stack.push(wx, sbx);
  25075. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  25076. break;
  25077. case 14: // endchar
  25078. this.output.push(COMMAND_MAP.endchar[0]);
  25079. break;
  25080. case 21: // rmoveto
  25081. if (this.flexing) {
  25082. break;
  25083. }
  25084. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  25085. break;
  25086. case 22: // hmoveto
  25087. if (this.flexing) {
  25088. // Add the dy for flex.
  25089. this.stack.push(0);
  25090. break;
  25091. }
  25092. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  25093. break;
  25094. case 30: // vhcurveto
  25095. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  25096. break;
  25097. case 31: // hvcurveto
  25098. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  25099. break;
  25100. case (12 << 8) + 0: // dotsection
  25101. // dotsection is a Type1 command to specify some hinting feature
  25102. // for dots that do not take a parameter and it can safely be
  25103. // ignored for Type2.
  25104. this.stack = [];
  25105. break;
  25106. case (12 << 8) + 1: // vstem3
  25107. if (!HINTING_ENABLED) {
  25108. this.stack = [];
  25109. break;
  25110. }
  25111. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  25112. // multiple parameters, so instead of returning [vh]stem3 take a
  25113. // shortcut and return [vhstem] instead.
  25114. error = this.executeCommand(2, COMMAND_MAP.vstem);
  25115. break;
  25116. case (12 << 8) + 2: // hstem3
  25117. if (!HINTING_ENABLED) {
  25118. this.stack = [];
  25119. break;
  25120. }
  25121. // See vstem3.
  25122. error = this.executeCommand(2, COMMAND_MAP.hstem);
  25123. break;
  25124. case (12 << 8) + 6: // seac
  25125. // seac is like type 2's special endchar but it doesn't use the
  25126. // first argument asb, so remove it.
  25127. if (seacAnalysisEnabled) {
  25128. this.seac = this.stack.splice(-4, 4);
  25129. error = this.executeCommand(0, COMMAND_MAP.endchar);
  25130. } else {
  25131. error = this.executeCommand(4, COMMAND_MAP.endchar);
  25132. }
  25133. break;
  25134. case (12 << 8) + 7: // sbw
  25135. if (this.stack.length < 4) {
  25136. error = true;
  25137. break;
  25138. }
  25139. // To convert to type2 we have to move the width value to the
  25140. // first part of the charstring and then use rmoveto with
  25141. // (dx, dy). The height argument will not be used for vmtx and
  25142. // vhea tables reconstruction -- ignoring it.
  25143. var wy = this.stack.pop();
  25144. wx = this.stack.pop();
  25145. var sby = this.stack.pop();
  25146. sbx = this.stack.pop();
  25147. this.lsb = sbx;
  25148. this.width = wx;
  25149. this.stack.push(wx, sbx, sby);
  25150. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  25151. break;
  25152. case (12 << 8) + 12: // div
  25153. if (this.stack.length < 2) {
  25154. error = true;
  25155. break;
  25156. }
  25157. var num2 = this.stack.pop();
  25158. var num1 = this.stack.pop();
  25159. this.stack.push(num1 / num2);
  25160. break;
  25161. case (12 << 8) + 16: // callothersubr
  25162. if (this.stack.length < 2) {
  25163. error = true;
  25164. break;
  25165. }
  25166. subrNumber = this.stack.pop();
  25167. var numArgs = this.stack.pop();
  25168. if (subrNumber === 0 && numArgs === 3) {
  25169. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  25170. this.stack.push(
  25171. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  25172. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  25173. flexArgs[4], // bcp2x
  25174. flexArgs[5], // bcp2y
  25175. flexArgs[6], // p2x
  25176. flexArgs[7], // p2y
  25177. flexArgs[8], // bcp3x
  25178. flexArgs[9], // bcp3y
  25179. flexArgs[10], // bcp4x
  25180. flexArgs[11], // bcp4y
  25181. flexArgs[12], // p3x
  25182. flexArgs[13], // p3y
  25183. flexArgs[14] // flexDepth
  25184. // 15 = finalx unused by flex
  25185. // 16 = finaly unused by flex
  25186. );
  25187. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  25188. this.flexing = false;
  25189. this.stack.push(flexArgs[15], flexArgs[16]);
  25190. } else if (subrNumber === 1 && numArgs === 0) {
  25191. this.flexing = true;
  25192. }
  25193. break;
  25194. case (12 << 8) + 17: // pop
  25195. // Ignore this since it is only used with othersubr.
  25196. break;
  25197. case (12 << 8) + 33: // setcurrentpoint
  25198. // Ignore for now.
  25199. this.stack = [];
  25200. break;
  25201. default:
  25202. warn('Unknown type 1 charstring command of "' + value + '"');
  25203. break;
  25204. }
  25205. if (error) {
  25206. break;
  25207. }
  25208. continue;
  25209. } else if (value <= 246) {
  25210. value = value - 139;
  25211. } else if (value <= 250) {
  25212. value = ((value - 247) * 256) + encoded[++i] + 108;
  25213. } else if (value <= 254) {
  25214. value = -((value - 251) * 256) - encoded[++i] - 108;
  25215. } else {
  25216. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  25217. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  25218. }
  25219. this.stack.push(value);
  25220. }
  25221. return error;
  25222. },
  25223. executeCommand: function(howManyArgs, command, keepStack) {
  25224. var stackLength = this.stack.length;
  25225. if (howManyArgs > stackLength) {
  25226. return true;
  25227. }
  25228. var start = stackLength - howManyArgs;
  25229. for (var i = start; i < stackLength; i++) {
  25230. var value = this.stack[i];
  25231. if (value === (value | 0)) { // int
  25232. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  25233. } else { // fixed point
  25234. value = (65536 * value) | 0;
  25235. this.output.push(255,
  25236. (value >> 24) & 0xFF,
  25237. (value >> 16) & 0xFF,
  25238. (value >> 8) & 0xFF,
  25239. value & 0xFF);
  25240. }
  25241. }
  25242. this.output.push.apply(this.output, command);
  25243. if (keepStack) {
  25244. this.stack.splice(start, howManyArgs);
  25245. } else {
  25246. this.stack.length = 0;
  25247. }
  25248. return false;
  25249. }
  25250. };
  25251. return Type1CharString;
  25252. })();
  25253. /*
  25254. * Type1Parser encapsulate the needed code for parsing a Type1 font
  25255. * program. Some of its logic depends on the Type2 charstrings
  25256. * structure.
  25257. * Note: this doesn't really parse the font since that would require evaluation
  25258. * of PostScript, but it is possible in most cases to extract what we need
  25259. * without a full parse.
  25260. */
  25261. var Type1Parser = (function Type1ParserClosure() {
  25262. /*
  25263. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  25264. * of Plaintext Bytes. The function took a key as a parameter which can be
  25265. * for decrypting the eexec block of for decoding charStrings.
  25266. */
  25267. var EEXEC_ENCRYPT_KEY = 55665;
  25268. var CHAR_STRS_ENCRYPT_KEY = 4330;
  25269. function isHexDigit(code) {
  25270. return code >= 48 && code <= 57 || // '0'-'9'
  25271. code >= 65 && code <= 70 || // 'A'-'F'
  25272. code >= 97 && code <= 102; // 'a'-'f'
  25273. }
  25274. function decrypt(data, key, discardNumber) {
  25275. if (discardNumber >= data.length) {
  25276. return new Uint8Array(0);
  25277. }
  25278. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  25279. for (i = 0; i < discardNumber; i++) {
  25280. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  25281. }
  25282. var count = data.length - discardNumber;
  25283. var decrypted = new Uint8Array(count);
  25284. for (i = discardNumber, j = 0; j < count; i++, j++) {
  25285. var value = data[i];
  25286. decrypted[j] = value ^ (r >> 8);
  25287. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25288. }
  25289. return decrypted;
  25290. }
  25291. function decryptAscii(data, key, discardNumber) {
  25292. var r = key | 0, c1 = 52845, c2 = 22719;
  25293. var count = data.length, maybeLength = count >>> 1;
  25294. var decrypted = new Uint8Array(maybeLength);
  25295. var i, j;
  25296. for (i = 0, j = 0; i < count; i++) {
  25297. var digit1 = data[i];
  25298. if (!isHexDigit(digit1)) {
  25299. continue;
  25300. }
  25301. i++;
  25302. var digit2;
  25303. while (i < count && !isHexDigit(digit2 = data[i])) {
  25304. i++;
  25305. }
  25306. if (i < count) {
  25307. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  25308. decrypted[j++] = value ^ (r >> 8);
  25309. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  25310. }
  25311. }
  25312. return Array.prototype.slice.call(decrypted, discardNumber, j);
  25313. }
  25314. function isSpecial(c) {
  25315. return c === 0x2F || // '/'
  25316. c === 0x5B || c === 0x5D || // '[', ']'
  25317. c === 0x7B || c === 0x7D || // '{', '}'
  25318. c === 0x28 || c === 0x29; // '(', ')'
  25319. }
  25320. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  25321. if (encrypted) {
  25322. var data = stream.getBytes();
  25323. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  25324. isHexDigit(data[2]) && isHexDigit(data[3]));
  25325. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  25326. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  25327. }
  25328. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  25329. this.stream = stream;
  25330. this.nextChar();
  25331. }
  25332. Type1Parser.prototype = {
  25333. readNumberArray: function Type1Parser_readNumberArray() {
  25334. this.getToken(); // read '[' or '{' (arrays can start with either)
  25335. var array = [];
  25336. while (true) {
  25337. var token = this.getToken();
  25338. if (token === null || token === ']' || token === '}') {
  25339. break;
  25340. }
  25341. array.push(parseFloat(token || 0));
  25342. }
  25343. return array;
  25344. },
  25345. readNumber: function Type1Parser_readNumber() {
  25346. var token = this.getToken();
  25347. return parseFloat(token || 0);
  25348. },
  25349. readInt: function Type1Parser_readInt() {
  25350. // Use '| 0' to prevent setting a double into length such as the double
  25351. // does not flow into the loop variable.
  25352. var token = this.getToken();
  25353. return parseInt(token || 0, 10) | 0;
  25354. },
  25355. readBoolean: function Type1Parser_readBoolean() {
  25356. var token = this.getToken();
  25357. // Use 1 and 0 since that's what type2 charstrings use.
  25358. return token === 'true' ? 1 : 0;
  25359. },
  25360. nextChar : function Type1_nextChar() {
  25361. return (this.currentChar = this.stream.getByte());
  25362. },
  25363. getToken: function Type1Parser_getToken() {
  25364. // Eat whitespace and comments.
  25365. var comment = false;
  25366. var ch = this.currentChar;
  25367. while (true) {
  25368. if (ch === -1) {
  25369. return null;
  25370. }
  25371. if (comment) {
  25372. if (ch === 0x0A || ch === 0x0D) {
  25373. comment = false;
  25374. }
  25375. } else if (ch === 0x25) { // '%'
  25376. comment = true;
  25377. } else if (!isSpace(ch)) {
  25378. break;
  25379. }
  25380. ch = this.nextChar();
  25381. }
  25382. if (isSpecial(ch)) {
  25383. this.nextChar();
  25384. return String.fromCharCode(ch);
  25385. }
  25386. var token = '';
  25387. do {
  25388. token += String.fromCharCode(ch);
  25389. ch = this.nextChar();
  25390. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  25391. return token;
  25392. },
  25393. /*
  25394. * Returns an object containing a Subrs array and a CharStrings
  25395. * array extracted from and eexec encrypted block of data
  25396. */
  25397. extractFontProgram: function Type1Parser_extractFontProgram() {
  25398. var stream = this.stream;
  25399. var subrs = [], charstrings = [];
  25400. var privateData = Object.create(null);
  25401. privateData['lenIV'] = 4;
  25402. var program = {
  25403. subrs: [],
  25404. charstrings: [],
  25405. properties: {
  25406. 'privateData': privateData
  25407. }
  25408. };
  25409. var token, length, data, lenIV, encoded;
  25410. while ((token = this.getToken()) !== null) {
  25411. if (token !== '/') {
  25412. continue;
  25413. }
  25414. token = this.getToken();
  25415. switch (token) {
  25416. case 'CharStrings':
  25417. // The number immediately following CharStrings must be greater or
  25418. // equal to the number of CharStrings.
  25419. this.getToken();
  25420. this.getToken(); // read in 'dict'
  25421. this.getToken(); // read in 'dup'
  25422. this.getToken(); // read in 'begin'
  25423. while(true) {
  25424. token = this.getToken();
  25425. if (token === null || token === 'end') {
  25426. break;
  25427. }
  25428. if (token !== '/') {
  25429. continue;
  25430. }
  25431. var glyph = this.getToken();
  25432. length = this.readInt();
  25433. this.getToken(); // read in 'RD' or '-|'
  25434. data = stream.makeSubStream(stream.pos, length);
  25435. lenIV = program.properties.privateData['lenIV'];
  25436. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25437. // Skip past the required space and binary data.
  25438. stream.skip(length);
  25439. this.nextChar();
  25440. token = this.getToken(); // read in 'ND' or '|-'
  25441. if (token === 'noaccess') {
  25442. this.getToken(); // read in 'def'
  25443. }
  25444. charstrings.push({
  25445. glyph: glyph,
  25446. encoded: encoded
  25447. });
  25448. }
  25449. break;
  25450. case 'Subrs':
  25451. var num = this.readInt();
  25452. this.getToken(); // read in 'array'
  25453. while ((token = this.getToken()) === 'dup') {
  25454. var index = this.readInt();
  25455. length = this.readInt();
  25456. this.getToken(); // read in 'RD' or '-|'
  25457. data = stream.makeSubStream(stream.pos, length);
  25458. lenIV = program.properties.privateData['lenIV'];
  25459. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  25460. // Skip past the required space and binary data.
  25461. stream.skip(length);
  25462. this.nextChar();
  25463. token = this.getToken(); // read in 'NP' or '|'
  25464. if (token === 'noaccess') {
  25465. this.getToken(); // read in 'put'
  25466. }
  25467. subrs[index] = encoded;
  25468. }
  25469. break;
  25470. case 'BlueValues':
  25471. case 'OtherBlues':
  25472. case 'FamilyBlues':
  25473. case 'FamilyOtherBlues':
  25474. var blueArray = this.readNumberArray();
  25475. // *Blue* values may contain invalid data: disables reading of
  25476. // those values when hinting is disabled.
  25477. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  25478. HINTING_ENABLED) {
  25479. program.properties.privateData[token] = blueArray;
  25480. }
  25481. break;
  25482. case 'StemSnapH':
  25483. case 'StemSnapV':
  25484. program.properties.privateData[token] = this.readNumberArray();
  25485. break;
  25486. case 'StdHW':
  25487. case 'StdVW':
  25488. program.properties.privateData[token] =
  25489. this.readNumberArray()[0];
  25490. break;
  25491. case 'BlueShift':
  25492. case 'lenIV':
  25493. case 'BlueFuzz':
  25494. case 'BlueScale':
  25495. case 'LanguageGroup':
  25496. case 'ExpansionFactor':
  25497. program.properties.privateData[token] = this.readNumber();
  25498. break;
  25499. case 'ForceBold':
  25500. program.properties.privateData[token] = this.readBoolean();
  25501. break;
  25502. }
  25503. }
  25504. for (var i = 0; i < charstrings.length; i++) {
  25505. glyph = charstrings[i].glyph;
  25506. encoded = charstrings[i].encoded;
  25507. var charString = new Type1CharString();
  25508. var error = charString.convert(encoded, subrs,
  25509. this.seacAnalysisEnabled);
  25510. var output = charString.output;
  25511. if (error) {
  25512. // It seems when FreeType encounters an error while evaluating a glyph
  25513. // that it completely ignores the glyph so we'll mimic that behaviour
  25514. // here and put an endchar to make the validator happy.
  25515. output = [14];
  25516. }
  25517. program.charstrings.push({
  25518. glyphName: glyph,
  25519. charstring: output,
  25520. width: charString.width,
  25521. lsb: charString.lsb,
  25522. seac: charString.seac
  25523. });
  25524. }
  25525. return program;
  25526. },
  25527. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  25528. var token;
  25529. while ((token = this.getToken()) !== null) {
  25530. if (token !== '/') {
  25531. continue;
  25532. }
  25533. token = this.getToken();
  25534. switch (token) {
  25535. case 'FontMatrix':
  25536. var matrix = this.readNumberArray();
  25537. properties.fontMatrix = matrix;
  25538. break;
  25539. case 'Encoding':
  25540. var encodingArg = this.getToken();
  25541. var encoding;
  25542. if (!/^\d+$/.test(encodingArg)) {
  25543. // encoding name is specified
  25544. encoding = getEncoding(encodingArg);
  25545. } else {
  25546. encoding = [];
  25547. var size = parseInt(encodingArg, 10) | 0;
  25548. this.getToken(); // read in 'array'
  25549. for (var j = 0; j < size; j++) {
  25550. token = this.getToken();
  25551. // skipping till first dup or def (e.g. ignoring for statement)
  25552. while (token !== 'dup' && token !== 'def') {
  25553. token = this.getToken();
  25554. if (token === null) {
  25555. return; // invalid header
  25556. }
  25557. }
  25558. if (token === 'def') {
  25559. break; // read all array data
  25560. }
  25561. var index = this.readInt();
  25562. this.getToken(); // read in '/'
  25563. var glyph = this.getToken();
  25564. encoding[index] = glyph;
  25565. this.getToken(); // read the in 'put'
  25566. }
  25567. }
  25568. properties.builtInEncoding = encoding;
  25569. break;
  25570. case 'FontBBox':
  25571. var fontBBox = this.readNumberArray();
  25572. // adjusting ascent/descent
  25573. properties.ascent = fontBBox[3];
  25574. properties.descent = fontBBox[1];
  25575. properties.ascentScaled = true;
  25576. break;
  25577. }
  25578. }
  25579. }
  25580. };
  25581. return Type1Parser;
  25582. })();
  25583. exports.Type1Parser = Type1Parser;
  25584. }));
  25585. (function (root, factory) {
  25586. {
  25587. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  25588. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  25589. }
  25590. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  25591. var Util = sharedUtil.Util;
  25592. var assert = sharedUtil.assert;
  25593. var warn = sharedUtil.warn;
  25594. var error = sharedUtil.error;
  25595. var isInt = sharedUtil.isInt;
  25596. var isString = sharedUtil.isString;
  25597. var MissingDataException = sharedUtil.MissingDataException;
  25598. var isName = corePrimitives.isName;
  25599. var isCmd = corePrimitives.isCmd;
  25600. var isStream = corePrimitives.isStream;
  25601. var StringStream = coreStream.StringStream;
  25602. var Lexer = coreParser.Lexer;
  25603. var isEOF = coreParser.isEOF;
  25604. var BUILT_IN_CMAPS = [
  25605. // << Start unicode maps.
  25606. 'Adobe-GB1-UCS2',
  25607. 'Adobe-CNS1-UCS2',
  25608. 'Adobe-Japan1-UCS2',
  25609. 'Adobe-Korea1-UCS2',
  25610. // >> End unicode maps.
  25611. '78-EUC-H',
  25612. '78-EUC-V',
  25613. '78-H',
  25614. '78-RKSJ-H',
  25615. '78-RKSJ-V',
  25616. '78-V',
  25617. '78ms-RKSJ-H',
  25618. '78ms-RKSJ-V',
  25619. '83pv-RKSJ-H',
  25620. '90ms-RKSJ-H',
  25621. '90ms-RKSJ-V',
  25622. '90msp-RKSJ-H',
  25623. '90msp-RKSJ-V',
  25624. '90pv-RKSJ-H',
  25625. '90pv-RKSJ-V',
  25626. 'Add-H',
  25627. 'Add-RKSJ-H',
  25628. 'Add-RKSJ-V',
  25629. 'Add-V',
  25630. 'Adobe-CNS1-0',
  25631. 'Adobe-CNS1-1',
  25632. 'Adobe-CNS1-2',
  25633. 'Adobe-CNS1-3',
  25634. 'Adobe-CNS1-4',
  25635. 'Adobe-CNS1-5',
  25636. 'Adobe-CNS1-6',
  25637. 'Adobe-GB1-0',
  25638. 'Adobe-GB1-1',
  25639. 'Adobe-GB1-2',
  25640. 'Adobe-GB1-3',
  25641. 'Adobe-GB1-4',
  25642. 'Adobe-GB1-5',
  25643. 'Adobe-Japan1-0',
  25644. 'Adobe-Japan1-1',
  25645. 'Adobe-Japan1-2',
  25646. 'Adobe-Japan1-3',
  25647. 'Adobe-Japan1-4',
  25648. 'Adobe-Japan1-5',
  25649. 'Adobe-Japan1-6',
  25650. 'Adobe-Korea1-0',
  25651. 'Adobe-Korea1-1',
  25652. 'Adobe-Korea1-2',
  25653. 'B5-H',
  25654. 'B5-V',
  25655. 'B5pc-H',
  25656. 'B5pc-V',
  25657. 'CNS-EUC-H',
  25658. 'CNS-EUC-V',
  25659. 'CNS1-H',
  25660. 'CNS1-V',
  25661. 'CNS2-H',
  25662. 'CNS2-V',
  25663. 'ETHK-B5-H',
  25664. 'ETHK-B5-V',
  25665. 'ETen-B5-H',
  25666. 'ETen-B5-V',
  25667. 'ETenms-B5-H',
  25668. 'ETenms-B5-V',
  25669. 'EUC-H',
  25670. 'EUC-V',
  25671. 'Ext-H',
  25672. 'Ext-RKSJ-H',
  25673. 'Ext-RKSJ-V',
  25674. 'Ext-V',
  25675. 'GB-EUC-H',
  25676. 'GB-EUC-V',
  25677. 'GB-H',
  25678. 'GB-V',
  25679. 'GBK-EUC-H',
  25680. 'GBK-EUC-V',
  25681. 'GBK2K-H',
  25682. 'GBK2K-V',
  25683. 'GBKp-EUC-H',
  25684. 'GBKp-EUC-V',
  25685. 'GBT-EUC-H',
  25686. 'GBT-EUC-V',
  25687. 'GBT-H',
  25688. 'GBT-V',
  25689. 'GBTpc-EUC-H',
  25690. 'GBTpc-EUC-V',
  25691. 'GBpc-EUC-H',
  25692. 'GBpc-EUC-V',
  25693. 'H',
  25694. 'HKdla-B5-H',
  25695. 'HKdla-B5-V',
  25696. 'HKdlb-B5-H',
  25697. 'HKdlb-B5-V',
  25698. 'HKgccs-B5-H',
  25699. 'HKgccs-B5-V',
  25700. 'HKm314-B5-H',
  25701. 'HKm314-B5-V',
  25702. 'HKm471-B5-H',
  25703. 'HKm471-B5-V',
  25704. 'HKscs-B5-H',
  25705. 'HKscs-B5-V',
  25706. 'Hankaku',
  25707. 'Hiragana',
  25708. 'KSC-EUC-H',
  25709. 'KSC-EUC-V',
  25710. 'KSC-H',
  25711. 'KSC-Johab-H',
  25712. 'KSC-Johab-V',
  25713. 'KSC-V',
  25714. 'KSCms-UHC-H',
  25715. 'KSCms-UHC-HW-H',
  25716. 'KSCms-UHC-HW-V',
  25717. 'KSCms-UHC-V',
  25718. 'KSCpc-EUC-H',
  25719. 'KSCpc-EUC-V',
  25720. 'Katakana',
  25721. 'NWP-H',
  25722. 'NWP-V',
  25723. 'RKSJ-H',
  25724. 'RKSJ-V',
  25725. 'Roman',
  25726. 'UniCNS-UCS2-H',
  25727. 'UniCNS-UCS2-V',
  25728. 'UniCNS-UTF16-H',
  25729. 'UniCNS-UTF16-V',
  25730. 'UniCNS-UTF32-H',
  25731. 'UniCNS-UTF32-V',
  25732. 'UniCNS-UTF8-H',
  25733. 'UniCNS-UTF8-V',
  25734. 'UniGB-UCS2-H',
  25735. 'UniGB-UCS2-V',
  25736. 'UniGB-UTF16-H',
  25737. 'UniGB-UTF16-V',
  25738. 'UniGB-UTF32-H',
  25739. 'UniGB-UTF32-V',
  25740. 'UniGB-UTF8-H',
  25741. 'UniGB-UTF8-V',
  25742. 'UniJIS-UCS2-H',
  25743. 'UniJIS-UCS2-HW-H',
  25744. 'UniJIS-UCS2-HW-V',
  25745. 'UniJIS-UCS2-V',
  25746. 'UniJIS-UTF16-H',
  25747. 'UniJIS-UTF16-V',
  25748. 'UniJIS-UTF32-H',
  25749. 'UniJIS-UTF32-V',
  25750. 'UniJIS-UTF8-H',
  25751. 'UniJIS-UTF8-V',
  25752. 'UniJIS2004-UTF16-H',
  25753. 'UniJIS2004-UTF16-V',
  25754. 'UniJIS2004-UTF32-H',
  25755. 'UniJIS2004-UTF32-V',
  25756. 'UniJIS2004-UTF8-H',
  25757. 'UniJIS2004-UTF8-V',
  25758. 'UniJISPro-UCS2-HW-V',
  25759. 'UniJISPro-UCS2-V',
  25760. 'UniJISPro-UTF8-V',
  25761. 'UniJISX0213-UTF32-H',
  25762. 'UniJISX0213-UTF32-V',
  25763. 'UniJISX02132004-UTF32-H',
  25764. 'UniJISX02132004-UTF32-V',
  25765. 'UniKS-UCS2-H',
  25766. 'UniKS-UCS2-V',
  25767. 'UniKS-UTF16-H',
  25768. 'UniKS-UTF16-V',
  25769. 'UniKS-UTF32-H',
  25770. 'UniKS-UTF32-V',
  25771. 'UniKS-UTF8-H',
  25772. 'UniKS-UTF8-V',
  25773. 'V',
  25774. 'WP-Symbol'];
  25775. // CMap, not to be confused with TrueType's cmap.
  25776. var CMap = (function CMapClosure() {
  25777. function CMap(builtInCMap) {
  25778. // Codespace ranges are stored as follows:
  25779. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  25780. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  25781. this.codespaceRanges = [[], [], [], []];
  25782. this.numCodespaceRanges = 0;
  25783. // Map entries have one of two forms.
  25784. // - cid chars are 16-bit unsigned integers, stored as integers.
  25785. // - bf chars are variable-length byte sequences, stored as strings, with
  25786. // one byte per character.
  25787. this._map = [];
  25788. this.name = '';
  25789. this.vertical = false;
  25790. this.useCMap = null;
  25791. this.builtInCMap = builtInCMap;
  25792. }
  25793. CMap.prototype = {
  25794. addCodespaceRange: function(n, low, high) {
  25795. this.codespaceRanges[n - 1].push(low, high);
  25796. this.numCodespaceRanges++;
  25797. },
  25798. mapCidRange: function(low, high, dstLow) {
  25799. while (low <= high) {
  25800. this._map[low++] = dstLow++;
  25801. }
  25802. },
  25803. mapBfRange: function(low, high, dstLow) {
  25804. var lastByte = dstLow.length - 1;
  25805. while (low <= high) {
  25806. this._map[low++] = dstLow;
  25807. // Only the last byte has to be incremented.
  25808. dstLow = dstLow.substr(0, lastByte) +
  25809. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  25810. }
  25811. },
  25812. mapBfRangeToArray: function(low, high, array) {
  25813. var i = 0, ii = array.length;
  25814. while (low <= high && i < ii) {
  25815. this._map[low] = array[i++];
  25816. ++low;
  25817. }
  25818. },
  25819. // This is used for both bf and cid chars.
  25820. mapOne: function(src, dst) {
  25821. this._map[src] = dst;
  25822. },
  25823. lookup: function(code) {
  25824. return this._map[code];
  25825. },
  25826. contains: function(code) {
  25827. return this._map[code] !== undefined;
  25828. },
  25829. forEach: function(callback) {
  25830. // Most maps have fewer than 65536 entries, and for those we use normal
  25831. // array iteration. But really sparse tables are possible -- e.g. with
  25832. // indices in the *billions*. For such tables we use for..in, which isn't
  25833. // ideal because it stringifies the indices for all present elements, but
  25834. // it does avoid iterating over every undefined entry.
  25835. var map = this._map;
  25836. var length = map.length;
  25837. var i;
  25838. if (length <= 0x10000) {
  25839. for (i = 0; i < length; i++) {
  25840. if (map[i] !== undefined) {
  25841. callback(i, map[i]);
  25842. }
  25843. }
  25844. } else {
  25845. for (i in this._map) {
  25846. callback(i, map[i]);
  25847. }
  25848. }
  25849. },
  25850. charCodeOf: function(value) {
  25851. return this._map.indexOf(value);
  25852. },
  25853. getMap: function() {
  25854. return this._map;
  25855. },
  25856. readCharCode: function(str, offset, out) {
  25857. var c = 0;
  25858. var codespaceRanges = this.codespaceRanges;
  25859. var codespaceRangesLen = this.codespaceRanges.length;
  25860. // 9.7.6.2 CMap Mapping
  25861. // The code length is at most 4.
  25862. for (var n = 0; n < codespaceRangesLen; n++) {
  25863. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  25864. // Check each codespace range to see if it falls within.
  25865. var codespaceRange = codespaceRanges[n];
  25866. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  25867. var low = codespaceRange[k++];
  25868. var high = codespaceRange[k++];
  25869. if (c >= low && c <= high) {
  25870. out.charcode = c;
  25871. out.length = n + 1;
  25872. return;
  25873. }
  25874. }
  25875. }
  25876. out.charcode = 0;
  25877. out.length = 1;
  25878. },
  25879. get length() {
  25880. return this._map.length;
  25881. },
  25882. get isIdentityCMap() {
  25883. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  25884. return false;
  25885. }
  25886. if (this._map.length !== 0x10000) {
  25887. return false;
  25888. }
  25889. for (var i = 0; i < 0x10000; i++) {
  25890. if (this._map[i] !== i) {
  25891. return false;
  25892. }
  25893. }
  25894. return true;
  25895. }
  25896. };
  25897. return CMap;
  25898. })();
  25899. // A special case of CMap, where the _map array implicitly has a length of
  25900. // 65536 and each element is equal to its index.
  25901. var IdentityCMap = (function IdentityCMapClosure() {
  25902. function IdentityCMap(vertical, n) {
  25903. CMap.call(this);
  25904. this.vertical = vertical;
  25905. this.addCodespaceRange(n, 0, 0xffff);
  25906. }
  25907. Util.inherit(IdentityCMap, CMap, {});
  25908. IdentityCMap.prototype = {
  25909. addCodespaceRange: CMap.prototype.addCodespaceRange,
  25910. mapCidRange: function(low, high, dstLow) {
  25911. error('should not call mapCidRange');
  25912. },
  25913. mapBfRange: function(low, high, dstLow) {
  25914. error('should not call mapBfRange');
  25915. },
  25916. mapBfRangeToArray: function(low, high, array) {
  25917. error('should not call mapBfRangeToArray');
  25918. },
  25919. mapOne: function(src, dst) {
  25920. error('should not call mapCidOne');
  25921. },
  25922. lookup: function(code) {
  25923. return (isInt(code) && code <= 0xffff) ? code : undefined;
  25924. },
  25925. contains: function(code) {
  25926. return isInt(code) && code <= 0xffff;
  25927. },
  25928. forEach: function(callback) {
  25929. for (var i = 0; i <= 0xffff; i++) {
  25930. callback(i, i);
  25931. }
  25932. },
  25933. charCodeOf: function(value) {
  25934. return (isInt(value) && value <= 0xffff) ? value : -1;
  25935. },
  25936. getMap: function() {
  25937. // Sometimes identity maps must be instantiated, but it's rare.
  25938. var map = new Array(0x10000);
  25939. for (var i = 0; i <= 0xffff; i++) {
  25940. map[i] = i;
  25941. }
  25942. return map;
  25943. },
  25944. readCharCode: CMap.prototype.readCharCode,
  25945. get length() {
  25946. return 0x10000;
  25947. },
  25948. get isIdentityCMap() {
  25949. error('should not access .isIdentityCMap');
  25950. }
  25951. };
  25952. return IdentityCMap;
  25953. })();
  25954. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  25955. function fetchBinaryData(url) {
  25956. return new Promise(function (resolve, reject) {
  25957. var request = new XMLHttpRequest();
  25958. request.open('GET', url, true);
  25959. request.responseType = 'arraybuffer';
  25960. request.onreadystatechange = function () {
  25961. if (request.readyState === XMLHttpRequest.DONE) {
  25962. if (!request.response || request.status !== 200 &&
  25963. request.status !== 0) {
  25964. reject(new Error('Unable to get binary cMap at: ' + url));
  25965. } else {
  25966. resolve(new Uint8Array(request.response));
  25967. }
  25968. }
  25969. };
  25970. request.send(null);
  25971. });
  25972. }
  25973. function hexToInt(a, size) {
  25974. var n = 0;
  25975. for (var i = 0; i <= size; i++) {
  25976. n = (n << 8) | a[i];
  25977. }
  25978. return n >>> 0;
  25979. }
  25980. function hexToStr(a, size) {
  25981. // This code is hot. Special-case some common values to avoid creating an
  25982. // object with subarray().
  25983. if (size === 1) {
  25984. return String.fromCharCode(a[0], a[1]);
  25985. }
  25986. if (size === 3) {
  25987. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  25988. }
  25989. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  25990. }
  25991. function addHex(a, b, size) {
  25992. var c = 0;
  25993. for (var i = size; i >= 0; i--) {
  25994. c += a[i] + b[i];
  25995. a[i] = c & 255;
  25996. c >>= 8;
  25997. }
  25998. }
  25999. function incHex(a, size) {
  26000. var c = 1;
  26001. for (var i = size; i >= 0 && c > 0; i--) {
  26002. c += a[i];
  26003. a[i] = c & 255;
  26004. c >>= 8;
  26005. }
  26006. }
  26007. var MAX_NUM_SIZE = 16;
  26008. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  26009. function BinaryCMapStream(data) {
  26010. this.buffer = data;
  26011. this.pos = 0;
  26012. this.end = data.length;
  26013. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  26014. }
  26015. BinaryCMapStream.prototype = {
  26016. readByte: function () {
  26017. if (this.pos >= this.end) {
  26018. return -1;
  26019. }
  26020. return this.buffer[this.pos++];
  26021. },
  26022. readNumber: function () {
  26023. var n = 0;
  26024. var last;
  26025. do {
  26026. var b = this.readByte();
  26027. if (b < 0) {
  26028. error('unexpected EOF in bcmap');
  26029. }
  26030. last = !(b & 0x80);
  26031. n = (n << 7) | (b & 0x7F);
  26032. } while (!last);
  26033. return n;
  26034. },
  26035. readSigned: function () {
  26036. var n = this.readNumber();
  26037. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  26038. },
  26039. readHex: function (num, size) {
  26040. num.set(this.buffer.subarray(this.pos,
  26041. this.pos + size + 1));
  26042. this.pos += size + 1;
  26043. },
  26044. readHexNumber: function (num, size) {
  26045. var last;
  26046. var stack = this.tmpBuf, sp = 0;
  26047. do {
  26048. var b = this.readByte();
  26049. if (b < 0) {
  26050. error('unexpected EOF in bcmap');
  26051. }
  26052. last = !(b & 0x80);
  26053. stack[sp++] = b & 0x7F;
  26054. } while (!last);
  26055. var i = size, buffer = 0, bufferSize = 0;
  26056. while (i >= 0) {
  26057. while (bufferSize < 8 && stack.length > 0) {
  26058. buffer = (stack[--sp] << bufferSize) | buffer;
  26059. bufferSize += 7;
  26060. }
  26061. num[i] = buffer & 255;
  26062. i--;
  26063. buffer >>= 8;
  26064. bufferSize -= 8;
  26065. }
  26066. },
  26067. readHexSigned: function (num, size) {
  26068. this.readHexNumber(num, size);
  26069. var sign = num[size] & 1 ? 255 : 0;
  26070. var c = 0;
  26071. for (var i = 0; i <= size; i++) {
  26072. c = ((c & 1) << 8) | num[i];
  26073. num[i] = (c >> 1) ^ sign;
  26074. }
  26075. },
  26076. readString: function () {
  26077. var len = this.readNumber();
  26078. var s = '';
  26079. for (var i = 0; i < len; i++) {
  26080. s += String.fromCharCode(this.readNumber());
  26081. }
  26082. return s;
  26083. }
  26084. };
  26085. function processBinaryCMap(url, cMap, extend) {
  26086. return fetchBinaryData(url).then(function (data) {
  26087. var stream = new BinaryCMapStream(data);
  26088. var header = stream.readByte();
  26089. cMap.vertical = !!(header & 1);
  26090. var useCMap = null;
  26091. var start = new Uint8Array(MAX_NUM_SIZE);
  26092. var end = new Uint8Array(MAX_NUM_SIZE);
  26093. var char = new Uint8Array(MAX_NUM_SIZE);
  26094. var charCode = new Uint8Array(MAX_NUM_SIZE);
  26095. var tmp = new Uint8Array(MAX_NUM_SIZE);
  26096. var code;
  26097. var b;
  26098. while ((b = stream.readByte()) >= 0) {
  26099. var type = b >> 5;
  26100. if (type === 7) { // metadata, e.g. comment or usecmap
  26101. switch (b & 0x1F) {
  26102. case 0:
  26103. stream.readString(); // skipping comment
  26104. break;
  26105. case 1:
  26106. useCMap = stream.readString();
  26107. break;
  26108. }
  26109. continue;
  26110. }
  26111. var sequence = !!(b & 0x10);
  26112. var dataSize = b & 15;
  26113. assert(dataSize + 1 <= MAX_NUM_SIZE);
  26114. var ucs2DataSize = 1;
  26115. var subitemsCount = stream.readNumber();
  26116. var i;
  26117. switch (type) {
  26118. case 0: // codespacerange
  26119. stream.readHex(start, dataSize);
  26120. stream.readHexNumber(end, dataSize);
  26121. addHex(end, start, dataSize);
  26122. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26123. hexToInt(end, dataSize));
  26124. for (i = 1; i < subitemsCount; i++) {
  26125. incHex(end, dataSize);
  26126. stream.readHexNumber(start, dataSize);
  26127. addHex(start, end, dataSize);
  26128. stream.readHexNumber(end, dataSize);
  26129. addHex(end, start, dataSize);
  26130. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  26131. hexToInt(end, dataSize));
  26132. }
  26133. break;
  26134. case 1: // notdefrange
  26135. stream.readHex(start, dataSize);
  26136. stream.readHexNumber(end, dataSize);
  26137. addHex(end, start, dataSize);
  26138. code = stream.readNumber();
  26139. // undefined range, skipping
  26140. for (i = 1; i < subitemsCount; i++) {
  26141. incHex(end, dataSize);
  26142. stream.readHexNumber(start, dataSize);
  26143. addHex(start, end, dataSize);
  26144. stream.readHexNumber(end, dataSize);
  26145. addHex(end, start, dataSize);
  26146. code = stream.readNumber();
  26147. // nop
  26148. }
  26149. break;
  26150. case 2: // cidchar
  26151. stream.readHex(char, dataSize);
  26152. code = stream.readNumber();
  26153. cMap.mapOne(hexToInt(char, dataSize), code);
  26154. for (i = 1; i < subitemsCount; i++) {
  26155. incHex(char, dataSize);
  26156. if (!sequence) {
  26157. stream.readHexNumber(tmp, dataSize);
  26158. addHex(char, tmp, dataSize);
  26159. }
  26160. code = stream.readSigned() + (code + 1);
  26161. cMap.mapOne(hexToInt(char, dataSize), code);
  26162. }
  26163. break;
  26164. case 3: // cidrange
  26165. stream.readHex(start, dataSize);
  26166. stream.readHexNumber(end, dataSize);
  26167. addHex(end, start, dataSize);
  26168. code = stream.readNumber();
  26169. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  26170. code);
  26171. for (i = 1; i < subitemsCount; i++) {
  26172. incHex(end, dataSize);
  26173. if (!sequence) {
  26174. stream.readHexNumber(start, dataSize);
  26175. addHex(start, end, dataSize);
  26176. } else {
  26177. start.set(end);
  26178. }
  26179. stream.readHexNumber(end, dataSize);
  26180. addHex(end, start, dataSize);
  26181. code = stream.readNumber();
  26182. cMap.mapCidRange(hexToInt(start, dataSize),
  26183. hexToInt(end, dataSize), code);
  26184. }
  26185. break;
  26186. case 4: // bfchar
  26187. stream.readHex(char, ucs2DataSize);
  26188. stream.readHex(charCode, dataSize);
  26189. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26190. hexToStr(charCode, dataSize));
  26191. for (i = 1; i < subitemsCount; i++) {
  26192. incHex(char, ucs2DataSize);
  26193. if (!sequence) {
  26194. stream.readHexNumber(tmp, ucs2DataSize);
  26195. addHex(char, tmp, ucs2DataSize);
  26196. }
  26197. incHex(charCode, dataSize);
  26198. stream.readHexSigned(tmp, dataSize);
  26199. addHex(charCode, tmp, dataSize);
  26200. cMap.mapOne(hexToInt(char, ucs2DataSize),
  26201. hexToStr(charCode, dataSize));
  26202. }
  26203. break;
  26204. case 5: // bfrange
  26205. stream.readHex(start, ucs2DataSize);
  26206. stream.readHexNumber(end, ucs2DataSize);
  26207. addHex(end, start, ucs2DataSize);
  26208. stream.readHex(charCode, dataSize);
  26209. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26210. hexToInt(end, ucs2DataSize),
  26211. hexToStr(charCode, dataSize));
  26212. for (i = 1; i < subitemsCount; i++) {
  26213. incHex(end, ucs2DataSize);
  26214. if (!sequence) {
  26215. stream.readHexNumber(start, ucs2DataSize);
  26216. addHex(start, end, ucs2DataSize);
  26217. } else {
  26218. start.set(end);
  26219. }
  26220. stream.readHexNumber(end, ucs2DataSize);
  26221. addHex(end, start, ucs2DataSize);
  26222. stream.readHex(charCode, dataSize);
  26223. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  26224. hexToInt(end, ucs2DataSize),
  26225. hexToStr(charCode, dataSize));
  26226. }
  26227. break;
  26228. default:
  26229. error('Unknown type: ' + type);
  26230. break;
  26231. }
  26232. }
  26233. if (useCMap) {
  26234. return extend(useCMap);
  26235. }
  26236. return cMap;
  26237. });
  26238. }
  26239. function BinaryCMapReader() {}
  26240. BinaryCMapReader.prototype = {
  26241. read: processBinaryCMap
  26242. };
  26243. return BinaryCMapReader;
  26244. })();
  26245. var CMapFactory = (function CMapFactoryClosure() {
  26246. function strToInt(str) {
  26247. var a = 0;
  26248. for (var i = 0; i < str.length; i++) {
  26249. a = (a << 8) | str.charCodeAt(i);
  26250. }
  26251. return a >>> 0;
  26252. }
  26253. function expectString(obj) {
  26254. if (!isString(obj)) {
  26255. error('Malformed CMap: expected string.');
  26256. }
  26257. }
  26258. function expectInt(obj) {
  26259. if (!isInt(obj)) {
  26260. error('Malformed CMap: expected int.');
  26261. }
  26262. }
  26263. function parseBfChar(cMap, lexer) {
  26264. while (true) {
  26265. var obj = lexer.getObj();
  26266. if (isEOF(obj)) {
  26267. break;
  26268. }
  26269. if (isCmd(obj, 'endbfchar')) {
  26270. return;
  26271. }
  26272. expectString(obj);
  26273. var src = strToInt(obj);
  26274. obj = lexer.getObj();
  26275. // TODO are /dstName used?
  26276. expectString(obj);
  26277. var dst = obj;
  26278. cMap.mapOne(src, dst);
  26279. }
  26280. }
  26281. function parseBfRange(cMap, lexer) {
  26282. while (true) {
  26283. var obj = lexer.getObj();
  26284. if (isEOF(obj)) {
  26285. break;
  26286. }
  26287. if (isCmd(obj, 'endbfrange')) {
  26288. return;
  26289. }
  26290. expectString(obj);
  26291. var low = strToInt(obj);
  26292. obj = lexer.getObj();
  26293. expectString(obj);
  26294. var high = strToInt(obj);
  26295. obj = lexer.getObj();
  26296. if (isInt(obj) || isString(obj)) {
  26297. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  26298. cMap.mapBfRange(low, high, dstLow);
  26299. } else if (isCmd(obj, '[')) {
  26300. obj = lexer.getObj();
  26301. var array = [];
  26302. while (!isCmd(obj, ']') && !isEOF(obj)) {
  26303. array.push(obj);
  26304. obj = lexer.getObj();
  26305. }
  26306. cMap.mapBfRangeToArray(low, high, array);
  26307. } else {
  26308. break;
  26309. }
  26310. }
  26311. error('Invalid bf range.');
  26312. }
  26313. function parseCidChar(cMap, lexer) {
  26314. while (true) {
  26315. var obj = lexer.getObj();
  26316. if (isEOF(obj)) {
  26317. break;
  26318. }
  26319. if (isCmd(obj, 'endcidchar')) {
  26320. return;
  26321. }
  26322. expectString(obj);
  26323. var src = strToInt(obj);
  26324. obj = lexer.getObj();
  26325. expectInt(obj);
  26326. var dst = obj;
  26327. cMap.mapOne(src, dst);
  26328. }
  26329. }
  26330. function parseCidRange(cMap, lexer) {
  26331. while (true) {
  26332. var obj = lexer.getObj();
  26333. if (isEOF(obj)) {
  26334. break;
  26335. }
  26336. if (isCmd(obj, 'endcidrange')) {
  26337. return;
  26338. }
  26339. expectString(obj);
  26340. var low = strToInt(obj);
  26341. obj = lexer.getObj();
  26342. expectString(obj);
  26343. var high = strToInt(obj);
  26344. obj = lexer.getObj();
  26345. expectInt(obj);
  26346. var dstLow = obj;
  26347. cMap.mapCidRange(low, high, dstLow);
  26348. }
  26349. }
  26350. function parseCodespaceRange(cMap, lexer) {
  26351. while (true) {
  26352. var obj = lexer.getObj();
  26353. if (isEOF(obj)) {
  26354. break;
  26355. }
  26356. if (isCmd(obj, 'endcodespacerange')) {
  26357. return;
  26358. }
  26359. if (!isString(obj)) {
  26360. break;
  26361. }
  26362. var low = strToInt(obj);
  26363. obj = lexer.getObj();
  26364. if (!isString(obj)) {
  26365. break;
  26366. }
  26367. var high = strToInt(obj);
  26368. cMap.addCodespaceRange(obj.length, low, high);
  26369. }
  26370. error('Invalid codespace range.');
  26371. }
  26372. function parseWMode(cMap, lexer) {
  26373. var obj = lexer.getObj();
  26374. if (isInt(obj)) {
  26375. cMap.vertical = !!obj;
  26376. }
  26377. }
  26378. function parseCMapName(cMap, lexer) {
  26379. var obj = lexer.getObj();
  26380. if (isName(obj) && isString(obj.name)) {
  26381. cMap.name = obj.name;
  26382. }
  26383. }
  26384. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  26385. var previous;
  26386. var embededUseCMap;
  26387. objLoop: while (true) {
  26388. try {
  26389. var obj = lexer.getObj();
  26390. if (isEOF(obj)) {
  26391. break;
  26392. } else if (isName(obj)) {
  26393. if (obj.name === 'WMode') {
  26394. parseWMode(cMap, lexer);
  26395. } else if (obj.name === 'CMapName') {
  26396. parseCMapName(cMap, lexer);
  26397. }
  26398. previous = obj;
  26399. } else if (isCmd(obj)) {
  26400. switch (obj.cmd) {
  26401. case 'endcmap':
  26402. break objLoop;
  26403. case 'usecmap':
  26404. if (isName(previous)) {
  26405. embededUseCMap = previous.name;
  26406. }
  26407. break;
  26408. case 'begincodespacerange':
  26409. parseCodespaceRange(cMap, lexer);
  26410. break;
  26411. case 'beginbfchar':
  26412. parseBfChar(cMap, lexer);
  26413. break;
  26414. case 'begincidchar':
  26415. parseCidChar(cMap, lexer);
  26416. break;
  26417. case 'beginbfrange':
  26418. parseBfRange(cMap, lexer);
  26419. break;
  26420. case 'begincidrange':
  26421. parseCidRange(cMap, lexer);
  26422. break;
  26423. }
  26424. }
  26425. } catch (ex) {
  26426. if (ex instanceof MissingDataException) {
  26427. throw ex;
  26428. }
  26429. warn('Invalid cMap data: ' + ex);
  26430. continue;
  26431. }
  26432. }
  26433. if (!useCMap && embededUseCMap) {
  26434. // Load the usecmap definition from the file only if there wasn't one
  26435. // specified.
  26436. useCMap = embededUseCMap;
  26437. }
  26438. if (useCMap) {
  26439. return extendCMap(cMap, builtInCMapParams, useCMap);
  26440. }
  26441. return Promise.resolve(cMap);
  26442. }
  26443. function extendCMap(cMap, builtInCMapParams, useCMap) {
  26444. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  26445. function(newCMap) {
  26446. cMap.useCMap = newCMap;
  26447. // If there aren't any code space ranges defined clone all the parent ones
  26448. // into this cMap.
  26449. if (cMap.numCodespaceRanges === 0) {
  26450. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  26451. for (var i = 0; i < useCodespaceRanges.length; i++) {
  26452. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  26453. }
  26454. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  26455. }
  26456. // Merge the map into the current one, making sure not to override
  26457. // any previously defined entries.
  26458. cMap.useCMap.forEach(function(key, value) {
  26459. if (!cMap.contains(key)) {
  26460. cMap.mapOne(key, cMap.useCMap.lookup(key));
  26461. }
  26462. });
  26463. return cMap;
  26464. });
  26465. }
  26466. function parseBinaryCMap(name, builtInCMapParams) {
  26467. var url = builtInCMapParams.url + name + '.bcmap';
  26468. var cMap = new CMap(true);
  26469. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  26470. return extendCMap(cMap, builtInCMapParams, useCMap);
  26471. });
  26472. }
  26473. function createBuiltInCMap(name, builtInCMapParams) {
  26474. if (name === 'Identity-H') {
  26475. return Promise.resolve(new IdentityCMap(false, 2));
  26476. } else if (name === 'Identity-V') {
  26477. return Promise.resolve(new IdentityCMap(true, 2));
  26478. }
  26479. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  26480. return Promise.reject(new Error('Unknown cMap name: ' + name));
  26481. }
  26482. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  26483. if (builtInCMapParams.packed) {
  26484. return parseBinaryCMap(name, builtInCMapParams);
  26485. }
  26486. return new Promise(function (resolve, reject) {
  26487. var url = builtInCMapParams.url + name;
  26488. var request = new XMLHttpRequest();
  26489. request.onreadystatechange = function () {
  26490. if (request.readyState === XMLHttpRequest.DONE) {
  26491. if (request.status === 200 || request.status === 0) {
  26492. var cMap = new CMap(true);
  26493. var lexer = new Lexer(new StringStream(request.responseText));
  26494. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  26495. function (parsedCMap) {
  26496. resolve(parsedCMap);
  26497. });
  26498. } else {
  26499. reject(new Error('Unable to get cMap at: ' + url));
  26500. }
  26501. }
  26502. };
  26503. request.open('GET', url, true);
  26504. request.send(null);
  26505. });
  26506. }
  26507. return {
  26508. create: function (encoding, builtInCMapParams, useCMap) {
  26509. if (isName(encoding)) {
  26510. return createBuiltInCMap(encoding.name, builtInCMapParams);
  26511. } else if (isStream(encoding)) {
  26512. var cMap = new CMap();
  26513. var lexer = new Lexer(encoding);
  26514. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  26515. function (parsedCMap) {
  26516. if (parsedCMap.isIdentityCMap) {
  26517. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  26518. }
  26519. return parsedCMap;
  26520. });
  26521. }
  26522. return Promise.reject(new Error('Encoding required.'));
  26523. }
  26524. };
  26525. })();
  26526. exports.CMap = CMap;
  26527. exports.CMapFactory = CMapFactory;
  26528. exports.IdentityCMap = IdentityCMap;
  26529. }));
  26530. (function (root, factory) {
  26531. {
  26532. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  26533. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList,
  26534. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  26535. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  26536. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  26537. }
  26538. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  26539. coreGlyphList, coreFontRenderer, coreEncodings,
  26540. coreStandardFonts, coreUnicode, coreType1Parser,
  26541. coreCFFParser) {
  26542. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26543. var FontType = sharedUtil.FontType;
  26544. var assert = sharedUtil.assert;
  26545. var bytesToString = sharedUtil.bytesToString;
  26546. var error = sharedUtil.error;
  26547. var info = sharedUtil.info;
  26548. var isArray = sharedUtil.isArray;
  26549. var isInt = sharedUtil.isInt;
  26550. var isNum = sharedUtil.isNum;
  26551. var readUint32 = sharedUtil.readUint32;
  26552. var shadow = sharedUtil.shadow;
  26553. var string32 = sharedUtil.string32;
  26554. var warn = sharedUtil.warn;
  26555. var MissingDataException = sharedUtil.MissingDataException;
  26556. var isSpace = sharedUtil.isSpace;
  26557. var Stream = coreStream.Stream;
  26558. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  26559. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  26560. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  26561. var StandardEncoding = coreEncodings.StandardEncoding;
  26562. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  26563. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  26564. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  26565. var getEncoding = coreEncodings.getEncoding;
  26566. var getStdFontMap = coreStandardFonts.getStdFontMap;
  26567. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  26568. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  26569. var getSupplementalGlyphMapForArialBlack =
  26570. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  26571. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  26572. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  26573. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  26574. var Type1Parser = coreType1Parser.Type1Parser;
  26575. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  26576. var CFFParser = coreCFFParser.CFFParser;
  26577. var CFFCompiler = coreCFFParser.CFFCompiler;
  26578. var CFF = coreCFFParser.CFF;
  26579. var CFFHeader = coreCFFParser.CFFHeader;
  26580. var CFFTopDict = coreCFFParser.CFFTopDict;
  26581. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  26582. var CFFStrings = coreCFFParser.CFFStrings;
  26583. var CFFIndex = coreCFFParser.CFFIndex;
  26584. var CFFCharset = coreCFFParser.CFFCharset;
  26585. // Unicode Private Use Area
  26586. var PRIVATE_USE_OFFSET_START = 0xE000;
  26587. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  26588. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  26589. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  26590. // except for Type 3 fonts
  26591. var PDF_GLYPH_SPACE_UNITS = 1000;
  26592. // Accented charactars are not displayed properly on Windows, using this flag
  26593. // to control analysis of seac charstrings.
  26594. var SEAC_ANALYSIS_ENABLED = false;
  26595. var FontFlags = {
  26596. FixedPitch: 1,
  26597. Serif: 2,
  26598. Symbolic: 4,
  26599. Script: 8,
  26600. Nonsymbolic: 32,
  26601. Italic: 64,
  26602. AllCap: 65536,
  26603. SmallCap: 131072,
  26604. ForceBold: 262144
  26605. };
  26606. var MacStandardGlyphOrdering = [
  26607. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  26608. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  26609. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  26610. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  26611. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  26612. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  26613. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  26614. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  26615. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  26616. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  26617. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  26618. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  26619. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  26620. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  26621. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  26622. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  26623. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  26624. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  26625. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  26626. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  26627. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  26628. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  26629. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  26630. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  26631. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  26632. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  26633. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  26634. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  26635. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  26636. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  26637. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  26638. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  26639. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  26640. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  26641. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  26642. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  26643. function adjustWidths(properties) {
  26644. if (!properties.fontMatrix) {
  26645. return;
  26646. }
  26647. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  26648. return;
  26649. }
  26650. // adjusting width to fontMatrix scale
  26651. var scale = 0.001 / properties.fontMatrix[0];
  26652. var glyphsWidths = properties.widths;
  26653. for (var glyph in glyphsWidths) {
  26654. glyphsWidths[glyph] *= scale;
  26655. }
  26656. properties.defaultWidth *= scale;
  26657. }
  26658. function adjustToUnicode(properties, builtInEncoding) {
  26659. if (properties.hasIncludedToUnicodeMap) {
  26660. return; // The font dictionary has a `ToUnicode` entry.
  26661. }
  26662. if (properties.hasEncoding) {
  26663. return; // The font dictionary has an `Encoding` entry.
  26664. }
  26665. if (builtInEncoding === properties.defaultEncoding) {
  26666. return; // No point in trying to adjust `toUnicode` if the encodings match.
  26667. }
  26668. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  26669. return;
  26670. }
  26671. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  26672. for (var charCode in builtInEncoding) {
  26673. var glyphName = builtInEncoding[charCode];
  26674. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  26675. if (unicode !== -1) {
  26676. toUnicode[charCode] = String.fromCharCode(unicode);
  26677. }
  26678. }
  26679. properties.toUnicode.amend(toUnicode);
  26680. }
  26681. function getFontType(type, subtype) {
  26682. switch (type) {
  26683. case 'Type1':
  26684. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  26685. case 'CIDFontType0':
  26686. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  26687. FontType.CIDFONTTYPE0;
  26688. case 'OpenType':
  26689. return FontType.OPENTYPE;
  26690. case 'TrueType':
  26691. return FontType.TRUETYPE;
  26692. case 'CIDFontType2':
  26693. return FontType.CIDFONTTYPE2;
  26694. case 'MMType1':
  26695. return FontType.MMTYPE1;
  26696. case 'Type0':
  26697. return FontType.TYPE0;
  26698. default:
  26699. return FontType.UNKNOWN;
  26700. }
  26701. }
  26702. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  26703. // in a 'uniXXXX' format -- attempting to recover proper ones.
  26704. function recoverGlyphName(name, glyphsUnicodeMap) {
  26705. if (glyphsUnicodeMap[name] !== undefined) {
  26706. return name;
  26707. }
  26708. // The glyph name is non-standard, trying to recover.
  26709. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  26710. if (unicode !== -1) {
  26711. for (var key in glyphsUnicodeMap) {
  26712. if (glyphsUnicodeMap[key] === unicode) {
  26713. return key;
  26714. }
  26715. }
  26716. }
  26717. info('Unable to recover a standard glyph name for: ' + name);
  26718. return name;
  26719. }
  26720. var Glyph = (function GlyphClosure() {
  26721. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  26722. isSpace, isInFont) {
  26723. this.fontChar = fontChar;
  26724. this.unicode = unicode;
  26725. this.accent = accent;
  26726. this.width = width;
  26727. this.vmetric = vmetric;
  26728. this.operatorListId = operatorListId;
  26729. this.isSpace = isSpace;
  26730. this.isInFont = isInFont;
  26731. }
  26732. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  26733. vmetric, operatorListId, isSpace,
  26734. isInFont) {
  26735. return this.fontChar === fontChar &&
  26736. this.unicode === unicode &&
  26737. this.accent === accent &&
  26738. this.width === width &&
  26739. this.vmetric === vmetric &&
  26740. this.operatorListId === operatorListId &&
  26741. this.isSpace === isSpace &&
  26742. this.isInFont === isInFont;
  26743. };
  26744. return Glyph;
  26745. })();
  26746. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  26747. function ToUnicodeMap(cmap) {
  26748. // The elements of this._map can be integers or strings, depending on how
  26749. // |cmap| was created.
  26750. this._map = cmap;
  26751. }
  26752. ToUnicodeMap.prototype = {
  26753. get length() {
  26754. return this._map.length;
  26755. },
  26756. forEach: function(callback) {
  26757. for (var charCode in this._map) {
  26758. callback(charCode, this._map[charCode].charCodeAt(0));
  26759. }
  26760. },
  26761. has: function(i) {
  26762. return this._map[i] !== undefined;
  26763. },
  26764. get: function(i) {
  26765. return this._map[i];
  26766. },
  26767. charCodeOf: function(v) {
  26768. return this._map.indexOf(v);
  26769. },
  26770. amend: function (map) {
  26771. for (var charCode in map) {
  26772. this._map[charCode] = map[charCode];
  26773. }
  26774. },
  26775. };
  26776. return ToUnicodeMap;
  26777. })();
  26778. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  26779. function IdentityToUnicodeMap(firstChar, lastChar) {
  26780. this.firstChar = firstChar;
  26781. this.lastChar = lastChar;
  26782. }
  26783. IdentityToUnicodeMap.prototype = {
  26784. get length() {
  26785. return (this.lastChar + 1) - this.firstChar;
  26786. },
  26787. forEach: function (callback) {
  26788. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  26789. callback(i, i);
  26790. }
  26791. },
  26792. has: function (i) {
  26793. return this.firstChar <= i && i <= this.lastChar;
  26794. },
  26795. get: function (i) {
  26796. if (this.firstChar <= i && i <= this.lastChar) {
  26797. return String.fromCharCode(i);
  26798. }
  26799. return undefined;
  26800. },
  26801. charCodeOf: function (v) {
  26802. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  26803. },
  26804. amend: function (map) {
  26805. error('Should not call amend()');
  26806. },
  26807. };
  26808. return IdentityToUnicodeMap;
  26809. })();
  26810. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  26811. function writeInt16(dest, offset, num) {
  26812. dest[offset] = (num >> 8) & 0xFF;
  26813. dest[offset + 1] = num & 0xFF;
  26814. }
  26815. function writeInt32(dest, offset, num) {
  26816. dest[offset] = (num >> 24) & 0xFF;
  26817. dest[offset + 1] = (num >> 16) & 0xFF;
  26818. dest[offset + 2] = (num >> 8) & 0xFF;
  26819. dest[offset + 3] = num & 0xFF;
  26820. }
  26821. function writeData(dest, offset, data) {
  26822. var i, ii;
  26823. if (data instanceof Uint8Array) {
  26824. dest.set(data, offset);
  26825. } else if (typeof data === 'string') {
  26826. for (i = 0, ii = data.length; i < ii; i++) {
  26827. dest[offset++] = data.charCodeAt(i) & 0xFF;
  26828. }
  26829. } else {
  26830. // treating everything else as array
  26831. for (i = 0, ii = data.length; i < ii; i++) {
  26832. dest[offset++] = data[i] & 0xFF;
  26833. }
  26834. }
  26835. }
  26836. function OpenTypeFileBuilder(sfnt) {
  26837. this.sfnt = sfnt;
  26838. this.tables = Object.create(null);
  26839. }
  26840. OpenTypeFileBuilder.getSearchParams =
  26841. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  26842. var maxPower2 = 1, log2 = 0;
  26843. while ((maxPower2 ^ entriesCount) > maxPower2) {
  26844. maxPower2 <<= 1;
  26845. log2++;
  26846. }
  26847. var searchRange = maxPower2 * entrySize;
  26848. return {
  26849. range: searchRange,
  26850. entry: log2,
  26851. rangeShift: entrySize * entriesCount - searchRange
  26852. };
  26853. };
  26854. var OTF_HEADER_SIZE = 12;
  26855. var OTF_TABLE_ENTRY_SIZE = 16;
  26856. OpenTypeFileBuilder.prototype = {
  26857. toArray: function OpenTypeFileBuilder_toArray() {
  26858. var sfnt = this.sfnt;
  26859. // Tables needs to be written by ascendant alphabetic order
  26860. var tables = this.tables;
  26861. var tablesNames = Object.keys(tables);
  26862. tablesNames.sort();
  26863. var numTables = tablesNames.length;
  26864. var i, j, jj, table, tableName;
  26865. // layout the tables data
  26866. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  26867. var tableOffsets = [offset];
  26868. for (i = 0; i < numTables; i++) {
  26869. table = tables[tablesNames[i]];
  26870. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  26871. offset += paddedLength;
  26872. tableOffsets.push(offset);
  26873. }
  26874. var file = new Uint8Array(offset);
  26875. // write the table data first (mostly for checksum)
  26876. for (i = 0; i < numTables; i++) {
  26877. table = tables[tablesNames[i]];
  26878. writeData(file, tableOffsets[i], table);
  26879. }
  26880. // sfnt version (4 bytes)
  26881. if (sfnt === 'true') {
  26882. // Windows hates the Mac TrueType sfnt version number
  26883. sfnt = string32(0x00010000);
  26884. }
  26885. file[0] = sfnt.charCodeAt(0) & 0xFF;
  26886. file[1] = sfnt.charCodeAt(1) & 0xFF;
  26887. file[2] = sfnt.charCodeAt(2) & 0xFF;
  26888. file[3] = sfnt.charCodeAt(3) & 0xFF;
  26889. // numTables (2 bytes)
  26890. writeInt16(file, 4, numTables);
  26891. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  26892. // searchRange (2 bytes)
  26893. writeInt16(file, 6, searchParams.range);
  26894. // entrySelector (2 bytes)
  26895. writeInt16(file, 8, searchParams.entry);
  26896. // rangeShift (2 bytes)
  26897. writeInt16(file, 10, searchParams.rangeShift);
  26898. offset = OTF_HEADER_SIZE;
  26899. // writing table entries
  26900. for (i = 0; i < numTables; i++) {
  26901. tableName = tablesNames[i];
  26902. file[offset] = tableName.charCodeAt(0) & 0xFF;
  26903. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  26904. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  26905. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  26906. // checksum
  26907. var checksum = 0;
  26908. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  26909. var quad = readUint32(file, j);
  26910. checksum = (checksum + quad) >>> 0;
  26911. }
  26912. writeInt32(file, offset + 4, checksum);
  26913. // offset
  26914. writeInt32(file, offset + 8, tableOffsets[i]);
  26915. // length
  26916. writeInt32(file, offset + 12, tables[tableName].length);
  26917. offset += OTF_TABLE_ENTRY_SIZE;
  26918. }
  26919. return file;
  26920. },
  26921. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  26922. if (tag in this.tables) {
  26923. throw new Error('Table ' + tag + ' already exists');
  26924. }
  26925. this.tables[tag] = data;
  26926. }
  26927. };
  26928. return OpenTypeFileBuilder;
  26929. })();
  26930. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  26931. // issues when they are painted on the canvas, e.g. complex-script shaping or
  26932. // control/whitespace characters. The ranges are listed in pairs: the first item
  26933. // is a code of the first problematic code, the second one is the next
  26934. // non-problematic code. The ranges must be in sorted order.
  26935. var ProblematicCharRanges = new Int32Array([
  26936. // Control characters.
  26937. 0x0000, 0x0020,
  26938. 0x007F, 0x00A1,
  26939. 0x00AD, 0x00AE,
  26940. // Chars that is used in complex-script shaping.
  26941. 0x0600, 0x0780,
  26942. 0x08A0, 0x10A0,
  26943. 0x1780, 0x1800,
  26944. 0x1C00, 0x1C50,
  26945. // General punctuation chars.
  26946. 0x2000, 0x2010,
  26947. 0x2011, 0x2012,
  26948. 0x2028, 0x2030,
  26949. 0x205F, 0x2070,
  26950. 0x25CC, 0x25CD,
  26951. 0x3000, 0x3001,
  26952. // Chars that is used in complex-script shaping.
  26953. 0xAA60, 0xAA80,
  26954. // Specials Unicode block.
  26955. 0xFFF0, 0x10000
  26956. ]);
  26957. /**
  26958. * 'Font' is the class the outside world should use, it encapsulate all the font
  26959. * decoding logics whatever type it is (assuming the font type is supported).
  26960. *
  26961. * For example to read a Type1 font and to attach it to the document:
  26962. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  26963. * type1Font.bind();
  26964. */
  26965. var Font = (function FontClosure() {
  26966. function Font(name, file, properties) {
  26967. var charCode, glyphName, unicode;
  26968. this.name = name;
  26969. this.loadedName = properties.loadedName;
  26970. this.isType3Font = properties.isType3Font;
  26971. this.sizes = [];
  26972. this.missingFile = false;
  26973. this.glyphCache = Object.create(null);
  26974. var names = name.split('+');
  26975. names = names.length > 1 ? names[1] : names[0];
  26976. names = names.split(/[-,_]/g)[0];
  26977. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  26978. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  26979. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  26980. var type = properties.type;
  26981. var subtype = properties.subtype;
  26982. this.type = type;
  26983. this.fallbackName = (this.isMonospace ? 'monospace' :
  26984. (this.isSerifFont ? 'serif' : 'sans-serif'));
  26985. this.differences = properties.differences;
  26986. this.widths = properties.widths;
  26987. this.defaultWidth = properties.defaultWidth;
  26988. this.composite = properties.composite;
  26989. this.wideChars = properties.wideChars;
  26990. this.cMap = properties.cMap;
  26991. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  26992. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  26993. this.fontMatrix = properties.fontMatrix;
  26994. this.bbox = properties.bbox;
  26995. this.toUnicode = properties.toUnicode;
  26996. this.toFontChar = [];
  26997. if (properties.type === 'Type3') {
  26998. for (charCode = 0; charCode < 256; charCode++) {
  26999. this.toFontChar[charCode] = (this.differences[charCode] ||
  27000. properties.defaultEncoding[charCode]);
  27001. }
  27002. this.fontType = FontType.TYPE3;
  27003. return;
  27004. }
  27005. this.cidEncoding = properties.cidEncoding;
  27006. this.vertical = properties.vertical;
  27007. if (this.vertical) {
  27008. this.vmetrics = properties.vmetrics;
  27009. this.defaultVMetrics = properties.defaultVMetrics;
  27010. }
  27011. var glyphsUnicodeMap;
  27012. if (!file || file.isEmpty) {
  27013. if (file) {
  27014. // Some bad PDF generators will include empty font files,
  27015. // attempting to recover by assuming that no file exists.
  27016. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  27017. }
  27018. this.missingFile = true;
  27019. // The file data is not specified. Trying to fix the font name
  27020. // to be used with the canvas.font.
  27021. var fontName = name.replace(/[,_]/g, '-');
  27022. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  27023. var isStandardFont = !!stdFontMap[fontName] ||
  27024. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  27025. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  27026. this.bold = (fontName.search(/bold/gi) !== -1);
  27027. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  27028. (fontName.search(/italic/gi) !== -1));
  27029. // Use 'name' instead of 'fontName' here because the original
  27030. // name ArialBlack for example will be replaced by Helvetica.
  27031. this.black = (name.search(/Black/g) !== -1);
  27032. // if at least one width is present, remeasure all chars when exists
  27033. this.remeasure = Object.keys(this.widths).length > 0;
  27034. if (isStandardFont && type === 'CIDFontType2' &&
  27035. properties.cidEncoding.indexOf('Identity-') === 0) {
  27036. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  27037. // Standard fonts might be embedded as CID font without glyph mapping.
  27038. // Building one based on GlyphMapForStandardFonts.
  27039. var map = [];
  27040. for (charCode in GlyphMapForStandardFonts) {
  27041. map[+charCode] = GlyphMapForStandardFonts[charCode];
  27042. }
  27043. if (/ArialBlack/i.test(name)) {
  27044. var SupplementalGlyphMapForArialBlack =
  27045. getSupplementalGlyphMapForArialBlack();
  27046. for (charCode in SupplementalGlyphMapForArialBlack) {
  27047. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  27048. }
  27049. }
  27050. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  27051. if (!isIdentityUnicode) {
  27052. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27053. map[+charCode] = unicodeCharCode;
  27054. });
  27055. }
  27056. this.toFontChar = map;
  27057. this.toUnicode = new ToUnicodeMap(map);
  27058. } else if (/Symbol/i.test(fontName)) {
  27059. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  27060. properties.differences);
  27061. } else if (/Dingbats/i.test(fontName)) {
  27062. if (/Wingdings/i.test(name)) {
  27063. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  27064. }
  27065. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  27066. getDingbatsGlyphsUnicode(),
  27067. properties.differences);
  27068. } else if (isStandardFont) {
  27069. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  27070. getGlyphsUnicode(),
  27071. properties.differences);
  27072. } else {
  27073. glyphsUnicodeMap = getGlyphsUnicode();
  27074. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  27075. if (!this.composite) {
  27076. glyphName = (properties.differences[charCode] ||
  27077. properties.defaultEncoding[charCode]);
  27078. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  27079. if (unicode !== -1) {
  27080. unicodeCharCode = unicode;
  27081. }
  27082. }
  27083. this.toFontChar[charCode] = unicodeCharCode;
  27084. }.bind(this));
  27085. }
  27086. this.loadedName = fontName.split('-')[0];
  27087. this.loading = false;
  27088. this.fontType = getFontType(type, subtype);
  27089. return;
  27090. }
  27091. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  27092. if (subtype === 'Type1C') {
  27093. if (type !== 'Type1' && type !== 'MMType1') {
  27094. // Some TrueType fonts by mistake claim Type1C
  27095. if (isTrueTypeFile(file)) {
  27096. subtype = 'TrueType';
  27097. } else {
  27098. type = 'Type1';
  27099. }
  27100. } else if (isOpenTypeFile(file)) {
  27101. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  27102. type = subtype = 'OpenType';
  27103. }
  27104. }
  27105. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  27106. type = 'CIDFontType0';
  27107. }
  27108. if (subtype === 'OpenType') {
  27109. type = 'OpenType';
  27110. }
  27111. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  27112. if (type === 'CIDFontType0') {
  27113. if (isType1File(file)) {
  27114. subtype = 'CIDFontType0';
  27115. } else if (isOpenTypeFile(file)) {
  27116. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  27117. type = subtype = 'OpenType';
  27118. } else {
  27119. subtype = 'CIDFontType0C';
  27120. }
  27121. }
  27122. var data;
  27123. switch (type) {
  27124. case 'MMType1':
  27125. info('MMType1 font (' + name + '), falling back to Type1.');
  27126. /* falls through */
  27127. case 'Type1':
  27128. case 'CIDFontType0':
  27129. this.mimetype = 'font/opentype';
  27130. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  27131. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  27132. adjustWidths(properties);
  27133. // Wrap the CFF data inside an OTF font file
  27134. data = this.convert(name, cff, properties);
  27135. break;
  27136. case 'OpenType':
  27137. case 'TrueType':
  27138. case 'CIDFontType2':
  27139. this.mimetype = 'font/opentype';
  27140. // Repair the TrueType file. It is can be damaged in the point of
  27141. // view of the sanitizer
  27142. data = this.checkAndRepair(name, file, properties);
  27143. if (this.isOpenType) {
  27144. adjustWidths(properties);
  27145. type = 'OpenType';
  27146. }
  27147. break;
  27148. default:
  27149. error('Font ' + type + ' is not supported');
  27150. break;
  27151. }
  27152. this.data = data;
  27153. this.fontType = getFontType(type, subtype);
  27154. // Transfer some properties again that could change during font conversion
  27155. this.fontMatrix = properties.fontMatrix;
  27156. this.widths = properties.widths;
  27157. this.defaultWidth = properties.defaultWidth;
  27158. this.toUnicode = properties.toUnicode;
  27159. this.encoding = properties.baseEncoding;
  27160. this.seacMap = properties.seacMap;
  27161. this.loading = true;
  27162. }
  27163. Font.getFontID = (function () {
  27164. var ID = 1;
  27165. return function Font_getFontID() {
  27166. return String(ID++);
  27167. };
  27168. })();
  27169. function int16(b0, b1) {
  27170. return (b0 << 8) + b1;
  27171. }
  27172. function signedInt16(b0, b1) {
  27173. var value = (b0 << 8) + b1;
  27174. return value & (1 << 15) ? value - 0x10000 : value;
  27175. }
  27176. function int32(b0, b1, b2, b3) {
  27177. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  27178. }
  27179. function string16(value) {
  27180. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27181. }
  27182. function safeString16(value) {
  27183. // clamp value to the 16-bit int range
  27184. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  27185. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  27186. }
  27187. function isTrueTypeFile(file) {
  27188. var header = file.peekBytes(4);
  27189. return readUint32(header, 0) === 0x00010000;
  27190. }
  27191. function isOpenTypeFile(file) {
  27192. var header = file.peekBytes(4);
  27193. return bytesToString(header) === 'OTTO';
  27194. }
  27195. function isType1File(file) {
  27196. var header = file.peekBytes(2);
  27197. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  27198. if (header[0] === 0x25 && header[1] === 0x21) {
  27199. return true;
  27200. }
  27201. // ... obviously some fonts violate that part of the specification,
  27202. // please refer to the comment in |Type1Font| below.
  27203. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  27204. return true;
  27205. }
  27206. return false;
  27207. }
  27208. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  27209. var toFontChar = [], unicode;
  27210. for (var i = 0, ii = encoding.length; i < ii; i++) {
  27211. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  27212. if (unicode !== -1) {
  27213. toFontChar[i] = unicode;
  27214. }
  27215. }
  27216. for (var charCode in differences) {
  27217. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  27218. if (unicode !== -1) {
  27219. toFontChar[+charCode] = unicode;
  27220. }
  27221. }
  27222. return toFontChar;
  27223. }
  27224. /**
  27225. * Helper function for |adjustMapping|.
  27226. * @return {boolean}
  27227. */
  27228. function isProblematicUnicodeLocation(code) {
  27229. // Using binary search to find a range start.
  27230. var i = 0, j = ProblematicCharRanges.length - 1;
  27231. while (i < j) {
  27232. var c = (i + j + 1) >> 1;
  27233. if (code < ProblematicCharRanges[c]) {
  27234. j = c - 1;
  27235. } else {
  27236. i = c;
  27237. }
  27238. }
  27239. // Even index means code in problematic range.
  27240. return !(i & 1);
  27241. }
  27242. /**
  27243. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  27244. * with their unicode value. It also moves char codes that are in known
  27245. * problematic locations.
  27246. * @return {Object} Two properties:
  27247. * 'toFontChar' - maps original char codes(the value that will be read
  27248. * from commands such as show text) to the char codes that will be used in the
  27249. * font that we build
  27250. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  27251. */
  27252. function adjustMapping(charCodeToGlyphId, properties) {
  27253. var toUnicode = properties.toUnicode;
  27254. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  27255. var isIdentityUnicode =
  27256. properties.toUnicode instanceof IdentityToUnicodeMap;
  27257. var newMap = Object.create(null);
  27258. var toFontChar = [];
  27259. var usedFontCharCodes = [];
  27260. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  27261. for (var originalCharCode in charCodeToGlyphId) {
  27262. originalCharCode |= 0;
  27263. var glyphId = charCodeToGlyphId[originalCharCode];
  27264. var fontCharCode = originalCharCode;
  27265. // First try to map the value to a unicode position if a non identity map
  27266. // was created.
  27267. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  27268. var unicode = toUnicode.get(fontCharCode);
  27269. // TODO: Try to map ligatures to the correct spot.
  27270. if (unicode.length === 1) {
  27271. fontCharCode = unicode.charCodeAt(0);
  27272. }
  27273. }
  27274. // Try to move control characters, special characters and already mapped
  27275. // characters to the private use area since they will not be drawn by
  27276. // canvas if left in their current position. Also, move characters if the
  27277. // font was symbolic and there is only an identity unicode map since the
  27278. // characters probably aren't in the correct position (fixes an issue
  27279. // with firefox and thuluthfont).
  27280. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  27281. isProblematicUnicodeLocation(fontCharCode) ||
  27282. (isSymbolic && isIdentityUnicode)) &&
  27283. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  27284. // Loop to try and find a free spot in the private use area.
  27285. do {
  27286. fontCharCode = nextAvailableFontCharCode++;
  27287. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  27288. fontCharCode = 0xF020;
  27289. nextAvailableFontCharCode = fontCharCode + 1;
  27290. }
  27291. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  27292. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  27293. }
  27294. newMap[fontCharCode] = glyphId;
  27295. toFontChar[originalCharCode] = fontCharCode;
  27296. usedFontCharCodes[fontCharCode] = true;
  27297. }
  27298. return {
  27299. toFontChar: toFontChar,
  27300. charCodeToGlyphId: newMap,
  27301. nextAvailableFontCharCode: nextAvailableFontCharCode
  27302. };
  27303. }
  27304. function getRanges(glyphs, numGlyphs) {
  27305. // Array.sort() sorts by characters, not numerically, so convert to an
  27306. // array of characters.
  27307. var codes = [];
  27308. for (var charCode in glyphs) {
  27309. // Remove an invalid glyph ID mappings to make OTS happy.
  27310. if (glyphs[charCode] >= numGlyphs) {
  27311. continue;
  27312. }
  27313. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  27314. }
  27315. codes.sort(function fontGetRangesSort(a, b) {
  27316. return a.fontCharCode - b.fontCharCode;
  27317. });
  27318. // Split the sorted codes into ranges.
  27319. var ranges = [];
  27320. var length = codes.length;
  27321. for (var n = 0; n < length; ) {
  27322. var start = codes[n].fontCharCode;
  27323. var codeIndices = [codes[n].glyphId];
  27324. ++n;
  27325. var end = start;
  27326. while (n < length && end + 1 === codes[n].fontCharCode) {
  27327. codeIndices.push(codes[n].glyphId);
  27328. ++end;
  27329. ++n;
  27330. if (end === 0xFFFF) {
  27331. break;
  27332. }
  27333. }
  27334. ranges.push([start, end, codeIndices]);
  27335. }
  27336. return ranges;
  27337. }
  27338. function createCmapTable(glyphs, numGlyphs) {
  27339. var ranges = getRanges(glyphs, numGlyphs);
  27340. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  27341. var cmap = '\x00\x00' + // version
  27342. string16(numTables) + // numTables
  27343. '\x00\x03' + // platformID
  27344. '\x00\x01' + // encodingID
  27345. string32(4 + numTables * 8); // start of the table record
  27346. var i, ii, j, jj;
  27347. for (i = ranges.length - 1; i >= 0; --i) {
  27348. if (ranges[i][0] <= 0xFFFF) { break; }
  27349. }
  27350. var bmpLength = i + 1;
  27351. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  27352. ranges[i][1] = 0xFFFE;
  27353. }
  27354. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  27355. var segCount = bmpLength + trailingRangesCount;
  27356. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  27357. // Fill up the 4 parallel arrays describing the segments.
  27358. var startCount = '';
  27359. var endCount = '';
  27360. var idDeltas = '';
  27361. var idRangeOffsets = '';
  27362. var glyphsIds = '';
  27363. var bias = 0;
  27364. var range, start, end, codes;
  27365. for (i = 0, ii = bmpLength; i < ii; i++) {
  27366. range = ranges[i];
  27367. start = range[0];
  27368. end = range[1];
  27369. startCount += string16(start);
  27370. endCount += string16(end);
  27371. codes = range[2];
  27372. var contiguous = true;
  27373. for (j = 1, jj = codes.length; j < jj; ++j) {
  27374. if (codes[j] !== codes[j - 1] + 1) {
  27375. contiguous = false;
  27376. break;
  27377. }
  27378. }
  27379. if (!contiguous) {
  27380. var offset = (segCount - i) * 2 + bias * 2;
  27381. bias += (end - start + 1);
  27382. idDeltas += string16(0);
  27383. idRangeOffsets += string16(offset);
  27384. for (j = 0, jj = codes.length; j < jj; ++j) {
  27385. glyphsIds += string16(codes[j]);
  27386. }
  27387. } else {
  27388. var startCode = codes[0];
  27389. idDeltas += string16((startCode - start) & 0xFFFF);
  27390. idRangeOffsets += string16(0);
  27391. }
  27392. }
  27393. if (trailingRangesCount > 0) {
  27394. endCount += '\xFF\xFF';
  27395. startCount += '\xFF\xFF';
  27396. idDeltas += '\x00\x01';
  27397. idRangeOffsets += '\x00\x00';
  27398. }
  27399. var format314 = '\x00\x00' + // language
  27400. string16(2 * segCount) +
  27401. string16(searchParams.range) +
  27402. string16(searchParams.entry) +
  27403. string16(searchParams.rangeShift) +
  27404. endCount + '\x00\x00' + startCount +
  27405. idDeltas + idRangeOffsets + glyphsIds;
  27406. var format31012 = '';
  27407. var header31012 = '';
  27408. if (numTables > 1) {
  27409. cmap += '\x00\x03' + // platformID
  27410. '\x00\x0A' + // encodingID
  27411. string32(4 + numTables * 8 +
  27412. 4 + format314.length); // start of the table record
  27413. format31012 = '';
  27414. for (i = 0, ii = ranges.length; i < ii; i++) {
  27415. range = ranges[i];
  27416. start = range[0];
  27417. codes = range[2];
  27418. var code = codes[0];
  27419. for (j = 1, jj = codes.length; j < jj; ++j) {
  27420. if (codes[j] !== codes[j - 1] + 1) {
  27421. end = range[0] + j - 1;
  27422. format31012 += string32(start) + // startCharCode
  27423. string32(end) + // endCharCode
  27424. string32(code); // startGlyphID
  27425. start = end + 1;
  27426. code = codes[j];
  27427. }
  27428. }
  27429. format31012 += string32(start) + // startCharCode
  27430. string32(range[1]) + // endCharCode
  27431. string32(code); // startGlyphID
  27432. }
  27433. header31012 = '\x00\x0C' + // format
  27434. '\x00\x00' + // reserved
  27435. string32(format31012.length + 16) + // length
  27436. '\x00\x00\x00\x00' + // language
  27437. string32(format31012.length / 12); // nGroups
  27438. }
  27439. return cmap + '\x00\x04' + // format
  27440. string16(format314.length + 4) + // length
  27441. format314 + header31012 + format31012;
  27442. }
  27443. function validateOS2Table(os2) {
  27444. var stream = new Stream(os2.data);
  27445. var version = stream.getUint16();
  27446. // TODO verify all OS/2 tables fields, but currently we validate only those
  27447. // that give us issues
  27448. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  27449. var selection = stream.getUint16();
  27450. if (version < 4 && (selection & 0x0300)) {
  27451. return false;
  27452. }
  27453. var firstChar = stream.getUint16();
  27454. var lastChar = stream.getUint16();
  27455. if (firstChar > lastChar) {
  27456. return false;
  27457. }
  27458. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  27459. var usWinAscent = stream.getUint16();
  27460. if (usWinAscent === 0) { // makes font unreadable by windows
  27461. return false;
  27462. }
  27463. // OS/2 appears to be valid, resetting some fields
  27464. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  27465. return true;
  27466. }
  27467. function createOS2Table(properties, charstrings, override) {
  27468. override = override || {
  27469. unitsPerEm: 0,
  27470. yMax: 0,
  27471. yMin: 0,
  27472. ascent: 0,
  27473. descent: 0
  27474. };
  27475. var ulUnicodeRange1 = 0;
  27476. var ulUnicodeRange2 = 0;
  27477. var ulUnicodeRange3 = 0;
  27478. var ulUnicodeRange4 = 0;
  27479. var firstCharIndex = null;
  27480. var lastCharIndex = 0;
  27481. if (charstrings) {
  27482. for (var code in charstrings) {
  27483. code |= 0;
  27484. if (firstCharIndex > code || !firstCharIndex) {
  27485. firstCharIndex = code;
  27486. }
  27487. if (lastCharIndex < code) {
  27488. lastCharIndex = code;
  27489. }
  27490. var position = getUnicodeRangeFor(code);
  27491. if (position < 32) {
  27492. ulUnicodeRange1 |= 1 << position;
  27493. } else if (position < 64) {
  27494. ulUnicodeRange2 |= 1 << position - 32;
  27495. } else if (position < 96) {
  27496. ulUnicodeRange3 |= 1 << position - 64;
  27497. } else if (position < 123) {
  27498. ulUnicodeRange4 |= 1 << position - 96;
  27499. } else {
  27500. error('Unicode ranges Bits > 123 are reserved for internal usage');
  27501. }
  27502. }
  27503. } else {
  27504. // TODO
  27505. firstCharIndex = 0;
  27506. lastCharIndex = 255;
  27507. }
  27508. var bbox = properties.bbox || [0, 0, 0, 0];
  27509. var unitsPerEm = (override.unitsPerEm ||
  27510. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  27511. // if the font units differ to the PDF glyph space units
  27512. // then scale up the values
  27513. var scale = (properties.ascentScaled ? 1.0 :
  27514. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  27515. var typoAscent = (override.ascent ||
  27516. Math.round(scale * (properties.ascent || bbox[3])));
  27517. var typoDescent = (override.descent ||
  27518. Math.round(scale * (properties.descent || bbox[1])));
  27519. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  27520. typoDescent = -typoDescent; // fixing incorrect descent
  27521. }
  27522. var winAscent = override.yMax || typoAscent;
  27523. var winDescent = -override.yMin || -typoDescent;
  27524. return '\x00\x03' + // version
  27525. '\x02\x24' + // xAvgCharWidth
  27526. '\x01\xF4' + // usWeightClass
  27527. '\x00\x05' + // usWidthClass
  27528. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  27529. '\x02\x8A' + // ySubscriptXSize
  27530. '\x02\xBB' + // ySubscriptYSize
  27531. '\x00\x00' + // ySubscriptXOffset
  27532. '\x00\x8C' + // ySubscriptYOffset
  27533. '\x02\x8A' + // ySuperScriptXSize
  27534. '\x02\xBB' + // ySuperScriptYSize
  27535. '\x00\x00' + // ySuperScriptXOffset
  27536. '\x01\xDF' + // ySuperScriptYOffset
  27537. '\x00\x31' + // yStrikeOutSize
  27538. '\x01\x02' + // yStrikeOutPosition
  27539. '\x00\x00' + // sFamilyClass
  27540. '\x00\x00\x06' +
  27541. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  27542. '\x00\x00\x00\x00\x00\x00' + // Panose
  27543. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  27544. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  27545. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  27546. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  27547. '\x2A\x32\x31\x2A' + // achVendID
  27548. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  27549. string16(firstCharIndex ||
  27550. properties.firstChar) + // usFirstCharIndex
  27551. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  27552. string16(typoAscent) + // sTypoAscender
  27553. string16(typoDescent) + // sTypoDescender
  27554. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  27555. string16(winAscent) + // usWinAscent
  27556. string16(winDescent) + // usWinDescent
  27557. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  27558. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  27559. string16(properties.xHeight) + // sxHeight
  27560. string16(properties.capHeight) + // sCapHeight
  27561. string16(0) + // usDefaultChar
  27562. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  27563. '\x00\x03'; // usMaxContext
  27564. }
  27565. function createPostTable(properties) {
  27566. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  27567. return ('\x00\x03\x00\x00' + // Version number
  27568. string32(angle) + // italicAngle
  27569. '\x00\x00' + // underlinePosition
  27570. '\x00\x00' + // underlineThickness
  27571. string32(properties.fixedPitch) + // isFixedPitch
  27572. '\x00\x00\x00\x00' + // minMemType42
  27573. '\x00\x00\x00\x00' + // maxMemType42
  27574. '\x00\x00\x00\x00' + // minMemType1
  27575. '\x00\x00\x00\x00'); // maxMemType1
  27576. }
  27577. function createNameTable(name, proto) {
  27578. if (!proto) {
  27579. proto = [[], []]; // no strings and unicode strings
  27580. }
  27581. var strings = [
  27582. proto[0][0] || 'Original licence', // 0.Copyright
  27583. proto[0][1] || name, // 1.Font family
  27584. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  27585. proto[0][3] || 'uniqueID', // 3.Unique ID
  27586. proto[0][4] || name, // 4.Full font name
  27587. proto[0][5] || 'Version 0.11', // 5.Version
  27588. proto[0][6] || '', // 6.Postscript name
  27589. proto[0][7] || 'Unknown', // 7.Trademark
  27590. proto[0][8] || 'Unknown', // 8.Manufacturer
  27591. proto[0][9] || 'Unknown' // 9.Designer
  27592. ];
  27593. // Mac want 1-byte per character strings while Windows want
  27594. // 2-bytes per character, so duplicate the names table
  27595. var stringsUnicode = [];
  27596. var i, ii, j, jj, str;
  27597. for (i = 0, ii = strings.length; i < ii; i++) {
  27598. str = proto[1][i] || strings[i];
  27599. var strBufUnicode = [];
  27600. for (j = 0, jj = str.length; j < jj; j++) {
  27601. strBufUnicode.push(string16(str.charCodeAt(j)));
  27602. }
  27603. stringsUnicode.push(strBufUnicode.join(''));
  27604. }
  27605. var names = [strings, stringsUnicode];
  27606. var platforms = ['\x00\x01', '\x00\x03'];
  27607. var encodings = ['\x00\x00', '\x00\x01'];
  27608. var languages = ['\x00\x00', '\x04\x09'];
  27609. var namesRecordCount = strings.length * platforms.length;
  27610. var nameTable =
  27611. '\x00\x00' + // format
  27612. string16(namesRecordCount) + // Number of names Record
  27613. string16(namesRecordCount * 12 + 6); // Storage
  27614. // Build the name records field
  27615. var strOffset = 0;
  27616. for (i = 0, ii = platforms.length; i < ii; i++) {
  27617. var strs = names[i];
  27618. for (j = 0, jj = strs.length; j < jj; j++) {
  27619. str = strs[j];
  27620. var nameRecord =
  27621. platforms[i] + // platform ID
  27622. encodings[i] + // encoding ID
  27623. languages[i] + // language ID
  27624. string16(j) + // name ID
  27625. string16(str.length) +
  27626. string16(strOffset);
  27627. nameTable += nameRecord;
  27628. strOffset += str.length;
  27629. }
  27630. }
  27631. nameTable += strings.join('') + stringsUnicode.join('');
  27632. return nameTable;
  27633. }
  27634. Font.prototype = {
  27635. name: null,
  27636. font: null,
  27637. mimetype: null,
  27638. encoding: null,
  27639. get renderer() {
  27640. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  27641. return shadow(this, 'renderer', renderer);
  27642. },
  27643. exportData: function Font_exportData() {
  27644. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  27645. var data = {};
  27646. for (var i in this) {
  27647. if (this.hasOwnProperty(i)) {
  27648. data[i] = this[i];
  27649. }
  27650. }
  27651. return data;
  27652. },
  27653. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  27654. function readTableEntry(file) {
  27655. var tag = bytesToString(file.getBytes(4));
  27656. var checksum = file.getInt32() >>> 0;
  27657. var offset = file.getInt32() >>> 0;
  27658. var length = file.getInt32() >>> 0;
  27659. // Read the table associated data
  27660. var previousPosition = file.pos;
  27661. file.pos = file.start ? file.start : 0;
  27662. file.skip(offset);
  27663. var data = file.getBytes(length);
  27664. file.pos = previousPosition;
  27665. if (tag === 'head') {
  27666. // clearing checksum adjustment
  27667. data[8] = data[9] = data[10] = data[11] = 0;
  27668. data[17] |= 0x20; //Set font optimized for cleartype flag
  27669. }
  27670. return {
  27671. tag: tag,
  27672. checksum: checksum,
  27673. length: length,
  27674. offset: offset,
  27675. data: data
  27676. };
  27677. }
  27678. function readOpenTypeHeader(ttf) {
  27679. return {
  27680. version: bytesToString(ttf.getBytes(4)),
  27681. numTables: ttf.getUint16(),
  27682. searchRange: ttf.getUint16(),
  27683. entrySelector: ttf.getUint16(),
  27684. rangeShift: ttf.getUint16()
  27685. };
  27686. }
  27687. /**
  27688. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  27689. * PDF spec
  27690. */
  27691. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  27692. if (!cmap) {
  27693. warn('No cmap table available.');
  27694. return {
  27695. platformId: -1,
  27696. encodingId: -1,
  27697. mappings: [],
  27698. hasShortCmap: false
  27699. };
  27700. }
  27701. var segment;
  27702. var start = (font.start ? font.start : 0) + cmap.offset;
  27703. font.pos = start;
  27704. var version = font.getUint16();
  27705. var numTables = font.getUint16();
  27706. var potentialTable;
  27707. var canBreak = false;
  27708. // There's an order of preference in terms of which cmap subtable to
  27709. // use:
  27710. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  27711. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  27712. // The following takes advantage of the fact that the tables are sorted
  27713. // to work.
  27714. for (var i = 0; i < numTables; i++) {
  27715. var platformId = font.getUint16();
  27716. var encodingId = font.getUint16();
  27717. var offset = font.getInt32() >>> 0;
  27718. var useTable = false;
  27719. if (platformId === 0 && encodingId === 0) {
  27720. useTable = true;
  27721. // Continue the loop since there still may be a higher priority
  27722. // table.
  27723. } else if (platformId === 1 && encodingId === 0) {
  27724. useTable = true;
  27725. // Continue the loop since there still may be a higher priority
  27726. // table.
  27727. } else if (platformId === 3 && encodingId === 1 &&
  27728. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  27729. useTable = true;
  27730. if (!isSymbolicFont) {
  27731. canBreak = true;
  27732. }
  27733. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  27734. useTable = true;
  27735. canBreak = true;
  27736. }
  27737. if (useTable) {
  27738. potentialTable = {
  27739. platformId: platformId,
  27740. encodingId: encodingId,
  27741. offset: offset
  27742. };
  27743. }
  27744. if (canBreak) {
  27745. break;
  27746. }
  27747. }
  27748. if (potentialTable) {
  27749. font.pos = start + potentialTable.offset;
  27750. }
  27751. if (!potentialTable || font.peekByte() === -1) {
  27752. warn('Could not find a preferred cmap table.');
  27753. return {
  27754. platformId: -1,
  27755. encodingId: -1,
  27756. mappings: [],
  27757. hasShortCmap: false
  27758. };
  27759. }
  27760. var format = font.getUint16();
  27761. var length = font.getUint16();
  27762. var language = font.getUint16();
  27763. var hasShortCmap = false;
  27764. var mappings = [];
  27765. var j, glyphId;
  27766. // TODO(mack): refactor this cmap subtable reading logic out
  27767. if (format === 0) {
  27768. for (j = 0; j < 256; j++) {
  27769. var index = font.getByte();
  27770. if (!index) {
  27771. continue;
  27772. }
  27773. mappings.push({
  27774. charCode: j,
  27775. glyphId: index
  27776. });
  27777. }
  27778. hasShortCmap = true;
  27779. } else if (format === 4) {
  27780. // re-creating the table in format 4 since the encoding
  27781. // might be changed
  27782. var segCount = (font.getUint16() >> 1);
  27783. font.getBytes(6); // skipping range fields
  27784. var segIndex, segments = [];
  27785. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27786. segments.push({ end: font.getUint16() });
  27787. }
  27788. font.getUint16();
  27789. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27790. segments[segIndex].start = font.getUint16();
  27791. }
  27792. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27793. segments[segIndex].delta = font.getUint16();
  27794. }
  27795. var offsetsCount = 0;
  27796. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27797. segment = segments[segIndex];
  27798. var rangeOffset = font.getUint16();
  27799. if (!rangeOffset) {
  27800. segment.offsetIndex = -1;
  27801. continue;
  27802. }
  27803. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  27804. segment.offsetIndex = offsetIndex;
  27805. offsetsCount = Math.max(offsetsCount, offsetIndex +
  27806. segment.end - segment.start + 1);
  27807. }
  27808. var offsets = [];
  27809. for (j = 0; j < offsetsCount; j++) {
  27810. offsets.push(font.getUint16());
  27811. }
  27812. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27813. segment = segments[segIndex];
  27814. start = segment.start;
  27815. var end = segment.end;
  27816. var delta = segment.delta;
  27817. offsetIndex = segment.offsetIndex;
  27818. for (j = start; j <= end; j++) {
  27819. if (j === 0xFFFF) {
  27820. continue;
  27821. }
  27822. glyphId = (offsetIndex < 0 ?
  27823. j : offsets[offsetIndex + j - start]);
  27824. glyphId = (glyphId + delta) & 0xFFFF;
  27825. if (glyphId === 0) {
  27826. continue;
  27827. }
  27828. mappings.push({
  27829. charCode: j,
  27830. glyphId: glyphId
  27831. });
  27832. }
  27833. }
  27834. } else if (format === 6) {
  27835. // Format 6 is a 2-bytes dense mapping, which means the font data
  27836. // lives glue together even if they are pretty far in the unicode
  27837. // table. (This looks weird, so I can have missed something), this
  27838. // works on Linux but seems to fails on Mac so let's rewrite the
  27839. // cmap table to a 3-1-4 style
  27840. var firstCode = font.getUint16();
  27841. var entryCount = font.getUint16();
  27842. for (j = 0; j < entryCount; j++) {
  27843. glyphId = font.getUint16();
  27844. var charCode = firstCode + j;
  27845. mappings.push({
  27846. charCode: charCode,
  27847. glyphId: glyphId
  27848. });
  27849. }
  27850. } else {
  27851. warn('cmap table has unsupported format: ' + format);
  27852. return {
  27853. platformId: -1,
  27854. encodingId: -1,
  27855. mappings: [],
  27856. hasShortCmap: false
  27857. };
  27858. }
  27859. // removing duplicate entries
  27860. mappings.sort(function (a, b) {
  27861. return a.charCode - b.charCode;
  27862. });
  27863. for (i = 1; i < mappings.length; i++) {
  27864. if (mappings[i - 1].charCode === mappings[i].charCode) {
  27865. mappings.splice(i, 1);
  27866. i--;
  27867. }
  27868. }
  27869. return {
  27870. platformId: potentialTable.platformId,
  27871. encodingId: potentialTable.encodingId,
  27872. mappings: mappings,
  27873. hasShortCmap: hasShortCmap
  27874. };
  27875. }
  27876. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  27877. if (!header) {
  27878. if (metrics) {
  27879. metrics.data = null;
  27880. }
  27881. return;
  27882. }
  27883. font.pos = (font.start ? font.start : 0) + header.offset;
  27884. font.pos += header.length - 2;
  27885. var numOfMetrics = font.getUint16();
  27886. if (numOfMetrics > numGlyphs) {
  27887. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  27888. 'greater than the numGlyphs (' + numGlyphs + ')');
  27889. // Reduce numOfMetrics if it is greater than numGlyphs
  27890. numOfMetrics = numGlyphs;
  27891. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  27892. header.data[35] = numOfMetrics & 0x00ff;
  27893. }
  27894. var numOfSidebearings = numGlyphs - numOfMetrics;
  27895. var numMissing = numOfSidebearings -
  27896. ((metrics.length - numOfMetrics * 4) >> 1);
  27897. if (numMissing > 0) {
  27898. // For each missing glyph, we set both the width and lsb to 0 (zero).
  27899. // Since we need to add two properties for each glyph, this explains
  27900. // the use of |numMissing * 2| when initializing the typed array.
  27901. var entries = new Uint8Array(metrics.length + numMissing * 2);
  27902. entries.set(metrics.data);
  27903. metrics.data = entries;
  27904. }
  27905. }
  27906. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  27907. hintsValid) {
  27908. if (sourceEnd - sourceStart <= 12) {
  27909. // glyph with data less than 12 is invalid one
  27910. return 0;
  27911. }
  27912. var glyf = source.subarray(sourceStart, sourceEnd);
  27913. var contoursCount = (glyf[0] << 8) | glyf[1];
  27914. if (contoursCount & 0x8000) {
  27915. // complex glyph, writing as is
  27916. dest.set(glyf, destStart);
  27917. return glyf.length;
  27918. }
  27919. var i, j = 10, flagsCount = 0;
  27920. for (i = 0; i < contoursCount; i++) {
  27921. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  27922. flagsCount = endPoint + 1;
  27923. j += 2;
  27924. }
  27925. // skipping instructions
  27926. var instructionsStart = j;
  27927. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  27928. j += 2 + instructionsLength;
  27929. var instructionsEnd = j;
  27930. // validating flags
  27931. var coordinatesLength = 0;
  27932. for (i = 0; i < flagsCount; i++) {
  27933. var flag = glyf[j++];
  27934. if (flag & 0xC0) {
  27935. // reserved flags must be zero, cleaning up
  27936. glyf[j - 1] = flag & 0x3F;
  27937. }
  27938. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  27939. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  27940. coordinatesLength += xyLength;
  27941. if (flag & 8) {
  27942. var repeat = glyf[j++];
  27943. i += repeat;
  27944. coordinatesLength += repeat * xyLength;
  27945. }
  27946. }
  27947. // glyph without coordinates will be rejected
  27948. if (coordinatesLength === 0) {
  27949. return 0;
  27950. }
  27951. var glyphDataLength = j + coordinatesLength;
  27952. if (glyphDataLength > glyf.length) {
  27953. // not enough data for coordinates
  27954. return 0;
  27955. }
  27956. if (!hintsValid && instructionsLength > 0) {
  27957. dest.set(glyf.subarray(0, instructionsStart), destStart);
  27958. dest.set([0, 0], destStart + instructionsStart);
  27959. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  27960. destStart + instructionsStart + 2);
  27961. glyphDataLength -= instructionsLength;
  27962. if (glyf.length - glyphDataLength > 3) {
  27963. glyphDataLength = (glyphDataLength + 3) & ~3;
  27964. }
  27965. return glyphDataLength;
  27966. }
  27967. if (glyf.length - glyphDataLength > 3) {
  27968. // truncating and aligning to 4 bytes the long glyph data
  27969. glyphDataLength = (glyphDataLength + 3) & ~3;
  27970. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  27971. return glyphDataLength;
  27972. }
  27973. // glyph data is fine
  27974. dest.set(glyf, destStart);
  27975. return glyf.length;
  27976. }
  27977. function sanitizeHead(head, numGlyphs, locaLength) {
  27978. var data = head.data;
  27979. // Validate version:
  27980. // Should always be 0x00010000
  27981. var version = int32(data[0], data[1], data[2], data[3]);
  27982. if (version >> 16 !== 1) {
  27983. info('Attempting to fix invalid version in head table: ' + version);
  27984. data[0] = 0;
  27985. data[1] = 1;
  27986. data[2] = 0;
  27987. data[3] = 0;
  27988. }
  27989. var indexToLocFormat = int16(data[50], data[51]);
  27990. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  27991. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  27992. indexToLocFormat);
  27993. // The value of indexToLocFormat should be 0 if the loca table
  27994. // consists of short offsets, and should be 1 if the loca table
  27995. // consists of long offsets.
  27996. //
  27997. // The number of entries in the loca table should be numGlyphs + 1.
  27998. //
  27999. // Using this information, we can work backwards to deduce if the
  28000. // size of each offset in the loca table, and thus figure out the
  28001. // appropriate value for indexToLocFormat.
  28002. var numGlyphsPlusOne = numGlyphs + 1;
  28003. if (locaLength === numGlyphsPlusOne << 1) {
  28004. // 0x0000 indicates the loca table consists of short offsets
  28005. data[50] = 0;
  28006. data[51] = 0;
  28007. } else if (locaLength === numGlyphsPlusOne << 2) {
  28008. // 0x0001 indicates the loca table consists of long offsets
  28009. data[50] = 0;
  28010. data[51] = 1;
  28011. } else {
  28012. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  28013. }
  28014. }
  28015. }
  28016. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  28017. isGlyphLocationsLong, hintsValid,
  28018. dupFirstEntry) {
  28019. var itemSize, itemDecode, itemEncode;
  28020. if (isGlyphLocationsLong) {
  28021. itemSize = 4;
  28022. itemDecode = function fontItemDecodeLong(data, offset) {
  28023. return (data[offset] << 24) | (data[offset + 1] << 16) |
  28024. (data[offset + 2] << 8) | data[offset + 3];
  28025. };
  28026. itemEncode = function fontItemEncodeLong(data, offset, value) {
  28027. data[offset] = (value >>> 24) & 0xFF;
  28028. data[offset + 1] = (value >> 16) & 0xFF;
  28029. data[offset + 2] = (value >> 8) & 0xFF;
  28030. data[offset + 3] = value & 0xFF;
  28031. };
  28032. } else {
  28033. itemSize = 2;
  28034. itemDecode = function fontItemDecode(data, offset) {
  28035. return (data[offset] << 9) | (data[offset + 1] << 1);
  28036. };
  28037. itemEncode = function fontItemEncode(data, offset, value) {
  28038. data[offset] = (value >> 9) & 0xFF;
  28039. data[offset + 1] = (value >> 1) & 0xFF;
  28040. };
  28041. }
  28042. var locaData = loca.data;
  28043. var locaDataSize = itemSize * (1 + numGlyphs);
  28044. // is loca.data too short or long?
  28045. if (locaData.length !== locaDataSize) {
  28046. locaData = new Uint8Array(locaDataSize);
  28047. locaData.set(loca.data.subarray(0, locaDataSize));
  28048. loca.data = locaData;
  28049. }
  28050. // removing the invalid glyphs
  28051. var oldGlyfData = glyf.data;
  28052. var oldGlyfDataLength = oldGlyfData.length;
  28053. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  28054. var startOffset = itemDecode(locaData, 0);
  28055. var writeOffset = 0;
  28056. var missingGlyphData = Object.create(null);
  28057. itemEncode(locaData, 0, writeOffset);
  28058. var i, j;
  28059. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28060. var endOffset = itemDecode(locaData, j);
  28061. if (endOffset > oldGlyfDataLength &&
  28062. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  28063. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  28064. // the glyf table size, which makes last glyph out of range.
  28065. endOffset = oldGlyfDataLength;
  28066. }
  28067. if (endOffset > oldGlyfDataLength) {
  28068. // glyph end offset points outside glyf data, rejecting the glyph
  28069. itemEncode(locaData, j, writeOffset);
  28070. startOffset = endOffset;
  28071. continue;
  28072. }
  28073. if (startOffset === endOffset) {
  28074. missingGlyphData[i] = true;
  28075. }
  28076. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  28077. newGlyfData, writeOffset, hintsValid);
  28078. writeOffset += newLength;
  28079. itemEncode(locaData, j, writeOffset);
  28080. startOffset = endOffset;
  28081. }
  28082. if (writeOffset === 0) {
  28083. // glyf table cannot be empty -- redoing the glyf and loca tables
  28084. // to have single glyph with one point
  28085. var simpleGlyph = new Uint8Array(
  28086. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  28087. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  28088. itemEncode(locaData, j, simpleGlyph.length);
  28089. }
  28090. glyf.data = simpleGlyph;
  28091. return missingGlyphData;
  28092. }
  28093. if (dupFirstEntry) {
  28094. var firstEntryLength = itemDecode(locaData, itemSize);
  28095. if (newGlyfData.length > firstEntryLength + writeOffset) {
  28096. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  28097. } else {
  28098. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  28099. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  28100. }
  28101. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  28102. itemEncode(loca.data, locaData.length - itemSize,
  28103. writeOffset + firstEntryLength);
  28104. } else {
  28105. glyf.data = newGlyfData.subarray(0, writeOffset);
  28106. }
  28107. return missingGlyphData;
  28108. }
  28109. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  28110. var start = (font.start ? font.start : 0) + post.offset;
  28111. font.pos = start;
  28112. var length = post.length, end = start + length;
  28113. var version = font.getInt32();
  28114. // skip rest to the tables
  28115. font.getBytes(28);
  28116. var glyphNames;
  28117. var valid = true;
  28118. var i;
  28119. switch (version) {
  28120. case 0x00010000:
  28121. glyphNames = MacStandardGlyphOrdering;
  28122. break;
  28123. case 0x00020000:
  28124. var numGlyphs = font.getUint16();
  28125. if (numGlyphs !== maxpNumGlyphs) {
  28126. valid = false;
  28127. break;
  28128. }
  28129. var glyphNameIndexes = [];
  28130. for (i = 0; i < numGlyphs; ++i) {
  28131. var index = font.getUint16();
  28132. if (index >= 32768) {
  28133. valid = false;
  28134. break;
  28135. }
  28136. glyphNameIndexes.push(index);
  28137. }
  28138. if (!valid) {
  28139. break;
  28140. }
  28141. var customNames = [];
  28142. var strBuf = [];
  28143. while (font.pos < end) {
  28144. var stringLength = font.getByte();
  28145. strBuf.length = stringLength;
  28146. for (i = 0; i < stringLength; ++i) {
  28147. strBuf[i] = String.fromCharCode(font.getByte());
  28148. }
  28149. customNames.push(strBuf.join(''));
  28150. }
  28151. glyphNames = [];
  28152. for (i = 0; i < numGlyphs; ++i) {
  28153. var j = glyphNameIndexes[i];
  28154. if (j < 258) {
  28155. glyphNames.push(MacStandardGlyphOrdering[j]);
  28156. continue;
  28157. }
  28158. glyphNames.push(customNames[j - 258]);
  28159. }
  28160. break;
  28161. case 0x00030000:
  28162. break;
  28163. default:
  28164. warn('Unknown/unsupported post table version ' + version);
  28165. valid = false;
  28166. if (properties.defaultEncoding) {
  28167. glyphNames = properties.defaultEncoding;
  28168. }
  28169. break;
  28170. }
  28171. properties.glyphNames = glyphNames;
  28172. return valid;
  28173. }
  28174. function readNameTable(nameTable) {
  28175. var start = (font.start ? font.start : 0) + nameTable.offset;
  28176. font.pos = start;
  28177. var names = [[], []];
  28178. var length = nameTable.length, end = start + length;
  28179. var format = font.getUint16();
  28180. var FORMAT_0_HEADER_LENGTH = 6;
  28181. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  28182. // unsupported name table format or table "too" small
  28183. return names;
  28184. }
  28185. var numRecords = font.getUint16();
  28186. var stringsStart = font.getUint16();
  28187. var records = [];
  28188. var NAME_RECORD_LENGTH = 12;
  28189. var i, ii;
  28190. for (i = 0; i < numRecords &&
  28191. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  28192. var r = {
  28193. platform: font.getUint16(),
  28194. encoding: font.getUint16(),
  28195. language: font.getUint16(),
  28196. name: font.getUint16(),
  28197. length: font.getUint16(),
  28198. offset: font.getUint16()
  28199. };
  28200. // using only Macintosh and Windows platform/encoding names
  28201. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  28202. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  28203. records.push(r);
  28204. }
  28205. }
  28206. for (i = 0, ii = records.length; i < ii; i++) {
  28207. var record = records[i];
  28208. if (record.length <= 0) {
  28209. continue; // Nothing to process, ignoring.
  28210. }
  28211. var pos = start + stringsStart + record.offset;
  28212. if (pos + record.length > end) {
  28213. continue; // outside of name table, ignoring
  28214. }
  28215. font.pos = pos;
  28216. var nameIndex = record.name;
  28217. if (record.encoding) {
  28218. // unicode
  28219. var str = '';
  28220. for (var j = 0, jj = record.length; j < jj; j += 2) {
  28221. str += String.fromCharCode(font.getUint16());
  28222. }
  28223. names[1][nameIndex] = str;
  28224. } else {
  28225. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  28226. }
  28227. }
  28228. return names;
  28229. }
  28230. var TTOpsStackDeltas = [
  28231. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  28232. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  28233. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  28234. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  28235. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  28236. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  28237. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  28238. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  28239. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  28240. // 0xC0-DF == -1 and 0xE0-FF == -2
  28241. function sanitizeTTProgram(table, ttContext) {
  28242. var data = table.data;
  28243. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  28244. var stack = [];
  28245. var callstack = [];
  28246. var functionsCalled = [];
  28247. var tooComplexToFollowFunctions =
  28248. ttContext.tooComplexToFollowFunctions;
  28249. var inFDEF = false, ifLevel = 0, inELSE = 0;
  28250. for (var ii = data.length; i < ii;) {
  28251. var op = data[i++];
  28252. // The TrueType instruction set docs can be found at
  28253. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  28254. if (op === 0x40) { // NPUSHB - pushes n bytes
  28255. n = data[i++];
  28256. if (inFDEF || inELSE) {
  28257. i += n;
  28258. } else {
  28259. for (j = 0; j < n; j++) {
  28260. stack.push(data[i++]);
  28261. }
  28262. }
  28263. } else if (op === 0x41) { // NPUSHW - pushes n words
  28264. n = data[i++];
  28265. if (inFDEF || inELSE) {
  28266. i += n * 2;
  28267. } else {
  28268. for (j = 0; j < n; j++) {
  28269. b = data[i++];
  28270. stack.push((b << 8) | data[i++]);
  28271. }
  28272. }
  28273. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  28274. n = op - 0xB0 + 1;
  28275. if (inFDEF || inELSE) {
  28276. i += n;
  28277. } else {
  28278. for (j = 0; j < n; j++) {
  28279. stack.push(data[i++]);
  28280. }
  28281. }
  28282. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  28283. n = op - 0xB8 + 1;
  28284. if (inFDEF || inELSE) {
  28285. i += n * 2;
  28286. } else {
  28287. for (j = 0; j < n; j++) {
  28288. b = data[i++];
  28289. stack.push((b << 8) | data[i++]);
  28290. }
  28291. }
  28292. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  28293. if (!inFDEF && !inELSE) {
  28294. // collecting inforamtion about which functions are used
  28295. funcId = stack[stack.length - 1];
  28296. ttContext.functionsUsed[funcId] = true;
  28297. if (funcId in ttContext.functionsStackDeltas) {
  28298. stack.length += ttContext.functionsStackDeltas[funcId];
  28299. } else if (funcId in ttContext.functionsDefined &&
  28300. functionsCalled.indexOf(funcId) < 0) {
  28301. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  28302. functionsCalled.push(funcId);
  28303. pc = ttContext.functionsDefined[funcId];
  28304. if (!pc) {
  28305. warn('TT: CALL non-existent function');
  28306. ttContext.hintsValid = false;
  28307. return;
  28308. }
  28309. data = pc.data;
  28310. i = pc.i;
  28311. }
  28312. }
  28313. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  28314. if (inFDEF || inELSE) {
  28315. warn('TT: nested FDEFs not allowed');
  28316. tooComplexToFollowFunctions = true;
  28317. }
  28318. inFDEF = true;
  28319. // collecting inforamtion about which functions are defined
  28320. lastDeff = i;
  28321. funcId = stack.pop();
  28322. ttContext.functionsDefined[funcId] = {data: data, i: i};
  28323. } else if (op === 0x2D) { // ENDF - end of function
  28324. if (inFDEF) {
  28325. inFDEF = false;
  28326. lastEndf = i;
  28327. } else {
  28328. pc = callstack.pop();
  28329. if (!pc) {
  28330. warn('TT: ENDF bad stack');
  28331. ttContext.hintsValid = false;
  28332. return;
  28333. }
  28334. funcId = functionsCalled.pop();
  28335. data = pc.data;
  28336. i = pc.i;
  28337. ttContext.functionsStackDeltas[funcId] =
  28338. stack.length - pc.stackTop;
  28339. }
  28340. } else if (op === 0x89) { // IDEF - instruction definition
  28341. if (inFDEF || inELSE) {
  28342. warn('TT: nested IDEFs not allowed');
  28343. tooComplexToFollowFunctions = true;
  28344. }
  28345. inFDEF = true;
  28346. // recording it as a function to track ENDF
  28347. lastDeff = i;
  28348. } else if (op === 0x58) { // IF
  28349. ++ifLevel;
  28350. } else if (op === 0x1B) { // ELSE
  28351. inELSE = ifLevel;
  28352. } else if (op === 0x59) { // EIF
  28353. if (inELSE === ifLevel) {
  28354. inELSE = 0;
  28355. }
  28356. --ifLevel;
  28357. } else if (op === 0x1C) { // JMPR
  28358. if (!inFDEF && !inELSE) {
  28359. var offset = stack[stack.length - 1];
  28360. // only jumping forward to prevent infinite loop
  28361. if (offset > 0) {
  28362. i += offset - 1;
  28363. }
  28364. }
  28365. }
  28366. // Adjusting stack not extactly, but just enough to get function id
  28367. if (!inFDEF && !inELSE) {
  28368. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  28369. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  28370. if (op >= 0x71 && op <= 0x75) {
  28371. n = stack.pop();
  28372. if (n === n) {
  28373. stackDelta = -n * 2;
  28374. }
  28375. }
  28376. while (stackDelta < 0 && stack.length > 0) {
  28377. stack.pop();
  28378. stackDelta++;
  28379. }
  28380. while (stackDelta > 0) {
  28381. stack.push(NaN); // pushing any number into stack
  28382. stackDelta--;
  28383. }
  28384. }
  28385. }
  28386. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  28387. var content = [data];
  28388. if (i > data.length) {
  28389. content.push(new Uint8Array(i - data.length));
  28390. }
  28391. if (lastDeff > lastEndf) {
  28392. warn('TT: complementing a missing function tail');
  28393. // new function definition started, but not finished
  28394. // complete function by [CLEAR, ENDF]
  28395. content.push(new Uint8Array([0x22, 0x2D]));
  28396. }
  28397. foldTTTable(table, content);
  28398. }
  28399. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  28400. if (ttContext.tooComplexToFollowFunctions) {
  28401. return;
  28402. }
  28403. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  28404. warn('TT: more functions defined than expected');
  28405. ttContext.hintsValid = false;
  28406. return;
  28407. }
  28408. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  28409. if (j > maxFunctionDefs) {
  28410. warn('TT: invalid function id: ' + j);
  28411. ttContext.hintsValid = false;
  28412. return;
  28413. }
  28414. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  28415. warn('TT: undefined function: ' + j);
  28416. ttContext.hintsValid = false;
  28417. return;
  28418. }
  28419. }
  28420. }
  28421. function foldTTTable(table, content) {
  28422. if (content.length > 1) {
  28423. // concatenating the content items
  28424. var newLength = 0;
  28425. var j, jj;
  28426. for (j = 0, jj = content.length; j < jj; j++) {
  28427. newLength += content[j].length;
  28428. }
  28429. newLength = (newLength + 3) & ~3;
  28430. var result = new Uint8Array(newLength);
  28431. var pos = 0;
  28432. for (j = 0, jj = content.length; j < jj; j++) {
  28433. result.set(content[j], pos);
  28434. pos += content[j].length;
  28435. }
  28436. table.data = result;
  28437. table.length = newLength;
  28438. }
  28439. }
  28440. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  28441. var ttContext = {
  28442. functionsDefined: [],
  28443. functionsUsed: [],
  28444. functionsStackDeltas: [],
  28445. tooComplexToFollowFunctions: false,
  28446. hintsValid: true
  28447. };
  28448. if (fpgm) {
  28449. sanitizeTTProgram(fpgm, ttContext);
  28450. }
  28451. if (prep) {
  28452. sanitizeTTProgram(prep, ttContext);
  28453. }
  28454. if (fpgm) {
  28455. checkInvalidFunctions(ttContext, maxFunctionDefs);
  28456. }
  28457. if (cvt && (cvt.length & 1)) {
  28458. var cvtData = new Uint8Array(cvt.length + 1);
  28459. cvtData.set(cvt.data);
  28460. cvt.data = cvtData;
  28461. }
  28462. return ttContext.hintsValid;
  28463. }
  28464. // The following steps modify the original font data, making copy
  28465. font = new Stream(new Uint8Array(font.getBytes()));
  28466. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  28467. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  28468. var header = readOpenTypeHeader(font);
  28469. var numTables = header.numTables;
  28470. var cff, cffFile;
  28471. var tables = Object.create(null);
  28472. tables['OS/2'] = null;
  28473. tables['cmap'] = null;
  28474. tables['head'] = null;
  28475. tables['hhea'] = null;
  28476. tables['hmtx'] = null;
  28477. tables['maxp'] = null;
  28478. tables['name'] = null;
  28479. tables['post'] = null;
  28480. var table;
  28481. for (var i = 0; i < numTables; i++) {
  28482. table = readTableEntry(font);
  28483. if (VALID_TABLES.indexOf(table.tag) < 0) {
  28484. continue; // skipping table if it's not a required or optional table
  28485. }
  28486. if (table.length === 0) {
  28487. continue; // skipping empty tables
  28488. }
  28489. tables[table.tag] = table;
  28490. }
  28491. var isTrueType = !tables['CFF '];
  28492. if (!isTrueType) {
  28493. // OpenType font
  28494. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  28495. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  28496. !tables['post']) {
  28497. // no major tables: throwing everything at CFFFont
  28498. cffFile = new Stream(tables['CFF '].data);
  28499. cff = new CFFFont(cffFile, properties);
  28500. adjustWidths(properties);
  28501. return this.convert(name, cff, properties);
  28502. }
  28503. delete tables['glyf'];
  28504. delete tables['loca'];
  28505. delete tables['fpgm'];
  28506. delete tables['prep'];
  28507. delete tables['cvt '];
  28508. this.isOpenType = true;
  28509. } else {
  28510. if (!tables['loca']) {
  28511. error('Required "loca" table is not found');
  28512. }
  28513. if (!tables['glyf']) {
  28514. warn('Required "glyf" table is not found -- trying to recover.');
  28515. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  28516. tables['glyf'] = {
  28517. tag: 'glyf',
  28518. data: new Uint8Array(0),
  28519. };
  28520. }
  28521. this.isOpenType = false;
  28522. }
  28523. if (!tables['maxp']) {
  28524. error('Required "maxp" table is not found');
  28525. }
  28526. font.pos = (font.start || 0) + tables['maxp'].offset;
  28527. var version = font.getInt32();
  28528. var numGlyphs = font.getUint16();
  28529. var maxFunctionDefs = 0;
  28530. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  28531. // maxZones can be invalid
  28532. font.pos += 8;
  28533. var maxZones = font.getUint16();
  28534. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  28535. tables['maxp'].data[14] = 0;
  28536. tables['maxp'].data[15] = 2;
  28537. }
  28538. font.pos += 4;
  28539. maxFunctionDefs = font.getUint16();
  28540. }
  28541. var dupFirstEntry = false;
  28542. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  28543. properties.toUnicode.get(0) > '\u0000') {
  28544. // oracle's defect (see 3427), duplicating first entry
  28545. dupFirstEntry = true;
  28546. numGlyphs++;
  28547. tables['maxp'].data[4] = numGlyphs >> 8;
  28548. tables['maxp'].data[5] = numGlyphs & 255;
  28549. }
  28550. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  28551. tables['cvt '], maxFunctionDefs);
  28552. if (!hintsValid) {
  28553. delete tables['fpgm'];
  28554. delete tables['prep'];
  28555. delete tables['cvt '];
  28556. }
  28557. // Ensure the hmtx table contains the advance width and
  28558. // sidebearings information for numGlyphs in the maxp table
  28559. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  28560. if (!tables['head']) {
  28561. error('Required "head" table is not found');
  28562. }
  28563. sanitizeHead(tables['head'], numGlyphs,
  28564. isTrueType ? tables['loca'].length : 0);
  28565. var missingGlyphs = Object.create(null);
  28566. if (isTrueType) {
  28567. var isGlyphLocationsLong = int16(tables['head'].data[50],
  28568. tables['head'].data[51]);
  28569. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  28570. numGlyphs, isGlyphLocationsLong,
  28571. hintsValid, dupFirstEntry);
  28572. }
  28573. if (!tables['hhea']) {
  28574. error('Required "hhea" table is not found');
  28575. }
  28576. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  28577. // Sometimes it's 0. That needs to be fixed
  28578. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  28579. tables['hhea'].data[10] = 0xFF;
  28580. tables['hhea'].data[11] = 0xFF;
  28581. }
  28582. // Extract some more font properties from the OpenType head and
  28583. // hhea tables; yMin and descent value are always negative.
  28584. var metricsOverride = {
  28585. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  28586. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  28587. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  28588. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  28589. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  28590. };
  28591. // PDF FontDescriptor metrics lie -- using data from actual font.
  28592. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  28593. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  28594. // The 'post' table has glyphs names.
  28595. if (tables['post']) {
  28596. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  28597. if (!valid) {
  28598. tables['post'] = null;
  28599. }
  28600. }
  28601. var charCodeToGlyphId = [], charCode;
  28602. var toUnicode = properties.toUnicode, widths = properties.widths;
  28603. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  28604. toUnicode.length === 0x10000);
  28605. // Helper function to try to skip mapping of empty glyphs.
  28606. // Note: In some cases, just relying on the glyph data doesn't work,
  28607. // hence we also use a few heuristics to fix various PDF files.
  28608. function hasGlyph(glyphId, charCode, widthCode) {
  28609. if (!missingGlyphs[glyphId]) {
  28610. return true;
  28611. }
  28612. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  28613. return true;
  28614. }
  28615. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  28616. return true;
  28617. }
  28618. return false;
  28619. }
  28620. if (properties.type === 'CIDFontType2') {
  28621. var cidToGidMap = properties.cidToGidMap || [];
  28622. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  28623. properties.cMap.forEach(function(charCode, cid) {
  28624. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  28625. var glyphId = -1;
  28626. if (isCidToGidMapEmpty) {
  28627. glyphId = cid;
  28628. } else if (cidToGidMap[cid] !== undefined) {
  28629. glyphId = cidToGidMap[cid];
  28630. }
  28631. if (glyphId >= 0 && glyphId < numGlyphs &&
  28632. hasGlyph(glyphId, charCode, cid)) {
  28633. charCodeToGlyphId[charCode] = glyphId;
  28634. }
  28635. });
  28636. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  28637. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  28638. // if the font has a `CIDToGIDMap` which has already mapped the first
  28639. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  28640. charCodeToGlyphId[0] = numGlyphs - 1;
  28641. }
  28642. } else {
  28643. // Most of the following logic in this code branch is based on the
  28644. // 9.6.6.4 of the PDF spec.
  28645. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
  28646. properties.hasEncoding);
  28647. var cmapPlatformId = cmapTable.platformId;
  28648. var cmapEncodingId = cmapTable.encodingId;
  28649. var cmapMappings = cmapTable.mappings;
  28650. var cmapMappingsLength = cmapMappings.length;
  28651. // The spec seems to imply that if the font is symbolic the encoding
  28652. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  28653. // where the the font is symbolic and it has an encoding.
  28654. if (properties.hasEncoding &&
  28655. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  28656. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  28657. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  28658. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  28659. // When no preferred cmap table was found and |baseEncodingName| is
  28660. // one of the predefined encodings, we seem to obtain a better
  28661. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  28662. // TODO: Note that this is a hack which should be removed as soon as
  28663. // we have proper support for more exotic cmap tables.
  28664. var baseEncoding = [];
  28665. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  28666. properties.baseEncodingName === 'WinAnsiEncoding') {
  28667. baseEncoding = getEncoding(properties.baseEncodingName);
  28668. }
  28669. var glyphsUnicodeMap = getGlyphsUnicode();
  28670. for (charCode = 0; charCode < 256; charCode++) {
  28671. var glyphName, standardGlyphName;
  28672. if (this.differences && charCode in this.differences) {
  28673. glyphName = this.differences[charCode];
  28674. } else if (charCode in baseEncoding &&
  28675. baseEncoding[charCode] !== '') {
  28676. glyphName = baseEncoding[charCode];
  28677. } else {
  28678. glyphName = StandardEncoding[charCode];
  28679. }
  28680. if (!glyphName) {
  28681. continue;
  28682. }
  28683. // Ensure that non-standard glyph names are resolved to valid ones.
  28684. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  28685. var unicodeOrCharCode, isUnicode = false;
  28686. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  28687. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  28688. isUnicode = true;
  28689. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  28690. // TODO: the encoding needs to be updated with mac os table.
  28691. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  28692. }
  28693. var found = false;
  28694. for (i = 0; i < cmapMappingsLength; ++i) {
  28695. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  28696. continue;
  28697. }
  28698. var code = isUnicode ? charCode : unicodeOrCharCode;
  28699. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  28700. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28701. found = true;
  28702. break;
  28703. }
  28704. }
  28705. if (!found && properties.glyphNames) {
  28706. // Try to map using the post table.
  28707. var glyphId = properties.glyphNames.indexOf(glyphName);
  28708. // The post table ought to use the same kind of glyph names as the
  28709. // `differences` array, but check the standard ones as a fallback.
  28710. if (glyphId === -1 && standardGlyphName !== glyphName) {
  28711. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  28712. }
  28713. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  28714. charCodeToGlyphId[charCode] = glyphId;
  28715. found = true;
  28716. }
  28717. }
  28718. if (!found) {
  28719. charCodeToGlyphId[charCode] = 0; // notdef
  28720. }
  28721. }
  28722. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  28723. // Default Unicode semantics, use the charcodes as is.
  28724. for (i = 0; i < cmapMappingsLength; ++i) {
  28725. charCodeToGlyphId[cmapMappings[i].charCode] =
  28726. cmapMappings[i].glyphId;
  28727. }
  28728. } else {
  28729. // For (3, 0) cmap tables:
  28730. // The charcode key being stored in charCodeToGlyphId is the lower
  28731. // byte of the two-byte charcodes of the cmap table since according to
  28732. // the spec: 'each byte from the string shall be prepended with the
  28733. // high byte of the range [of charcodes in the cmap table], to form
  28734. // a two-byte character, which shall be used to select the
  28735. // associated glyph description from the subtable'.
  28736. //
  28737. // For (1, 0) cmap tables:
  28738. // 'single bytes from the string shall be used to look up the
  28739. // associated glyph descriptions from the subtable'. This means
  28740. // charcodes in the cmap will be single bytes, so no-op since
  28741. // glyph.charCode & 0xFF === glyph.charCode
  28742. for (i = 0; i < cmapMappingsLength; ++i) {
  28743. charCode = cmapMappings[i].charCode & 0xFF;
  28744. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28745. }
  28746. }
  28747. }
  28748. if (charCodeToGlyphId.length === 0) {
  28749. // defines at least one glyph
  28750. charCodeToGlyphId[0] = 0;
  28751. }
  28752. // Converting glyphs and ids into font's cmap table
  28753. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  28754. this.toFontChar = newMapping.toFontChar;
  28755. tables['cmap'] = {
  28756. tag: 'cmap',
  28757. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  28758. };
  28759. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  28760. tables['OS/2'] = {
  28761. tag: 'OS/2',
  28762. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  28763. metricsOverride)
  28764. };
  28765. }
  28766. // Rewrite the 'post' table if needed
  28767. if (!tables['post']) {
  28768. tables['post'] = {
  28769. tag: 'post',
  28770. data: createPostTable(properties)
  28771. };
  28772. }
  28773. if (!isTrueType) {
  28774. try {
  28775. // Trying to repair CFF file
  28776. cffFile = new Stream(tables['CFF '].data);
  28777. var parser = new CFFParser(cffFile, properties,
  28778. SEAC_ANALYSIS_ENABLED);
  28779. cff = parser.parse();
  28780. var compiler = new CFFCompiler(cff);
  28781. tables['CFF '].data = compiler.compile();
  28782. } catch (e) {
  28783. warn('Failed to compile font ' + properties.loadedName);
  28784. }
  28785. }
  28786. // Re-creating 'name' table
  28787. if (!tables['name']) {
  28788. tables['name'] = {
  28789. tag: 'name',
  28790. data: createNameTable(this.name)
  28791. };
  28792. } else {
  28793. // ... using existing 'name' table as prototype
  28794. var namePrototype = readNameTable(tables['name']);
  28795. tables['name'].data = createNameTable(name, namePrototype);
  28796. }
  28797. var builder = new OpenTypeFileBuilder(header.version);
  28798. for (var tableTag in tables) {
  28799. builder.addTable(tableTag, tables[tableTag].data);
  28800. }
  28801. return builder.toArray();
  28802. },
  28803. convert: function Font_convert(fontName, font, properties) {
  28804. // TODO: Check the charstring widths to determine this.
  28805. properties.fixedPitch = false;
  28806. if (properties.builtInEncoding) {
  28807. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  28808. // data, attempt to use the `builtInEncoding` to improve text selection.
  28809. adjustToUnicode(properties, properties.builtInEncoding);
  28810. }
  28811. var mapping = font.getGlyphMapping(properties);
  28812. var newMapping = adjustMapping(mapping, properties);
  28813. this.toFontChar = newMapping.toFontChar;
  28814. var numGlyphs = font.numGlyphs;
  28815. function getCharCodes(charCodeToGlyphId, glyphId) {
  28816. var charCodes = null;
  28817. for (var charCode in charCodeToGlyphId) {
  28818. if (glyphId === charCodeToGlyphId[charCode]) {
  28819. if (!charCodes) {
  28820. charCodes = [];
  28821. }
  28822. charCodes.push(charCode | 0);
  28823. }
  28824. }
  28825. return charCodes;
  28826. }
  28827. function createCharCode(charCodeToGlyphId, glyphId) {
  28828. for (var charCode in charCodeToGlyphId) {
  28829. if (glyphId === charCodeToGlyphId[charCode]) {
  28830. return charCode | 0;
  28831. }
  28832. }
  28833. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  28834. glyphId;
  28835. return newMapping.nextAvailableFontCharCode++;
  28836. }
  28837. var seacs = font.seacs;
  28838. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  28839. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  28840. var charset = font.getCharset();
  28841. var seacMap = Object.create(null);
  28842. for (var glyphId in seacs) {
  28843. glyphId |= 0;
  28844. var seac = seacs[glyphId];
  28845. var baseGlyphName = StandardEncoding[seac[2]];
  28846. var accentGlyphName = StandardEncoding[seac[3]];
  28847. var baseGlyphId = charset.indexOf(baseGlyphName);
  28848. var accentGlyphId = charset.indexOf(accentGlyphName);
  28849. if (baseGlyphId < 0 || accentGlyphId < 0) {
  28850. continue;
  28851. }
  28852. var accentOffset = {
  28853. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  28854. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  28855. };
  28856. var charCodes = getCharCodes(mapping, glyphId);
  28857. if (!charCodes) {
  28858. // There's no point in mapping it if the char code was never mapped
  28859. // to begin with.
  28860. continue;
  28861. }
  28862. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  28863. var charCode = charCodes[i];
  28864. // Find a fontCharCode that maps to the base and accent glyphs.
  28865. // If one doesn't exists, create it.
  28866. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  28867. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  28868. baseGlyphId);
  28869. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  28870. accentGlyphId);
  28871. seacMap[charCode] = {
  28872. baseFontCharCode: baseFontCharCode,
  28873. accentFontCharCode: accentFontCharCode,
  28874. accentOffset: accentOffset
  28875. };
  28876. }
  28877. }
  28878. properties.seacMap = seacMap;
  28879. }
  28880. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  28881. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  28882. // PostScript Font Program
  28883. builder.addTable('CFF ', font.data);
  28884. // OS/2 and Windows Specific metrics
  28885. builder.addTable('OS/2', createOS2Table(properties,
  28886. newMapping.charCodeToGlyphId));
  28887. // Character to glyphs mapping
  28888. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  28889. numGlyphs));
  28890. // Font header
  28891. builder.addTable('head',
  28892. '\x00\x01\x00\x00' + // Version number
  28893. '\x00\x00\x10\x00' + // fontRevision
  28894. '\x00\x00\x00\x00' + // checksumAdjustement
  28895. '\x5F\x0F\x3C\xF5' + // magicNumber
  28896. '\x00\x00' + // Flags
  28897. safeString16(unitsPerEm) + // unitsPerEM
  28898. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  28899. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  28900. '\x00\x00' + // xMin
  28901. safeString16(properties.descent) + // yMin
  28902. '\x0F\xFF' + // xMax
  28903. safeString16(properties.ascent) + // yMax
  28904. string16(properties.italicAngle ? 2 : 0) + // macStyle
  28905. '\x00\x11' + // lowestRecPPEM
  28906. '\x00\x00' + // fontDirectionHint
  28907. '\x00\x00' + // indexToLocFormat
  28908. '\x00\x00'); // glyphDataFormat
  28909. // Horizontal header
  28910. builder.addTable('hhea',
  28911. '\x00\x01\x00\x00' + // Version number
  28912. safeString16(properties.ascent) + // Typographic Ascent
  28913. safeString16(properties.descent) + // Typographic Descent
  28914. '\x00\x00' + // Line Gap
  28915. '\xFF\xFF' + // advanceWidthMax
  28916. '\x00\x00' + // minLeftSidebearing
  28917. '\x00\x00' + // minRightSidebearing
  28918. '\x00\x00' + // xMaxExtent
  28919. safeString16(properties.capHeight) + // caretSlopeRise
  28920. safeString16(Math.tan(properties.italicAngle) *
  28921. properties.xHeight) + // caretSlopeRun
  28922. '\x00\x00' + // caretOffset
  28923. '\x00\x00' + // -reserved-
  28924. '\x00\x00' + // -reserved-
  28925. '\x00\x00' + // -reserved-
  28926. '\x00\x00' + // -reserved-
  28927. '\x00\x00' + // metricDataFormat
  28928. string16(numGlyphs)); // Number of HMetrics
  28929. // Horizontal metrics
  28930. builder.addTable('hmtx', (function fontFieldsHmtx() {
  28931. var charstrings = font.charstrings;
  28932. var cffWidths = font.cff ? font.cff.widths : null;
  28933. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  28934. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  28935. var width = 0;
  28936. if (charstrings) {
  28937. var charstring = charstrings[i - 1];
  28938. width = 'width' in charstring ? charstring.width : 0;
  28939. } else if (cffWidths) {
  28940. width = Math.ceil(cffWidths[i] || 0);
  28941. }
  28942. hmtx += string16(width) + string16(0);
  28943. }
  28944. return hmtx;
  28945. })());
  28946. // Maximum profile
  28947. builder.addTable('maxp',
  28948. '\x00\x00\x50\x00' + // Version number
  28949. string16(numGlyphs)); // Num of glyphs
  28950. // Naming tables
  28951. builder.addTable('name', createNameTable(fontName));
  28952. // PostScript information
  28953. builder.addTable('post', createPostTable(properties));
  28954. return builder.toArray();
  28955. },
  28956. get spaceWidth() {
  28957. if ('_shadowWidth' in this) {
  28958. return this._shadowWidth;
  28959. }
  28960. // trying to estimate space character width
  28961. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  28962. var width;
  28963. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  28964. var glyphName = possibleSpaceReplacements[i];
  28965. // if possible, getting width by glyph name
  28966. if (glyphName in this.widths) {
  28967. width = this.widths[glyphName];
  28968. break;
  28969. }
  28970. var glyphsUnicodeMap = getGlyphsUnicode();
  28971. var glyphUnicode = glyphsUnicodeMap[glyphName];
  28972. // finding the charcode via unicodeToCID map
  28973. var charcode = 0;
  28974. if (this.composite) {
  28975. if (this.cMap.contains(glyphUnicode)) {
  28976. charcode = this.cMap.lookup(glyphUnicode);
  28977. }
  28978. }
  28979. // ... via toUnicode map
  28980. if (!charcode && this.toUnicode) {
  28981. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  28982. }
  28983. // setting it to unicode if negative or undefined
  28984. if (charcode <= 0) {
  28985. charcode = glyphUnicode;
  28986. }
  28987. // trying to get width via charcode
  28988. width = this.widths[charcode];
  28989. if (width) {
  28990. break; // the non-zero width found
  28991. }
  28992. }
  28993. width = width || this.defaultWidth;
  28994. // Do not shadow the property here. See discussion:
  28995. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  28996. this._shadowWidth = width;
  28997. return width;
  28998. },
  28999. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  29000. var fontCharCode, width, operatorListId;
  29001. var widthCode = charcode;
  29002. if (this.cMap && this.cMap.contains(charcode)) {
  29003. widthCode = this.cMap.lookup(charcode);
  29004. }
  29005. width = this.widths[widthCode];
  29006. width = isNum(width) ? width : this.defaultWidth;
  29007. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  29008. var unicode = this.toUnicode.get(charcode) || charcode;
  29009. if (typeof unicode === 'number') {
  29010. unicode = String.fromCharCode(unicode);
  29011. }
  29012. var isInFont = charcode in this.toFontChar;
  29013. // First try the toFontChar map, if it's not there then try falling
  29014. // back to the char code.
  29015. fontCharCode = this.toFontChar[charcode] || charcode;
  29016. if (this.missingFile) {
  29017. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  29018. }
  29019. if (this.isType3Font) {
  29020. // Font char code in this case is actually a glyph name.
  29021. operatorListId = fontCharCode;
  29022. }
  29023. var accent = null;
  29024. if (this.seacMap && this.seacMap[charcode]) {
  29025. isInFont = true;
  29026. var seac = this.seacMap[charcode];
  29027. fontCharCode = seac.baseFontCharCode;
  29028. accent = {
  29029. fontChar: String.fromCharCode(seac.accentFontCharCode),
  29030. offset: seac.accentOffset
  29031. };
  29032. }
  29033. var fontChar = String.fromCharCode(fontCharCode);
  29034. var glyph = this.glyphCache[charcode];
  29035. if (!glyph ||
  29036. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  29037. operatorListId, isSpace, isInFont)) {
  29038. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  29039. operatorListId, isSpace, isInFont);
  29040. this.glyphCache[charcode] = glyph;
  29041. }
  29042. return glyph;
  29043. },
  29044. charsToGlyphs: function Font_charsToGlyphs(chars) {
  29045. var charsCache = this.charsCache;
  29046. var glyphs, glyph, charcode;
  29047. // if we translated this string before, just grab it from the cache
  29048. if (charsCache) {
  29049. glyphs = charsCache[chars];
  29050. if (glyphs) {
  29051. return glyphs;
  29052. }
  29053. }
  29054. // lazily create the translation cache
  29055. if (!charsCache) {
  29056. charsCache = this.charsCache = Object.create(null);
  29057. }
  29058. glyphs = [];
  29059. var charsCacheKey = chars;
  29060. var i = 0, ii;
  29061. if (this.cMap) {
  29062. // composite fonts have multi-byte strings convert the string from
  29063. // single-byte to multi-byte
  29064. var c = Object.create(null);
  29065. while (i < chars.length) {
  29066. this.cMap.readCharCode(chars, i, c);
  29067. charcode = c.charcode;
  29068. var length = c.length;
  29069. i += length;
  29070. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  29071. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  29072. glyph = this.charToGlyph(charcode, isSpace);
  29073. glyphs.push(glyph);
  29074. }
  29075. } else {
  29076. for (i = 0, ii = chars.length; i < ii; ++i) {
  29077. charcode = chars.charCodeAt(i);
  29078. glyph = this.charToGlyph(charcode, charcode === 0x20);
  29079. glyphs.push(glyph);
  29080. }
  29081. }
  29082. // Enter the translated string into the cache
  29083. return (charsCache[charsCacheKey] = glyphs);
  29084. }
  29085. };
  29086. return Font;
  29087. })();
  29088. var ErrorFont = (function ErrorFontClosure() {
  29089. function ErrorFont(error) {
  29090. this.error = error;
  29091. this.loadedName = 'g_font_error';
  29092. this.loading = false;
  29093. }
  29094. ErrorFont.prototype = {
  29095. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  29096. return [];
  29097. },
  29098. exportData: function ErrorFont_exportData() {
  29099. return {error: this.error};
  29100. }
  29101. };
  29102. return ErrorFont;
  29103. })();
  29104. /**
  29105. * Shared logic for building a char code to glyph id mapping for Type1 and
  29106. * simple CFF fonts. See section 9.6.6.2 of the spec.
  29107. * @param {Object} properties Font properties object.
  29108. * @param {Object} builtInEncoding The encoding contained within the actual font
  29109. * data.
  29110. * @param {Array} glyphNames Array of glyph names where the index is the
  29111. * glyph ID.
  29112. * @returns {Object} A char code to glyph ID map.
  29113. */
  29114. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  29115. var charCodeToGlyphId = Object.create(null);
  29116. var glyphId, charCode, baseEncoding;
  29117. if (properties.baseEncodingName) {
  29118. // If a valid base encoding name was used, the mapping is initialized with
  29119. // that.
  29120. baseEncoding = getEncoding(properties.baseEncodingName);
  29121. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29122. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29123. if (glyphId >= 0) {
  29124. charCodeToGlyphId[charCode] = glyphId;
  29125. } else {
  29126. charCodeToGlyphId[charCode] = 0; // notdef
  29127. }
  29128. }
  29129. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  29130. // For a symbolic font the encoding should be the fonts built-in
  29131. // encoding.
  29132. for (charCode in builtInEncoding) {
  29133. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  29134. }
  29135. } else {
  29136. // For non-symbolic fonts that don't have a base encoding the standard
  29137. // encoding should be used.
  29138. baseEncoding = StandardEncoding;
  29139. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  29140. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  29141. if (glyphId >= 0) {
  29142. charCodeToGlyphId[charCode] = glyphId;
  29143. } else {
  29144. charCodeToGlyphId[charCode] = 0; // notdef
  29145. }
  29146. }
  29147. }
  29148. // Lastly, merge in the differences.
  29149. var differences = properties.differences, glyphsUnicodeMap;
  29150. if (differences) {
  29151. for (charCode in differences) {
  29152. var glyphName = differences[charCode];
  29153. glyphId = glyphNames.indexOf(glyphName);
  29154. if (glyphId === -1) {
  29155. if (!glyphsUnicodeMap) {
  29156. glyphsUnicodeMap = getGlyphsUnicode();
  29157. }
  29158. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  29159. if (standardGlyphName !== glyphName) {
  29160. glyphId = glyphNames.indexOf(standardGlyphName);
  29161. }
  29162. }
  29163. if (glyphId >= 0) {
  29164. charCodeToGlyphId[charCode] = glyphId;
  29165. } else {
  29166. charCodeToGlyphId[charCode] = 0; // notdef
  29167. }
  29168. }
  29169. }
  29170. return charCodeToGlyphId;
  29171. }
  29172. // Type1Font is also a CIDFontType0.
  29173. var Type1Font = (function Type1FontClosure() {
  29174. function findBlock(streamBytes, signature, startIndex) {
  29175. var streamBytesLength = streamBytes.length;
  29176. var signatureLength = signature.length;
  29177. var scanLength = streamBytesLength - signatureLength;
  29178. var i = startIndex, j, found = false;
  29179. while (i < scanLength) {
  29180. j = 0;
  29181. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  29182. j++;
  29183. }
  29184. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  29185. i += j;
  29186. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  29187. i++;
  29188. }
  29189. found = true;
  29190. break;
  29191. }
  29192. i++;
  29193. }
  29194. return {
  29195. found: found,
  29196. length: i,
  29197. };
  29198. }
  29199. function getHeaderBlock(stream, suggestedLength) {
  29200. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  29201. var streamStartPos = stream.pos; // Save the initial stream position.
  29202. var headerBytes, headerBytesLength, block;
  29203. try {
  29204. headerBytes = stream.getBytes(suggestedLength);
  29205. headerBytesLength = headerBytes.length;
  29206. } catch (ex) {
  29207. if (ex instanceof MissingDataException) {
  29208. throw ex;
  29209. }
  29210. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  29211. // cannot hold the result of `getBytes`, and fallback to simply checking
  29212. // the entire stream (fixes issue3928.pdf).
  29213. }
  29214. if (headerBytesLength === suggestedLength) {
  29215. // Most of the time `suggestedLength` is correct, so to speed things up we
  29216. // initially only check the last few bytes to see if the header was found.
  29217. // Otherwise we (potentially) check the entire stream to prevent errors in
  29218. // `Type1Parser` (fixes issue5686.pdf).
  29219. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  29220. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  29221. if (block.found && block.length === suggestedLength) {
  29222. return {
  29223. stream: new Stream(headerBytes),
  29224. length: suggestedLength,
  29225. };
  29226. }
  29227. }
  29228. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  29229. stream.pos = streamStartPos; // Reset the stream position.
  29230. var SCAN_BLOCK_LENGTH = 2048;
  29231. var actualLength;
  29232. while (true) {
  29233. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  29234. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  29235. if (block.length === 0) {
  29236. break;
  29237. }
  29238. stream.pos += block.length; // Update the stream position.
  29239. if (block.found) {
  29240. actualLength = stream.pos - streamStartPos;
  29241. break;
  29242. }
  29243. }
  29244. stream.pos = streamStartPos; // Reset the stream position.
  29245. if (actualLength) {
  29246. return {
  29247. stream: new Stream(stream.getBytes(actualLength)),
  29248. length: actualLength,
  29249. };
  29250. }
  29251. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  29252. return {
  29253. stream: new Stream(stream.getBytes(suggestedLength)),
  29254. length: suggestedLength,
  29255. };
  29256. }
  29257. function getEexecBlock(stream, suggestedLength) {
  29258. // We should ideally parse the eexec block to ensure that `suggestedLength`
  29259. // is correct, so we don't truncate the block data if it's too small.
  29260. // However, this would also require checking if the fixed-content portion
  29261. // exists (using the 'Length3' property), and ensuring that it's valid.
  29262. //
  29263. // Given that `suggestedLength` almost always is correct, all the validation
  29264. // would require a great deal of unnecessary parsing for most fonts.
  29265. // To save time, we always fetch the entire stream instead, which also avoid
  29266. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  29267. //
  29268. // NOTE: This means that the function can include the fixed-content portion
  29269. // in the returned eexec block. In practice this does *not* seem to matter,
  29270. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  29271. var eexecBytes = stream.getBytes();
  29272. return {
  29273. stream: new Stream(eexecBytes),
  29274. length: eexecBytes.length,
  29275. };
  29276. }
  29277. function Type1Font(name, file, properties) {
  29278. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  29279. // Also, length1 and length2 might be off by 6 bytes as well.
  29280. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  29281. var PFB_HEADER_SIZE = 6;
  29282. var headerBlockLength = properties.length1;
  29283. var eexecBlockLength = properties.length2;
  29284. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  29285. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  29286. if (pfbHeaderPresent) {
  29287. file.skip(PFB_HEADER_SIZE);
  29288. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29289. (pfbHeader[3] << 8) | pfbHeader[2];
  29290. }
  29291. // Get the data block containing glyphs and subrs information
  29292. var headerBlock = getHeaderBlock(file, headerBlockLength);
  29293. headerBlockLength = headerBlock.length;
  29294. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  29295. SEAC_ANALYSIS_ENABLED);
  29296. headerBlockParser.extractFontHeader(properties);
  29297. if (pfbHeaderPresent) {
  29298. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  29299. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29300. (pfbHeader[3] << 8) | pfbHeader[2];
  29301. }
  29302. // Decrypt the data blocks and retrieve it's content
  29303. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  29304. eexecBlockLength = eexecBlock.length;
  29305. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  29306. SEAC_ANALYSIS_ENABLED);
  29307. var data = eexecBlockParser.extractFontProgram();
  29308. for (var info in data.properties) {
  29309. properties[info] = data.properties[info];
  29310. }
  29311. var charstrings = data.charstrings;
  29312. var type2Charstrings = this.getType2Charstrings(charstrings);
  29313. var subrs = this.getType2Subrs(data.subrs);
  29314. this.charstrings = charstrings;
  29315. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  29316. subrs, properties);
  29317. this.seacs = this.getSeacs(data.charstrings);
  29318. }
  29319. Type1Font.prototype = {
  29320. get numGlyphs() {
  29321. return this.charstrings.length + 1;
  29322. },
  29323. getCharset: function Type1Font_getCharset() {
  29324. var charset = ['.notdef'];
  29325. var charstrings = this.charstrings;
  29326. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29327. charset.push(charstrings[glyphId].glyphName);
  29328. }
  29329. return charset;
  29330. },
  29331. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  29332. var charstrings = this.charstrings;
  29333. var glyphNames = ['.notdef'], glyphId;
  29334. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29335. glyphNames.push(charstrings[glyphId].glyphName);
  29336. }
  29337. var encoding = properties.builtInEncoding;
  29338. if (encoding) {
  29339. var builtInEncoding = Object.create(null);
  29340. for (var charCode in encoding) {
  29341. glyphId = glyphNames.indexOf(encoding[charCode]);
  29342. if (glyphId >= 0) {
  29343. builtInEncoding[charCode] = glyphId;
  29344. }
  29345. }
  29346. }
  29347. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  29348. },
  29349. getSeacs: function Type1Font_getSeacs(charstrings) {
  29350. var i, ii;
  29351. var seacMap = [];
  29352. for (i = 0, ii = charstrings.length; i < ii; i++) {
  29353. var charstring = charstrings[i];
  29354. if (charstring.seac) {
  29355. // Offset by 1 for .notdef
  29356. seacMap[i + 1] = charstring.seac;
  29357. }
  29358. }
  29359. return seacMap;
  29360. },
  29361. getType2Charstrings: function Type1Font_getType2Charstrings(
  29362. type1Charstrings) {
  29363. var type2Charstrings = [];
  29364. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  29365. type2Charstrings.push(type1Charstrings[i].charstring);
  29366. }
  29367. return type2Charstrings;
  29368. },
  29369. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  29370. var bias = 0;
  29371. var count = type1Subrs.length;
  29372. if (count < 1133) {
  29373. bias = 107;
  29374. } else if (count < 33769) {
  29375. bias = 1131;
  29376. } else {
  29377. bias = 32768;
  29378. }
  29379. // Add a bunch of empty subrs to deal with the Type2 bias
  29380. var type2Subrs = [];
  29381. var i;
  29382. for (i = 0; i < bias; i++) {
  29383. type2Subrs.push([0x0B]);
  29384. }
  29385. for (i = 0; i < count; i++) {
  29386. type2Subrs.push(type1Subrs[i]);
  29387. }
  29388. return type2Subrs;
  29389. },
  29390. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  29391. properties) {
  29392. var cff = new CFF();
  29393. cff.header = new CFFHeader(1, 0, 4, 4);
  29394. cff.names = [name];
  29395. var topDict = new CFFTopDict();
  29396. // CFF strings IDs 0...390 are predefined names, so refering
  29397. // to entries in our own String INDEX starts at SID 391.
  29398. topDict.setByName('version', 391);
  29399. topDict.setByName('Notice', 392);
  29400. topDict.setByName('FullName', 393);
  29401. topDict.setByName('FamilyName', 394);
  29402. topDict.setByName('Weight', 395);
  29403. topDict.setByName('Encoding', null); // placeholder
  29404. topDict.setByName('FontMatrix', properties.fontMatrix);
  29405. topDict.setByName('FontBBox', properties.bbox);
  29406. topDict.setByName('charset', null); // placeholder
  29407. topDict.setByName('CharStrings', null); // placeholder
  29408. topDict.setByName('Private', null); // placeholder
  29409. cff.topDict = topDict;
  29410. var strings = new CFFStrings();
  29411. strings.add('Version 0.11'); // Version
  29412. strings.add('See original notice'); // Notice
  29413. strings.add(name); // FullName
  29414. strings.add(name); // FamilyName
  29415. strings.add('Medium'); // Weight
  29416. cff.strings = strings;
  29417. cff.globalSubrIndex = new CFFIndex();
  29418. var count = glyphs.length;
  29419. var charsetArray = [0];
  29420. var i, ii;
  29421. for (i = 0; i < count; i++) {
  29422. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  29423. // TODO: Insert the string and correctly map it. Previously it was
  29424. // thought mapping names that aren't in the standard strings to .notdef
  29425. // was fine, however in issue818 when mapping them all to .notdef the
  29426. // adieresis glyph no longer worked.
  29427. if (index === -1) {
  29428. index = 0;
  29429. }
  29430. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  29431. }
  29432. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  29433. var charStringsIndex = new CFFIndex();
  29434. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29435. for (i = 0; i < count; i++) {
  29436. var glyph = glyphs[i];
  29437. // If the CharString outline is empty, replace it with .notdef to
  29438. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  29439. if (glyph.length === 0) {
  29440. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29441. continue;
  29442. }
  29443. charStringsIndex.add(glyph);
  29444. }
  29445. cff.charStrings = charStringsIndex;
  29446. var privateDict = new CFFPrivateDict();
  29447. privateDict.setByName('Subrs', null); // placeholder
  29448. var fields = [
  29449. 'BlueValues',
  29450. 'OtherBlues',
  29451. 'FamilyBlues',
  29452. 'FamilyOtherBlues',
  29453. 'StemSnapH',
  29454. 'StemSnapV',
  29455. 'BlueShift',
  29456. 'BlueFuzz',
  29457. 'BlueScale',
  29458. 'LanguageGroup',
  29459. 'ExpansionFactor',
  29460. 'ForceBold',
  29461. 'StdHW',
  29462. 'StdVW'
  29463. ];
  29464. for (i = 0, ii = fields.length; i < ii; i++) {
  29465. var field = fields[i];
  29466. if (!(field in properties.privateData)) {
  29467. continue;
  29468. }
  29469. var value = properties.privateData[field];
  29470. if (isArray(value)) {
  29471. // All of the private dictionary array data in CFF must be stored as
  29472. // "delta-encoded" numbers.
  29473. for (var j = value.length - 1; j > 0; j--) {
  29474. value[j] -= value[j - 1]; // ... difference from previous value
  29475. }
  29476. }
  29477. privateDict.setByName(field, value);
  29478. }
  29479. cff.topDict.privateDict = privateDict;
  29480. var subrIndex = new CFFIndex();
  29481. for (i = 0, ii = subrs.length; i < ii; i++) {
  29482. subrIndex.add(subrs[i]);
  29483. }
  29484. privateDict.subrsIndex = subrIndex;
  29485. var compiler = new CFFCompiler(cff);
  29486. return compiler.compile();
  29487. }
  29488. };
  29489. return Type1Font;
  29490. })();
  29491. var CFFFont = (function CFFFontClosure() {
  29492. function CFFFont(file, properties) {
  29493. this.properties = properties;
  29494. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  29495. this.cff = parser.parse();
  29496. var compiler = new CFFCompiler(this.cff);
  29497. this.seacs = this.cff.seacs;
  29498. try {
  29499. this.data = compiler.compile();
  29500. } catch (e) {
  29501. warn('Failed to compile font ' + properties.loadedName);
  29502. // There may have just been an issue with the compiler, set the data
  29503. // anyway and hope the font loaded.
  29504. this.data = file;
  29505. }
  29506. }
  29507. CFFFont.prototype = {
  29508. get numGlyphs() {
  29509. return this.cff.charStrings.count;
  29510. },
  29511. getCharset: function CFFFont_getCharset() {
  29512. return this.cff.charset.charset;
  29513. },
  29514. getGlyphMapping: function CFFFont_getGlyphMapping() {
  29515. var cff = this.cff;
  29516. var properties = this.properties;
  29517. var charsets = cff.charset.charset;
  29518. var charCodeToGlyphId;
  29519. var glyphId;
  29520. if (properties.composite) {
  29521. charCodeToGlyphId = Object.create(null);
  29522. if (cff.isCIDFont) {
  29523. // If the font is actually a CID font then we should use the charset
  29524. // to map CIDs to GIDs.
  29525. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  29526. var cid = charsets[glyphId];
  29527. var charCode = properties.cMap.charCodeOf(cid);
  29528. charCodeToGlyphId[charCode] = glyphId;
  29529. }
  29530. } else {
  29531. // If it is NOT actually a CID font then CIDs should be mapped
  29532. // directly to GIDs.
  29533. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  29534. charCodeToGlyphId[glyphId] = glyphId;
  29535. }
  29536. }
  29537. return charCodeToGlyphId;
  29538. }
  29539. var encoding = cff.encoding ? cff.encoding.encoding : null;
  29540. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  29541. return charCodeToGlyphId;
  29542. }
  29543. };
  29544. return CFFFont;
  29545. })();
  29546. // Workaround for seac on Windows.
  29547. (function checkSeacSupport() {
  29548. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29549. SEAC_ANALYSIS_ENABLED = true;
  29550. }
  29551. })();
  29552. // Workaround for Private Use Area characters in Chrome on Windows
  29553. // http://code.google.com/p/chromium/issues/detail?id=122465
  29554. // https://github.com/mozilla/pdf.js/issues/1689
  29555. (function checkChromeWindows() {
  29556. if (typeof navigator !== 'undefined' &&
  29557. /Windows.*Chrome/.test(navigator.userAgent)) {
  29558. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29559. }
  29560. })();
  29561. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29562. exports.ErrorFont = ErrorFont;
  29563. exports.Font = Font;
  29564. exports.FontFlags = FontFlags;
  29565. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29566. exports.ToUnicodeMap = ToUnicodeMap;
  29567. exports.getFontType = getFontType;
  29568. }));
  29569. (function (root, factory) {
  29570. {
  29571. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29572. root.pdfjsCoreParser);
  29573. }
  29574. }(this, function (exports, sharedUtil, coreParser) {
  29575. var error = sharedUtil.error;
  29576. var isSpace = sharedUtil.isSpace;
  29577. var EOF = coreParser.EOF;
  29578. var PostScriptParser = (function PostScriptParserClosure() {
  29579. function PostScriptParser(lexer) {
  29580. this.lexer = lexer;
  29581. this.operators = [];
  29582. this.token = null;
  29583. this.prev = null;
  29584. }
  29585. PostScriptParser.prototype = {
  29586. nextToken: function PostScriptParser_nextToken() {
  29587. this.prev = this.token;
  29588. this.token = this.lexer.getToken();
  29589. },
  29590. accept: function PostScriptParser_accept(type) {
  29591. if (this.token.type === type) {
  29592. this.nextToken();
  29593. return true;
  29594. }
  29595. return false;
  29596. },
  29597. expect: function PostScriptParser_expect(type) {
  29598. if (this.accept(type)) {
  29599. return true;
  29600. }
  29601. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29602. type + '.');
  29603. },
  29604. parse: function PostScriptParser_parse() {
  29605. this.nextToken();
  29606. this.expect(PostScriptTokenTypes.LBRACE);
  29607. this.parseBlock();
  29608. this.expect(PostScriptTokenTypes.RBRACE);
  29609. return this.operators;
  29610. },
  29611. parseBlock: function PostScriptParser_parseBlock() {
  29612. while (true) {
  29613. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29614. this.operators.push(this.prev.value);
  29615. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29616. this.operators.push(this.prev.value);
  29617. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29618. this.parseCondition();
  29619. } else {
  29620. return;
  29621. }
  29622. }
  29623. },
  29624. parseCondition: function PostScriptParser_parseCondition() {
  29625. // Add two place holders that will be updated later
  29626. var conditionLocation = this.operators.length;
  29627. this.operators.push(null, null);
  29628. this.parseBlock();
  29629. this.expect(PostScriptTokenTypes.RBRACE);
  29630. if (this.accept(PostScriptTokenTypes.IF)) {
  29631. // The true block is right after the 'if' so it just falls through on
  29632. // true else it jumps and skips the true block.
  29633. this.operators[conditionLocation] = this.operators.length;
  29634. this.operators[conditionLocation + 1] = 'jz';
  29635. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29636. var jumpLocation = this.operators.length;
  29637. this.operators.push(null, null);
  29638. var endOfTrue = this.operators.length;
  29639. this.parseBlock();
  29640. this.expect(PostScriptTokenTypes.RBRACE);
  29641. this.expect(PostScriptTokenTypes.IFELSE);
  29642. // The jump is added at the end of the true block to skip the false
  29643. // block.
  29644. this.operators[jumpLocation] = this.operators.length;
  29645. this.operators[jumpLocation + 1] = 'j';
  29646. this.operators[conditionLocation] = endOfTrue;
  29647. this.operators[conditionLocation + 1] = 'jz';
  29648. } else {
  29649. error('PS Function: error parsing conditional.');
  29650. }
  29651. }
  29652. };
  29653. return PostScriptParser;
  29654. })();
  29655. var PostScriptTokenTypes = {
  29656. LBRACE: 0,
  29657. RBRACE: 1,
  29658. NUMBER: 2,
  29659. OPERATOR: 3,
  29660. IF: 4,
  29661. IFELSE: 5
  29662. };
  29663. var PostScriptToken = (function PostScriptTokenClosure() {
  29664. function PostScriptToken(type, value) {
  29665. this.type = type;
  29666. this.value = value;
  29667. }
  29668. var opCache = Object.create(null);
  29669. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29670. var opValue = opCache[op];
  29671. if (opValue) {
  29672. return opValue;
  29673. }
  29674. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29675. };
  29676. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29677. '{');
  29678. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29679. '}');
  29680. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29681. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29682. 'IFELSE');
  29683. return PostScriptToken;
  29684. })();
  29685. var PostScriptLexer = (function PostScriptLexerClosure() {
  29686. function PostScriptLexer(stream) {
  29687. this.stream = stream;
  29688. this.nextChar();
  29689. this.strBuf = [];
  29690. }
  29691. PostScriptLexer.prototype = {
  29692. nextChar: function PostScriptLexer_nextChar() {
  29693. return (this.currentChar = this.stream.getByte());
  29694. },
  29695. getToken: function PostScriptLexer_getToken() {
  29696. var comment = false;
  29697. var ch = this.currentChar;
  29698. // skip comments
  29699. while (true) {
  29700. if (ch < 0) {
  29701. return EOF;
  29702. }
  29703. if (comment) {
  29704. if (ch === 0x0A || ch === 0x0D) {
  29705. comment = false;
  29706. }
  29707. } else if (ch === 0x25) { // '%'
  29708. comment = true;
  29709. } else if (!isSpace(ch)) {
  29710. break;
  29711. }
  29712. ch = this.nextChar();
  29713. }
  29714. switch (ch | 0) {
  29715. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29716. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29717. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29718. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29719. this.getNumber());
  29720. case 0x7B: // '{'
  29721. this.nextChar();
  29722. return PostScriptToken.LBRACE;
  29723. case 0x7D: // '}'
  29724. this.nextChar();
  29725. return PostScriptToken.RBRACE;
  29726. }
  29727. // operator
  29728. var strBuf = this.strBuf;
  29729. strBuf.length = 0;
  29730. strBuf[0] = String.fromCharCode(ch);
  29731. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29732. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29733. strBuf.push(String.fromCharCode(ch));
  29734. }
  29735. var str = strBuf.join('');
  29736. switch (str.toLowerCase()) {
  29737. case 'if':
  29738. return PostScriptToken.IF;
  29739. case 'ifelse':
  29740. return PostScriptToken.IFELSE;
  29741. default:
  29742. return PostScriptToken.getOperator(str);
  29743. }
  29744. },
  29745. getNumber: function PostScriptLexer_getNumber() {
  29746. var ch = this.currentChar;
  29747. var strBuf = this.strBuf;
  29748. strBuf.length = 0;
  29749. strBuf[0] = String.fromCharCode(ch);
  29750. while ((ch = this.nextChar()) >= 0) {
  29751. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29752. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29753. strBuf.push(String.fromCharCode(ch));
  29754. } else {
  29755. break;
  29756. }
  29757. }
  29758. var value = parseFloat(strBuf.join(''));
  29759. if (isNaN(value)) {
  29760. error('Invalid floating point number: ' + value);
  29761. }
  29762. return value;
  29763. }
  29764. };
  29765. return PostScriptLexer;
  29766. })();
  29767. exports.PostScriptLexer = PostScriptLexer;
  29768. exports.PostScriptParser = PostScriptParser;
  29769. }));
  29770. (function (root, factory) {
  29771. {
  29772. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29773. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29774. }
  29775. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29776. var error = sharedUtil.error;
  29777. var info = sharedUtil.info;
  29778. var isArray = sharedUtil.isArray;
  29779. var isBool = sharedUtil.isBool;
  29780. var isDict = corePrimitives.isDict;
  29781. var isStream = corePrimitives.isStream;
  29782. var PostScriptLexer = corePsParser.PostScriptLexer;
  29783. var PostScriptParser = corePsParser.PostScriptParser;
  29784. var PDFFunction = (function PDFFunctionClosure() {
  29785. var CONSTRUCT_SAMPLED = 0;
  29786. var CONSTRUCT_INTERPOLATED = 2;
  29787. var CONSTRUCT_STICHED = 3;
  29788. var CONSTRUCT_POSTSCRIPT = 4;
  29789. return {
  29790. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29791. str) {
  29792. var i, ii;
  29793. var length = 1;
  29794. for (i = 0, ii = size.length; i < ii; i++) {
  29795. length *= size[i];
  29796. }
  29797. length *= outputSize;
  29798. var array = new Array(length);
  29799. var codeSize = 0;
  29800. var codeBuf = 0;
  29801. // 32 is a valid bps so shifting won't work
  29802. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29803. var strBytes = str.getBytes((length * bps + 7) / 8);
  29804. var strIdx = 0;
  29805. for (i = 0; i < length; i++) {
  29806. while (codeSize < bps) {
  29807. codeBuf <<= 8;
  29808. codeBuf |= strBytes[strIdx++];
  29809. codeSize += 8;
  29810. }
  29811. codeSize -= bps;
  29812. array[i] = (codeBuf >> codeSize) * sampleMul;
  29813. codeBuf &= (1 << codeSize) - 1;
  29814. }
  29815. return array;
  29816. },
  29817. getIR: function PDFFunction_getIR(xref, fn) {
  29818. var dict = fn.dict;
  29819. if (!dict) {
  29820. dict = fn;
  29821. }
  29822. var types = [this.constructSampled,
  29823. null,
  29824. this.constructInterpolated,
  29825. this.constructStiched,
  29826. this.constructPostScript];
  29827. var typeNum = dict.get('FunctionType');
  29828. var typeFn = types[typeNum];
  29829. if (!typeFn) {
  29830. error('Unknown type of function');
  29831. }
  29832. return typeFn.call(this, fn, dict, xref);
  29833. },
  29834. fromIR: function PDFFunction_fromIR(IR) {
  29835. var type = IR[0];
  29836. switch (type) {
  29837. case CONSTRUCT_SAMPLED:
  29838. return this.constructSampledFromIR(IR);
  29839. case CONSTRUCT_INTERPOLATED:
  29840. return this.constructInterpolatedFromIR(IR);
  29841. case CONSTRUCT_STICHED:
  29842. return this.constructStichedFromIR(IR);
  29843. //case CONSTRUCT_POSTSCRIPT:
  29844. default:
  29845. return this.constructPostScriptFromIR(IR);
  29846. }
  29847. },
  29848. parse: function PDFFunction_parse(xref, fn) {
  29849. var IR = this.getIR(xref, fn);
  29850. return this.fromIR(IR);
  29851. },
  29852. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29853. if (!isArray(fnObj)) {
  29854. // not an array -- parsing as regular function
  29855. return this.parse(xref, fnObj);
  29856. }
  29857. var fnArray = [];
  29858. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29859. var obj = xref.fetchIfRef(fnObj[j]);
  29860. fnArray.push(PDFFunction.parse(xref, obj));
  29861. }
  29862. return function (src, srcOffset, dest, destOffset) {
  29863. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29864. fnArray[i](src, srcOffset, dest, destOffset + i);
  29865. }
  29866. };
  29867. },
  29868. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29869. function toMultiArray(arr) {
  29870. var inputLength = arr.length;
  29871. var out = [];
  29872. var index = 0;
  29873. for (var i = 0; i < inputLength; i += 2) {
  29874. out[index] = [arr[i], arr[i + 1]];
  29875. ++index;
  29876. }
  29877. return out;
  29878. }
  29879. var domain = dict.getArray('Domain');
  29880. var range = dict.getArray('Range');
  29881. if (!domain || !range) {
  29882. error('No domain or range');
  29883. }
  29884. var inputSize = domain.length / 2;
  29885. var outputSize = range.length / 2;
  29886. domain = toMultiArray(domain);
  29887. range = toMultiArray(range);
  29888. var size = dict.get('Size');
  29889. var bps = dict.get('BitsPerSample');
  29890. var order = dict.get('Order') || 1;
  29891. if (order !== 1) {
  29892. // No description how cubic spline interpolation works in PDF32000:2008
  29893. // As in poppler, ignoring order, linear interpolation may work as good
  29894. info('No support for cubic spline interpolation: ' + order);
  29895. }
  29896. var encode = dict.getArray('Encode');
  29897. if (!encode) {
  29898. encode = [];
  29899. for (var i = 0; i < inputSize; ++i) {
  29900. encode.push(0);
  29901. encode.push(size[i] - 1);
  29902. }
  29903. }
  29904. encode = toMultiArray(encode);
  29905. var decode = dict.getArray('Decode');
  29906. if (!decode) {
  29907. decode = range;
  29908. } else {
  29909. decode = toMultiArray(decode);
  29910. }
  29911. var samples = this.getSampleArray(size, outputSize, bps, str);
  29912. return [
  29913. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  29914. outputSize, Math.pow(2, bps) - 1, range
  29915. ];
  29916. },
  29917. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  29918. // See chapter 3, page 109 of the PDF reference
  29919. function interpolate(x, xmin, xmax, ymin, ymax) {
  29920. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  29921. }
  29922. return function constructSampledFromIRResult(src, srcOffset,
  29923. dest, destOffset) {
  29924. // See chapter 3, page 110 of the PDF reference.
  29925. var m = IR[1];
  29926. var domain = IR[2];
  29927. var encode = IR[3];
  29928. var decode = IR[4];
  29929. var samples = IR[5];
  29930. var size = IR[6];
  29931. var n = IR[7];
  29932. //var mask = IR[8];
  29933. var range = IR[9];
  29934. // Building the cube vertices: its part and sample index
  29935. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  29936. var cubeVertices = 1 << m;
  29937. var cubeN = new Float64Array(cubeVertices);
  29938. var cubeVertex = new Uint32Array(cubeVertices);
  29939. var i, j;
  29940. for (j = 0; j < cubeVertices; j++) {
  29941. cubeN[j] = 1;
  29942. }
  29943. var k = n, pos = 1;
  29944. // Map x_i to y_j for 0 <= i < m using the sampled function.
  29945. for (i = 0; i < m; ++i) {
  29946. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  29947. var domain_2i = domain[i][0];
  29948. var domain_2i_1 = domain[i][1];
  29949. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  29950. domain_2i_1);
  29951. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  29952. // Encode_2i, Encode_2i+1)
  29953. var e = interpolate(xi, domain_2i, domain_2i_1,
  29954. encode[i][0], encode[i][1]);
  29955. // e_i' = min(max(e_i, 0), Size_i - 1)
  29956. var size_i = size[i];
  29957. e = Math.min(Math.max(e, 0), size_i - 1);
  29958. // Adjusting the cube: N and vertex sample index
  29959. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  29960. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  29961. var n1 = e - e0; // (e - e0) / (e1 - e0);
  29962. var offset0 = e0 * k;
  29963. var offset1 = offset0 + k; // e1 * k
  29964. for (j = 0; j < cubeVertices; j++) {
  29965. if (j & pos) {
  29966. cubeN[j] *= n1;
  29967. cubeVertex[j] += offset1;
  29968. } else {
  29969. cubeN[j] *= n0;
  29970. cubeVertex[j] += offset0;
  29971. }
  29972. }
  29973. k *= size_i;
  29974. pos <<= 1;
  29975. }
  29976. for (j = 0; j < n; ++j) {
  29977. // Sum all cube vertices' samples portions
  29978. var rj = 0;
  29979. for (i = 0; i < cubeVertices; i++) {
  29980. rj += samples[cubeVertex[i] + j] * cubeN[i];
  29981. }
  29982. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  29983. // Decode_2j, Decode_2j+1)
  29984. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  29985. // y_j = min(max(r_j, range_2j), range_2j+1)
  29986. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  29987. range[j][1]);
  29988. }
  29989. };
  29990. },
  29991. constructInterpolated: function PDFFunction_constructInterpolated(str,
  29992. dict) {
  29993. var c0 = dict.getArray('C0') || [0];
  29994. var c1 = dict.getArray('C1') || [1];
  29995. var n = dict.get('N');
  29996. if (!isArray(c0) || !isArray(c1)) {
  29997. error('Illegal dictionary for interpolated function');
  29998. }
  29999. var length = c0.length;
  30000. var diff = [];
  30001. for (var i = 0; i < length; ++i) {
  30002. diff.push(c1[i] - c0[i]);
  30003. }
  30004. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30005. },
  30006. constructInterpolatedFromIR:
  30007. function PDFFunction_constructInterpolatedFromIR(IR) {
  30008. var c0 = IR[1];
  30009. var diff = IR[2];
  30010. var n = IR[3];
  30011. var length = diff.length;
  30012. return function constructInterpolatedFromIRResult(src, srcOffset,
  30013. dest, destOffset) {
  30014. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30015. for (var j = 0; j < length; ++j) {
  30016. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30017. }
  30018. };
  30019. },
  30020. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30021. var domain = dict.getArray('Domain');
  30022. if (!domain) {
  30023. error('No domain');
  30024. }
  30025. var inputSize = domain.length / 2;
  30026. if (inputSize !== 1) {
  30027. error('Bad domain for stiched function');
  30028. }
  30029. var fnRefs = dict.get('Functions');
  30030. var fns = [];
  30031. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30032. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30033. }
  30034. var bounds = dict.getArray('Bounds');
  30035. var encode = dict.getArray('Encode');
  30036. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30037. },
  30038. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30039. var domain = IR[1];
  30040. var bounds = IR[2];
  30041. var encode = IR[3];
  30042. var fnsIR = IR[4];
  30043. var fns = [];
  30044. var tmpBuf = new Float32Array(1);
  30045. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30046. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30047. }
  30048. return function constructStichedFromIRResult(src, srcOffset,
  30049. dest, destOffset) {
  30050. var clip = function constructStichedFromIRClip(v, min, max) {
  30051. if (v > max) {
  30052. v = max;
  30053. } else if (v < min) {
  30054. v = min;
  30055. }
  30056. return v;
  30057. };
  30058. // clip to domain
  30059. var v = clip(src[srcOffset], domain[0], domain[1]);
  30060. // calculate which bound the value is in
  30061. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30062. if (v < bounds[i]) {
  30063. break;
  30064. }
  30065. }
  30066. // encode value into domain of function
  30067. var dmin = domain[0];
  30068. if (i > 0) {
  30069. dmin = bounds[i - 1];
  30070. }
  30071. var dmax = domain[1];
  30072. if (i < bounds.length) {
  30073. dmax = bounds[i];
  30074. }
  30075. var rmin = encode[2 * i];
  30076. var rmax = encode[2 * i + 1];
  30077. // Prevent the value from becoming NaN as a result
  30078. // of division by zero (fixes issue6113.pdf).
  30079. tmpBuf[0] = dmin === dmax ? rmin :
  30080. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30081. // call the appropriate function
  30082. fns[i](tmpBuf, 0, dest, destOffset);
  30083. };
  30084. },
  30085. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30086. xref) {
  30087. var domain = dict.getArray('Domain');
  30088. var range = dict.getArray('Range');
  30089. if (!domain) {
  30090. error('No domain.');
  30091. }
  30092. if (!range) {
  30093. error('No range.');
  30094. }
  30095. var lexer = new PostScriptLexer(fn);
  30096. var parser = new PostScriptParser(lexer);
  30097. var code = parser.parse();
  30098. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30099. },
  30100. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30101. IR) {
  30102. var domain = IR[1];
  30103. var range = IR[2];
  30104. var code = IR[3];
  30105. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30106. if (compiled) {
  30107. // Compiled function consists of simple expressions such as addition,
  30108. // subtraction, Math.max, and also contains 'var' and 'return'
  30109. // statements. See the generation in the PostScriptCompiler below.
  30110. /*jshint -W054 */
  30111. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30112. }
  30113. info('Unable to compile PS function');
  30114. var numOutputs = range.length >> 1;
  30115. var numInputs = domain.length >> 1;
  30116. var evaluator = new PostScriptEvaluator(code);
  30117. // Cache the values for a big speed up, the cache size is limited though
  30118. // since the number of possible values can be huge from a PS function.
  30119. var cache = Object.create(null);
  30120. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30121. // seen in our tests.
  30122. var MAX_CACHE_SIZE = 2048 * 4;
  30123. var cache_available = MAX_CACHE_SIZE;
  30124. var tmpBuf = new Float32Array(numInputs);
  30125. return function constructPostScriptFromIRResult(src, srcOffset,
  30126. dest, destOffset) {
  30127. var i, value;
  30128. var key = '';
  30129. var input = tmpBuf;
  30130. for (i = 0; i < numInputs; i++) {
  30131. value = src[srcOffset + i];
  30132. input[i] = value;
  30133. key += value + '_';
  30134. }
  30135. var cachedValue = cache[key];
  30136. if (cachedValue !== undefined) {
  30137. dest.set(cachedValue, destOffset);
  30138. return;
  30139. }
  30140. var output = new Float32Array(numOutputs);
  30141. var stack = evaluator.execute(input);
  30142. var stackIndex = stack.length - numOutputs;
  30143. for (i = 0; i < numOutputs; i++) {
  30144. value = stack[stackIndex + i];
  30145. var bound = range[i * 2];
  30146. if (value < bound) {
  30147. value = bound;
  30148. } else {
  30149. bound = range[i * 2 +1];
  30150. if (value > bound) {
  30151. value = bound;
  30152. }
  30153. }
  30154. output[i] = value;
  30155. }
  30156. if (cache_available > 0) {
  30157. cache_available--;
  30158. cache[key] = output;
  30159. }
  30160. dest.set(output, destOffset);
  30161. };
  30162. }
  30163. };
  30164. })();
  30165. function isPDFFunction(v) {
  30166. var fnDict;
  30167. if (typeof v !== 'object') {
  30168. return false;
  30169. } else if (isDict(v)) {
  30170. fnDict = v;
  30171. } else if (isStream(v)) {
  30172. fnDict = v.dict;
  30173. } else {
  30174. return false;
  30175. }
  30176. return fnDict.has('FunctionType');
  30177. }
  30178. var PostScriptStack = (function PostScriptStackClosure() {
  30179. var MAX_STACK_SIZE = 100;
  30180. function PostScriptStack(initialStack) {
  30181. this.stack = !initialStack ? [] :
  30182. Array.prototype.slice.call(initialStack, 0);
  30183. }
  30184. PostScriptStack.prototype = {
  30185. push: function PostScriptStack_push(value) {
  30186. if (this.stack.length >= MAX_STACK_SIZE) {
  30187. error('PostScript function stack overflow.');
  30188. }
  30189. this.stack.push(value);
  30190. },
  30191. pop: function PostScriptStack_pop() {
  30192. if (this.stack.length <= 0) {
  30193. error('PostScript function stack underflow.');
  30194. }
  30195. return this.stack.pop();
  30196. },
  30197. copy: function PostScriptStack_copy(n) {
  30198. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30199. error('PostScript function stack overflow.');
  30200. }
  30201. var stack = this.stack;
  30202. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30203. stack.push(stack[i]);
  30204. }
  30205. },
  30206. index: function PostScriptStack_index(n) {
  30207. this.push(this.stack[this.stack.length - n - 1]);
  30208. },
  30209. // rotate the last n stack elements p times
  30210. roll: function PostScriptStack_roll(n, p) {
  30211. var stack = this.stack;
  30212. var l = stack.length - n;
  30213. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30214. for (i = l, j = r; i < j; i++, j--) {
  30215. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30216. }
  30217. for (i = l, j = c - 1; i < j; i++, j--) {
  30218. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30219. }
  30220. for (i = c, j = r; i < j; i++, j--) {
  30221. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30222. }
  30223. }
  30224. };
  30225. return PostScriptStack;
  30226. })();
  30227. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30228. function PostScriptEvaluator(operators) {
  30229. this.operators = operators;
  30230. }
  30231. PostScriptEvaluator.prototype = {
  30232. execute: function PostScriptEvaluator_execute(initialStack) {
  30233. var stack = new PostScriptStack(initialStack);
  30234. var counter = 0;
  30235. var operators = this.operators;
  30236. var length = operators.length;
  30237. var operator, a, b;
  30238. while (counter < length) {
  30239. operator = operators[counter++];
  30240. if (typeof operator === 'number') {
  30241. // Operator is really an operand and should be pushed to the stack.
  30242. stack.push(operator);
  30243. continue;
  30244. }
  30245. switch (operator) {
  30246. // non standard ps operators
  30247. case 'jz': // jump if false
  30248. b = stack.pop();
  30249. a = stack.pop();
  30250. if (!a) {
  30251. counter = b;
  30252. }
  30253. break;
  30254. case 'j': // jump
  30255. a = stack.pop();
  30256. counter = a;
  30257. break;
  30258. // all ps operators in alphabetical order (excluding if/ifelse)
  30259. case 'abs':
  30260. a = stack.pop();
  30261. stack.push(Math.abs(a));
  30262. break;
  30263. case 'add':
  30264. b = stack.pop();
  30265. a = stack.pop();
  30266. stack.push(a + b);
  30267. break;
  30268. case 'and':
  30269. b = stack.pop();
  30270. a = stack.pop();
  30271. if (isBool(a) && isBool(b)) {
  30272. stack.push(a && b);
  30273. } else {
  30274. stack.push(a & b);
  30275. }
  30276. break;
  30277. case 'atan':
  30278. a = stack.pop();
  30279. stack.push(Math.atan(a));
  30280. break;
  30281. case 'bitshift':
  30282. b = stack.pop();
  30283. a = stack.pop();
  30284. if (a > 0) {
  30285. stack.push(a << b);
  30286. } else {
  30287. stack.push(a >> b);
  30288. }
  30289. break;
  30290. case 'ceiling':
  30291. a = stack.pop();
  30292. stack.push(Math.ceil(a));
  30293. break;
  30294. case 'copy':
  30295. a = stack.pop();
  30296. stack.copy(a);
  30297. break;
  30298. case 'cos':
  30299. a = stack.pop();
  30300. stack.push(Math.cos(a));
  30301. break;
  30302. case 'cvi':
  30303. a = stack.pop() | 0;
  30304. stack.push(a);
  30305. break;
  30306. case 'cvr':
  30307. // noop
  30308. break;
  30309. case 'div':
  30310. b = stack.pop();
  30311. a = stack.pop();
  30312. stack.push(a / b);
  30313. break;
  30314. case 'dup':
  30315. stack.copy(1);
  30316. break;
  30317. case 'eq':
  30318. b = stack.pop();
  30319. a = stack.pop();
  30320. stack.push(a === b);
  30321. break;
  30322. case 'exch':
  30323. stack.roll(2, 1);
  30324. break;
  30325. case 'exp':
  30326. b = stack.pop();
  30327. a = stack.pop();
  30328. stack.push(Math.pow(a, b));
  30329. break;
  30330. case 'false':
  30331. stack.push(false);
  30332. break;
  30333. case 'floor':
  30334. a = stack.pop();
  30335. stack.push(Math.floor(a));
  30336. break;
  30337. case 'ge':
  30338. b = stack.pop();
  30339. a = stack.pop();
  30340. stack.push(a >= b);
  30341. break;
  30342. case 'gt':
  30343. b = stack.pop();
  30344. a = stack.pop();
  30345. stack.push(a > b);
  30346. break;
  30347. case 'idiv':
  30348. b = stack.pop();
  30349. a = stack.pop();
  30350. stack.push((a / b) | 0);
  30351. break;
  30352. case 'index':
  30353. a = stack.pop();
  30354. stack.index(a);
  30355. break;
  30356. case 'le':
  30357. b = stack.pop();
  30358. a = stack.pop();
  30359. stack.push(a <= b);
  30360. break;
  30361. case 'ln':
  30362. a = stack.pop();
  30363. stack.push(Math.log(a));
  30364. break;
  30365. case 'log':
  30366. a = stack.pop();
  30367. stack.push(Math.log(a) / Math.LN10);
  30368. break;
  30369. case 'lt':
  30370. b = stack.pop();
  30371. a = stack.pop();
  30372. stack.push(a < b);
  30373. break;
  30374. case 'mod':
  30375. b = stack.pop();
  30376. a = stack.pop();
  30377. stack.push(a % b);
  30378. break;
  30379. case 'mul':
  30380. b = stack.pop();
  30381. a = stack.pop();
  30382. stack.push(a * b);
  30383. break;
  30384. case 'ne':
  30385. b = stack.pop();
  30386. a = stack.pop();
  30387. stack.push(a !== b);
  30388. break;
  30389. case 'neg':
  30390. a = stack.pop();
  30391. stack.push(-a);
  30392. break;
  30393. case 'not':
  30394. a = stack.pop();
  30395. if (isBool(a)) {
  30396. stack.push(!a);
  30397. } else {
  30398. stack.push(~a);
  30399. }
  30400. break;
  30401. case 'or':
  30402. b = stack.pop();
  30403. a = stack.pop();
  30404. if (isBool(a) && isBool(b)) {
  30405. stack.push(a || b);
  30406. } else {
  30407. stack.push(a | b);
  30408. }
  30409. break;
  30410. case 'pop':
  30411. stack.pop();
  30412. break;
  30413. case 'roll':
  30414. b = stack.pop();
  30415. a = stack.pop();
  30416. stack.roll(a, b);
  30417. break;
  30418. case 'round':
  30419. a = stack.pop();
  30420. stack.push(Math.round(a));
  30421. break;
  30422. case 'sin':
  30423. a = stack.pop();
  30424. stack.push(Math.sin(a));
  30425. break;
  30426. case 'sqrt':
  30427. a = stack.pop();
  30428. stack.push(Math.sqrt(a));
  30429. break;
  30430. case 'sub':
  30431. b = stack.pop();
  30432. a = stack.pop();
  30433. stack.push(a - b);
  30434. break;
  30435. case 'true':
  30436. stack.push(true);
  30437. break;
  30438. case 'truncate':
  30439. a = stack.pop();
  30440. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30441. stack.push(a);
  30442. break;
  30443. case 'xor':
  30444. b = stack.pop();
  30445. a = stack.pop();
  30446. if (isBool(a) && isBool(b)) {
  30447. stack.push(a !== b);
  30448. } else {
  30449. stack.push(a ^ b);
  30450. }
  30451. break;
  30452. default:
  30453. error('Unknown operator ' + operator);
  30454. break;
  30455. }
  30456. }
  30457. return stack.stack;
  30458. }
  30459. };
  30460. return PostScriptEvaluator;
  30461. })();
  30462. // Most of the PDFs functions consist of simple operations such as:
  30463. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30464. //
  30465. // We can compile most of such programs, and at the same moment, we can
  30466. // optimize some expressions using basic math properties. Keeping track of
  30467. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30468. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30469. function AstNode(type) {
  30470. this.type = type;
  30471. }
  30472. AstNode.prototype.visit = function (visitor) {
  30473. throw new Error('abstract method');
  30474. };
  30475. function AstArgument(index, min, max) {
  30476. AstNode.call(this, 'args');
  30477. this.index = index;
  30478. this.min = min;
  30479. this.max = max;
  30480. }
  30481. AstArgument.prototype = Object.create(AstNode.prototype);
  30482. AstArgument.prototype.visit = function (visitor) {
  30483. visitor.visitArgument(this);
  30484. };
  30485. function AstLiteral(number) {
  30486. AstNode.call(this, 'literal');
  30487. this.number = number;
  30488. this.min = number;
  30489. this.max = number;
  30490. }
  30491. AstLiteral.prototype = Object.create(AstNode.prototype);
  30492. AstLiteral.prototype.visit = function (visitor) {
  30493. visitor.visitLiteral(this);
  30494. };
  30495. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30496. AstNode.call(this, 'binary');
  30497. this.op = op;
  30498. this.arg1 = arg1;
  30499. this.arg2 = arg2;
  30500. this.min = min;
  30501. this.max = max;
  30502. }
  30503. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30504. AstBinaryOperation.prototype.visit = function (visitor) {
  30505. visitor.visitBinaryOperation(this);
  30506. };
  30507. function AstMin(arg, max) {
  30508. AstNode.call(this, 'max');
  30509. this.arg = arg;
  30510. this.min = arg.min;
  30511. this.max = max;
  30512. }
  30513. AstMin.prototype = Object.create(AstNode.prototype);
  30514. AstMin.prototype.visit = function (visitor) {
  30515. visitor.visitMin(this);
  30516. };
  30517. function AstVariable(index, min, max) {
  30518. AstNode.call(this, 'var');
  30519. this.index = index;
  30520. this.min = min;
  30521. this.max = max;
  30522. }
  30523. AstVariable.prototype = Object.create(AstNode.prototype);
  30524. AstVariable.prototype.visit = function (visitor) {
  30525. visitor.visitVariable(this);
  30526. };
  30527. function AstVariableDefinition(variable, arg) {
  30528. AstNode.call(this, 'definition');
  30529. this.variable = variable;
  30530. this.arg = arg;
  30531. }
  30532. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30533. AstVariableDefinition.prototype.visit = function (visitor) {
  30534. visitor.visitVariableDefinition(this);
  30535. };
  30536. function ExpressionBuilderVisitor() {
  30537. this.parts = [];
  30538. }
  30539. ExpressionBuilderVisitor.prototype = {
  30540. visitArgument: function (arg) {
  30541. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30542. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30543. },
  30544. visitVariable: function (variable) {
  30545. this.parts.push('v', variable.index);
  30546. },
  30547. visitLiteral: function (literal) {
  30548. this.parts.push(literal.number);
  30549. },
  30550. visitBinaryOperation: function (operation) {
  30551. this.parts.push('(');
  30552. operation.arg1.visit(this);
  30553. this.parts.push(' ', operation.op, ' ');
  30554. operation.arg2.visit(this);
  30555. this.parts.push(')');
  30556. },
  30557. visitVariableDefinition: function (definition) {
  30558. this.parts.push('var ');
  30559. definition.variable.visit(this);
  30560. this.parts.push(' = ');
  30561. definition.arg.visit(this);
  30562. this.parts.push(';');
  30563. },
  30564. visitMin: function (max) {
  30565. this.parts.push('Math.min(');
  30566. max.arg.visit(this);
  30567. this.parts.push(', ', max.max, ')');
  30568. },
  30569. toString: function () {
  30570. return this.parts.join('');
  30571. }
  30572. };
  30573. function buildAddOperation(num1, num2) {
  30574. if (num2.type === 'literal' && num2.number === 0) {
  30575. // optimization: second operand is 0
  30576. return num1;
  30577. }
  30578. if (num1.type === 'literal' && num1.number === 0) {
  30579. // optimization: first operand is 0
  30580. return num2;
  30581. }
  30582. if (num2.type === 'literal' && num1.type === 'literal') {
  30583. // optimization: operands operand are literals
  30584. return new AstLiteral(num1.number + num2.number);
  30585. }
  30586. return new AstBinaryOperation('+', num1, num2,
  30587. num1.min + num2.min, num1.max + num2.max);
  30588. }
  30589. function buildMulOperation(num1, num2) {
  30590. if (num2.type === 'literal') {
  30591. // optimization: second operands is a literal...
  30592. if (num2.number === 0) {
  30593. return new AstLiteral(0); // and it's 0
  30594. } else if (num2.number === 1) {
  30595. return num1; // and it's 1
  30596. } else if (num1.type === 'literal') {
  30597. // ... and first operands is a literal too
  30598. return new AstLiteral(num1.number * num2.number);
  30599. }
  30600. }
  30601. if (num1.type === 'literal') {
  30602. // optimization: first operands is a literal...
  30603. if (num1.number === 0) {
  30604. return new AstLiteral(0); // and it's 0
  30605. } else if (num1.number === 1) {
  30606. return num2; // and it's 1
  30607. }
  30608. }
  30609. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30610. num1.max * num2.min, num1.max * num2.max);
  30611. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30612. num1.max * num2.min, num1.max * num2.max);
  30613. return new AstBinaryOperation('*', num1, num2, min, max);
  30614. }
  30615. function buildSubOperation(num1, num2) {
  30616. if (num2.type === 'literal') {
  30617. // optimization: second operands is a literal...
  30618. if (num2.number === 0) {
  30619. return num1; // ... and it's 0
  30620. } else if (num1.type === 'literal') {
  30621. // ... and first operands is a literal too
  30622. return new AstLiteral(num1.number - num2.number);
  30623. }
  30624. }
  30625. if (num2.type === 'binary' && num2.op === '-' &&
  30626. num1.type === 'literal' && num1.number === 1 &&
  30627. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30628. // optimization for case: 1 - (1 - x)
  30629. return num2.arg2;
  30630. }
  30631. return new AstBinaryOperation('-', num1, num2,
  30632. num1.min - num2.max, num1.max - num2.min);
  30633. }
  30634. function buildMinOperation(num1, max) {
  30635. if (num1.min >= max) {
  30636. // optimization: num1 min value is not less than required max
  30637. return new AstLiteral(max); // just returning max
  30638. } else if (num1.max <= max) {
  30639. // optimization: num1 max value is not greater than required max
  30640. return num1; // just returning an argument
  30641. }
  30642. return new AstMin(num1, max);
  30643. }
  30644. function PostScriptCompiler() {}
  30645. PostScriptCompiler.prototype = {
  30646. compile: function PostScriptCompiler_compile(code, domain, range) {
  30647. var stack = [];
  30648. var i, ii;
  30649. var instructions = [];
  30650. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30651. var lastRegister = 0;
  30652. var n, j;
  30653. var num1, num2, ast1, ast2, tmpVar, item;
  30654. for (i = 0; i < inputSize; i++) {
  30655. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30656. }
  30657. for (i = 0, ii = code.length; i < ii; i++) {
  30658. item = code[i];
  30659. if (typeof item === 'number') {
  30660. stack.push(new AstLiteral(item));
  30661. continue;
  30662. }
  30663. switch (item) {
  30664. case 'add':
  30665. if (stack.length < 2) {
  30666. return null;
  30667. }
  30668. num2 = stack.pop();
  30669. num1 = stack.pop();
  30670. stack.push(buildAddOperation(num1, num2));
  30671. break;
  30672. case 'cvr':
  30673. if (stack.length < 1) {
  30674. return null;
  30675. }
  30676. break;
  30677. case 'mul':
  30678. if (stack.length < 2) {
  30679. return null;
  30680. }
  30681. num2 = stack.pop();
  30682. num1 = stack.pop();
  30683. stack.push(buildMulOperation(num1, num2));
  30684. break;
  30685. case 'sub':
  30686. if (stack.length < 2) {
  30687. return null;
  30688. }
  30689. num2 = stack.pop();
  30690. num1 = stack.pop();
  30691. stack.push(buildSubOperation(num1, num2));
  30692. break;
  30693. case 'exch':
  30694. if (stack.length < 2) {
  30695. return null;
  30696. }
  30697. ast1 = stack.pop(); ast2 = stack.pop();
  30698. stack.push(ast1, ast2);
  30699. break;
  30700. case 'pop':
  30701. if (stack.length < 1) {
  30702. return null;
  30703. }
  30704. stack.pop();
  30705. break;
  30706. case 'index':
  30707. if (stack.length < 1) {
  30708. return null;
  30709. }
  30710. num1 = stack.pop();
  30711. if (num1.type !== 'literal') {
  30712. return null;
  30713. }
  30714. n = num1.number;
  30715. if (n < 0 || (n|0) !== n || stack.length < n) {
  30716. return null;
  30717. }
  30718. ast1 = stack[stack.length - n - 1];
  30719. if (ast1.type === 'literal' || ast1.type === 'var') {
  30720. stack.push(ast1);
  30721. break;
  30722. }
  30723. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30724. stack[stack.length - n - 1] = tmpVar;
  30725. stack.push(tmpVar);
  30726. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30727. break;
  30728. case 'dup':
  30729. if (stack.length < 1) {
  30730. return null;
  30731. }
  30732. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30733. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30734. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30735. // special case of the commands sequence for the min operation
  30736. num1 = stack.pop();
  30737. stack.push(buildMinOperation(num1, code[i + 1]));
  30738. i += 6;
  30739. break;
  30740. }
  30741. ast1 = stack[stack.length - 1];
  30742. if (ast1.type === 'literal' || ast1.type === 'var') {
  30743. // we don't have to save into intermediate variable a literal or
  30744. // variable.
  30745. stack.push(ast1);
  30746. break;
  30747. }
  30748. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30749. stack[stack.length - 1] = tmpVar;
  30750. stack.push(tmpVar);
  30751. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30752. break;
  30753. case 'roll':
  30754. if (stack.length < 2) {
  30755. return null;
  30756. }
  30757. num2 = stack.pop();
  30758. num1 = stack.pop();
  30759. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30760. // both roll operands must be numbers
  30761. return null;
  30762. }
  30763. j = num2.number;
  30764. n = num1.number;
  30765. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30766. // ... and integers
  30767. return null;
  30768. }
  30769. j = ((j % n) + n) % n;
  30770. if (j === 0) {
  30771. break; // just skipping -- there are nothing to rotate
  30772. }
  30773. Array.prototype.push.apply(stack,
  30774. stack.splice(stack.length - n, n - j));
  30775. break;
  30776. default:
  30777. return null; // unsupported operator
  30778. }
  30779. }
  30780. if (stack.length !== outputSize) {
  30781. return null;
  30782. }
  30783. var result = [];
  30784. instructions.forEach(function (instruction) {
  30785. var statementBuilder = new ExpressionBuilderVisitor();
  30786. instruction.visit(statementBuilder);
  30787. result.push(statementBuilder.toString());
  30788. });
  30789. stack.forEach(function (expr, i) {
  30790. var statementBuilder = new ExpressionBuilderVisitor();
  30791. expr.visit(statementBuilder);
  30792. var min = range[i * 2], max = range[i * 2 + 1];
  30793. var out = [statementBuilder.toString()];
  30794. if (min > expr.min) {
  30795. out.unshift('Math.max(', min, ', ');
  30796. out.push(')');
  30797. }
  30798. if (max < expr.max) {
  30799. out.unshift('Math.min(', max, ', ');
  30800. out.push(')');
  30801. }
  30802. out.unshift('dest[destOffset + ', i, '] = ');
  30803. out.push(';');
  30804. result.push(out.join(''));
  30805. });
  30806. return result.join('\n');
  30807. }
  30808. };
  30809. return PostScriptCompiler;
  30810. })();
  30811. exports.isPDFFunction = isPDFFunction;
  30812. exports.PDFFunction = PDFFunction;
  30813. exports.PostScriptEvaluator = PostScriptEvaluator;
  30814. exports.PostScriptCompiler = PostScriptCompiler;
  30815. }));
  30816. (function (root, factory) {
  30817. {
  30818. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30819. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  30820. }
  30821. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  30822. var error = sharedUtil.error;
  30823. var info = sharedUtil.info;
  30824. var isArray = sharedUtil.isArray;
  30825. var isString = sharedUtil.isString;
  30826. var shadow = sharedUtil.shadow;
  30827. var warn = sharedUtil.warn;
  30828. var isDict = corePrimitives.isDict;
  30829. var isName = corePrimitives.isName;
  30830. var isStream = corePrimitives.isStream;
  30831. var PDFFunction = coreFunction.PDFFunction;
  30832. var ColorSpace = (function ColorSpaceClosure() {
  30833. /**
  30834. * Resizes an RGB image with 3 components.
  30835. * @param {TypedArray} src - The source buffer.
  30836. * @param {Number} bpc - Number of bits per component.
  30837. * @param {Number} w1 - Original width.
  30838. * @param {Number} h1 - Original height.
  30839. * @param {Number} w2 - New width.
  30840. * @param {Number} h2 - New height.
  30841. * @param {Number} alpha01 - Size reserved for the alpha channel.
  30842. * @param {TypedArray} dest - The destination buffer.
  30843. */
  30844. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  30845. var COMPONENTS = 3;
  30846. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  30847. var xRatio = w1 / w2;
  30848. var yRatio = h1 / h2;
  30849. var i, j, py, newIndex = 0, oldIndex;
  30850. var xScaled = new Uint16Array(w2);
  30851. var w1Scanline = w1 * COMPONENTS;
  30852. for (i = 0; i < w2; i++) {
  30853. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  30854. }
  30855. for (i = 0; i < h2; i++) {
  30856. py = Math.floor(i * yRatio) * w1Scanline;
  30857. for (j = 0; j < w2; j++) {
  30858. oldIndex = py + xScaled[j];
  30859. dest[newIndex++] = src[oldIndex++];
  30860. dest[newIndex++] = src[oldIndex++];
  30861. dest[newIndex++] = src[oldIndex++];
  30862. newIndex += alpha01;
  30863. }
  30864. }
  30865. }
  30866. // Constructor should define this.numComps, this.defaultColor, this.name
  30867. function ColorSpace() {
  30868. error('should not call ColorSpace constructor');
  30869. }
  30870. ColorSpace.prototype = {
  30871. /**
  30872. * Converts the color value to the RGB color. The color components are
  30873. * located in the src array starting from the srcOffset. Returns the array
  30874. * of the rgb components, each value ranging from [0,255].
  30875. */
  30876. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30877. var rgb = new Uint8Array(3);
  30878. this.getRgbItem(src, srcOffset, rgb, 0);
  30879. return rgb;
  30880. },
  30881. /**
  30882. * Converts the color value to the RGB color, similar to the getRgb method.
  30883. * The result placed into the dest array starting from the destOffset.
  30884. */
  30885. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  30886. dest, destOffset) {
  30887. error('Should not call ColorSpace.getRgbItem');
  30888. },
  30889. /**
  30890. * Converts the specified number of the color values to the RGB colors.
  30891. * The colors are located in the src array starting from the srcOffset.
  30892. * The result is placed into the dest array starting from the destOffset.
  30893. * The src array items shall be in [0,2^bits) range, the dest array items
  30894. * will be in [0,255] range. alpha01 indicates how many alpha components
  30895. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  30896. * array).
  30897. */
  30898. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  30899. dest, destOffset, bits,
  30900. alpha01) {
  30901. error('Should not call ColorSpace.getRgbBuffer');
  30902. },
  30903. /**
  30904. * Determines the number of bytes required to store the result of the
  30905. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  30906. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  30907. */
  30908. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  30909. alpha01) {
  30910. error('Should not call ColorSpace.getOutputLength');
  30911. },
  30912. /**
  30913. * Returns true if source data will be equal the result/output data.
  30914. */
  30915. isPassthrough: function ColorSpace_isPassthrough(bits) {
  30916. return false;
  30917. },
  30918. /**
  30919. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  30920. * how many alpha components there are in the dest array; it will be either
  30921. * 0 (RGB array) or 1 (RGBA array).
  30922. */
  30923. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  30924. originalHeight, width, height,
  30925. actualHeight, bpc, comps, alpha01) {
  30926. var count = originalWidth * originalHeight;
  30927. var rgbBuf = null;
  30928. var numComponentColors = 1 << bpc;
  30929. var needsResizing = originalHeight !== height || originalWidth !== width;
  30930. var i, ii;
  30931. if (this.isPassthrough(bpc)) {
  30932. rgbBuf = comps;
  30933. } else if (this.numComps === 1 && count > numComponentColors &&
  30934. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  30935. // Optimization: create a color map when there is just one component and
  30936. // we are converting more colors than the size of the color map. We
  30937. // don't build the map if the colorspace is gray or rgb since those
  30938. // methods are faster than building a map. This mainly offers big speed
  30939. // ups for indexed and alternate colorspaces.
  30940. //
  30941. // TODO it may be worth while to cache the color map. While running
  30942. // testing I never hit a cache so I will leave that out for now (perhaps
  30943. // we are reparsing colorspaces too much?).
  30944. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  30945. new Uint16Array(numComponentColors);
  30946. var key;
  30947. for (i = 0; i < numComponentColors; i++) {
  30948. allColors[i] = i;
  30949. }
  30950. var colorMap = new Uint8Array(numComponentColors * 3);
  30951. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  30952. /* alpha01 = */ 0);
  30953. var destPos, rgbPos;
  30954. if (!needsResizing) {
  30955. // Fill in the RGB values directly into |dest|.
  30956. destPos = 0;
  30957. for (i = 0; i < count; ++i) {
  30958. key = comps[i] * 3;
  30959. dest[destPos++] = colorMap[key];
  30960. dest[destPos++] = colorMap[key + 1];
  30961. dest[destPos++] = colorMap[key + 2];
  30962. destPos += alpha01;
  30963. }
  30964. } else {
  30965. rgbBuf = new Uint8Array(count * 3);
  30966. rgbPos = 0;
  30967. for (i = 0; i < count; ++i) {
  30968. key = comps[i] * 3;
  30969. rgbBuf[rgbPos++] = colorMap[key];
  30970. rgbBuf[rgbPos++] = colorMap[key + 1];
  30971. rgbBuf[rgbPos++] = colorMap[key + 2];
  30972. }
  30973. }
  30974. } else {
  30975. if (!needsResizing) {
  30976. // Fill in the RGB values directly into |dest|.
  30977. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  30978. alpha01);
  30979. } else {
  30980. rgbBuf = new Uint8Array(count * 3);
  30981. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  30982. /* alpha01 = */ 0);
  30983. }
  30984. }
  30985. if (rgbBuf) {
  30986. if (needsResizing) {
  30987. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight,
  30988. width, height, alpha01, dest);
  30989. } else {
  30990. rgbPos = 0;
  30991. destPos = 0;
  30992. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  30993. dest[destPos++] = rgbBuf[rgbPos++];
  30994. dest[destPos++] = rgbBuf[rgbPos++];
  30995. dest[destPos++] = rgbBuf[rgbPos++];
  30996. destPos += alpha01;
  30997. }
  30998. }
  30999. }
  31000. },
  31001. /**
  31002. * True if the colorspace has components in the default range of [0, 1].
  31003. * This should be true for all colorspaces except for lab color spaces
  31004. * which are [0,100], [-128, 127], [-128, 127].
  31005. */
  31006. usesZeroToOneRange: true
  31007. };
  31008. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31009. var IR = ColorSpace.parseToIR(cs, xref, res);
  31010. if (IR instanceof AlternateCS) {
  31011. return IR;
  31012. }
  31013. return ColorSpace.fromIR(IR);
  31014. };
  31015. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31016. var name = isArray(IR) ? IR[0] : IR;
  31017. var whitePoint, blackPoint, gamma;
  31018. switch (name) {
  31019. case 'DeviceGrayCS':
  31020. return this.singletons.gray;
  31021. case 'DeviceRgbCS':
  31022. return this.singletons.rgb;
  31023. case 'DeviceCmykCS':
  31024. return this.singletons.cmyk;
  31025. case 'CalGrayCS':
  31026. whitePoint = IR[1];
  31027. blackPoint = IR[2];
  31028. gamma = IR[3];
  31029. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31030. case 'CalRGBCS':
  31031. whitePoint = IR[1];
  31032. blackPoint = IR[2];
  31033. gamma = IR[3];
  31034. var matrix = IR[4];
  31035. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31036. case 'PatternCS':
  31037. var basePatternCS = IR[1];
  31038. if (basePatternCS) {
  31039. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31040. }
  31041. return new PatternCS(basePatternCS);
  31042. case 'IndexedCS':
  31043. var baseIndexedCS = IR[1];
  31044. var hiVal = IR[2];
  31045. var lookup = IR[3];
  31046. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31047. case 'AlternateCS':
  31048. var numComps = IR[1];
  31049. var alt = IR[2];
  31050. var tintFnIR = IR[3];
  31051. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31052. PDFFunction.fromIR(tintFnIR));
  31053. case 'LabCS':
  31054. whitePoint = IR[1];
  31055. blackPoint = IR[2];
  31056. var range = IR[3];
  31057. return new LabCS(whitePoint, blackPoint, range);
  31058. default:
  31059. error('Unknown name ' + name);
  31060. }
  31061. return null;
  31062. };
  31063. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31064. if (isName(cs)) {
  31065. var colorSpaces = res.get('ColorSpace');
  31066. if (isDict(colorSpaces)) {
  31067. var refcs = colorSpaces.get(cs.name);
  31068. if (refcs) {
  31069. cs = refcs;
  31070. }
  31071. }
  31072. }
  31073. cs = xref.fetchIfRef(cs);
  31074. var mode;
  31075. if (isName(cs)) {
  31076. mode = cs.name;
  31077. this.mode = mode;
  31078. switch (mode) {
  31079. case 'DeviceGray':
  31080. case 'G':
  31081. return 'DeviceGrayCS';
  31082. case 'DeviceRGB':
  31083. case 'RGB':
  31084. return 'DeviceRgbCS';
  31085. case 'DeviceCMYK':
  31086. case 'CMYK':
  31087. return 'DeviceCmykCS';
  31088. case 'Pattern':
  31089. return ['PatternCS', null];
  31090. default:
  31091. error('unrecognized colorspace ' + mode);
  31092. }
  31093. } else if (isArray(cs)) {
  31094. mode = xref.fetchIfRef(cs[0]).name;
  31095. this.mode = mode;
  31096. var numComps, params, alt, whitePoint, blackPoint, gamma;
  31097. switch (mode) {
  31098. case 'DeviceGray':
  31099. case 'G':
  31100. return 'DeviceGrayCS';
  31101. case 'DeviceRGB':
  31102. case 'RGB':
  31103. return 'DeviceRgbCS';
  31104. case 'DeviceCMYK':
  31105. case 'CMYK':
  31106. return 'DeviceCmykCS';
  31107. case 'CalGray':
  31108. params = xref.fetchIfRef(cs[1]);
  31109. whitePoint = params.getArray('WhitePoint');
  31110. blackPoint = params.getArray('BlackPoint');
  31111. gamma = params.get('Gamma');
  31112. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  31113. case 'CalRGB':
  31114. params = xref.fetchIfRef(cs[1]);
  31115. whitePoint = params.getArray('WhitePoint');
  31116. blackPoint = params.getArray('BlackPoint');
  31117. gamma = params.getArray('Gamma');
  31118. var matrix = params.getArray('Matrix');
  31119. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  31120. case 'ICCBased':
  31121. var stream = xref.fetchIfRef(cs[1]);
  31122. var dict = stream.dict;
  31123. numComps = dict.get('N');
  31124. alt = dict.get('Alternate');
  31125. if (alt) {
  31126. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31127. // Parse the /Alternate CS to ensure that the number of components
  31128. // are correct, and also (indirectly) that it is not a PatternCS.
  31129. var altCS = ColorSpace.fromIR(altIR);
  31130. if (altCS.numComps === numComps) {
  31131. return altIR;
  31132. }
  31133. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31134. }
  31135. if (numComps === 1) {
  31136. return 'DeviceGrayCS';
  31137. } else if (numComps === 3) {
  31138. return 'DeviceRgbCS';
  31139. } else if (numComps === 4) {
  31140. return 'DeviceCmykCS';
  31141. }
  31142. break;
  31143. case 'Pattern':
  31144. var basePatternCS = cs[1] || null;
  31145. if (basePatternCS) {
  31146. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31147. }
  31148. return ['PatternCS', basePatternCS];
  31149. case 'Indexed':
  31150. case 'I':
  31151. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31152. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31153. var lookup = xref.fetchIfRef(cs[3]);
  31154. if (isStream(lookup)) {
  31155. lookup = lookup.getBytes();
  31156. }
  31157. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31158. case 'Separation':
  31159. case 'DeviceN':
  31160. var name = xref.fetchIfRef(cs[1]);
  31161. numComps = 1;
  31162. if (isName(name)) {
  31163. numComps = 1;
  31164. } else if (isArray(name)) {
  31165. numComps = name.length;
  31166. }
  31167. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31168. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31169. return ['AlternateCS', numComps, alt, tintFnIR];
  31170. case 'Lab':
  31171. params = xref.fetchIfRef(cs[1]);
  31172. whitePoint = params.getArray('WhitePoint');
  31173. blackPoint = params.getArray('BlackPoint');
  31174. var range = params.getArray('Range');
  31175. return ['LabCS', whitePoint, blackPoint, range];
  31176. default:
  31177. error('unimplemented color space object "' + mode + '"');
  31178. }
  31179. } else {
  31180. error('unrecognized color space object: "' + cs + '"');
  31181. }
  31182. return null;
  31183. };
  31184. /**
  31185. * Checks if a decode map matches the default decode map for a color space.
  31186. * This handles the general decode maps where there are two values per
  31187. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31188. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31189. * slightly different.
  31190. * @param {Array} decode Decode map (usually from an image).
  31191. * @param {Number} n Number of components the color space has.
  31192. */
  31193. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31194. if (!isArray(decode)) {
  31195. return true;
  31196. }
  31197. if (n * 2 !== decode.length) {
  31198. warn('The decode map is not the correct length');
  31199. return true;
  31200. }
  31201. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31202. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31203. return false;
  31204. }
  31205. }
  31206. return true;
  31207. };
  31208. ColorSpace.singletons = {
  31209. get gray() {
  31210. return shadow(this, 'gray', new DeviceGrayCS());
  31211. },
  31212. get rgb() {
  31213. return shadow(this, 'rgb', new DeviceRgbCS());
  31214. },
  31215. get cmyk() {
  31216. return shadow(this, 'cmyk', new DeviceCmykCS());
  31217. }
  31218. };
  31219. return ColorSpace;
  31220. })();
  31221. /**
  31222. * Alternate color space handles both Separation and DeviceN color spaces. A
  31223. * Separation color space is actually just a DeviceN with one color component.
  31224. * Both color spaces use a tinting function to convert colors to a base color
  31225. * space.
  31226. */
  31227. var AlternateCS = (function AlternateCSClosure() {
  31228. function AlternateCS(numComps, base, tintFn) {
  31229. this.name = 'Alternate';
  31230. this.numComps = numComps;
  31231. this.defaultColor = new Float32Array(numComps);
  31232. for (var i = 0; i < numComps; ++i) {
  31233. this.defaultColor[i] = 1;
  31234. }
  31235. this.base = base;
  31236. this.tintFn = tintFn;
  31237. this.tmpBuf = new Float32Array(base.numComps);
  31238. }
  31239. AlternateCS.prototype = {
  31240. getRgb: ColorSpace.prototype.getRgb,
  31241. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31242. dest, destOffset) {
  31243. var tmpBuf = this.tmpBuf;
  31244. this.tintFn(src, srcOffset, tmpBuf, 0);
  31245. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31246. },
  31247. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31248. dest, destOffset, bits,
  31249. alpha01) {
  31250. var tintFn = this.tintFn;
  31251. var base = this.base;
  31252. var scale = 1 / ((1 << bits) - 1);
  31253. var baseNumComps = base.numComps;
  31254. var usesZeroToOneRange = base.usesZeroToOneRange;
  31255. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31256. alpha01 === 0;
  31257. var pos = isPassthrough ? destOffset : 0;
  31258. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31259. var numComps = this.numComps;
  31260. var scaled = new Float32Array(numComps);
  31261. var tinted = new Float32Array(baseNumComps);
  31262. var i, j;
  31263. if (usesZeroToOneRange) {
  31264. for (i = 0; i < count; i++) {
  31265. for (j = 0; j < numComps; j++) {
  31266. scaled[j] = src[srcOffset++] * scale;
  31267. }
  31268. tintFn(scaled, 0, tinted, 0);
  31269. for (j = 0; j < baseNumComps; j++) {
  31270. baseBuf[pos++] = tinted[j] * 255;
  31271. }
  31272. }
  31273. } else {
  31274. for (i = 0; i < count; i++) {
  31275. for (j = 0; j < numComps; j++) {
  31276. scaled[j] = src[srcOffset++] * scale;
  31277. }
  31278. tintFn(scaled, 0, tinted, 0);
  31279. base.getRgbItem(tinted, 0, baseBuf, pos);
  31280. pos += baseNumComps;
  31281. }
  31282. }
  31283. if (!isPassthrough) {
  31284. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31285. }
  31286. },
  31287. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31288. alpha01) {
  31289. return this.base.getOutputLength(inputLength *
  31290. this.base.numComps / this.numComps,
  31291. alpha01);
  31292. },
  31293. isPassthrough: ColorSpace.prototype.isPassthrough,
  31294. fillRgb: ColorSpace.prototype.fillRgb,
  31295. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31296. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31297. },
  31298. usesZeroToOneRange: true
  31299. };
  31300. return AlternateCS;
  31301. })();
  31302. var PatternCS = (function PatternCSClosure() {
  31303. function PatternCS(baseCS) {
  31304. this.name = 'Pattern';
  31305. this.base = baseCS;
  31306. }
  31307. PatternCS.prototype = {};
  31308. return PatternCS;
  31309. })();
  31310. var IndexedCS = (function IndexedCSClosure() {
  31311. function IndexedCS(base, highVal, lookup) {
  31312. this.name = 'Indexed';
  31313. this.numComps = 1;
  31314. this.defaultColor = new Uint8Array([0]);
  31315. this.base = base;
  31316. this.highVal = highVal;
  31317. var baseNumComps = base.numComps;
  31318. var length = baseNumComps * highVal;
  31319. var lookupArray;
  31320. if (isStream(lookup)) {
  31321. lookupArray = new Uint8Array(length);
  31322. var bytes = lookup.getBytes(length);
  31323. lookupArray.set(bytes);
  31324. } else if (isString(lookup)) {
  31325. lookupArray = new Uint8Array(length);
  31326. for (var i = 0; i < length; ++i) {
  31327. lookupArray[i] = lookup.charCodeAt(i);
  31328. }
  31329. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31330. lookupArray = lookup;
  31331. } else {
  31332. error('Unrecognized lookup table: ' + lookup);
  31333. }
  31334. this.lookup = lookupArray;
  31335. }
  31336. IndexedCS.prototype = {
  31337. getRgb: ColorSpace.prototype.getRgb,
  31338. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31339. dest, destOffset) {
  31340. var numComps = this.base.numComps;
  31341. var start = src[srcOffset] * numComps;
  31342. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31343. },
  31344. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31345. dest, destOffset, bits,
  31346. alpha01) {
  31347. var base = this.base;
  31348. var numComps = base.numComps;
  31349. var outputDelta = base.getOutputLength(numComps, alpha01);
  31350. var lookup = this.lookup;
  31351. for (var i = 0; i < count; ++i) {
  31352. var lookupPos = src[srcOffset++] * numComps;
  31353. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31354. destOffset += outputDelta;
  31355. }
  31356. },
  31357. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31358. return this.base.getOutputLength(inputLength * this.base.numComps,
  31359. alpha01);
  31360. },
  31361. isPassthrough: ColorSpace.prototype.isPassthrough,
  31362. fillRgb: ColorSpace.prototype.fillRgb,
  31363. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31364. // indexed color maps shouldn't be changed
  31365. return true;
  31366. },
  31367. usesZeroToOneRange: true
  31368. };
  31369. return IndexedCS;
  31370. })();
  31371. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31372. function DeviceGrayCS() {
  31373. this.name = 'DeviceGray';
  31374. this.numComps = 1;
  31375. this.defaultColor = new Float32Array([0]);
  31376. }
  31377. DeviceGrayCS.prototype = {
  31378. getRgb: ColorSpace.prototype.getRgb,
  31379. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31380. dest, destOffset) {
  31381. var c = (src[srcOffset] * 255) | 0;
  31382. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31383. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31384. },
  31385. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31386. dest, destOffset, bits,
  31387. alpha01) {
  31388. var scale = 255 / ((1 << bits) - 1);
  31389. var j = srcOffset, q = destOffset;
  31390. for (var i = 0; i < count; ++i) {
  31391. var c = (scale * src[j++]) | 0;
  31392. dest[q++] = c;
  31393. dest[q++] = c;
  31394. dest[q++] = c;
  31395. q += alpha01;
  31396. }
  31397. },
  31398. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31399. alpha01) {
  31400. return inputLength * (3 + alpha01);
  31401. },
  31402. isPassthrough: ColorSpace.prototype.isPassthrough,
  31403. fillRgb: ColorSpace.prototype.fillRgb,
  31404. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31405. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31406. },
  31407. usesZeroToOneRange: true
  31408. };
  31409. return DeviceGrayCS;
  31410. })();
  31411. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31412. function DeviceRgbCS() {
  31413. this.name = 'DeviceRGB';
  31414. this.numComps = 3;
  31415. this.defaultColor = new Float32Array([0, 0, 0]);
  31416. }
  31417. DeviceRgbCS.prototype = {
  31418. getRgb: ColorSpace.prototype.getRgb,
  31419. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31420. dest, destOffset) {
  31421. var r = (src[srcOffset] * 255) | 0;
  31422. var g = (src[srcOffset + 1] * 255) | 0;
  31423. var b = (src[srcOffset + 2] * 255) | 0;
  31424. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31425. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31426. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31427. },
  31428. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31429. dest, destOffset, bits,
  31430. alpha01) {
  31431. if (bits === 8 && alpha01 === 0) {
  31432. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31433. return;
  31434. }
  31435. var scale = 255 / ((1 << bits) - 1);
  31436. var j = srcOffset, q = destOffset;
  31437. for (var i = 0; i < count; ++i) {
  31438. dest[q++] = (scale * src[j++]) | 0;
  31439. dest[q++] = (scale * src[j++]) | 0;
  31440. dest[q++] = (scale * src[j++]) | 0;
  31441. q += alpha01;
  31442. }
  31443. },
  31444. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31445. alpha01) {
  31446. return (inputLength * (3 + alpha01) / 3) | 0;
  31447. },
  31448. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31449. return bits === 8;
  31450. },
  31451. fillRgb: ColorSpace.prototype.fillRgb,
  31452. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31453. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31454. },
  31455. usesZeroToOneRange: true
  31456. };
  31457. return DeviceRgbCS;
  31458. })();
  31459. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31460. // The coefficients below was found using numerical analysis: the method of
  31461. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31462. // where color_value is the tabular value from the table of sampled RGB colors
  31463. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31464. // CMYK color conversion using the estimation below:
  31465. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31466. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31467. var c = src[srcOffset + 0] * srcScale;
  31468. var m = src[srcOffset + 1] * srcScale;
  31469. var y = src[srcOffset + 2] * srcScale;
  31470. var k = src[srcOffset + 3] * srcScale;
  31471. var r =
  31472. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31473. 18.82290502165302 * y + 212.25662451639585 * k +
  31474. -285.2331026137004) +
  31475. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31476. -17.873870861415444 * k - 5.497006427196366) +
  31477. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31478. 17.5119270841813) +
  31479. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31480. var g =
  31481. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31482. 6.871425592049007 * y + 31.159100130055922 * k +
  31483. -79.2970844816548) +
  31484. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31485. 131.35250912493976 * k - 190.9453302588951) +
  31486. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31487. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31488. var b =
  31489. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31490. 30.89978309703729 * y - 0.23883238689178934 * k +
  31491. -14.183576799673286) +
  31492. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31493. 50.606957656360734 * k - 112.23884253719248) +
  31494. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31495. -193.58209356861505) +
  31496. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31497. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31498. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31499. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31500. }
  31501. function DeviceCmykCS() {
  31502. this.name = 'DeviceCMYK';
  31503. this.numComps = 4;
  31504. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31505. }
  31506. DeviceCmykCS.prototype = {
  31507. getRgb: ColorSpace.prototype.getRgb,
  31508. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31509. dest, destOffset) {
  31510. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31511. },
  31512. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31513. dest, destOffset, bits,
  31514. alpha01) {
  31515. var scale = 1 / ((1 << bits) - 1);
  31516. for (var i = 0; i < count; i++) {
  31517. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31518. srcOffset += 4;
  31519. destOffset += 3 + alpha01;
  31520. }
  31521. },
  31522. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31523. alpha01) {
  31524. return (inputLength / 4 * (3 + alpha01)) | 0;
  31525. },
  31526. isPassthrough: ColorSpace.prototype.isPassthrough,
  31527. fillRgb: ColorSpace.prototype.fillRgb,
  31528. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31529. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31530. },
  31531. usesZeroToOneRange: true
  31532. };
  31533. return DeviceCmykCS;
  31534. })();
  31535. //
  31536. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31537. //
  31538. var CalGrayCS = (function CalGrayCSClosure() {
  31539. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31540. this.name = 'CalGray';
  31541. this.numComps = 1;
  31542. this.defaultColor = new Float32Array([0]);
  31543. if (!whitePoint) {
  31544. error('WhitePoint missing - required for color space CalGray');
  31545. }
  31546. blackPoint = blackPoint || [0, 0, 0];
  31547. gamma = gamma || 1;
  31548. // Translate arguments to spec variables.
  31549. this.XW = whitePoint[0];
  31550. this.YW = whitePoint[1];
  31551. this.ZW = whitePoint[2];
  31552. this.XB = blackPoint[0];
  31553. this.YB = blackPoint[1];
  31554. this.ZB = blackPoint[2];
  31555. this.G = gamma;
  31556. // Validate variables as per spec.
  31557. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31558. error('Invalid WhitePoint components for ' + this.name +
  31559. ', no fallback available');
  31560. }
  31561. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31562. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31563. this.XB = this.YB = this.ZB = 0;
  31564. }
  31565. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31566. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31567. ', ZB: ' + this.ZB + ', only default values are supported.');
  31568. }
  31569. if (this.G < 1) {
  31570. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31571. ', falling back to default');
  31572. this.G = 1;
  31573. }
  31574. }
  31575. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31576. // A represents a gray component of a calibrated gray space.
  31577. // A <---> AG in the spec
  31578. var A = src[srcOffset] * scale;
  31579. var AG = Math.pow(A, cs.G);
  31580. // Computes L as per spec. ( = cs.YW * AG )
  31581. // Except if other than default BlackPoint values are used.
  31582. var L = cs.YW * AG;
  31583. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31584. // Convert values to rgb range [0, 255].
  31585. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31586. dest[destOffset] = val;
  31587. dest[destOffset + 1] = val;
  31588. dest[destOffset + 2] = val;
  31589. }
  31590. CalGrayCS.prototype = {
  31591. getRgb: ColorSpace.prototype.getRgb,
  31592. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31593. dest, destOffset) {
  31594. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31595. },
  31596. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31597. dest, destOffset, bits,
  31598. alpha01) {
  31599. var scale = 1 / ((1 << bits) - 1);
  31600. for (var i = 0; i < count; ++i) {
  31601. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31602. srcOffset += 1;
  31603. destOffset += 3 + alpha01;
  31604. }
  31605. },
  31606. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31607. return inputLength * (3 + alpha01);
  31608. },
  31609. isPassthrough: ColorSpace.prototype.isPassthrough,
  31610. fillRgb: ColorSpace.prototype.fillRgb,
  31611. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31612. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31613. },
  31614. usesZeroToOneRange: true
  31615. };
  31616. return CalGrayCS;
  31617. })();
  31618. //
  31619. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31620. //
  31621. var CalRGBCS = (function CalRGBCSClosure() {
  31622. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31623. // matrices.
  31624. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31625. 0.8951, 0.2664, -0.1614,
  31626. -0.7502, 1.7135, 0.0367,
  31627. 0.0389, -0.0685, 1.0296]);
  31628. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31629. 0.9869929, -0.1470543, 0.1599627,
  31630. 0.4323053, 0.5183603, 0.0492912,
  31631. -0.0085287, 0.0400428, 0.9684867]);
  31632. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31633. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31634. 3.2404542, -1.5371385, -0.4985314,
  31635. -0.9692660, 1.8760108, 0.0415560,
  31636. 0.0556434, -0.2040259, 1.0572252]);
  31637. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31638. var tempNormalizeMatrix = new Float32Array(3);
  31639. var tempConvertMatrix1 = new Float32Array(3);
  31640. var tempConvertMatrix2 = new Float32Array(3);
  31641. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31642. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31643. this.name = 'CalRGB';
  31644. this.numComps = 3;
  31645. this.defaultColor = new Float32Array(3);
  31646. if (!whitePoint) {
  31647. error('WhitePoint missing - required for color space CalRGB');
  31648. }
  31649. blackPoint = blackPoint || new Float32Array(3);
  31650. gamma = gamma || new Float32Array([1, 1, 1]);
  31651. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31652. // Translate arguments to spec variables.
  31653. var XW = whitePoint[0];
  31654. var YW = whitePoint[1];
  31655. var ZW = whitePoint[2];
  31656. this.whitePoint = whitePoint;
  31657. var XB = blackPoint[0];
  31658. var YB = blackPoint[1];
  31659. var ZB = blackPoint[2];
  31660. this.blackPoint = blackPoint;
  31661. this.GR = gamma[0];
  31662. this.GG = gamma[1];
  31663. this.GB = gamma[2];
  31664. this.MXA = matrix[0];
  31665. this.MYA = matrix[1];
  31666. this.MZA = matrix[2];
  31667. this.MXB = matrix[3];
  31668. this.MYB = matrix[4];
  31669. this.MZB = matrix[5];
  31670. this.MXC = matrix[6];
  31671. this.MYC = matrix[7];
  31672. this.MZC = matrix[8];
  31673. // Validate variables as per spec.
  31674. if (XW < 0 || ZW < 0 || YW !== 1) {
  31675. error('Invalid WhitePoint components for ' + this.name +
  31676. ', no fallback available');
  31677. }
  31678. if (XB < 0 || YB < 0 || ZB < 0) {
  31679. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31680. ', ' + ZB + '], falling back to default');
  31681. this.blackPoint = new Float32Array(3);
  31682. }
  31683. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31684. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31685. '] for ' + this.name + ', falling back to default');
  31686. this.GR = this.GG = this.GB = 1;
  31687. }
  31688. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31689. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31690. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31691. info('Invalid Matrix for ' + this.name + ' [' +
  31692. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31693. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31694. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31695. '], falling back to default');
  31696. this.MXA = this.MYB = this.MZC = 1;
  31697. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31698. }
  31699. }
  31700. function matrixProduct(a, b, result) {
  31701. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31702. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31703. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31704. }
  31705. function convertToFlat(sourceWhitePoint, LMS, result) {
  31706. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31707. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31708. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31709. }
  31710. function convertToD65(sourceWhitePoint, LMS, result) {
  31711. var D65X = 0.95047;
  31712. var D65Y = 1;
  31713. var D65Z = 1.08883;
  31714. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31715. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31716. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31717. }
  31718. function sRGBTransferFunction(color) {
  31719. // See http://en.wikipedia.org/wiki/SRGB.
  31720. if (color <= 0.0031308){
  31721. return adjustToRange(0, 1, 12.92 * color);
  31722. }
  31723. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31724. }
  31725. function adjustToRange(min, max, value) {
  31726. return Math.max(min, Math.min(max, value));
  31727. }
  31728. function decodeL(L) {
  31729. if (L < 0) {
  31730. return -decodeL(-L);
  31731. }
  31732. if (L > 8.0) {
  31733. return Math.pow(((L + 16) / 116), 3);
  31734. }
  31735. return L * DECODE_L_CONSTANT;
  31736. }
  31737. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31738. // In case the blackPoint is already the default blackPoint then there is
  31739. // no need to do compensation.
  31740. if (sourceBlackPoint[0] === 0 &&
  31741. sourceBlackPoint[1] === 0 &&
  31742. sourceBlackPoint[2] === 0) {
  31743. result[0] = XYZ_Flat[0];
  31744. result[1] = XYZ_Flat[1];
  31745. result[2] = XYZ_Flat[2];
  31746. return;
  31747. }
  31748. // For the blackPoint calculation details, please see
  31749. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31750. // AdobeBPC.pdf.
  31751. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31752. var zeroDecodeL = decodeL(0);
  31753. var X_DST = zeroDecodeL;
  31754. var X_SRC = decodeL(sourceBlackPoint[0]);
  31755. var Y_DST = zeroDecodeL;
  31756. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31757. var Z_DST = zeroDecodeL;
  31758. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31759. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31760. var X_Offset = 1 - X_Scale;
  31761. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31762. var Y_Offset = 1 - Y_Scale;
  31763. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31764. var Z_Offset = 1 - Z_Scale;
  31765. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31766. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31767. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31768. }
  31769. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31770. // In case the whitePoint is already flat then there is no need to do
  31771. // normalization.
  31772. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31773. result[0] = XYZ_In[0];
  31774. result[1] = XYZ_In[1];
  31775. result[2] = XYZ_In[2];
  31776. return;
  31777. }
  31778. var LMS = result;
  31779. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31780. var LMS_Flat = tempNormalizeMatrix;
  31781. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31782. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31783. }
  31784. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31785. var LMS = result;
  31786. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31787. var LMS_D65 = tempNormalizeMatrix;
  31788. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31789. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31790. }
  31791. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31792. // A, B and C represent a red, green and blue components of a calibrated
  31793. // rgb space.
  31794. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31795. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31796. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31797. // A <---> AGR in the spec
  31798. // B <---> BGG in the spec
  31799. // C <---> CGB in the spec
  31800. var AGR = Math.pow(A, cs.GR);
  31801. var BGG = Math.pow(B, cs.GG);
  31802. var CGB = Math.pow(C, cs.GB);
  31803. // Computes intermediate variables L, M, N as per spec.
  31804. // To decode X, Y, Z values map L, M, N directly to them.
  31805. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31806. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31807. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31808. // The following calculations are based on this document:
  31809. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31810. // AdobeBPC.pdf.
  31811. var XYZ = tempConvertMatrix1;
  31812. XYZ[0] = X;
  31813. XYZ[1] = Y;
  31814. XYZ[2] = Z;
  31815. var XYZ_Flat = tempConvertMatrix2;
  31816. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31817. var XYZ_Black = tempConvertMatrix1;
  31818. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31819. var XYZ_D65 = tempConvertMatrix2;
  31820. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31821. var SRGB = tempConvertMatrix1;
  31822. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31823. var sR = sRGBTransferFunction(SRGB[0]);
  31824. var sG = sRGBTransferFunction(SRGB[1]);
  31825. var sB = sRGBTransferFunction(SRGB[2]);
  31826. // Convert the values to rgb range [0, 255].
  31827. dest[destOffset] = Math.round(sR * 255);
  31828. dest[destOffset + 1] = Math.round(sG * 255);
  31829. dest[destOffset + 2] = Math.round(sB * 255);
  31830. }
  31831. CalRGBCS.prototype = {
  31832. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31833. var rgb = new Uint8Array(3);
  31834. this.getRgbItem(src, srcOffset, rgb, 0);
  31835. return rgb;
  31836. },
  31837. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31838. dest, destOffset) {
  31839. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31840. },
  31841. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31842. dest, destOffset, bits,
  31843. alpha01) {
  31844. var scale = 1 / ((1 << bits) - 1);
  31845. for (var i = 0; i < count; ++i) {
  31846. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31847. srcOffset += 3;
  31848. destOffset += 3 + alpha01;
  31849. }
  31850. },
  31851. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31852. return (inputLength * (3 + alpha01) / 3) | 0;
  31853. },
  31854. isPassthrough: ColorSpace.prototype.isPassthrough,
  31855. fillRgb: ColorSpace.prototype.fillRgb,
  31856. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31857. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31858. },
  31859. usesZeroToOneRange: true
  31860. };
  31861. return CalRGBCS;
  31862. })();
  31863. //
  31864. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31865. //
  31866. var LabCS = (function LabCSClosure() {
  31867. function LabCS(whitePoint, blackPoint, range) {
  31868. this.name = 'Lab';
  31869. this.numComps = 3;
  31870. this.defaultColor = new Float32Array([0, 0, 0]);
  31871. if (!whitePoint) {
  31872. error('WhitePoint missing - required for color space Lab');
  31873. }
  31874. blackPoint = blackPoint || [0, 0, 0];
  31875. range = range || [-100, 100, -100, 100];
  31876. // Translate args to spec variables
  31877. this.XW = whitePoint[0];
  31878. this.YW = whitePoint[1];
  31879. this.ZW = whitePoint[2];
  31880. this.amin = range[0];
  31881. this.amax = range[1];
  31882. this.bmin = range[2];
  31883. this.bmax = range[3];
  31884. // These are here just for completeness - the spec doesn't offer any
  31885. // formulas that use BlackPoint in Lab
  31886. this.XB = blackPoint[0];
  31887. this.YB = blackPoint[1];
  31888. this.ZB = blackPoint[2];
  31889. // Validate vars as per spec
  31890. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31891. error('Invalid WhitePoint components, no fallback available');
  31892. }
  31893. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31894. info('Invalid BlackPoint, falling back to default');
  31895. this.XB = this.YB = this.ZB = 0;
  31896. }
  31897. if (this.amin > this.amax || this.bmin > this.bmax) {
  31898. info('Invalid Range, falling back to defaults');
  31899. this.amin = -100;
  31900. this.amax = 100;
  31901. this.bmin = -100;
  31902. this.bmax = 100;
  31903. }
  31904. }
  31905. // Function g(x) from spec
  31906. function fn_g(x) {
  31907. if (x >= 6 / 29) {
  31908. return x * x * x;
  31909. } else {
  31910. return (108 / 841) * (x - 4 / 29);
  31911. }
  31912. }
  31913. function decode(value, high1, low2, high2) {
  31914. return low2 + (value) * (high2 - low2) / (high1);
  31915. }
  31916. // If decoding is needed maxVal should be 2^bits per component - 1.
  31917. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  31918. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  31919. // not the usual [0, 1]. If a command like setFillColor is used the src
  31920. // values will already be within the correct range. However, if we are
  31921. // converting an image we have to map the values to the correct range given
  31922. // above.
  31923. // Ls,as,bs <---> L*,a*,b* in the spec
  31924. var Ls = src[srcOffset];
  31925. var as = src[srcOffset + 1];
  31926. var bs = src[srcOffset + 2];
  31927. if (maxVal !== false) {
  31928. Ls = decode(Ls, maxVal, 0, 100);
  31929. as = decode(as, maxVal, cs.amin, cs.amax);
  31930. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  31931. }
  31932. // Adjust limits of 'as' and 'bs'
  31933. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  31934. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  31935. // Computes intermediate variables X,Y,Z as per spec
  31936. var M = (Ls + 16) / 116;
  31937. var L = M + (as / 500);
  31938. var N = M - (bs / 200);
  31939. var X = cs.XW * fn_g(L);
  31940. var Y = cs.YW * fn_g(M);
  31941. var Z = cs.ZW * fn_g(N);
  31942. var r, g, b;
  31943. // Using different conversions for D50 and D65 white points,
  31944. // per http://www.color.org/srgb.pdf
  31945. if (cs.ZW < 1) {
  31946. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  31947. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  31948. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  31949. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  31950. } else {
  31951. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  31952. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  31953. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  31954. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  31955. }
  31956. // clamp color values to [0,1] range then convert to [0,255] range.
  31957. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  31958. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  31959. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  31960. }
  31961. LabCS.prototype = {
  31962. getRgb: ColorSpace.prototype.getRgb,
  31963. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  31964. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  31965. },
  31966. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  31967. dest, destOffset, bits,
  31968. alpha01) {
  31969. var maxVal = (1 << bits) - 1;
  31970. for (var i = 0; i < count; i++) {
  31971. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  31972. srcOffset += 3;
  31973. destOffset += 3 + alpha01;
  31974. }
  31975. },
  31976. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  31977. return (inputLength * (3 + alpha01) / 3) | 0;
  31978. },
  31979. isPassthrough: ColorSpace.prototype.isPassthrough,
  31980. fillRgb: ColorSpace.prototype.fillRgb,
  31981. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  31982. // XXX: Decoding is handled with the lab conversion because of the strange
  31983. // ranges that are used.
  31984. return true;
  31985. },
  31986. usesZeroToOneRange: false
  31987. };
  31988. return LabCS;
  31989. })();
  31990. exports.ColorSpace = ColorSpace;
  31991. }));
  31992. (function (root, factory) {
  31993. {
  31994. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  31995. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  31996. root.pdfjsCoreJpx);
  31997. }
  31998. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  31999. coreStream, coreJpx) {
  32000. var ImageKind = sharedUtil.ImageKind;
  32001. var assert = sharedUtil.assert;
  32002. var error = sharedUtil.error;
  32003. var info = sharedUtil.info;
  32004. var isArray = sharedUtil.isArray;
  32005. var warn = sharedUtil.warn;
  32006. var Name = corePrimitives.Name;
  32007. var isStream = corePrimitives.isStream;
  32008. var ColorSpace = coreColorSpace.ColorSpace;
  32009. var DecodeStream = coreStream.DecodeStream;
  32010. var JpegStream = coreStream.JpegStream;
  32011. var JpxImage = coreJpx.JpxImage;
  32012. var PDFImage = (function PDFImageClosure() {
  32013. /**
  32014. * Decodes the image using native decoder if possible. Resolves the promise
  32015. * when the image data is ready.
  32016. */
  32017. function handleImageData(image, nativeDecoder) {
  32018. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  32019. return nativeDecoder.decode(image);
  32020. } else {
  32021. return Promise.resolve(image);
  32022. }
  32023. }
  32024. /**
  32025. * Decode and clamp a value. The formula is different from the spec because we
  32026. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32027. */
  32028. function decodeAndClamp(value, addend, coefficient, max) {
  32029. value = addend + value * coefficient;
  32030. // Clamp the value to the range
  32031. return (value < 0 ? 0 : (value > max ? max : value));
  32032. }
  32033. /**
  32034. * Resizes an image mask with 1 component.
  32035. * @param {TypedArray} src - The source buffer.
  32036. * @param {Number} bpc - Number of bits per component.
  32037. * @param {Number} w1 - Original width.
  32038. * @param {Number} h1 - Original height.
  32039. * @param {Number} w2 - New width.
  32040. * @param {Number} h2 - New height.
  32041. * @returns {TypedArray} The resized image mask buffer.
  32042. */
  32043. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  32044. var length = w2 * h2;
  32045. var dest = (bpc <= 8 ? new Uint8Array(length) :
  32046. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32047. var xRatio = w1 / w2;
  32048. var yRatio = h1 / h2;
  32049. var i, j, py, newIndex = 0, oldIndex;
  32050. var xScaled = new Uint16Array(w2);
  32051. var w1Scanline = w1;
  32052. for (i = 0; i < w2; i++) {
  32053. xScaled[i] = Math.floor(i * xRatio);
  32054. }
  32055. for (i = 0; i < h2; i++) {
  32056. py = Math.floor(i * yRatio) * w1Scanline;
  32057. for (j = 0; j < w2; j++) {
  32058. oldIndex = py + xScaled[j];
  32059. dest[newIndex++] = src[oldIndex];
  32060. }
  32061. }
  32062. return dest;
  32063. }
  32064. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32065. this.image = image;
  32066. var dict = image.dict;
  32067. if (dict.has('Filter')) {
  32068. var filter = dict.get('Filter').name;
  32069. if (filter === 'JPXDecode') {
  32070. var jpxImage = new JpxImage();
  32071. jpxImage.parseImageProperties(image.stream);
  32072. image.stream.reset();
  32073. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32074. image.numComps = jpxImage.componentsCount;
  32075. } else if (filter === 'JBIG2Decode') {
  32076. image.bitsPerComponent = 1;
  32077. image.numComps = 1;
  32078. }
  32079. }
  32080. // TODO cache rendered images?
  32081. this.width = dict.get('Width', 'W');
  32082. this.height = dict.get('Height', 'H');
  32083. if (this.width < 1 || this.height < 1) {
  32084. error('Invalid image width: ' + this.width + ' or height: ' +
  32085. this.height);
  32086. }
  32087. this.interpolate = dict.get('Interpolate', 'I') || false;
  32088. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32089. this.matte = dict.get('Matte') || false;
  32090. var bitsPerComponent = image.bitsPerComponent;
  32091. if (!bitsPerComponent) {
  32092. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32093. if (!bitsPerComponent) {
  32094. if (this.imageMask) {
  32095. bitsPerComponent = 1;
  32096. } else {
  32097. error('Bits per component missing in image: ' + this.imageMask);
  32098. }
  32099. }
  32100. }
  32101. this.bpc = bitsPerComponent;
  32102. if (!this.imageMask) {
  32103. var colorSpace = dict.get('ColorSpace', 'CS');
  32104. if (!colorSpace) {
  32105. info('JPX images (which do not require color spaces)');
  32106. switch (image.numComps) {
  32107. case 1:
  32108. colorSpace = Name.get('DeviceGray');
  32109. break;
  32110. case 3:
  32111. colorSpace = Name.get('DeviceRGB');
  32112. break;
  32113. case 4:
  32114. colorSpace = Name.get('DeviceCMYK');
  32115. break;
  32116. default:
  32117. error('JPX images with ' + this.numComps +
  32118. ' color components not supported.');
  32119. }
  32120. }
  32121. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32122. this.numComps = this.colorSpace.numComps;
  32123. }
  32124. this.decode = dict.getArray('Decode', 'D');
  32125. this.needsDecode = false;
  32126. if (this.decode &&
  32127. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32128. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32129. this.needsDecode = true;
  32130. // Do some preprocessing to avoid more math.
  32131. var max = (1 << bitsPerComponent) - 1;
  32132. this.decodeCoefficients = [];
  32133. this.decodeAddends = [];
  32134. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32135. var dmin = this.decode[i];
  32136. var dmax = this.decode[i + 1];
  32137. this.decodeCoefficients[j] = dmax - dmin;
  32138. this.decodeAddends[j] = max * dmin;
  32139. }
  32140. }
  32141. if (smask) {
  32142. this.smask = new PDFImage(xref, res, smask, false);
  32143. } else if (mask) {
  32144. if (isStream(mask)) {
  32145. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32146. if (!imageMask) {
  32147. warn('Ignoring /Mask in image without /ImageMask.');
  32148. } else {
  32149. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32150. }
  32151. } else {
  32152. // Color key mask (just an array).
  32153. this.mask = mask;
  32154. }
  32155. }
  32156. }
  32157. /**
  32158. * Handles processing of image data and returns the Promise that is resolved
  32159. * with a PDFImage when the image is ready to be used.
  32160. */
  32161. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32162. res, image, inline,
  32163. nativeDecoder) {
  32164. var imagePromise = handleImageData(image, nativeDecoder);
  32165. var smaskPromise;
  32166. var maskPromise;
  32167. var smask = image.dict.get('SMask');
  32168. var mask = image.dict.get('Mask');
  32169. if (smask) {
  32170. smaskPromise = handleImageData(smask, nativeDecoder);
  32171. maskPromise = Promise.resolve(null);
  32172. } else {
  32173. smaskPromise = Promise.resolve(null);
  32174. if (mask) {
  32175. if (isStream(mask)) {
  32176. maskPromise = handleImageData(mask, nativeDecoder);
  32177. } else if (isArray(mask)) {
  32178. maskPromise = Promise.resolve(mask);
  32179. } else {
  32180. warn('Unsupported mask format.');
  32181. maskPromise = Promise.resolve(null);
  32182. }
  32183. } else {
  32184. maskPromise = Promise.resolve(null);
  32185. }
  32186. }
  32187. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32188. function(results) {
  32189. var imageData = results[0];
  32190. var smaskData = results[1];
  32191. var maskData = results[2];
  32192. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32193. });
  32194. };
  32195. PDFImage.createMask =
  32196. function PDFImage_createMask(imgArray, width, height,
  32197. imageIsFromDecodeStream, inverseDecode) {
  32198. // |imgArray| might not contain full data for every pixel of the mask, so
  32199. // we need to distinguish between |computedLength| and |actualLength|.
  32200. // In particular, if inverseDecode is true, then the array we return must
  32201. // have a length of |computedLength|.
  32202. var computedLength = ((width + 7) >> 3) * height;
  32203. var actualLength = imgArray.byteLength;
  32204. var haveFullData = computedLength === actualLength;
  32205. var data, i;
  32206. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32207. // imgArray came from a DecodeStream and its data is in an appropriate
  32208. // form, so we can just transfer it.
  32209. data = imgArray;
  32210. } else if (!inverseDecode) {
  32211. data = new Uint8Array(actualLength);
  32212. data.set(imgArray);
  32213. } else {
  32214. data = new Uint8Array(computedLength);
  32215. data.set(imgArray);
  32216. for (i = actualLength; i < computedLength; i++) {
  32217. data[i] = 0xff;
  32218. }
  32219. }
  32220. // If necessary, invert the original mask data (but not any extra we might
  32221. // have added above). It's safe to modify the array -- whether it's the
  32222. // original or a copy, we're about to transfer it anyway, so nothing else
  32223. // in this thread can be relying on its contents.
  32224. if (inverseDecode) {
  32225. for (i = 0; i < actualLength; i++) {
  32226. data[i] = ~data[i];
  32227. }
  32228. }
  32229. return {data: data, width: width, height: height};
  32230. };
  32231. PDFImage.prototype = {
  32232. get drawWidth() {
  32233. return Math.max(this.width,
  32234. this.smask && this.smask.width || 0,
  32235. this.mask && this.mask.width || 0);
  32236. },
  32237. get drawHeight() {
  32238. return Math.max(this.height,
  32239. this.smask && this.smask.height || 0,
  32240. this.mask && this.mask.height || 0);
  32241. },
  32242. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32243. var bpc = this.bpc;
  32244. var numComps = this.numComps;
  32245. var decodeAddends = this.decodeAddends;
  32246. var decodeCoefficients = this.decodeCoefficients;
  32247. var max = (1 << bpc) - 1;
  32248. var i, ii;
  32249. if (bpc === 1) {
  32250. // If the buffer needed decode that means it just needs to be inverted.
  32251. for (i = 0, ii = buffer.length; i < ii; i++) {
  32252. buffer[i] = +!(buffer[i]);
  32253. }
  32254. return;
  32255. }
  32256. var index = 0;
  32257. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32258. for (var j = 0; j < numComps; j++) {
  32259. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32260. decodeCoefficients[j], max);
  32261. index++;
  32262. }
  32263. }
  32264. },
  32265. getComponents: function PDFImage_getComponents(buffer) {
  32266. var bpc = this.bpc;
  32267. // This image doesn't require any extra work.
  32268. if (bpc === 8) {
  32269. return buffer;
  32270. }
  32271. var width = this.width;
  32272. var height = this.height;
  32273. var numComps = this.numComps;
  32274. var length = width * height * numComps;
  32275. var bufferPos = 0;
  32276. var output = (bpc <= 8 ? new Uint8Array(length) :
  32277. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32278. var rowComps = width * numComps;
  32279. var max = (1 << bpc) - 1;
  32280. var i = 0, ii, buf;
  32281. if (bpc === 1) {
  32282. // Optimization for reading 1 bpc images.
  32283. var mask, loop1End, loop2End;
  32284. for (var j = 0; j < height; j++) {
  32285. loop1End = i + (rowComps & ~7);
  32286. loop2End = i + rowComps;
  32287. // unroll loop for all full bytes
  32288. while (i < loop1End) {
  32289. buf = buffer[bufferPos++];
  32290. output[i] = (buf >> 7) & 1;
  32291. output[i + 1] = (buf >> 6) & 1;
  32292. output[i + 2] = (buf >> 5) & 1;
  32293. output[i + 3] = (buf >> 4) & 1;
  32294. output[i + 4] = (buf >> 3) & 1;
  32295. output[i + 5] = (buf >> 2) & 1;
  32296. output[i + 6] = (buf >> 1) & 1;
  32297. output[i + 7] = buf & 1;
  32298. i += 8;
  32299. }
  32300. // handle remaining bits
  32301. if (i < loop2End) {
  32302. buf = buffer[bufferPos++];
  32303. mask = 128;
  32304. while (i < loop2End) {
  32305. output[i++] = +!!(buf & mask);
  32306. mask >>= 1;
  32307. }
  32308. }
  32309. }
  32310. } else {
  32311. // The general case that handles all other bpc values.
  32312. var bits = 0;
  32313. buf = 0;
  32314. for (i = 0, ii = length; i < ii; ++i) {
  32315. if (i % rowComps === 0) {
  32316. buf = 0;
  32317. bits = 0;
  32318. }
  32319. while (bits < bpc) {
  32320. buf = (buf << 8) | buffer[bufferPos++];
  32321. bits += 8;
  32322. }
  32323. var remainingBits = bits - bpc;
  32324. var value = buf >> remainingBits;
  32325. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32326. buf = buf & ((1 << remainingBits) - 1);
  32327. bits = remainingBits;
  32328. }
  32329. }
  32330. return output;
  32331. },
  32332. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32333. actualHeight, image) {
  32334. var smask = this.smask;
  32335. var mask = this.mask;
  32336. var alphaBuf, sw, sh, i, ii, j;
  32337. if (smask) {
  32338. sw = smask.width;
  32339. sh = smask.height;
  32340. alphaBuf = new Uint8Array(sw * sh);
  32341. smask.fillGrayBuffer(alphaBuf);
  32342. if (sw !== width || sh !== height) {
  32343. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh,
  32344. width, height);
  32345. }
  32346. } else if (mask) {
  32347. if (mask instanceof PDFImage) {
  32348. sw = mask.width;
  32349. sh = mask.height;
  32350. alphaBuf = new Uint8Array(sw * sh);
  32351. mask.numComps = 1;
  32352. mask.fillGrayBuffer(alphaBuf);
  32353. // Need to invert values in rgbaBuf
  32354. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32355. alphaBuf[i] = 255 - alphaBuf[i];
  32356. }
  32357. if (sw !== width || sh !== height) {
  32358. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh,
  32359. width, height);
  32360. }
  32361. } else if (isArray(mask)) {
  32362. // Color key mask: if any of the components are outside the range
  32363. // then they should be painted.
  32364. alphaBuf = new Uint8Array(width * height);
  32365. var numComps = this.numComps;
  32366. for (i = 0, ii = width * height; i < ii; ++i) {
  32367. var opacity = 0;
  32368. var imageOffset = i * numComps;
  32369. for (j = 0; j < numComps; ++j) {
  32370. var color = image[imageOffset + j];
  32371. var maskOffset = j * 2;
  32372. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32373. opacity = 255;
  32374. break;
  32375. }
  32376. }
  32377. alphaBuf[i] = opacity;
  32378. }
  32379. } else {
  32380. error('Unknown mask format.');
  32381. }
  32382. }
  32383. if (alphaBuf) {
  32384. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32385. rgbaBuf[j] = alphaBuf[i];
  32386. }
  32387. } else {
  32388. // No mask.
  32389. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32390. rgbaBuf[j] = 255;
  32391. }
  32392. }
  32393. },
  32394. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32395. var matte = this.smask && this.smask.matte;
  32396. if (!matte) {
  32397. return;
  32398. }
  32399. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32400. var matteR = matteRgb[0];
  32401. var matteG = matteRgb[1];
  32402. var matteB = matteRgb[2];
  32403. var length = width * height * 4;
  32404. var r, g, b;
  32405. for (var i = 0; i < length; i += 4) {
  32406. var alpha = buffer[i + 3];
  32407. if (alpha === 0) {
  32408. // according formula we have to get Infinity in all components
  32409. // making it white (typical paper color) should be okay
  32410. buffer[i] = 255;
  32411. buffer[i + 1] = 255;
  32412. buffer[i + 2] = 255;
  32413. continue;
  32414. }
  32415. var k = 255 / alpha;
  32416. r = (buffer[i] - matteR) * k + matteR;
  32417. g = (buffer[i + 1] - matteG) * k + matteG;
  32418. b = (buffer[i + 2] - matteB) * k + matteB;
  32419. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32420. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32421. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32422. }
  32423. },
  32424. createImageData: function PDFImage_createImageData(forceRGBA) {
  32425. var drawWidth = this.drawWidth;
  32426. var drawHeight = this.drawHeight;
  32427. var imgData = { // other fields are filled in below
  32428. width: drawWidth,
  32429. height: drawHeight
  32430. };
  32431. var numComps = this.numComps;
  32432. var originalWidth = this.width;
  32433. var originalHeight = this.height;
  32434. var bpc = this.bpc;
  32435. // Rows start at byte boundary.
  32436. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32437. var imgArray;
  32438. if (!forceRGBA) {
  32439. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32440. // without any complications, we pass a same-sized copy to the main
  32441. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32442. // of memory for many scanned documents. It's also much faster.
  32443. //
  32444. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32445. // complications, we avoid expanding by 1.333x to RGBA form.
  32446. var kind;
  32447. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32448. kind = ImageKind.GRAYSCALE_1BPP;
  32449. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32450. !this.needsDecode) {
  32451. kind = ImageKind.RGB_24BPP;
  32452. }
  32453. if (kind && !this.smask && !this.mask &&
  32454. drawWidth === originalWidth && drawHeight === originalHeight) {
  32455. imgData.kind = kind;
  32456. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32457. // If imgArray came from a DecodeStream, we're safe to transfer it
  32458. // (and thus detach its underlying buffer) because it will constitute
  32459. // the entire DecodeStream's data. But if it came from a Stream, we
  32460. // need to copy it because it'll only be a portion of the Stream's
  32461. // data, and the rest will be read later on.
  32462. if (this.image instanceof DecodeStream) {
  32463. imgData.data = imgArray;
  32464. } else {
  32465. var newArray = new Uint8Array(imgArray.length);
  32466. newArray.set(imgArray);
  32467. imgData.data = newArray;
  32468. }
  32469. if (this.needsDecode) {
  32470. // Invert the buffer (which must be grayscale if we reached here).
  32471. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32472. var buffer = imgData.data;
  32473. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32474. buffer[i] ^= 0xff;
  32475. }
  32476. }
  32477. return imgData;
  32478. }
  32479. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32480. (this.colorSpace.name === 'DeviceGray' ||
  32481. this.colorSpace.name === 'DeviceRGB' ||
  32482. this.colorSpace.name === 'DeviceCMYK')) {
  32483. imgData.kind = ImageKind.RGB_24BPP;
  32484. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32485. drawWidth, drawHeight, true);
  32486. return imgData;
  32487. }
  32488. }
  32489. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32490. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32491. var actualHeight = 0 | (imgArray.length / rowBytes *
  32492. drawHeight / originalHeight);
  32493. var comps = this.getComponents(imgArray);
  32494. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32495. // more compact RGB_24BPP form if allowable.
  32496. var alpha01, maybeUndoPreblend;
  32497. if (!forceRGBA && !this.smask && !this.mask) {
  32498. imgData.kind = ImageKind.RGB_24BPP;
  32499. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32500. alpha01 = 0;
  32501. maybeUndoPreblend = false;
  32502. } else {
  32503. imgData.kind = ImageKind.RGBA_32BPP;
  32504. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32505. alpha01 = 1;
  32506. maybeUndoPreblend = true;
  32507. // Color key masking (opacity) must be performed before decoding.
  32508. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32509. comps);
  32510. }
  32511. if (this.needsDecode) {
  32512. this.decodeBuffer(comps);
  32513. }
  32514. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32515. drawWidth, drawHeight, actualHeight, bpc, comps,
  32516. alpha01);
  32517. if (maybeUndoPreblend) {
  32518. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32519. }
  32520. return imgData;
  32521. },
  32522. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32523. var numComps = this.numComps;
  32524. if (numComps !== 1) {
  32525. error('Reading gray scale from a color image: ' + numComps);
  32526. }
  32527. var width = this.width;
  32528. var height = this.height;
  32529. var bpc = this.bpc;
  32530. // rows start at byte boundary
  32531. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32532. var imgArray = this.getImageBytes(height * rowBytes);
  32533. var comps = this.getComponents(imgArray);
  32534. var i, length;
  32535. if (bpc === 1) {
  32536. // inline decoding (= inversion) for 1 bpc images
  32537. length = width * height;
  32538. if (this.needsDecode) {
  32539. // invert and scale to {0, 255}
  32540. for (i = 0; i < length; ++i) {
  32541. buffer[i] = (comps[i] - 1) & 255;
  32542. }
  32543. } else {
  32544. // scale to {0, 255}
  32545. for (i = 0; i < length; ++i) {
  32546. buffer[i] = (-comps[i]) & 255;
  32547. }
  32548. }
  32549. return;
  32550. }
  32551. if (this.needsDecode) {
  32552. this.decodeBuffer(comps);
  32553. }
  32554. length = width * height;
  32555. // we aren't using a colorspace so we need to scale the value
  32556. var scale = 255 / ((1 << bpc) - 1);
  32557. for (i = 0; i < length; ++i) {
  32558. buffer[i] = (scale * comps[i]) | 0;
  32559. }
  32560. },
  32561. getImageBytes: function PDFImage_getImageBytes(length,
  32562. drawWidth, drawHeight,
  32563. forceRGB) {
  32564. this.image.reset();
  32565. this.image.drawWidth = drawWidth || this.width;
  32566. this.image.drawHeight = drawHeight || this.height;
  32567. this.image.forceRGB = !!forceRGB;
  32568. return this.image.getBytes(length);
  32569. }
  32570. };
  32571. return PDFImage;
  32572. })();
  32573. exports.PDFImage = PDFImage;
  32574. }));
  32575. (function (root, factory) {
  32576. {
  32577. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32578. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32579. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32580. }
  32581. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32582. coreChunkedStream, coreColorSpace) {
  32583. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32584. var MissingDataException = sharedUtil.MissingDataException;
  32585. var XRefParseException = sharedUtil.XRefParseException;
  32586. var assert = sharedUtil.assert;
  32587. var bytesToString = sharedUtil.bytesToString;
  32588. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32589. var error = sharedUtil.error;
  32590. var info = sharedUtil.info;
  32591. var isArray = sharedUtil.isArray;
  32592. var isInt = sharedUtil.isInt;
  32593. var isString = sharedUtil.isString;
  32594. var shadow = sharedUtil.shadow;
  32595. var stringToPDFString = sharedUtil.stringToPDFString;
  32596. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32597. var warn = sharedUtil.warn;
  32598. var isValidUrl = sharedUtil.isValidUrl;
  32599. var Util = sharedUtil.Util;
  32600. var Ref = corePrimitives.Ref;
  32601. var RefSet = corePrimitives.RefSet;
  32602. var RefSetCache = corePrimitives.RefSetCache;
  32603. var isName = corePrimitives.isName;
  32604. var isCmd = corePrimitives.isCmd;
  32605. var isDict = corePrimitives.isDict;
  32606. var isRef = corePrimitives.isRef;
  32607. var isRefsEqual = corePrimitives.isRefsEqual;
  32608. var isStream = corePrimitives.isStream;
  32609. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32610. var Lexer = coreParser.Lexer;
  32611. var Parser = coreParser.Parser;
  32612. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32613. var ColorSpace = coreColorSpace.ColorSpace;
  32614. var Catalog = (function CatalogClosure() {
  32615. function Catalog(pdfManager, xref, pageFactory) {
  32616. this.pdfManager = pdfManager;
  32617. this.xref = xref;
  32618. this.catDict = xref.getCatalogObj();
  32619. this.fontCache = new RefSetCache();
  32620. assert(isDict(this.catDict),
  32621. 'catalog object is not a dictionary');
  32622. // TODO refactor to move getPage() to the PDFDocument.
  32623. this.pageFactory = pageFactory;
  32624. this.pagePromises = [];
  32625. }
  32626. Catalog.prototype = {
  32627. get metadata() {
  32628. var streamRef = this.catDict.getRaw('Metadata');
  32629. if (!isRef(streamRef)) {
  32630. return shadow(this, 'metadata', null);
  32631. }
  32632. var encryptMetadata = (!this.xref.encrypt ? false :
  32633. this.xref.encrypt.encryptMetadata);
  32634. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32635. var metadata;
  32636. if (stream && isDict(stream.dict)) {
  32637. var type = stream.dict.get('Type');
  32638. var subtype = stream.dict.get('Subtype');
  32639. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  32640. // XXX: This should examine the charset the XML document defines,
  32641. // however since there are currently no real means to decode
  32642. // arbitrary charsets, let's just hope that the author of the PDF
  32643. // was reasonable enough to stick with the XML default charset,
  32644. // which is UTF-8.
  32645. try {
  32646. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32647. } catch (e) {
  32648. info('Skipping invalid metadata.');
  32649. }
  32650. }
  32651. }
  32652. return shadow(this, 'metadata', metadata);
  32653. },
  32654. get toplevelPagesDict() {
  32655. var pagesObj = this.catDict.get('Pages');
  32656. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32657. // shadow the prototype getter
  32658. return shadow(this, 'toplevelPagesDict', pagesObj);
  32659. },
  32660. get documentOutline() {
  32661. var obj = null;
  32662. try {
  32663. obj = this.readDocumentOutline();
  32664. } catch (ex) {
  32665. if (ex instanceof MissingDataException) {
  32666. throw ex;
  32667. }
  32668. warn('Unable to read document outline');
  32669. }
  32670. return shadow(this, 'documentOutline', obj);
  32671. },
  32672. readDocumentOutline: function Catalog_readDocumentOutline() {
  32673. var obj = this.catDict.get('Outlines');
  32674. if (!isDict(obj)) {
  32675. return null;
  32676. }
  32677. obj = obj.getRaw('First');
  32678. if (!isRef(obj)) {
  32679. return null;
  32680. }
  32681. var root = { items: [] };
  32682. var queue = [{obj: obj, parent: root}];
  32683. // To avoid recursion, keep track of the already processed items.
  32684. var processed = new RefSet();
  32685. processed.put(obj);
  32686. var xref = this.xref, blackColor = new Uint8Array(3);
  32687. while (queue.length > 0) {
  32688. var i = queue.shift();
  32689. var outlineDict = xref.fetchIfRef(i.obj);
  32690. if (outlineDict === null) {
  32691. continue;
  32692. }
  32693. assert(outlineDict.has('Title'), 'Invalid outline item');
  32694. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32695. if (actionDict) {
  32696. var destEntry = actionDict.get('D');
  32697. if (destEntry) {
  32698. dest = destEntry;
  32699. } else {
  32700. var uriEntry = actionDict.get('URI');
  32701. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32702. url = uriEntry;
  32703. }
  32704. }
  32705. } else if (outlineDict.has('Dest')) {
  32706. dest = outlineDict.getRaw('Dest');
  32707. if (isName(dest)) {
  32708. dest = dest.name;
  32709. }
  32710. }
  32711. var title = outlineDict.get('Title');
  32712. var flags = outlineDict.get('F') || 0;
  32713. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  32714. // We only need to parse the color when it's valid, and non-default.
  32715. if (isArray(color) && color.length === 3 &&
  32716. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32717. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32718. }
  32719. var outlineItem = {
  32720. dest: dest,
  32721. url: url,
  32722. title: stringToPDFString(title),
  32723. color: rgbColor,
  32724. count: outlineDict.get('Count'),
  32725. bold: !!(flags & 2),
  32726. italic: !!(flags & 1),
  32727. items: []
  32728. };
  32729. i.parent.items.push(outlineItem);
  32730. obj = outlineDict.getRaw('First');
  32731. if (isRef(obj) && !processed.has(obj)) {
  32732. queue.push({obj: obj, parent: outlineItem});
  32733. processed.put(obj);
  32734. }
  32735. obj = outlineDict.getRaw('Next');
  32736. if (isRef(obj) && !processed.has(obj)) {
  32737. queue.push({obj: obj, parent: i.parent});
  32738. processed.put(obj);
  32739. }
  32740. }
  32741. return (root.items.length > 0 ? root.items : null);
  32742. },
  32743. get numPages() {
  32744. var obj = this.toplevelPagesDict.get('Count');
  32745. assert(
  32746. isInt(obj),
  32747. 'page count in top level pages object is not an integer'
  32748. );
  32749. // shadow the prototype getter
  32750. return shadow(this, 'num', obj);
  32751. },
  32752. get destinations() {
  32753. function fetchDestination(dest) {
  32754. return isDict(dest) ? dest.get('D') : dest;
  32755. }
  32756. var xref = this.xref;
  32757. var dests = {}, nameTreeRef, nameDictionaryRef;
  32758. var obj = this.catDict.get('Names');
  32759. if (obj && obj.has('Dests')) {
  32760. nameTreeRef = obj.getRaw('Dests');
  32761. } else if (this.catDict.has('Dests')) {
  32762. nameDictionaryRef = this.catDict.get('Dests');
  32763. }
  32764. if (nameDictionaryRef) {
  32765. // reading simple destination dictionary
  32766. obj = nameDictionaryRef;
  32767. obj.forEach(function catalogForEach(key, value) {
  32768. if (!value) {
  32769. return;
  32770. }
  32771. dests[key] = fetchDestination(value);
  32772. });
  32773. }
  32774. if (nameTreeRef) {
  32775. var nameTree = new NameTree(nameTreeRef, xref);
  32776. var names = nameTree.getAll();
  32777. for (var name in names) {
  32778. dests[name] = fetchDestination(names[name]);
  32779. }
  32780. }
  32781. return shadow(this, 'destinations', dests);
  32782. },
  32783. getDestination: function Catalog_getDestination(destinationId) {
  32784. function fetchDestination(dest) {
  32785. return isDict(dest) ? dest.get('D') : dest;
  32786. }
  32787. var xref = this.xref;
  32788. var dest = null, nameTreeRef, nameDictionaryRef;
  32789. var obj = this.catDict.get('Names');
  32790. if (obj && obj.has('Dests')) {
  32791. nameTreeRef = obj.getRaw('Dests');
  32792. } else if (this.catDict.has('Dests')) {
  32793. nameDictionaryRef = this.catDict.get('Dests');
  32794. }
  32795. if (nameDictionaryRef) { // Simple destination dictionary.
  32796. var value = nameDictionaryRef.get(destinationId);
  32797. if (value) {
  32798. dest = fetchDestination(value);
  32799. }
  32800. }
  32801. if (nameTreeRef) {
  32802. var nameTree = new NameTree(nameTreeRef, xref);
  32803. dest = fetchDestination(nameTree.get(destinationId));
  32804. }
  32805. return dest;
  32806. },
  32807. get pageLabels() {
  32808. var obj = null;
  32809. try {
  32810. obj = this.readPageLabels();
  32811. } catch (ex) {
  32812. if (ex instanceof MissingDataException) {
  32813. throw ex;
  32814. }
  32815. warn('Unable to read page labels.');
  32816. }
  32817. return shadow(this, 'pageLabels', obj);
  32818. },
  32819. readPageLabels: function Catalog_readPageLabels() {
  32820. var obj = this.catDict.getRaw('PageLabels');
  32821. if (!obj) {
  32822. return null;
  32823. }
  32824. var pageLabels = new Array(this.numPages);
  32825. var style = null;
  32826. var prefix = '';
  32827. var start = 1;
  32828. var numberTree = new NumberTree(obj, this.xref);
  32829. var nums = numberTree.getAll();
  32830. var currentLabel = '', currentIndex = 1;
  32831. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32832. if (i in nums) {
  32833. var labelDict = nums[i];
  32834. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32835. var type = labelDict.get('Type');
  32836. assert(!type || isName(type, 'PageLabel'),
  32837. 'Invalid type in PageLabel dictionary.');
  32838. var s = labelDict.get('S');
  32839. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32840. style = (s ? s.name : null);
  32841. prefix = labelDict.get('P') || '';
  32842. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32843. start = labelDict.get('St') || 1;
  32844. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32845. currentIndex = start;
  32846. }
  32847. switch (style) {
  32848. case 'D':
  32849. currentLabel = currentIndex;
  32850. break;
  32851. case 'R':
  32852. case 'r':
  32853. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32854. break;
  32855. case 'A':
  32856. case 'a':
  32857. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32858. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32859. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32860. var letterIndex = currentIndex - 1;
  32861. var character = String.fromCharCode(baseCharCode +
  32862. (letterIndex % LIMIT));
  32863. var charBuf = [];
  32864. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32865. charBuf.push(character);
  32866. }
  32867. currentLabel = charBuf.join('');
  32868. break;
  32869. default:
  32870. assert(!style,
  32871. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32872. }
  32873. pageLabels[i] = prefix + currentLabel;
  32874. currentLabel = '';
  32875. currentIndex++;
  32876. }
  32877. return pageLabels;
  32878. },
  32879. get attachments() {
  32880. var xref = this.xref;
  32881. var attachments = null, nameTreeRef;
  32882. var obj = this.catDict.get('Names');
  32883. if (obj) {
  32884. nameTreeRef = obj.getRaw('EmbeddedFiles');
  32885. }
  32886. if (nameTreeRef) {
  32887. var nameTree = new NameTree(nameTreeRef, xref);
  32888. var names = nameTree.getAll();
  32889. for (var name in names) {
  32890. var fs = new FileSpec(names[name], xref);
  32891. if (!attachments) {
  32892. attachments = Object.create(null);
  32893. }
  32894. attachments[stringToPDFString(name)] = fs.serializable;
  32895. }
  32896. }
  32897. return shadow(this, 'attachments', attachments);
  32898. },
  32899. get javaScript() {
  32900. var xref = this.xref;
  32901. var obj = this.catDict.get('Names');
  32902. var javaScript = [];
  32903. function appendIfJavaScriptDict(jsDict) {
  32904. var type = jsDict.get('S');
  32905. if (!isName(type, 'JavaScript')) {
  32906. return;
  32907. }
  32908. var js = jsDict.get('JS');
  32909. if (isStream(js)) {
  32910. js = bytesToString(js.getBytes());
  32911. } else if (!isString(js)) {
  32912. return;
  32913. }
  32914. javaScript.push(stringToPDFString(js));
  32915. }
  32916. if (obj && obj.has('JavaScript')) {
  32917. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  32918. var names = nameTree.getAll();
  32919. for (var name in names) {
  32920. // We don't really use the JavaScript right now. This code is
  32921. // defensive so we don't cause errors on document load.
  32922. var jsDict = names[name];
  32923. if (isDict(jsDict)) {
  32924. appendIfJavaScriptDict(jsDict);
  32925. }
  32926. }
  32927. }
  32928. // Append OpenAction actions to javaScript array
  32929. var openactionDict = this.catDict.get('OpenAction');
  32930. if (isDict(openactionDict, 'Action')) {
  32931. var actionType = openactionDict.get('S');
  32932. if (isName(actionType, 'Named')) {
  32933. // The named Print action is not a part of the PDF 1.7 specification,
  32934. // but is supported by many PDF readers/writers (including Adobe's).
  32935. var action = openactionDict.get('N');
  32936. if (isName(action, 'Print')) {
  32937. javaScript.push('print({});');
  32938. }
  32939. } else {
  32940. appendIfJavaScriptDict(openactionDict);
  32941. }
  32942. }
  32943. return shadow(this, 'javaScript', javaScript);
  32944. },
  32945. cleanup: function Catalog_cleanup() {
  32946. var promises = [];
  32947. this.fontCache.forEach(function (promise) {
  32948. promises.push(promise);
  32949. });
  32950. return Promise.all(promises).then(function (translatedFonts) {
  32951. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  32952. var font = translatedFonts[i].dict;
  32953. delete font.translated;
  32954. }
  32955. this.fontCache.clear();
  32956. }.bind(this));
  32957. },
  32958. getPage: function Catalog_getPage(pageIndex) {
  32959. if (!(pageIndex in this.pagePromises)) {
  32960. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  32961. function (a) {
  32962. var dict = a[0];
  32963. var ref = a[1];
  32964. return this.pageFactory.createPage(pageIndex, dict, ref,
  32965. this.fontCache);
  32966. }.bind(this)
  32967. );
  32968. }
  32969. return this.pagePromises[pageIndex];
  32970. },
  32971. getPageDict: function Catalog_getPageDict(pageIndex) {
  32972. var capability = createPromiseCapability();
  32973. var nodesToVisit = [this.catDict.getRaw('Pages')];
  32974. var currentPageIndex = 0;
  32975. var xref = this.xref;
  32976. var checkAllKids = false;
  32977. function next() {
  32978. while (nodesToVisit.length) {
  32979. var currentNode = nodesToVisit.pop();
  32980. if (isRef(currentNode)) {
  32981. xref.fetchAsync(currentNode).then(function (obj) {
  32982. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  32983. if (pageIndex === currentPageIndex) {
  32984. capability.resolve([obj, currentNode]);
  32985. } else {
  32986. currentPageIndex++;
  32987. next();
  32988. }
  32989. return;
  32990. }
  32991. nodesToVisit.push(obj);
  32992. next();
  32993. }, capability.reject);
  32994. return;
  32995. }
  32996. // Must be a child page dictionary.
  32997. assert(
  32998. isDict(currentNode),
  32999. 'page dictionary kid reference points to wrong type of object'
  33000. );
  33001. var count = currentNode.get('Count');
  33002. // If the current node doesn't have any children, avoid getting stuck
  33003. // in an empty node further down in the tree (see issue5644.pdf).
  33004. if (count === 0) {
  33005. checkAllKids = true;
  33006. }
  33007. // Skip nodes where the page can't be.
  33008. if (currentPageIndex + count <= pageIndex) {
  33009. currentPageIndex += count;
  33010. continue;
  33011. }
  33012. var kids = currentNode.get('Kids');
  33013. assert(isArray(kids), 'page dictionary kids object is not an array');
  33014. if (!checkAllKids && count === kids.length) {
  33015. // Nodes that don't have the page have been skipped and this is the
  33016. // bottom of the tree which means the page requested must be a
  33017. // descendant of this pages node. Ideally we would just resolve the
  33018. // promise with the page ref here, but there is the case where more
  33019. // pages nodes could link to single a page (see issue 3666 pdf). To
  33020. // handle this push it back on the queue so if it is a pages node it
  33021. // will be descended into.
  33022. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  33023. currentPageIndex = pageIndex;
  33024. continue;
  33025. } else {
  33026. for (var last = kids.length - 1; last >= 0; last--) {
  33027. nodesToVisit.push(kids[last]);
  33028. }
  33029. }
  33030. }
  33031. capability.reject('Page index ' + pageIndex + ' not found.');
  33032. }
  33033. next();
  33034. return capability.promise;
  33035. },
  33036. getPageIndex: function Catalog_getPageIndex(pageRef) {
  33037. // The page tree nodes have the count of all the leaves below them. To get
  33038. // how many pages are before we just have to walk up the tree and keep
  33039. // adding the count of siblings to the left of the node.
  33040. var xref = this.xref;
  33041. function pagesBeforeRef(kidRef) {
  33042. var total = 0;
  33043. var parentRef;
  33044. return xref.fetchAsync(kidRef).then(function (node) {
  33045. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') &&
  33046. !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  33047. throw new Error('The reference does not point to a /Page Dict.');
  33048. }
  33049. if (!node) {
  33050. return null;
  33051. }
  33052. assert(isDict(node), 'node must be a Dict.');
  33053. parentRef = node.getRaw('Parent');
  33054. return node.getAsync('Parent');
  33055. }).then(function (parent) {
  33056. if (!parent) {
  33057. return null;
  33058. }
  33059. assert(isDict(parent), 'parent must be a Dict.');
  33060. return parent.getAsync('Kids');
  33061. }).then(function (kids) {
  33062. if (!kids) {
  33063. return null;
  33064. }
  33065. var kidPromises = [];
  33066. var found = false;
  33067. for (var i = 0; i < kids.length; i++) {
  33068. var kid = kids[i];
  33069. assert(isRef(kid), 'kid must be a Ref.');
  33070. if (kid.num === kidRef.num) {
  33071. found = true;
  33072. break;
  33073. }
  33074. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  33075. if (kid.has('Count')) {
  33076. var count = kid.get('Count');
  33077. total += count;
  33078. } else { // page leaf node
  33079. total++;
  33080. }
  33081. }));
  33082. }
  33083. if (!found) {
  33084. error('kid ref not found in parents kids');
  33085. }
  33086. return Promise.all(kidPromises).then(function () {
  33087. return [total, parentRef];
  33088. });
  33089. });
  33090. }
  33091. var total = 0;
  33092. function next(ref) {
  33093. return pagesBeforeRef(ref).then(function (args) {
  33094. if (!args) {
  33095. return total;
  33096. }
  33097. var count = args[0];
  33098. var parentRef = args[1];
  33099. total += count;
  33100. return next(parentRef);
  33101. });
  33102. }
  33103. return next(pageRef);
  33104. }
  33105. };
  33106. return Catalog;
  33107. })();
  33108. var XRef = (function XRefClosure() {
  33109. function XRef(stream, password) {
  33110. this.stream = stream;
  33111. this.entries = [];
  33112. this.xrefstms = Object.create(null);
  33113. // prepare the XRef cache
  33114. this.cache = [];
  33115. this.password = password;
  33116. this.stats = {
  33117. streamTypes: [],
  33118. fontTypes: []
  33119. };
  33120. }
  33121. XRef.prototype = {
  33122. setStartXRef: function XRef_setStartXRef(startXRef) {
  33123. // Store the starting positions of xref tables as we process them
  33124. // so we can recover from missing data errors
  33125. this.startXRefQueue = [startXRef];
  33126. },
  33127. parse: function XRef_parse(recoveryMode) {
  33128. var trailerDict;
  33129. if (!recoveryMode) {
  33130. trailerDict = this.readXRef();
  33131. } else {
  33132. warn('Indexing all PDF objects');
  33133. trailerDict = this.indexObjects();
  33134. }
  33135. trailerDict.assignXref(this);
  33136. this.trailer = trailerDict;
  33137. var encrypt = trailerDict.get('Encrypt');
  33138. if (encrypt) {
  33139. var ids = trailerDict.get('ID');
  33140. var fileId = (ids && ids.length) ? ids[0] : '';
  33141. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33142. this.password);
  33143. }
  33144. // get the root dictionary (catalog) object
  33145. if (!(this.root = trailerDict.get('Root'))) {
  33146. error('Invalid root reference');
  33147. }
  33148. },
  33149. processXRefTable: function XRef_processXRefTable(parser) {
  33150. if (!('tableState' in this)) {
  33151. // Stores state of the table as we process it so we can resume
  33152. // from middle of table in case of missing data error
  33153. this.tableState = {
  33154. entryNum: 0,
  33155. streamPos: parser.lexer.stream.pos,
  33156. parserBuf1: parser.buf1,
  33157. parserBuf2: parser.buf2
  33158. };
  33159. }
  33160. var obj = this.readXRefTable(parser);
  33161. // Sanity check
  33162. if (!isCmd(obj, 'trailer')) {
  33163. error('Invalid XRef table: could not find trailer dictionary');
  33164. }
  33165. // Read trailer dictionary, e.g.
  33166. // trailer
  33167. // << /Size 22
  33168. // /Root 20R
  33169. // /Info 10R
  33170. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33171. // >>
  33172. // The parser goes through the entire stream << ... >> and provides
  33173. // a getter interface for the key-value table
  33174. var dict = parser.getObj();
  33175. // The pdflib PDF generator can generate a nested trailer dictionary
  33176. if (!isDict(dict) && dict.dict) {
  33177. dict = dict.dict;
  33178. }
  33179. if (!isDict(dict)) {
  33180. error('Invalid XRef table: could not parse trailer dictionary');
  33181. }
  33182. delete this.tableState;
  33183. return dict;
  33184. },
  33185. readXRefTable: function XRef_readXRefTable(parser) {
  33186. // Example of cross-reference table:
  33187. // xref
  33188. // 0 1 <-- subsection header (first obj #, obj count)
  33189. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33190. // 23 2 <-- subsection header ... and so on ...
  33191. // 0000025518 00002 n
  33192. // 0000025635 00000 n
  33193. // trailer
  33194. // ...
  33195. var stream = parser.lexer.stream;
  33196. var tableState = this.tableState;
  33197. stream.pos = tableState.streamPos;
  33198. parser.buf1 = tableState.parserBuf1;
  33199. parser.buf2 = tableState.parserBuf2;
  33200. // Outer loop is over subsection headers
  33201. var obj;
  33202. while (true) {
  33203. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33204. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33205. break;
  33206. }
  33207. tableState.firstEntryNum = obj;
  33208. tableState.entryCount = parser.getObj();
  33209. }
  33210. var first = tableState.firstEntryNum;
  33211. var count = tableState.entryCount;
  33212. if (!isInt(first) || !isInt(count)) {
  33213. error('Invalid XRef table: wrong types in subsection header');
  33214. }
  33215. // Inner loop is over objects themselves
  33216. for (var i = tableState.entryNum; i < count; i++) {
  33217. tableState.streamPos = stream.pos;
  33218. tableState.entryNum = i;
  33219. tableState.parserBuf1 = parser.buf1;
  33220. tableState.parserBuf2 = parser.buf2;
  33221. var entry = {};
  33222. entry.offset = parser.getObj();
  33223. entry.gen = parser.getObj();
  33224. var type = parser.getObj();
  33225. if (isCmd(type, 'f')) {
  33226. entry.free = true;
  33227. } else if (isCmd(type, 'n')) {
  33228. entry.uncompressed = true;
  33229. }
  33230. // Validate entry obj
  33231. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33232. !(entry.free || entry.uncompressed)) {
  33233. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33234. }
  33235. // The first xref table entry, i.e. obj 0, should be free. Attempting
  33236. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  33237. if (i === 0 && entry.free && first === 1) {
  33238. first = 0;
  33239. }
  33240. if (!this.entries[i + first]) {
  33241. this.entries[i + first] = entry;
  33242. }
  33243. }
  33244. tableState.entryNum = 0;
  33245. tableState.streamPos = stream.pos;
  33246. tableState.parserBuf1 = parser.buf1;
  33247. tableState.parserBuf2 = parser.buf2;
  33248. delete tableState.firstEntryNum;
  33249. delete tableState.entryCount;
  33250. }
  33251. // Sanity check: as per spec, first object must be free
  33252. if (this.entries[0] && !this.entries[0].free) {
  33253. error('Invalid XRef table: unexpected first object');
  33254. }
  33255. return obj;
  33256. },
  33257. processXRefStream: function XRef_processXRefStream(stream) {
  33258. if (!('streamState' in this)) {
  33259. // Stores state of the stream as we process it so we can resume
  33260. // from middle of stream in case of missing data error
  33261. var streamParameters = stream.dict;
  33262. var byteWidths = streamParameters.get('W');
  33263. var range = streamParameters.get('Index');
  33264. if (!range) {
  33265. range = [0, streamParameters.get('Size')];
  33266. }
  33267. this.streamState = {
  33268. entryRanges: range,
  33269. byteWidths: byteWidths,
  33270. entryNum: 0,
  33271. streamPos: stream.pos
  33272. };
  33273. }
  33274. this.readXRefStream(stream);
  33275. delete this.streamState;
  33276. return stream.dict;
  33277. },
  33278. readXRefStream: function XRef_readXRefStream(stream) {
  33279. var i, j;
  33280. var streamState = this.streamState;
  33281. stream.pos = streamState.streamPos;
  33282. var byteWidths = streamState.byteWidths;
  33283. var typeFieldWidth = byteWidths[0];
  33284. var offsetFieldWidth = byteWidths[1];
  33285. var generationFieldWidth = byteWidths[2];
  33286. var entryRanges = streamState.entryRanges;
  33287. while (entryRanges.length > 0) {
  33288. var first = entryRanges[0];
  33289. var n = entryRanges[1];
  33290. if (!isInt(first) || !isInt(n)) {
  33291. error('Invalid XRef range fields: ' + first + ', ' + n);
  33292. }
  33293. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33294. !isInt(generationFieldWidth)) {
  33295. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33296. }
  33297. for (i = streamState.entryNum; i < n; ++i) {
  33298. streamState.entryNum = i;
  33299. streamState.streamPos = stream.pos;
  33300. var type = 0, offset = 0, generation = 0;
  33301. for (j = 0; j < typeFieldWidth; ++j) {
  33302. type = (type << 8) | stream.getByte();
  33303. }
  33304. // if type field is absent, its default value is 1
  33305. if (typeFieldWidth === 0) {
  33306. type = 1;
  33307. }
  33308. for (j = 0; j < offsetFieldWidth; ++j) {
  33309. offset = (offset << 8) | stream.getByte();
  33310. }
  33311. for (j = 0; j < generationFieldWidth; ++j) {
  33312. generation = (generation << 8) | stream.getByte();
  33313. }
  33314. var entry = {};
  33315. entry.offset = offset;
  33316. entry.gen = generation;
  33317. switch (type) {
  33318. case 0:
  33319. entry.free = true;
  33320. break;
  33321. case 1:
  33322. entry.uncompressed = true;
  33323. break;
  33324. case 2:
  33325. break;
  33326. default:
  33327. error('Invalid XRef entry type: ' + type);
  33328. }
  33329. if (!this.entries[first + i]) {
  33330. this.entries[first + i] = entry;
  33331. }
  33332. }
  33333. streamState.entryNum = 0;
  33334. streamState.streamPos = stream.pos;
  33335. entryRanges.splice(0, 2);
  33336. }
  33337. },
  33338. indexObjects: function XRef_indexObjects() {
  33339. // Simple scan through the PDF content to find objects,
  33340. // trailers and XRef streams.
  33341. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33342. var PERCENT = 0x25, LT = 0x3C;
  33343. function readToken(data, offset) {
  33344. var token = '', ch = data[offset];
  33345. while (ch !== LF && ch !== CR && ch !== LT) {
  33346. if (++offset >= data.length) {
  33347. break;
  33348. }
  33349. token += String.fromCharCode(ch);
  33350. ch = data[offset];
  33351. }
  33352. return token;
  33353. }
  33354. function skipUntil(data, offset, what) {
  33355. var length = what.length, dataLength = data.length;
  33356. var skipped = 0;
  33357. // finding byte sequence
  33358. while (offset < dataLength) {
  33359. var i = 0;
  33360. while (i < length && data[offset + i] === what[i]) {
  33361. ++i;
  33362. }
  33363. if (i >= length) {
  33364. break; // sequence found
  33365. }
  33366. offset++;
  33367. skipped++;
  33368. }
  33369. return skipped;
  33370. }
  33371. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33372. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33373. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33374. 101, 102]);
  33375. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33376. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33377. // Clear out any existing entries, since they may be bogus.
  33378. this.entries.length = 0;
  33379. var stream = this.stream;
  33380. stream.pos = 0;
  33381. var buffer = stream.getBytes();
  33382. var position = stream.start, length = buffer.length;
  33383. var trailers = [], xrefStms = [];
  33384. while (position < length) {
  33385. var ch = buffer[position];
  33386. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33387. ++position;
  33388. continue;
  33389. }
  33390. if (ch === PERCENT) { // %-comment
  33391. do {
  33392. ++position;
  33393. if (position >= length) {
  33394. break;
  33395. }
  33396. ch = buffer[position];
  33397. } while (ch !== LF && ch !== CR);
  33398. continue;
  33399. }
  33400. var token = readToken(buffer, position);
  33401. var m;
  33402. if (token.indexOf('xref') === 0 &&
  33403. (token.length === 4 || /\s/.test(token[4]))) {
  33404. position += skipUntil(buffer, position, trailerBytes);
  33405. trailers.push(position);
  33406. position += skipUntil(buffer, position, startxrefBytes);
  33407. } else if ((m = objRegExp.exec(token))) {
  33408. if (typeof this.entries[m[1]] === 'undefined') {
  33409. this.entries[m[1]] = {
  33410. offset: position - stream.start,
  33411. gen: m[2] | 0,
  33412. uncompressed: true
  33413. };
  33414. }
  33415. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33416. var content = buffer.subarray(position, position + contentLength);
  33417. // checking XRef stream suspect
  33418. // (it shall have '/XRef' and next char is not a letter)
  33419. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33420. if (xrefTagOffset < contentLength &&
  33421. content[xrefTagOffset + 5] < 64) {
  33422. xrefStms.push(position - stream.start);
  33423. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33424. }
  33425. position += contentLength;
  33426. } else if (token.indexOf('trailer') === 0 &&
  33427. (token.length === 7 || /\s/.test(token[7]))) {
  33428. trailers.push(position);
  33429. position += skipUntil(buffer, position, startxrefBytes);
  33430. } else {
  33431. position += token.length + 1;
  33432. }
  33433. }
  33434. // reading XRef streams
  33435. var i, ii;
  33436. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33437. this.startXRefQueue.push(xrefStms[i]);
  33438. this.readXRef(/* recoveryMode */ true);
  33439. }
  33440. // finding main trailer
  33441. var dict;
  33442. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33443. stream.pos = trailers[i];
  33444. var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
  33445. /* xref = */ this, /* recoveryMode = */ true);
  33446. var obj = parser.getObj();
  33447. if (!isCmd(obj, 'trailer')) {
  33448. continue;
  33449. }
  33450. // read the trailer dictionary
  33451. dict = parser.getObj();
  33452. if (!isDict(dict)) {
  33453. continue;
  33454. }
  33455. // taking the first one with 'ID'
  33456. if (dict.has('ID')) {
  33457. return dict;
  33458. }
  33459. }
  33460. // no tailer with 'ID', taking last one (if exists)
  33461. if (dict) {
  33462. return dict;
  33463. }
  33464. // nothing helps
  33465. // calling error() would reject worker with an UnknownErrorException.
  33466. throw new InvalidPDFException('Invalid PDF structure');
  33467. },
  33468. readXRef: function XRef_readXRef(recoveryMode) {
  33469. var stream = this.stream;
  33470. try {
  33471. while (this.startXRefQueue.length) {
  33472. var startXRef = this.startXRefQueue[0];
  33473. stream.pos = startXRef + stream.start;
  33474. var parser = new Parser(new Lexer(stream), true, this);
  33475. var obj = parser.getObj();
  33476. var dict;
  33477. // Get dictionary
  33478. if (isCmd(obj, 'xref')) {
  33479. // Parse end-of-file XRef
  33480. dict = this.processXRefTable(parser);
  33481. if (!this.topDict) {
  33482. this.topDict = dict;
  33483. }
  33484. // Recursively get other XRefs 'XRefStm', if any
  33485. obj = dict.get('XRefStm');
  33486. if (isInt(obj)) {
  33487. var pos = obj;
  33488. // ignore previously loaded xref streams
  33489. // (possible infinite recursion)
  33490. if (!(pos in this.xrefstms)) {
  33491. this.xrefstms[pos] = 1;
  33492. this.startXRefQueue.push(pos);
  33493. }
  33494. }
  33495. } else if (isInt(obj)) {
  33496. // Parse in-stream XRef
  33497. if (!isInt(parser.getObj()) ||
  33498. !isCmd(parser.getObj(), 'obj') ||
  33499. !isStream(obj = parser.getObj())) {
  33500. error('Invalid XRef stream');
  33501. }
  33502. dict = this.processXRefStream(obj);
  33503. if (!this.topDict) {
  33504. this.topDict = dict;
  33505. }
  33506. if (!dict) {
  33507. error('Failed to read XRef stream');
  33508. }
  33509. } else {
  33510. error('Invalid XRef stream header');
  33511. }
  33512. // Recursively get previous dictionary, if any
  33513. obj = dict.get('Prev');
  33514. if (isInt(obj)) {
  33515. this.startXRefQueue.push(obj);
  33516. } else if (isRef(obj)) {
  33517. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33518. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33519. this.startXRefQueue.push(obj.num);
  33520. }
  33521. this.startXRefQueue.shift();
  33522. }
  33523. return this.topDict;
  33524. } catch (e) {
  33525. if (e instanceof MissingDataException) {
  33526. throw e;
  33527. }
  33528. info('(while reading XRef): ' + e);
  33529. }
  33530. if (recoveryMode) {
  33531. return;
  33532. }
  33533. throw new XRefParseException();
  33534. },
  33535. getEntry: function XRef_getEntry(i) {
  33536. var xrefEntry = this.entries[i];
  33537. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33538. return xrefEntry;
  33539. }
  33540. return null;
  33541. },
  33542. fetchIfRef: function XRef_fetchIfRef(obj) {
  33543. if (!isRef(obj)) {
  33544. return obj;
  33545. }
  33546. return this.fetch(obj);
  33547. },
  33548. fetch: function XRef_fetch(ref, suppressEncryption) {
  33549. assert(isRef(ref), 'ref object is not a reference');
  33550. var num = ref.num;
  33551. if (num in this.cache) {
  33552. var cacheEntry = this.cache[num];
  33553. return cacheEntry;
  33554. }
  33555. var xrefEntry = this.getEntry(num);
  33556. // the referenced entry can be free
  33557. if (xrefEntry === null) {
  33558. return (this.cache[num] = null);
  33559. }
  33560. if (xrefEntry.uncompressed) {
  33561. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33562. } else {
  33563. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33564. }
  33565. if (isDict(xrefEntry)){
  33566. xrefEntry.objId = ref.toString();
  33567. } else if (isStream(xrefEntry)) {
  33568. xrefEntry.dict.objId = ref.toString();
  33569. }
  33570. return xrefEntry;
  33571. },
  33572. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33573. suppressEncryption) {
  33574. var gen = ref.gen;
  33575. var num = ref.num;
  33576. if (xrefEntry.gen !== gen) {
  33577. error('inconsistent generation in XRef');
  33578. }
  33579. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33580. this.stream.start);
  33581. var parser = new Parser(new Lexer(stream), true, this);
  33582. var obj1 = parser.getObj();
  33583. var obj2 = parser.getObj();
  33584. var obj3 = parser.getObj();
  33585. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33586. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33587. !isCmd(obj3)) {
  33588. error('bad XRef entry');
  33589. }
  33590. if (!isCmd(obj3, 'obj')) {
  33591. // some bad PDFs use "obj1234" and really mean 1234
  33592. if (obj3.cmd.indexOf('obj') === 0) {
  33593. num = parseInt(obj3.cmd.substring(3), 10);
  33594. if (!isNaN(num)) {
  33595. return num;
  33596. }
  33597. }
  33598. error('bad XRef entry');
  33599. }
  33600. if (this.encrypt && !suppressEncryption) {
  33601. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33602. } else {
  33603. xrefEntry = parser.getObj();
  33604. }
  33605. if (!isStream(xrefEntry)) {
  33606. this.cache[num] = xrefEntry;
  33607. }
  33608. return xrefEntry;
  33609. },
  33610. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33611. suppressEncryption) {
  33612. var tableOffset = xrefEntry.offset;
  33613. var stream = this.fetch(new Ref(tableOffset, 0));
  33614. if (!isStream(stream)) {
  33615. error('bad ObjStm stream');
  33616. }
  33617. var first = stream.dict.get('First');
  33618. var n = stream.dict.get('N');
  33619. if (!isInt(first) || !isInt(n)) {
  33620. error('invalid first and n parameters for ObjStm stream');
  33621. }
  33622. var parser = new Parser(new Lexer(stream), false, this);
  33623. parser.allowStreams = true;
  33624. var i, entries = [], num, nums = [];
  33625. // read the object numbers to populate cache
  33626. for (i = 0; i < n; ++i) {
  33627. num = parser.getObj();
  33628. if (!isInt(num)) {
  33629. error('invalid object number in the ObjStm stream: ' + num);
  33630. }
  33631. nums.push(num);
  33632. var offset = parser.getObj();
  33633. if (!isInt(offset)) {
  33634. error('invalid object offset in the ObjStm stream: ' + offset);
  33635. }
  33636. }
  33637. // read stream objects for cache
  33638. for (i = 0; i < n; ++i) {
  33639. entries.push(parser.getObj());
  33640. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  33641. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  33642. if (isCmd(parser.buf1, 'endobj')) {
  33643. parser.shift();
  33644. }
  33645. num = nums[i];
  33646. var entry = this.entries[num];
  33647. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33648. this.cache[num] = entries[i];
  33649. }
  33650. }
  33651. xrefEntry = entries[xrefEntry.gen];
  33652. if (xrefEntry === undefined) {
  33653. error('bad XRef entry for compressed object');
  33654. }
  33655. return xrefEntry;
  33656. },
  33657. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33658. if (!isRef(obj)) {
  33659. return Promise.resolve(obj);
  33660. }
  33661. return this.fetchAsync(obj);
  33662. },
  33663. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33664. var streamManager = this.stream.manager;
  33665. var xref = this;
  33666. return new Promise(function tryFetch(resolve, reject) {
  33667. try {
  33668. resolve(xref.fetch(ref, suppressEncryption));
  33669. } catch (e) {
  33670. if (e instanceof MissingDataException) {
  33671. streamManager.requestRange(e.begin, e.end).then(function () {
  33672. tryFetch(resolve, reject);
  33673. }, reject);
  33674. return;
  33675. }
  33676. reject(e);
  33677. }
  33678. });
  33679. },
  33680. getCatalogObj: function XRef_getCatalogObj() {
  33681. return this.root;
  33682. }
  33683. };
  33684. return XRef;
  33685. })();
  33686. /**
  33687. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33688. * see the specification (7.9.6 and 7.9.7) for additional details.
  33689. * TODO: implement all the Dict functions and make this more efficient.
  33690. */
  33691. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33692. function NameOrNumberTree(root, xref) {
  33693. throw new Error('Cannot initialize NameOrNumberTree.');
  33694. }
  33695. NameOrNumberTree.prototype = {
  33696. getAll: function NameOrNumberTree_getAll() {
  33697. var dict = Object.create(null);
  33698. if (!this.root) {
  33699. return dict;
  33700. }
  33701. var xref = this.xref;
  33702. // Reading Name/Number tree.
  33703. var processed = new RefSet();
  33704. processed.put(this.root);
  33705. var queue = [this.root];
  33706. while (queue.length > 0) {
  33707. var i, n;
  33708. var obj = xref.fetchIfRef(queue.shift());
  33709. if (!isDict(obj)) {
  33710. continue;
  33711. }
  33712. if (obj.has('Kids')) {
  33713. var kids = obj.get('Kids');
  33714. for (i = 0, n = kids.length; i < n; i++) {
  33715. var kid = kids[i];
  33716. assert(!processed.has(kid),
  33717. 'Duplicate entry in "' + this._type + '" tree.');
  33718. queue.push(kid);
  33719. processed.put(kid);
  33720. }
  33721. continue;
  33722. }
  33723. var entries = obj.get(this._type);
  33724. if (isArray(entries)) {
  33725. for (i = 0, n = entries.length; i < n; i += 2) {
  33726. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33727. }
  33728. }
  33729. }
  33730. return dict;
  33731. },
  33732. get: function NameOrNumberTree_get(key) {
  33733. if (!this.root) {
  33734. return null;
  33735. }
  33736. var xref = this.xref;
  33737. var kidsOrEntries = xref.fetchIfRef(this.root);
  33738. var loopCount = 0;
  33739. var MAX_LEVELS = 10;
  33740. var l, r, m;
  33741. // Perform a binary search to quickly find the entry that
  33742. // contains the key we are looking for.
  33743. while (kidsOrEntries.has('Kids')) {
  33744. if (++loopCount > MAX_LEVELS) {
  33745. warn('Search depth limit reached for "' + this._type + '" tree.');
  33746. return null;
  33747. }
  33748. var kids = kidsOrEntries.get('Kids');
  33749. if (!isArray(kids)) {
  33750. return null;
  33751. }
  33752. l = 0;
  33753. r = kids.length - 1;
  33754. while (l <= r) {
  33755. m = (l + r) >> 1;
  33756. var kid = xref.fetchIfRef(kids[m]);
  33757. var limits = kid.get('Limits');
  33758. if (key < xref.fetchIfRef(limits[0])) {
  33759. r = m - 1;
  33760. } else if (key > xref.fetchIfRef(limits[1])) {
  33761. l = m + 1;
  33762. } else {
  33763. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33764. break;
  33765. }
  33766. }
  33767. if (l > r) {
  33768. return null;
  33769. }
  33770. }
  33771. // If we get here, then we have found the right entry. Now go through the
  33772. // entries in the dictionary until we find the key we're looking for.
  33773. var entries = kidsOrEntries.get(this._type);
  33774. if (isArray(entries)) {
  33775. // Perform a binary search to reduce the lookup time.
  33776. l = 0;
  33777. r = entries.length - 2;
  33778. while (l <= r) {
  33779. // Check only even indices (0, 2, 4, ...) because the
  33780. // odd indices contain the actual data.
  33781. m = (l + r) & ~1;
  33782. var currentKey = xref.fetchIfRef(entries[m]);
  33783. if (key < currentKey) {
  33784. r = m - 2;
  33785. } else if (key > currentKey) {
  33786. l = m + 2;
  33787. } else {
  33788. return xref.fetchIfRef(entries[m + 1]);
  33789. }
  33790. }
  33791. }
  33792. return null;
  33793. }
  33794. };
  33795. return NameOrNumberTree;
  33796. })();
  33797. var NameTree = (function NameTreeClosure() {
  33798. function NameTree(root, xref) {
  33799. this.root = root;
  33800. this.xref = xref;
  33801. this._type = 'Names';
  33802. }
  33803. Util.inherit(NameTree, NameOrNumberTree, {});
  33804. return NameTree;
  33805. })();
  33806. var NumberTree = (function NumberTreeClosure() {
  33807. function NumberTree(root, xref) {
  33808. this.root = root;
  33809. this.xref = xref;
  33810. this._type = 'Nums';
  33811. }
  33812. Util.inherit(NumberTree, NameOrNumberTree, {});
  33813. return NumberTree;
  33814. })();
  33815. /**
  33816. * "A PDF file can refer to the contents of another file by using a File
  33817. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33818. * NOTE: Only embedded files are supported (as part of the attachments support)
  33819. * TODO: support the 'URL' file system (with caching if !/V), portable
  33820. * collections attributes and related files (/RF)
  33821. */
  33822. var FileSpec = (function FileSpecClosure() {
  33823. function FileSpec(root, xref) {
  33824. if (!root || !isDict(root)) {
  33825. return;
  33826. }
  33827. this.xref = xref;
  33828. this.root = root;
  33829. if (root.has('FS')) {
  33830. this.fs = root.get('FS');
  33831. }
  33832. this.description = root.has('Desc') ?
  33833. stringToPDFString(root.get('Desc')) :
  33834. '';
  33835. if (root.has('RF')) {
  33836. warn('Related file specifications are not supported');
  33837. }
  33838. this.contentAvailable = true;
  33839. if (!root.has('EF')) {
  33840. this.contentAvailable = false;
  33841. warn('Non-embedded file specifications are not supported');
  33842. }
  33843. }
  33844. function pickPlatformItem(dict) {
  33845. // Look for the filename in this order:
  33846. // UF, F, Unix, Mac, DOS
  33847. if (dict.has('UF')) {
  33848. return dict.get('UF');
  33849. } else if (dict.has('F')) {
  33850. return dict.get('F');
  33851. } else if (dict.has('Unix')) {
  33852. return dict.get('Unix');
  33853. } else if (dict.has('Mac')) {
  33854. return dict.get('Mac');
  33855. } else if (dict.has('DOS')) {
  33856. return dict.get('DOS');
  33857. } else {
  33858. return null;
  33859. }
  33860. }
  33861. FileSpec.prototype = {
  33862. get filename() {
  33863. if (!this._filename && this.root) {
  33864. var filename = pickPlatformItem(this.root) || 'unnamed';
  33865. this._filename = stringToPDFString(filename).
  33866. replace(/\\\\/g, '\\').
  33867. replace(/\\\//g, '/').
  33868. replace(/\\/g, '/');
  33869. }
  33870. return this._filename;
  33871. },
  33872. get content() {
  33873. if (!this.contentAvailable) {
  33874. return null;
  33875. }
  33876. if (!this.contentRef && this.root) {
  33877. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33878. }
  33879. var content = null;
  33880. if (this.contentRef) {
  33881. var xref = this.xref;
  33882. var fileObj = xref.fetchIfRef(this.contentRef);
  33883. if (fileObj && isStream(fileObj)) {
  33884. content = fileObj.getBytes();
  33885. } else {
  33886. warn('Embedded file specification points to non-existing/invalid ' +
  33887. 'content');
  33888. }
  33889. } else {
  33890. warn('Embedded file specification does not have a content');
  33891. }
  33892. return content;
  33893. },
  33894. get serializable() {
  33895. return {
  33896. filename: this.filename,
  33897. content: this.content
  33898. };
  33899. }
  33900. };
  33901. return FileSpec;
  33902. })();
  33903. /**
  33904. * A helper for loading missing data in object graphs. It traverses the graph
  33905. * depth first and queues up any objects that have missing data. Once it has
  33906. * has traversed as many objects that are available it attempts to bundle the
  33907. * missing data requests and then resume from the nodes that weren't ready.
  33908. *
  33909. * NOTE: It provides protection from circular references by keeping track of
  33910. * of loaded references. However, you must be careful not to load any graphs
  33911. * that have references to the catalog or other pages since that will cause the
  33912. * entire PDF document object graph to be traversed.
  33913. */
  33914. var ObjectLoader = (function() {
  33915. function mayHaveChildren(value) {
  33916. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  33917. }
  33918. function addChildren(node, nodesToVisit) {
  33919. var value;
  33920. if (isDict(node) || isStream(node)) {
  33921. var map;
  33922. if (isDict(node)) {
  33923. map = node.map;
  33924. } else {
  33925. map = node.dict.map;
  33926. }
  33927. for (var key in map) {
  33928. value = map[key];
  33929. if (mayHaveChildren(value)) {
  33930. nodesToVisit.push(value);
  33931. }
  33932. }
  33933. } else if (isArray(node)) {
  33934. for (var i = 0, ii = node.length; i < ii; i++) {
  33935. value = node[i];
  33936. if (mayHaveChildren(value)) {
  33937. nodesToVisit.push(value);
  33938. }
  33939. }
  33940. }
  33941. }
  33942. function ObjectLoader(obj, keys, xref) {
  33943. this.obj = obj;
  33944. this.keys = keys;
  33945. this.xref = xref;
  33946. this.refSet = null;
  33947. this.capability = null;
  33948. }
  33949. ObjectLoader.prototype = {
  33950. load: function ObjectLoader_load() {
  33951. var keys = this.keys;
  33952. this.capability = createPromiseCapability();
  33953. // Don't walk the graph if all the data is already loaded.
  33954. if (!(this.xref.stream instanceof ChunkedStream) ||
  33955. this.xref.stream.getMissingChunks().length === 0) {
  33956. this.capability.resolve();
  33957. return this.capability.promise;
  33958. }
  33959. this.refSet = new RefSet();
  33960. // Setup the initial nodes to visit.
  33961. var nodesToVisit = [];
  33962. for (var i = 0; i < keys.length; i++) {
  33963. nodesToVisit.push(this.obj[keys[i]]);
  33964. }
  33965. this._walk(nodesToVisit);
  33966. return this.capability.promise;
  33967. },
  33968. _walk: function ObjectLoader_walk(nodesToVisit) {
  33969. var nodesToRevisit = [];
  33970. var pendingRequests = [];
  33971. // DFS walk of the object graph.
  33972. while (nodesToVisit.length) {
  33973. var currentNode = nodesToVisit.pop();
  33974. // Only references or chunked streams can cause missing data exceptions.
  33975. if (isRef(currentNode)) {
  33976. // Skip nodes that have already been visited.
  33977. if (this.refSet.has(currentNode)) {
  33978. continue;
  33979. }
  33980. try {
  33981. var ref = currentNode;
  33982. this.refSet.put(ref);
  33983. currentNode = this.xref.fetch(currentNode);
  33984. } catch (e) {
  33985. if (!(e instanceof MissingDataException)) {
  33986. throw e;
  33987. }
  33988. nodesToRevisit.push(currentNode);
  33989. pendingRequests.push({ begin: e.begin, end: e.end });
  33990. }
  33991. }
  33992. if (currentNode && currentNode.getBaseStreams) {
  33993. var baseStreams = currentNode.getBaseStreams();
  33994. var foundMissingData = false;
  33995. for (var i = 0; i < baseStreams.length; i++) {
  33996. var stream = baseStreams[i];
  33997. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  33998. foundMissingData = true;
  33999. pendingRequests.push({
  34000. begin: stream.start,
  34001. end: stream.end
  34002. });
  34003. }
  34004. }
  34005. if (foundMissingData) {
  34006. nodesToRevisit.push(currentNode);
  34007. }
  34008. }
  34009. addChildren(currentNode, nodesToVisit);
  34010. }
  34011. if (pendingRequests.length) {
  34012. this.xref.stream.manager.requestRanges(pendingRequests).then(
  34013. function pendingRequestCallback() {
  34014. nodesToVisit = nodesToRevisit;
  34015. for (var i = 0; i < nodesToRevisit.length; i++) {
  34016. var node = nodesToRevisit[i];
  34017. // Remove any reference nodes from the currrent refset so they
  34018. // aren't skipped when we revist them.
  34019. if (isRef(node)) {
  34020. this.refSet.remove(node);
  34021. }
  34022. }
  34023. this._walk(nodesToVisit);
  34024. }.bind(this), this.capability.reject);
  34025. return;
  34026. }
  34027. // Everything is loaded.
  34028. this.refSet = null;
  34029. this.capability.resolve();
  34030. }
  34031. };
  34032. return ObjectLoader;
  34033. })();
  34034. exports.Catalog = Catalog;
  34035. exports.ObjectLoader = ObjectLoader;
  34036. exports.XRef = XRef;
  34037. exports.FileSpec = FileSpec;
  34038. }));
  34039. (function (root, factory) {
  34040. {
  34041. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  34042. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  34043. root.pdfjsCoreColorSpace);
  34044. }
  34045. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  34046. coreColorSpace) {
  34047. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34048. var MissingDataException = sharedUtil.MissingDataException;
  34049. var Util = sharedUtil.Util;
  34050. var assert = sharedUtil.assert;
  34051. var error = sharedUtil.error;
  34052. var info = sharedUtil.info;
  34053. var warn = sharedUtil.warn;
  34054. var isStream = corePrimitives.isStream;
  34055. var PDFFunction = coreFunction.PDFFunction;
  34056. var ColorSpace = coreColorSpace.ColorSpace;
  34057. var ShadingType = {
  34058. FUNCTION_BASED: 1,
  34059. AXIAL: 2,
  34060. RADIAL: 3,
  34061. FREE_FORM_MESH: 4,
  34062. LATTICE_FORM_MESH: 5,
  34063. COONS_PATCH_MESH: 6,
  34064. TENSOR_PATCH_MESH: 7
  34065. };
  34066. var Pattern = (function PatternClosure() {
  34067. // Constructor should define this.getPattern
  34068. function Pattern() {
  34069. error('should not call Pattern constructor');
  34070. }
  34071. Pattern.prototype = {
  34072. // Input: current Canvas context
  34073. // Output: the appropriate fillStyle or strokeStyle
  34074. getPattern: function Pattern_getPattern(ctx) {
  34075. error('Should not call Pattern.getStyle: ' + ctx);
  34076. }
  34077. };
  34078. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  34079. res, handler) {
  34080. var dict = isStream(shading) ? shading.dict : shading;
  34081. var type = dict.get('ShadingType');
  34082. try {
  34083. switch (type) {
  34084. case ShadingType.AXIAL:
  34085. case ShadingType.RADIAL:
  34086. // Both radial and axial shadings are handled by RadialAxial shading.
  34087. return new Shadings.RadialAxial(dict, matrix, xref, res);
  34088. case ShadingType.FREE_FORM_MESH:
  34089. case ShadingType.LATTICE_FORM_MESH:
  34090. case ShadingType.COONS_PATCH_MESH:
  34091. case ShadingType.TENSOR_PATCH_MESH:
  34092. return new Shadings.Mesh(shading, matrix, xref, res);
  34093. default:
  34094. throw new Error('Unsupported ShadingType: ' + type);
  34095. }
  34096. } catch (ex) {
  34097. if (ex instanceof MissingDataException) {
  34098. throw ex;
  34099. }
  34100. handler.send('UnsupportedFeature',
  34101. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  34102. warn(ex);
  34103. return new Shadings.Dummy();
  34104. }
  34105. };
  34106. return Pattern;
  34107. })();
  34108. var Shadings = {};
  34109. // A small number to offset the first/last color stops so we can insert ones to
  34110. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  34111. Shadings.SMALL_NUMBER = 1e-6;
  34112. // Radial and axial shading have very similar implementations
  34113. // If needed, the implementations can be broken into two classes
  34114. Shadings.RadialAxial = (function RadialAxialClosure() {
  34115. function RadialAxial(dict, matrix, xref, res) {
  34116. this.matrix = matrix;
  34117. this.coordsArr = dict.getArray('Coords');
  34118. this.shadingType = dict.get('ShadingType');
  34119. this.type = 'Pattern';
  34120. var cs = dict.get('ColorSpace', 'CS');
  34121. cs = ColorSpace.parse(cs, xref, res);
  34122. this.cs = cs;
  34123. var t0 = 0.0, t1 = 1.0;
  34124. if (dict.has('Domain')) {
  34125. var domainArr = dict.getArray('Domain');
  34126. t0 = domainArr[0];
  34127. t1 = domainArr[1];
  34128. }
  34129. var extendStart = false, extendEnd = false;
  34130. if (dict.has('Extend')) {
  34131. var extendArr = dict.getArray('Extend');
  34132. extendStart = extendArr[0];
  34133. extendEnd = extendArr[1];
  34134. }
  34135. if (this.shadingType === ShadingType.RADIAL &&
  34136. (!extendStart || !extendEnd)) {
  34137. // Radial gradient only currently works if either circle is fully within
  34138. // the other circle.
  34139. var x1 = this.coordsArr[0];
  34140. var y1 = this.coordsArr[1];
  34141. var r1 = this.coordsArr[2];
  34142. var x2 = this.coordsArr[3];
  34143. var y2 = this.coordsArr[4];
  34144. var r2 = this.coordsArr[5];
  34145. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34146. if (r1 <= r2 + distance &&
  34147. r2 <= r1 + distance) {
  34148. warn('Unsupported radial gradient.');
  34149. }
  34150. }
  34151. this.extendStart = extendStart;
  34152. this.extendEnd = extendEnd;
  34153. var fnObj = dict.get('Function');
  34154. var fn = PDFFunction.parseArray(xref, fnObj);
  34155. // 10 samples seems good enough for now, but probably won't work
  34156. // if there are sharp color changes. Ideally, we would implement
  34157. // the spec faithfully and add lossless optimizations.
  34158. var diff = t1 - t0;
  34159. var step = diff / 10;
  34160. var colorStops = this.colorStops = [];
  34161. // Protect against bad domains so we don't end up in an infinte loop below.
  34162. if (t0 >= t1 || step <= 0) {
  34163. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34164. // now.
  34165. info('Bad shading domain.');
  34166. return;
  34167. }
  34168. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34169. var rgbColor;
  34170. for (var i = t0; i <= t1; i += step) {
  34171. ratio[0] = i;
  34172. fn(ratio, 0, color, 0);
  34173. rgbColor = cs.getRgb(color, 0);
  34174. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34175. colorStops.push([(i - t0) / diff, cssColor]);
  34176. }
  34177. var background = 'transparent';
  34178. if (dict.has('Background')) {
  34179. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34180. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34181. }
  34182. if (!extendStart) {
  34183. // Insert a color stop at the front and offset the first real color stop
  34184. // so it doesn't conflict with the one we insert.
  34185. colorStops.unshift([0, background]);
  34186. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34187. }
  34188. if (!extendEnd) {
  34189. // Same idea as above in extendStart but for the end.
  34190. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34191. colorStops.push([1, background]);
  34192. }
  34193. this.colorStops = colorStops;
  34194. }
  34195. RadialAxial.prototype = {
  34196. getIR: function RadialAxial_getIR() {
  34197. var coordsArr = this.coordsArr;
  34198. var shadingType = this.shadingType;
  34199. var type, p0, p1, r0, r1;
  34200. if (shadingType === ShadingType.AXIAL) {
  34201. p0 = [coordsArr[0], coordsArr[1]];
  34202. p1 = [coordsArr[2], coordsArr[3]];
  34203. r0 = null;
  34204. r1 = null;
  34205. type = 'axial';
  34206. } else if (shadingType === ShadingType.RADIAL) {
  34207. p0 = [coordsArr[0], coordsArr[1]];
  34208. p1 = [coordsArr[3], coordsArr[4]];
  34209. r0 = coordsArr[2];
  34210. r1 = coordsArr[5];
  34211. type = 'radial';
  34212. } else {
  34213. error('getPattern type unknown: ' + shadingType);
  34214. }
  34215. var matrix = this.matrix;
  34216. if (matrix) {
  34217. p0 = Util.applyTransform(p0, matrix);
  34218. p1 = Util.applyTransform(p1, matrix);
  34219. if (shadingType === ShadingType.RADIAL) {
  34220. var scale = Util.singularValueDecompose2dScale(matrix);
  34221. r0 *= scale[0];
  34222. r1 *= scale[1];
  34223. }
  34224. }
  34225. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34226. }
  34227. };
  34228. return RadialAxial;
  34229. })();
  34230. // All mesh shading. For now, they will be presented as set of the triangles
  34231. // to be drawn on the canvas and rgb color for each vertex.
  34232. Shadings.Mesh = (function MeshClosure() {
  34233. function MeshStreamReader(stream, context) {
  34234. this.stream = stream;
  34235. this.context = context;
  34236. this.buffer = 0;
  34237. this.bufferLength = 0;
  34238. var numComps = context.numComps;
  34239. this.tmpCompsBuf = new Float32Array(numComps);
  34240. var csNumComps = context.colorSpace.numComps;
  34241. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34242. this.tmpCompsBuf;
  34243. }
  34244. MeshStreamReader.prototype = {
  34245. get hasData() {
  34246. if (this.stream.end) {
  34247. return this.stream.pos < this.stream.end;
  34248. }
  34249. if (this.bufferLength > 0) {
  34250. return true;
  34251. }
  34252. var nextByte = this.stream.getByte();
  34253. if (nextByte < 0) {
  34254. return false;
  34255. }
  34256. this.buffer = nextByte;
  34257. this.bufferLength = 8;
  34258. return true;
  34259. },
  34260. readBits: function MeshStreamReader_readBits(n) {
  34261. var buffer = this.buffer;
  34262. var bufferLength = this.bufferLength;
  34263. if (n === 32) {
  34264. if (bufferLength === 0) {
  34265. return ((this.stream.getByte() << 24) |
  34266. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34267. this.stream.getByte()) >>> 0;
  34268. }
  34269. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34270. (this.stream.getByte() << 8) | this.stream.getByte();
  34271. var nextByte = this.stream.getByte();
  34272. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34273. return ((buffer << (8 - bufferLength)) |
  34274. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34275. }
  34276. if (n === 8 && bufferLength === 0) {
  34277. return this.stream.getByte();
  34278. }
  34279. while (bufferLength < n) {
  34280. buffer = (buffer << 8) | this.stream.getByte();
  34281. bufferLength += 8;
  34282. }
  34283. bufferLength -= n;
  34284. this.bufferLength = bufferLength;
  34285. this.buffer = buffer & ((1 << bufferLength) - 1);
  34286. return buffer >> bufferLength;
  34287. },
  34288. align: function MeshStreamReader_align() {
  34289. this.buffer = 0;
  34290. this.bufferLength = 0;
  34291. },
  34292. readFlag: function MeshStreamReader_readFlag() {
  34293. return this.readBits(this.context.bitsPerFlag);
  34294. },
  34295. readCoordinate: function MeshStreamReader_readCoordinate() {
  34296. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34297. var xi = this.readBits(bitsPerCoordinate);
  34298. var yi = this.readBits(bitsPerCoordinate);
  34299. var decode = this.context.decode;
  34300. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34301. 2.3283064365386963e-10; // 2 ^ -32
  34302. return [
  34303. xi * scale * (decode[1] - decode[0]) + decode[0],
  34304. yi * scale * (decode[3] - decode[2]) + decode[2]
  34305. ];
  34306. },
  34307. readComponents: function MeshStreamReader_readComponents() {
  34308. var numComps = this.context.numComps;
  34309. var bitsPerComponent = this.context.bitsPerComponent;
  34310. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34311. 2.3283064365386963e-10; // 2 ^ -32
  34312. var decode = this.context.decode;
  34313. var components = this.tmpCompsBuf;
  34314. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34315. var ci = this.readBits(bitsPerComponent);
  34316. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34317. }
  34318. var color = this.tmpCsCompsBuf;
  34319. if (this.context.colorFn) {
  34320. this.context.colorFn(components, 0, color, 0);
  34321. }
  34322. return this.context.colorSpace.getRgb(color, 0);
  34323. }
  34324. };
  34325. function decodeType4Shading(mesh, reader) {
  34326. var coords = mesh.coords;
  34327. var colors = mesh.colors;
  34328. var operators = [];
  34329. var ps = []; // not maintaining cs since that will match ps
  34330. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34331. while (reader.hasData) {
  34332. var f = reader.readFlag();
  34333. var coord = reader.readCoordinate();
  34334. var color = reader.readComponents();
  34335. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34336. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34337. switch (f) {
  34338. case 0:
  34339. verticesLeft = 3;
  34340. break;
  34341. case 1:
  34342. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34343. verticesLeft = 1;
  34344. break;
  34345. case 2:
  34346. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34347. verticesLeft = 1;
  34348. break;
  34349. }
  34350. operators.push(f);
  34351. }
  34352. ps.push(coords.length);
  34353. coords.push(coord);
  34354. colors.push(color);
  34355. verticesLeft--;
  34356. reader.align();
  34357. }
  34358. mesh.figures.push({
  34359. type: 'triangles',
  34360. coords: new Int32Array(ps),
  34361. colors: new Int32Array(ps),
  34362. });
  34363. }
  34364. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34365. var coords = mesh.coords;
  34366. var colors = mesh.colors;
  34367. var ps = []; // not maintaining cs since that will match ps
  34368. while (reader.hasData) {
  34369. var coord = reader.readCoordinate();
  34370. var color = reader.readComponents();
  34371. ps.push(coords.length);
  34372. coords.push(coord);
  34373. colors.push(color);
  34374. }
  34375. mesh.figures.push({
  34376. type: 'lattice',
  34377. coords: new Int32Array(ps),
  34378. colors: new Int32Array(ps),
  34379. verticesPerRow: verticesPerRow
  34380. });
  34381. }
  34382. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34383. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34384. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34385. var getB = (function getBClosure() {
  34386. function buildB(count) {
  34387. var lut = [];
  34388. for (var i = 0; i <= count; i++) {
  34389. var t = i / count, t_ = 1 - t;
  34390. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34391. 3 * t * t * t_, t * t * t]));
  34392. }
  34393. return lut;
  34394. }
  34395. var cache = [];
  34396. return function getB(count) {
  34397. if (!cache[count]) {
  34398. cache[count] = buildB(count);
  34399. }
  34400. return cache[count];
  34401. };
  34402. })();
  34403. function buildFigureFromPatch(mesh, index) {
  34404. var figure = mesh.figures[index];
  34405. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34406. var coords = mesh.coords, colors = mesh.colors;
  34407. var pi = figure.coords;
  34408. var ci = figure.colors;
  34409. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34410. coords[pi[12]][0], coords[pi[15]][0]);
  34411. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34412. coords[pi[12]][1], coords[pi[15]][1]);
  34413. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34414. coords[pi[12]][0], coords[pi[15]][0]);
  34415. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34416. coords[pi[12]][1], coords[pi[15]][1]);
  34417. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34418. (mesh.bounds[2] - mesh.bounds[0]));
  34419. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34420. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34421. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34422. (mesh.bounds[3] - mesh.bounds[1]));
  34423. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34424. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34425. var verticesPerRow = splitXBy + 1;
  34426. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34427. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34428. var k = 0;
  34429. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34430. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34431. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34432. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34433. for (var row = 0; row <= splitYBy; row++) {
  34434. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34435. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34436. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34437. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34438. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34439. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34440. for (var col = 0; col <= splitXBy; col++, k++) {
  34441. if ((row === 0 || row === splitYBy) &&
  34442. (col === 0 || col === splitXBy)) {
  34443. continue;
  34444. }
  34445. var x = 0, y = 0;
  34446. var q = 0;
  34447. for (var i = 0; i <= 3; i++) {
  34448. for (var j = 0; j <= 3; j++, q++) {
  34449. var m = bRow[row][i] * bCol[col][j];
  34450. x += coords[pi[q]][0] * m;
  34451. y += coords[pi[q]][1] * m;
  34452. }
  34453. }
  34454. figureCoords[k] = coords.length;
  34455. coords.push([x, y]);
  34456. figureColors[k] = colors.length;
  34457. var newColor = new Uint8Array(3);
  34458. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34459. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34460. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34461. colors.push(newColor);
  34462. }
  34463. }
  34464. figureCoords[0] = pi[0];
  34465. figureColors[0] = ci[0];
  34466. figureCoords[splitXBy] = pi[3];
  34467. figureColors[splitXBy] = ci[1];
  34468. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34469. figureColors[verticesPerRow * splitYBy] = ci[2];
  34470. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34471. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34472. mesh.figures[index] = {
  34473. type: 'lattice',
  34474. coords: figureCoords,
  34475. colors: figureColors,
  34476. verticesPerRow: verticesPerRow
  34477. };
  34478. }
  34479. function decodeType6Shading(mesh, reader) {
  34480. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34481. var coords = mesh.coords;
  34482. var colors = mesh.colors;
  34483. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34484. var cs = new Int32Array(4); // c00, c30, c03, c33
  34485. while (reader.hasData) {
  34486. var f = reader.readFlag();
  34487. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34488. var i, ii;
  34489. var pi = coords.length;
  34490. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34491. coords.push(reader.readCoordinate());
  34492. }
  34493. var ci = colors.length;
  34494. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34495. colors.push(reader.readComponents());
  34496. }
  34497. var tmp1, tmp2, tmp3, tmp4;
  34498. switch (f) {
  34499. case 0:
  34500. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34501. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34502. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34503. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34504. cs[2] = ci + 1; cs[3] = ci + 2;
  34505. cs[0] = ci; cs[1] = ci + 3;
  34506. break;
  34507. case 1:
  34508. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34509. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34510. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34511. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34512. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34513. tmp1 = cs[2]; tmp2 = cs[3];
  34514. cs[2] = tmp2; cs[3] = ci;
  34515. cs[0] = tmp1; cs[1] = ci + 1;
  34516. break;
  34517. case 2:
  34518. tmp1 = ps[15];
  34519. tmp2 = ps[11];
  34520. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34521. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34522. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34523. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34524. tmp1 = cs[3];
  34525. cs[2] = cs[1]; cs[3] = ci;
  34526. cs[0] = tmp1; cs[1] = ci + 1;
  34527. break;
  34528. case 3:
  34529. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34530. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34531. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34532. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34533. cs[2] = cs[0]; cs[3] = ci;
  34534. cs[0] = cs[1]; cs[1] = ci + 1;
  34535. break;
  34536. }
  34537. // set p11, p12, p21, p22
  34538. ps[5] = coords.length;
  34539. coords.push([
  34540. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34541. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34542. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34543. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34544. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34545. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34546. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34547. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34548. ]);
  34549. ps[6] = coords.length;
  34550. coords.push([
  34551. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34552. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34553. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34554. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34555. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34556. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34557. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34558. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34559. ]);
  34560. ps[9] = coords.length;
  34561. coords.push([
  34562. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34563. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34564. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34565. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34566. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34567. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34568. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34569. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34570. ]);
  34571. ps[10] = coords.length;
  34572. coords.push([
  34573. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34574. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34575. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34576. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34577. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34578. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34579. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34580. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34581. ]);
  34582. mesh.figures.push({
  34583. type: 'patch',
  34584. coords: new Int32Array(ps), // making copies of ps and cs
  34585. colors: new Int32Array(cs)
  34586. });
  34587. }
  34588. }
  34589. function decodeType7Shading(mesh, reader) {
  34590. var coords = mesh.coords;
  34591. var colors = mesh.colors;
  34592. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34593. var cs = new Int32Array(4); // c00, c30, c03, c33
  34594. while (reader.hasData) {
  34595. var f = reader.readFlag();
  34596. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34597. var i, ii;
  34598. var pi = coords.length;
  34599. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34600. coords.push(reader.readCoordinate());
  34601. }
  34602. var ci = colors.length;
  34603. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34604. colors.push(reader.readComponents());
  34605. }
  34606. var tmp1, tmp2, tmp3, tmp4;
  34607. switch (f) {
  34608. case 0:
  34609. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34610. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34611. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34612. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34613. cs[2] = ci + 1; cs[3] = ci + 2;
  34614. cs[0] = ci; cs[1] = ci + 3;
  34615. break;
  34616. case 1:
  34617. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34618. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34619. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34620. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34621. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34622. tmp1 = cs[2]; tmp2 = cs[3];
  34623. cs[2] = tmp2; cs[3] = ci;
  34624. cs[0] = tmp1; cs[1] = ci + 1;
  34625. break;
  34626. case 2:
  34627. tmp1 = ps[15];
  34628. tmp2 = ps[11];
  34629. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34630. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34631. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34632. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34633. tmp1 = cs[3];
  34634. cs[2] = cs[1]; cs[3] = ci;
  34635. cs[0] = tmp1; cs[1] = ci + 1;
  34636. break;
  34637. case 3:
  34638. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34639. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34640. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34641. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34642. cs[2] = cs[0]; cs[3] = ci;
  34643. cs[0] = cs[1]; cs[1] = ci + 1;
  34644. break;
  34645. }
  34646. mesh.figures.push({
  34647. type: 'patch',
  34648. coords: new Int32Array(ps), // making copies of ps and cs
  34649. colors: new Int32Array(cs)
  34650. });
  34651. }
  34652. }
  34653. function updateBounds(mesh) {
  34654. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34655. maxX = minX, maxY = minY;
  34656. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34657. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34658. minX = minX > x ? x : minX;
  34659. minY = minY > y ? y : minY;
  34660. maxX = maxX < x ? x : maxX;
  34661. maxY = maxY < y ? y : maxY;
  34662. }
  34663. mesh.bounds = [minX, minY, maxX, maxY];
  34664. }
  34665. function packData(mesh) {
  34666. var i, ii, j, jj;
  34667. var coords = mesh.coords;
  34668. var coordsPacked = new Float32Array(coords.length * 2);
  34669. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34670. var xy = coords[i];
  34671. coordsPacked[j++] = xy[0];
  34672. coordsPacked[j++] = xy[1];
  34673. }
  34674. mesh.coords = coordsPacked;
  34675. var colors = mesh.colors;
  34676. var colorsPacked = new Uint8Array(colors.length * 3);
  34677. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34678. var c = colors[i];
  34679. colorsPacked[j++] = c[0];
  34680. colorsPacked[j++] = c[1];
  34681. colorsPacked[j++] = c[2];
  34682. }
  34683. mesh.colors = colorsPacked;
  34684. var figures = mesh.figures;
  34685. for (i = 0, ii = figures.length; i < ii; i++) {
  34686. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34687. for (j = 0, jj = ps.length; j < jj; j++) {
  34688. ps[j] *= 2;
  34689. cs[j] *= 3;
  34690. }
  34691. }
  34692. }
  34693. function Mesh(stream, matrix, xref, res) {
  34694. assert(isStream(stream), 'Mesh data is not a stream');
  34695. var dict = stream.dict;
  34696. this.matrix = matrix;
  34697. this.shadingType = dict.get('ShadingType');
  34698. this.type = 'Pattern';
  34699. this.bbox = dict.getArray('BBox');
  34700. var cs = dict.get('ColorSpace', 'CS');
  34701. cs = ColorSpace.parse(cs, xref, res);
  34702. this.cs = cs;
  34703. this.background = dict.has('Background') ?
  34704. cs.getRgb(dict.get('Background'), 0) : null;
  34705. var fnObj = dict.get('Function');
  34706. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34707. this.coords = [];
  34708. this.colors = [];
  34709. this.figures = [];
  34710. var decodeContext = {
  34711. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34712. bitsPerComponent: dict.get('BitsPerComponent'),
  34713. bitsPerFlag: dict.get('BitsPerFlag'),
  34714. decode: dict.getArray('Decode'),
  34715. colorFn: fn,
  34716. colorSpace: cs,
  34717. numComps: fn ? 1 : cs.numComps
  34718. };
  34719. var reader = new MeshStreamReader(stream, decodeContext);
  34720. var patchMesh = false;
  34721. switch (this.shadingType) {
  34722. case ShadingType.FREE_FORM_MESH:
  34723. decodeType4Shading(this, reader);
  34724. break;
  34725. case ShadingType.LATTICE_FORM_MESH:
  34726. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34727. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34728. decodeType5Shading(this, reader, verticesPerRow);
  34729. break;
  34730. case ShadingType.COONS_PATCH_MESH:
  34731. decodeType6Shading(this, reader);
  34732. patchMesh = true;
  34733. break;
  34734. case ShadingType.TENSOR_PATCH_MESH:
  34735. decodeType7Shading(this, reader);
  34736. patchMesh = true;
  34737. break;
  34738. default:
  34739. error('Unsupported mesh type.');
  34740. break;
  34741. }
  34742. if (patchMesh) {
  34743. // dirty bounds calculation for determining, how dense shall be triangles
  34744. updateBounds(this);
  34745. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34746. buildFigureFromPatch(this, i);
  34747. }
  34748. }
  34749. // calculate bounds
  34750. updateBounds(this);
  34751. packData(this);
  34752. }
  34753. Mesh.prototype = {
  34754. getIR: function Mesh_getIR() {
  34755. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34756. this.bounds, this.matrix, this.bbox, this.background];
  34757. }
  34758. };
  34759. return Mesh;
  34760. })();
  34761. Shadings.Dummy = (function DummyClosure() {
  34762. function Dummy() {
  34763. this.type = 'Pattern';
  34764. }
  34765. Dummy.prototype = {
  34766. getIR: function Dummy_getIR() {
  34767. return ['Dummy'];
  34768. }
  34769. };
  34770. return Dummy;
  34771. })();
  34772. function getTilingPatternIR(operatorList, dict, args) {
  34773. var matrix = dict.getArray('Matrix');
  34774. var bbox = dict.getArray('BBox');
  34775. var xstep = dict.get('XStep');
  34776. var ystep = dict.get('YStep');
  34777. var paintType = dict.get('PaintType');
  34778. var tilingType = dict.get('TilingType');
  34779. return [
  34780. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34781. paintType, tilingType
  34782. ];
  34783. }
  34784. exports.Pattern = Pattern;
  34785. exports.getTilingPatternIR = getTilingPatternIR;
  34786. }));
  34787. (function (root, factory) {
  34788. {
  34789. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34790. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34791. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34792. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34793. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34794. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34795. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  34796. }
  34797. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34798. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34799. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34800. coreEncodings, coreStandardFonts, coreUnicode,
  34801. coreGlyphList) {
  34802. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34803. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34804. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34805. var ImageKind = sharedUtil.ImageKind;
  34806. var OPS = sharedUtil.OPS;
  34807. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34808. var Util = sharedUtil.Util;
  34809. var assert = sharedUtil.assert;
  34810. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34811. var error = sharedUtil.error;
  34812. var info = sharedUtil.info;
  34813. var isArray = sharedUtil.isArray;
  34814. var isNum = sharedUtil.isNum;
  34815. var isString = sharedUtil.isString;
  34816. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34817. var warn = sharedUtil.warn;
  34818. var Dict = corePrimitives.Dict;
  34819. var Name = corePrimitives.Name;
  34820. var isCmd = corePrimitives.isCmd;
  34821. var isDict = corePrimitives.isDict;
  34822. var isName = corePrimitives.isName;
  34823. var isRef = corePrimitives.isRef;
  34824. var isStream = corePrimitives.isStream;
  34825. var DecodeStream = coreStream.DecodeStream;
  34826. var JpegStream = coreStream.JpegStream;
  34827. var Stream = coreStream.Stream;
  34828. var Lexer = coreParser.Lexer;
  34829. var Parser = coreParser.Parser;
  34830. var isEOF = coreParser.isEOF;
  34831. var PDFImage = coreImage.PDFImage;
  34832. var ColorSpace = coreColorSpace.ColorSpace;
  34833. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34834. var ErrorFont = coreFonts.ErrorFont;
  34835. var FontFlags = coreFonts.FontFlags;
  34836. var Font = coreFonts.Font;
  34837. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34838. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34839. var getFontType = coreFonts.getFontType;
  34840. var isPDFFunction = coreFunction.isPDFFunction;
  34841. var PDFFunction = coreFunction.PDFFunction;
  34842. var Pattern = corePattern.Pattern;
  34843. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34844. var CMapFactory = coreCMap.CMapFactory;
  34845. var IdentityCMap = coreCMap.IdentityCMap;
  34846. var getMetrics = coreMetrics.getMetrics;
  34847. var bidi = coreBidi.bidi;
  34848. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34849. var StandardEncoding = coreEncodings.StandardEncoding;
  34850. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34851. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34852. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34853. var getEncoding = coreEncodings.getEncoding;
  34854. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34855. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34856. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34857. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34858. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34859. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  34860. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34861. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34862. var DefaultPartialEvaluatorOptions = {
  34863. forceDataSchema: false,
  34864. maxImageSize: -1,
  34865. disableFontFace: false,
  34866. cMapOptions: { url: null, packed: false }
  34867. };
  34868. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  34869. this.xref = xref;
  34870. this.resources = resources;
  34871. this.handler = handler;
  34872. this.forceDataSchema = forceDataSchema;
  34873. }
  34874. NativeImageDecoder.prototype = {
  34875. canDecode: function (image) {
  34876. return image instanceof JpegStream &&
  34877. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  34878. },
  34879. decode: function (image) {
  34880. // For natively supported JPEGs send them to the main thread for decoding.
  34881. var dict = image.dict;
  34882. var colorSpace = dict.get('ColorSpace', 'CS');
  34883. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  34884. var numComps = colorSpace.numComps;
  34885. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  34886. [image.getIR(this.forceDataSchema), numComps]);
  34887. return decodePromise.then(function (message) {
  34888. var data = message.data;
  34889. return new Stream(data, 0, data.length, image.dict);
  34890. });
  34891. }
  34892. };
  34893. /**
  34894. * Checks if the image can be decoded and displayed by the browser without any
  34895. * further processing such as color space conversions.
  34896. */
  34897. NativeImageDecoder.isSupported =
  34898. function NativeImageDecoder_isSupported(image, xref, res) {
  34899. var dict = image.dict;
  34900. if (dict.has('DecodeParms') || dict.has('DP')) {
  34901. return false;
  34902. }
  34903. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  34904. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  34905. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  34906. };
  34907. /**
  34908. * Checks if the image can be decoded by the browser.
  34909. */
  34910. NativeImageDecoder.isDecodable =
  34911. function NativeImageDecoder_isDecodable(image, xref, res) {
  34912. var dict = image.dict;
  34913. if (dict.has('DecodeParms') || dict.has('DP')) {
  34914. return false;
  34915. }
  34916. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  34917. return (cs.numComps === 1 || cs.numComps === 3) &&
  34918. cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  34919. };
  34920. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34921. uniquePrefix, idCounters, fontCache, options) {
  34922. this.pdfManager = pdfManager;
  34923. this.xref = xref;
  34924. this.handler = handler;
  34925. this.pageIndex = pageIndex;
  34926. this.uniquePrefix = uniquePrefix;
  34927. this.idCounters = idCounters;
  34928. this.fontCache = fontCache;
  34929. this.options = options || DefaultPartialEvaluatorOptions;
  34930. }
  34931. // Trying to minimize Date.now() usage and check every 100 time
  34932. var TIME_SLOT_DURATION_MS = 20;
  34933. var CHECK_TIME_EVERY = 100;
  34934. function TimeSlotManager() {
  34935. this.reset();
  34936. }
  34937. TimeSlotManager.prototype = {
  34938. check: function TimeSlotManager_check() {
  34939. if (++this.checked < CHECK_TIME_EVERY) {
  34940. return false;
  34941. }
  34942. this.checked = 0;
  34943. return this.endTime <= Date.now();
  34944. },
  34945. reset: function TimeSlotManager_reset() {
  34946. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34947. this.checked = 0;
  34948. }
  34949. };
  34950. var deferred = Promise.resolve();
  34951. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34952. PartialEvaluator.prototype = {
  34953. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34954. if (!isDict(resources)) {
  34955. return false;
  34956. }
  34957. var processed = Object.create(null);
  34958. if (resources.objId) {
  34959. processed[resources.objId] = true;
  34960. }
  34961. var nodes = [resources], xref = this.xref;
  34962. while (nodes.length) {
  34963. var key, i, ii;
  34964. var node = nodes.shift();
  34965. // First check the current resources for blend modes.
  34966. var graphicStates = node.get('ExtGState');
  34967. if (isDict(graphicStates)) {
  34968. var graphicStatesKeys = graphicStates.getKeys();
  34969. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  34970. key = graphicStatesKeys[i];
  34971. var graphicState = graphicStates.get(key);
  34972. var bm = graphicState.get('BM');
  34973. if (isName(bm) && bm.name !== 'Normal') {
  34974. return true;
  34975. }
  34976. }
  34977. }
  34978. // Descend into the XObjects to look for more resources and blend modes.
  34979. var xObjects = node.get('XObject');
  34980. if (!isDict(xObjects)) {
  34981. continue;
  34982. }
  34983. var xObjectsKeys = xObjects.getKeys();
  34984. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  34985. key = xObjectsKeys[i];
  34986. var xObject = xObjects.getRaw(key);
  34987. if (isRef(xObject)) {
  34988. if (processed[xObject.toString()]) {
  34989. // The XObject has already been processed, and by avoiding a
  34990. // redundant `xref.fetch` we can *significantly* reduce the load
  34991. // time for badly generated PDF files (fixes issue6961.pdf).
  34992. continue;
  34993. }
  34994. xObject = xref.fetch(xObject);
  34995. }
  34996. if (!isStream(xObject)) {
  34997. continue;
  34998. }
  34999. if (xObject.dict.objId) {
  35000. if (processed[xObject.dict.objId]) {
  35001. // stream has objId and is processed already
  35002. continue;
  35003. }
  35004. processed[xObject.dict.objId] = true;
  35005. }
  35006. var xResources = xObject.dict.get('Resources');
  35007. // Checking objId to detect an infinite loop.
  35008. if (isDict(xResources) &&
  35009. (!xResources.objId || !processed[xResources.objId])) {
  35010. nodes.push(xResources);
  35011. if (xResources.objId) {
  35012. processed[xResources.objId] = true;
  35013. }
  35014. }
  35015. }
  35016. }
  35017. return false;
  35018. },
  35019. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  35020. xobj, smask,
  35021. operatorList,
  35022. task,
  35023. initialState) {
  35024. var matrix = xobj.dict.getArray('Matrix');
  35025. var bbox = xobj.dict.getArray('BBox');
  35026. var group = xobj.dict.get('Group');
  35027. if (group) {
  35028. var groupOptions = {
  35029. matrix: matrix,
  35030. bbox: bbox,
  35031. smask: smask,
  35032. isolated: false,
  35033. knockout: false
  35034. };
  35035. var groupSubtype = group.get('S');
  35036. var colorSpace;
  35037. if (isName(groupSubtype, 'Transparency')) {
  35038. groupOptions.isolated = (group.get('I') || false);
  35039. groupOptions.knockout = (group.get('K') || false);
  35040. colorSpace = (group.has('CS') ?
  35041. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  35042. }
  35043. if (smask && smask.backdrop) {
  35044. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  35045. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  35046. }
  35047. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  35048. }
  35049. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  35050. return this.getOperatorList(xobj, task,
  35051. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  35052. then(function () {
  35053. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  35054. if (group) {
  35055. operatorList.addOp(OPS.endGroup, [groupOptions]);
  35056. }
  35057. });
  35058. },
  35059. buildPaintImageXObject:
  35060. function PartialEvaluator_buildPaintImageXObject(resources, image,
  35061. inline, operatorList,
  35062. cacheKey, imageCache) {
  35063. var self = this;
  35064. var dict = image.dict;
  35065. var w = dict.get('Width', 'W');
  35066. var h = dict.get('Height', 'H');
  35067. if (!(w && isNum(w)) || !(h && isNum(h))) {
  35068. warn('Image dimensions are missing, or not numbers.');
  35069. return;
  35070. }
  35071. var maxImageSize = this.options.maxImageSize;
  35072. if (maxImageSize !== -1 && w * h > maxImageSize) {
  35073. warn('Image exceeded maximum allowed size and was removed.');
  35074. return;
  35075. }
  35076. var imageMask = (dict.get('ImageMask', 'IM') || false);
  35077. var imgData, args;
  35078. if (imageMask) {
  35079. // This depends on a tmpCanvas being filled with the
  35080. // current fillStyle, such that processing the pixel
  35081. // data can't be done here. Instead of creating a
  35082. // complete PDFImage, only read the information needed
  35083. // for later.
  35084. var width = dict.get('Width', 'W');
  35085. var height = dict.get('Height', 'H');
  35086. var bitStrideLength = (width + 7) >> 3;
  35087. var imgArray = image.getBytes(bitStrideLength * height);
  35088. var decode = dict.getArray('Decode', 'D');
  35089. var inverseDecode = (!!decode && decode[0] > 0);
  35090. imgData = PDFImage.createMask(imgArray, width, height,
  35091. image instanceof DecodeStream,
  35092. inverseDecode);
  35093. imgData.cached = true;
  35094. args = [imgData];
  35095. operatorList.addOp(OPS.paintImageMaskXObject, args);
  35096. if (cacheKey) {
  35097. imageCache[cacheKey] = {
  35098. fn: OPS.paintImageMaskXObject,
  35099. args: args
  35100. };
  35101. }
  35102. return;
  35103. }
  35104. var softMask = (dict.get('SMask', 'SM') || false);
  35105. var mask = (dict.get('Mask') || false);
  35106. var SMALL_IMAGE_DIMENSIONS = 200;
  35107. // Inlining small images into the queue as RGB data
  35108. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  35109. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  35110. var imageObj = new PDFImage(this.xref, resources, image,
  35111. inline, null, null);
  35112. // We force the use of RGBA_32BPP images here, because we can't handle
  35113. // any other kind.
  35114. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  35115. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  35116. return;
  35117. }
  35118. // If there is no imageMask, create the PDFImage and a lot
  35119. // of image processing can be done here.
  35120. var uniquePrefix = (this.uniquePrefix || '');
  35121. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  35122. operatorList.addDependency(objId);
  35123. args = [objId, w, h];
  35124. if (!softMask && !mask && image instanceof JpegStream &&
  35125. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  35126. // These JPEGs don't need any more processing so we can just send it.
  35127. operatorList.addOp(OPS.paintJpegXObject, args);
  35128. this.handler.send('obj',
  35129. [objId, this.pageIndex, 'JpegStream',
  35130. image.getIR(this.options.forceDataSchema)]);
  35131. return;
  35132. }
  35133. // Creates native image decoder only if a JPEG image or mask is present.
  35134. var nativeImageDecoder = null;
  35135. if (image instanceof JpegStream || mask instanceof JpegStream ||
  35136. softMask instanceof JpegStream) {
  35137. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  35138. self.handler, self.options.forceDataSchema);
  35139. }
  35140. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  35141. nativeImageDecoder).
  35142. then(function(imageObj) {
  35143. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  35144. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  35145. [imgData.data.buffer]);
  35146. }).then(undefined, function (reason) {
  35147. warn('Unable to decode image: ' + reason);
  35148. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  35149. });
  35150. operatorList.addOp(OPS.paintImageXObject, args);
  35151. if (cacheKey) {
  35152. imageCache[cacheKey] = {
  35153. fn: OPS.paintImageXObject,
  35154. args: args
  35155. };
  35156. }
  35157. },
  35158. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  35159. operatorList, task,
  35160. stateManager) {
  35161. var smaskContent = smask.get('G');
  35162. var smaskOptions = {
  35163. subtype: smask.get('S').name,
  35164. backdrop: smask.get('BC')
  35165. };
  35166. // The SMask might have a alpha/luminosity value transfer function --
  35167. // we will build a map of integer values in range 0..255 to be fast.
  35168. var transferObj = smask.get('TR');
  35169. if (isPDFFunction(transferObj)) {
  35170. var transferFn = PDFFunction.parse(this.xref, transferObj);
  35171. var transferMap = new Uint8Array(256);
  35172. var tmp = new Float32Array(1);
  35173. for (var i = 0; i < 256; i++) {
  35174. tmp[0] = i / 255;
  35175. transferFn(tmp, 0, tmp, 0);
  35176. transferMap[i] = (tmp[0] * 255) | 0;
  35177. }
  35178. smaskOptions.transferMap = transferMap;
  35179. }
  35180. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  35181. operatorList, task, stateManager.state.clone());
  35182. },
  35183. handleTilingType:
  35184. function PartialEvaluator_handleTilingType(fn, args, resources,
  35185. pattern, patternDict,
  35186. operatorList, task) {
  35187. // Create an IR of the pattern code.
  35188. var tilingOpList = new OperatorList();
  35189. // Merge the available resources, to prevent issues when the patternDict
  35190. // is missing some /Resources entries (fixes issue6541.pdf).
  35191. var resourcesArray = [patternDict.get('Resources'), resources];
  35192. var patternResources = Dict.merge(this.xref, resourcesArray);
  35193. return this.getOperatorList(pattern, task, patternResources,
  35194. tilingOpList).then(function () {
  35195. // Add the dependencies to the parent operator list so they are
  35196. // resolved before sub operator list is executed synchronously.
  35197. operatorList.addDependencies(tilingOpList.dependencies);
  35198. operatorList.addOp(fn, getTilingPatternIR({
  35199. fnArray: tilingOpList.fnArray,
  35200. argsArray: tilingOpList.argsArray
  35201. }, patternDict, args));
  35202. });
  35203. },
  35204. handleSetFont:
  35205. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35206. operatorList, task, state) {
  35207. // TODO(mack): Not needed?
  35208. var fontName;
  35209. if (fontArgs) {
  35210. fontArgs = fontArgs.slice();
  35211. fontName = fontArgs[0].name;
  35212. }
  35213. var self = this;
  35214. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35215. function (translated) {
  35216. if (!translated.font.isType3Font) {
  35217. return translated;
  35218. }
  35219. return translated.loadType3Data(self, resources, operatorList, task).
  35220. then(function () {
  35221. return translated;
  35222. }, function (reason) {
  35223. // Error in the font data -- sending unsupported feature notification.
  35224. self.handler.send('UnsupportedFeature',
  35225. {featureId: UNSUPPORTED_FEATURES.font});
  35226. return new TranslatedFont('g_font_error',
  35227. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35228. });
  35229. }).then(function (translated) {
  35230. state.font = translated.font;
  35231. translated.send(self.handler);
  35232. return translated.loadedName;
  35233. });
  35234. },
  35235. handleText: function PartialEvaluator_handleText(chars, state) {
  35236. var font = state.font;
  35237. var glyphs = font.charsToGlyphs(chars);
  35238. var isAddToPathSet = !!(state.textRenderingMode &
  35239. TextRenderingMode.ADD_TO_PATH_FLAG);
  35240. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  35241. var buildPath = function (fontChar) {
  35242. if (!font.renderer.hasBuiltPath(fontChar)) {
  35243. var path = font.renderer.getPathJs(fontChar);
  35244. this.handler.send('commonobj', [
  35245. font.loadedName + '_path_' + fontChar,
  35246. 'FontPath',
  35247. path
  35248. ]);
  35249. }
  35250. }.bind(this);
  35251. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35252. var glyph = glyphs[i];
  35253. buildPath(glyph.fontChar);
  35254. // If the glyph has an accent we need to build a path for its
  35255. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35256. var accent = glyph.accent;
  35257. if (accent && accent.fontChar) {
  35258. buildPath(accent.fontChar);
  35259. }
  35260. }
  35261. }
  35262. return glyphs;
  35263. },
  35264. setGState: function PartialEvaluator_setGState(resources, gState,
  35265. operatorList, task,
  35266. xref, stateManager) {
  35267. // This array holds the converted/processed state data.
  35268. var gStateObj = [];
  35269. var gStateKeys = gState.getKeys();
  35270. var self = this;
  35271. var promise = Promise.resolve();
  35272. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35273. var key = gStateKeys[i];
  35274. var value = gState.get(key);
  35275. switch (key) {
  35276. case 'Type':
  35277. break;
  35278. case 'LW':
  35279. case 'LC':
  35280. case 'LJ':
  35281. case 'ML':
  35282. case 'D':
  35283. case 'RI':
  35284. case 'FL':
  35285. case 'CA':
  35286. case 'ca':
  35287. gStateObj.push([key, value]);
  35288. break;
  35289. case 'Font':
  35290. promise = promise.then(function () {
  35291. return self.handleSetFont(resources, null, value[0], operatorList,
  35292. task, stateManager.state).
  35293. then(function (loadedName) {
  35294. operatorList.addDependency(loadedName);
  35295. gStateObj.push([key, [loadedName, value[1]]]);
  35296. });
  35297. });
  35298. break;
  35299. case 'BM':
  35300. gStateObj.push([key, value]);
  35301. break;
  35302. case 'SMask':
  35303. if (isName(value, 'None')) {
  35304. gStateObj.push([key, false]);
  35305. break;
  35306. }
  35307. if (isDict(value)) {
  35308. promise = promise.then(function (dict) {
  35309. return self.handleSMask(dict, resources, operatorList,
  35310. task, stateManager);
  35311. }.bind(this, value));
  35312. gStateObj.push([key, true]);
  35313. } else {
  35314. warn('Unsupported SMask type');
  35315. }
  35316. break;
  35317. // Only generate info log messages for the following since
  35318. // they are unlikely to have a big impact on the rendering.
  35319. case 'OP':
  35320. case 'op':
  35321. case 'OPM':
  35322. case 'BG':
  35323. case 'BG2':
  35324. case 'UCR':
  35325. case 'UCR2':
  35326. case 'TR':
  35327. case 'TR2':
  35328. case 'HT':
  35329. case 'SM':
  35330. case 'SA':
  35331. case 'AIS':
  35332. case 'TK':
  35333. // TODO implement these operators.
  35334. info('graphic state operator ' + key);
  35335. break;
  35336. default:
  35337. info('Unknown graphic state operator ' + key);
  35338. break;
  35339. }
  35340. }
  35341. return promise.then(function () {
  35342. if (gStateObj.length > 0) {
  35343. operatorList.addOp(OPS.setGState, [gStateObj]);
  35344. }
  35345. });
  35346. },
  35347. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35348. resources) {
  35349. function errorFont() {
  35350. return Promise.resolve(new TranslatedFont('g_font_error',
  35351. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35352. }
  35353. var fontRef;
  35354. if (font) { // Loading by ref.
  35355. assert(isRef(font));
  35356. fontRef = font;
  35357. } else { // Loading by name.
  35358. var fontRes = resources.get('Font');
  35359. if (fontRes) {
  35360. fontRef = fontRes.getRaw(fontName);
  35361. } else {
  35362. warn('fontRes not available');
  35363. return errorFont();
  35364. }
  35365. }
  35366. if (!fontRef) {
  35367. warn('fontRef not available');
  35368. return errorFont();
  35369. }
  35370. if (this.fontCache.has(fontRef)) {
  35371. return this.fontCache.get(fontRef);
  35372. }
  35373. font = xref.fetchIfRef(fontRef);
  35374. if (!isDict(font)) {
  35375. return errorFont();
  35376. }
  35377. // We are holding `font.translated` references just for `fontRef`s that
  35378. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  35379. if (font.translated) {
  35380. return font.translated;
  35381. }
  35382. var fontCapability = createPromiseCapability();
  35383. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35384. var descriptor = preEvaluatedFont.descriptor;
  35385. var fontRefIsRef = isRef(fontRef), fontID;
  35386. if (fontRefIsRef) {
  35387. fontID = fontRef.toString();
  35388. }
  35389. if (isDict(descriptor)) {
  35390. if (!descriptor.fontAliases) {
  35391. descriptor.fontAliases = Object.create(null);
  35392. }
  35393. var fontAliases = descriptor.fontAliases;
  35394. var hash = preEvaluatedFont.hash;
  35395. if (fontAliases[hash]) {
  35396. var aliasFontRef = fontAliases[hash].aliasRef;
  35397. if (fontRefIsRef && aliasFontRef &&
  35398. this.fontCache.has(aliasFontRef)) {
  35399. this.fontCache.putAlias(fontRef, aliasFontRef);
  35400. return this.fontCache.get(fontRef);
  35401. }
  35402. } else {
  35403. fontAliases[hash] = {
  35404. fontID: Font.getFontID()
  35405. };
  35406. }
  35407. if (fontRefIsRef) {
  35408. fontAliases[hash].aliasRef = fontRef;
  35409. }
  35410. fontID = fontAliases[hash].fontID;
  35411. }
  35412. // Workaround for bad PDF generators that reference fonts incorrectly,
  35413. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  35414. // In this case we should not put the font into `this.fontCache` (which is
  35415. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  35416. //
  35417. // However, if we don't cache the font it's not possible to remove it
  35418. // when `cleanup` is triggered from the API, which causes issues on
  35419. // subsequent rendering operations (see issue7403.pdf).
  35420. // A simple workaround would be to just not hold `font.translated`
  35421. // references in this case, but this would force us to unnecessarily load
  35422. // the same fonts over and over.
  35423. //
  35424. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  35425. // key in `this.fontCache`, to allow the font to be cached.
  35426. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  35427. // keys. Also, since `fontRef` is used when getting cached fonts,
  35428. // we'll not accidentally match fonts cached with the `fontID`.
  35429. if (fontRefIsRef) {
  35430. this.fontCache.put(fontRef, fontCapability.promise);
  35431. } else {
  35432. if (!fontID) {
  35433. fontID = (this.uniquePrefix || 'F_') + (++this.idCounters.obj);
  35434. }
  35435. this.fontCache.put('id_' + fontID, fontCapability.promise);
  35436. }
  35437. assert(fontID, 'The "fontID" must be defined.');
  35438. // Keep track of each font we translated so the caller can
  35439. // load them asynchronously before calling display on a page.
  35440. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  35441. font.translated = fontCapability.promise;
  35442. // TODO move promises into translate font
  35443. var translatedPromise;
  35444. try {
  35445. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  35446. } catch (e) {
  35447. translatedPromise = Promise.reject(e);
  35448. }
  35449. var self = this;
  35450. translatedPromise.then(function (translatedFont) {
  35451. if (translatedFont.fontType !== undefined) {
  35452. var xrefFontStats = xref.stats.fontTypes;
  35453. xrefFontStats[translatedFont.fontType] = true;
  35454. }
  35455. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35456. translatedFont, font));
  35457. }, function (reason) {
  35458. // TODO fontCapability.reject?
  35459. // Error in the font data -- sending unsupported feature notification.
  35460. self.handler.send('UnsupportedFeature',
  35461. {featureId: UNSUPPORTED_FEATURES.font});
  35462. try {
  35463. // error, but it's still nice to have font type reported
  35464. var descriptor = preEvaluatedFont.descriptor;
  35465. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35466. var subtype = fontFile3 && fontFile3.get('Subtype');
  35467. var fontType = getFontType(preEvaluatedFont.type,
  35468. subtype && subtype.name);
  35469. var xrefFontStats = xref.stats.fontTypes;
  35470. xrefFontStats[fontType] = true;
  35471. } catch (ex) { }
  35472. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35473. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35474. font));
  35475. });
  35476. return fontCapability.promise;
  35477. },
  35478. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35479. var lastIndex = operatorList.length - 1;
  35480. if (!args) {
  35481. args = [];
  35482. }
  35483. if (lastIndex < 0 ||
  35484. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35485. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35486. } else {
  35487. var opArgs = operatorList.argsArray[lastIndex];
  35488. opArgs[0].push(fn);
  35489. Array.prototype.push.apply(opArgs[1], args);
  35490. }
  35491. },
  35492. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35493. cs, patterns, resources, task, xref) {
  35494. // compile tiling patterns
  35495. var patternName = args[args.length - 1];
  35496. // SCN/scn applies patterns along with normal colors
  35497. var pattern;
  35498. if (isName(patternName) &&
  35499. (pattern = patterns.get(patternName.name))) {
  35500. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35501. var typeNum = dict.get('PatternType');
  35502. if (typeNum === TILING_PATTERN) {
  35503. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35504. return this.handleTilingType(fn, color, resources, pattern,
  35505. dict, operatorList, task);
  35506. } else if (typeNum === SHADING_PATTERN) {
  35507. var shading = dict.get('Shading');
  35508. var matrix = dict.getArray('Matrix');
  35509. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35510. this.handler);
  35511. operatorList.addOp(fn, pattern.getIR());
  35512. return Promise.resolve();
  35513. } else {
  35514. return Promise.reject('Unknown PatternType: ' + typeNum);
  35515. }
  35516. }
  35517. // TODO shall we fail here?
  35518. operatorList.addOp(fn, args);
  35519. return Promise.resolve();
  35520. },
  35521. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35522. task,
  35523. resources,
  35524. operatorList,
  35525. initialState) {
  35526. var self = this;
  35527. var xref = this.xref;
  35528. var imageCache = Object.create(null);
  35529. assert(operatorList);
  35530. resources = (resources || Dict.empty);
  35531. var xobjs = (resources.get('XObject') || Dict.empty);
  35532. var patterns = (resources.get('Pattern') || Dict.empty);
  35533. var stateManager = new StateManager(initialState || new EvalState());
  35534. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35535. var timeSlotManager = new TimeSlotManager();
  35536. return new Promise(function promiseBody(resolve, reject) {
  35537. var next = function (promise) {
  35538. promise.then(function () {
  35539. try {
  35540. promiseBody(resolve, reject);
  35541. } catch (ex) {
  35542. reject(ex);
  35543. }
  35544. }, reject);
  35545. };
  35546. task.ensureNotTerminated();
  35547. timeSlotManager.reset();
  35548. var stop, operation = {}, i, ii, cs;
  35549. while (!(stop = timeSlotManager.check())) {
  35550. // The arguments parsed by read() are used beyond this loop, so we
  35551. // cannot reuse the same array on each iteration. Therefore we pass
  35552. // in |null| as the initial value (see the comment on
  35553. // EvaluatorPreprocessor_read() for why).
  35554. operation.args = null;
  35555. if (!(preprocessor.read(operation))) {
  35556. break;
  35557. }
  35558. var args = operation.args;
  35559. var fn = operation.fn;
  35560. switch (fn | 0) {
  35561. case OPS.paintXObject:
  35562. if (args[0].code) {
  35563. break;
  35564. }
  35565. // eagerly compile XForm objects
  35566. var name = args[0].name;
  35567. if (!name) {
  35568. warn('XObject must be referred to by name.');
  35569. continue;
  35570. }
  35571. if (imageCache[name] !== undefined) {
  35572. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35573. args = null;
  35574. continue;
  35575. }
  35576. var xobj = xobjs.get(name);
  35577. if (xobj) {
  35578. assert(isStream(xobj), 'XObject should be a stream');
  35579. var type = xobj.dict.get('Subtype');
  35580. assert(isName(type), 'XObject should have a Name subtype');
  35581. if (type.name === 'Form') {
  35582. stateManager.save();
  35583. next(self.buildFormXObject(resources, xobj, null,
  35584. operatorList, task,
  35585. stateManager.state.clone()).
  35586. then(function () {
  35587. stateManager.restore();
  35588. }));
  35589. return;
  35590. } else if (type.name === 'Image') {
  35591. self.buildPaintImageXObject(resources, xobj, false,
  35592. operatorList, name, imageCache);
  35593. args = null;
  35594. continue;
  35595. } else if (type.name === 'PS') {
  35596. // PostScript XObjects are unused when viewing documents.
  35597. // See section 4.7.1 of Adobe's PDF reference.
  35598. info('Ignored XObject subtype PS');
  35599. continue;
  35600. } else {
  35601. error('Unhandled XObject subtype ' + type.name);
  35602. }
  35603. }
  35604. break;
  35605. case OPS.setFont:
  35606. var fontSize = args[1];
  35607. // eagerly collect all fonts
  35608. next(self.handleSetFont(resources, args, null, operatorList,
  35609. task, stateManager.state).
  35610. then(function (loadedName) {
  35611. operatorList.addDependency(loadedName);
  35612. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35613. }));
  35614. return;
  35615. case OPS.endInlineImage:
  35616. var cacheKey = args[0].cacheKey;
  35617. if (cacheKey) {
  35618. var cacheEntry = imageCache[cacheKey];
  35619. if (cacheEntry !== undefined) {
  35620. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35621. args = null;
  35622. continue;
  35623. }
  35624. }
  35625. self.buildPaintImageXObject(resources, args[0], true,
  35626. operatorList, cacheKey, imageCache);
  35627. args = null;
  35628. continue;
  35629. case OPS.showText:
  35630. args[0] = self.handleText(args[0], stateManager.state);
  35631. break;
  35632. case OPS.showSpacedText:
  35633. var arr = args[0];
  35634. var combinedGlyphs = [];
  35635. var arrLength = arr.length;
  35636. var state = stateManager.state;
  35637. for (i = 0; i < arrLength; ++i) {
  35638. var arrItem = arr[i];
  35639. if (isString(arrItem)) {
  35640. Array.prototype.push.apply(combinedGlyphs,
  35641. self.handleText(arrItem, state));
  35642. } else if (isNum(arrItem)) {
  35643. combinedGlyphs.push(arrItem);
  35644. }
  35645. }
  35646. args[0] = combinedGlyphs;
  35647. fn = OPS.showText;
  35648. break;
  35649. case OPS.nextLineShowText:
  35650. operatorList.addOp(OPS.nextLine);
  35651. args[0] = self.handleText(args[0], stateManager.state);
  35652. fn = OPS.showText;
  35653. break;
  35654. case OPS.nextLineSetSpacingShowText:
  35655. operatorList.addOp(OPS.nextLine);
  35656. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35657. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35658. args[0] = self.handleText(args[0], stateManager.state);
  35659. fn = OPS.showText;
  35660. break;
  35661. case OPS.setTextRenderingMode:
  35662. stateManager.state.textRenderingMode = args[0];
  35663. break;
  35664. case OPS.setFillColorSpace:
  35665. stateManager.state.fillColorSpace =
  35666. ColorSpace.parse(args[0], xref, resources);
  35667. continue;
  35668. case OPS.setStrokeColorSpace:
  35669. stateManager.state.strokeColorSpace =
  35670. ColorSpace.parse(args[0], xref, resources);
  35671. continue;
  35672. case OPS.setFillColor:
  35673. cs = stateManager.state.fillColorSpace;
  35674. args = cs.getRgb(args, 0);
  35675. fn = OPS.setFillRGBColor;
  35676. break;
  35677. case OPS.setStrokeColor:
  35678. cs = stateManager.state.strokeColorSpace;
  35679. args = cs.getRgb(args, 0);
  35680. fn = OPS.setStrokeRGBColor;
  35681. break;
  35682. case OPS.setFillGray:
  35683. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35684. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35685. fn = OPS.setFillRGBColor;
  35686. break;
  35687. case OPS.setStrokeGray:
  35688. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35689. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35690. fn = OPS.setStrokeRGBColor;
  35691. break;
  35692. case OPS.setFillCMYKColor:
  35693. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35694. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35695. fn = OPS.setFillRGBColor;
  35696. break;
  35697. case OPS.setStrokeCMYKColor:
  35698. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35699. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35700. fn = OPS.setStrokeRGBColor;
  35701. break;
  35702. case OPS.setFillRGBColor:
  35703. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35704. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35705. break;
  35706. case OPS.setStrokeRGBColor:
  35707. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35708. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35709. break;
  35710. case OPS.setFillColorN:
  35711. cs = stateManager.state.fillColorSpace;
  35712. if (cs.name === 'Pattern') {
  35713. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  35714. cs, patterns, resources, task, xref));
  35715. return;
  35716. }
  35717. args = cs.getRgb(args, 0);
  35718. fn = OPS.setFillRGBColor;
  35719. break;
  35720. case OPS.setStrokeColorN:
  35721. cs = stateManager.state.strokeColorSpace;
  35722. if (cs.name === 'Pattern') {
  35723. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  35724. cs, patterns, resources, task, xref));
  35725. return;
  35726. }
  35727. args = cs.getRgb(args, 0);
  35728. fn = OPS.setStrokeRGBColor;
  35729. break;
  35730. case OPS.shadingFill:
  35731. var shadingRes = resources.get('Shading');
  35732. if (!shadingRes) {
  35733. error('No shading resource found');
  35734. }
  35735. var shading = shadingRes.get(args[0].name);
  35736. if (!shading) {
  35737. error('No shading object found');
  35738. }
  35739. var shadingFill = Pattern.parseShading(shading, null, xref,
  35740. resources, self.handler);
  35741. var patternIR = shadingFill.getIR();
  35742. args = [patternIR];
  35743. fn = OPS.shadingFill;
  35744. break;
  35745. case OPS.setGState:
  35746. var dictName = args[0];
  35747. var extGState = resources.get('ExtGState');
  35748. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35749. break;
  35750. }
  35751. var gState = extGState.get(dictName.name);
  35752. next(self.setGState(resources, gState, operatorList, task, xref,
  35753. stateManager));
  35754. return;
  35755. case OPS.moveTo:
  35756. case OPS.lineTo:
  35757. case OPS.curveTo:
  35758. case OPS.curveTo2:
  35759. case OPS.curveTo3:
  35760. case OPS.closePath:
  35761. self.buildPath(operatorList, fn, args);
  35762. continue;
  35763. case OPS.rectangle:
  35764. self.buildPath(operatorList, fn, args);
  35765. continue;
  35766. case OPS.markPoint:
  35767. case OPS.markPointProps:
  35768. case OPS.beginMarkedContent:
  35769. case OPS.beginMarkedContentProps:
  35770. case OPS.endMarkedContent:
  35771. case OPS.beginCompat:
  35772. case OPS.endCompat:
  35773. // Ignore operators where the corresponding handlers are known to
  35774. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35775. // serialization errors and is also a bit more efficient.
  35776. // We could also try to serialize all objects in a general way,
  35777. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35778. // but doing so is meaningless without knowing the semantics.
  35779. continue;
  35780. default:
  35781. // Note: Ignore the operator if it has `Dict` arguments, since
  35782. // those are non-serializable, otherwise postMessage will throw
  35783. // "An object could not be cloned.".
  35784. if (args !== null) {
  35785. for (i = 0, ii = args.length; i < ii; i++) {
  35786. if (args[i] instanceof Dict) {
  35787. break;
  35788. }
  35789. }
  35790. if (i < ii) {
  35791. warn('getOperatorList - ignoring operator: ' + fn);
  35792. continue;
  35793. }
  35794. }
  35795. }
  35796. operatorList.addOp(fn, args);
  35797. }
  35798. if (stop) {
  35799. next(deferred);
  35800. return;
  35801. }
  35802. // Some PDFs don't close all restores inside object/form.
  35803. // Closing those for them.
  35804. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35805. operatorList.addOp(OPS.restore, []);
  35806. }
  35807. resolve();
  35808. });
  35809. },
  35810. getTextContent:
  35811. function PartialEvaluator_getTextContent(stream, task, resources,
  35812. stateManager,
  35813. normalizeWhitespace,
  35814. combineTextItems) {
  35815. stateManager = (stateManager || new StateManager(new TextState()));
  35816. var WhitespaceRegexp = /\s/g;
  35817. var textContent = {
  35818. items: [],
  35819. styles: Object.create(null)
  35820. };
  35821. var textContentItem = {
  35822. initialized: false,
  35823. str: [],
  35824. width: 0,
  35825. height: 0,
  35826. vertical: false,
  35827. lastAdvanceWidth: 0,
  35828. lastAdvanceHeight: 0,
  35829. textAdvanceScale: 0,
  35830. spaceWidth: 0,
  35831. fakeSpaceMin: Infinity,
  35832. fakeMultiSpaceMin: Infinity,
  35833. fakeMultiSpaceMax: -0,
  35834. textRunBreakAllowed: false,
  35835. transform: null,
  35836. fontName: null
  35837. };
  35838. var SPACE_FACTOR = 0.3;
  35839. var MULTI_SPACE_FACTOR = 1.5;
  35840. var MULTI_SPACE_FACTOR_MAX = 4;
  35841. var self = this;
  35842. var xref = this.xref;
  35843. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35844. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35845. var xobjs = null;
  35846. var xobjsCache = Object.create(null);
  35847. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35848. var textState;
  35849. function ensureTextContentItem() {
  35850. if (textContentItem.initialized) {
  35851. return textContentItem;
  35852. }
  35853. var font = textState.font;
  35854. if (!(font.loadedName in textContent.styles)) {
  35855. textContent.styles[font.loadedName] = {
  35856. fontFamily: font.fallbackName,
  35857. ascent: font.ascent,
  35858. descent: font.descent,
  35859. vertical: font.vertical
  35860. };
  35861. }
  35862. textContentItem.fontName = font.loadedName;
  35863. // 9.4.4 Text Space Details
  35864. var tsm = [textState.fontSize * textState.textHScale, 0,
  35865. 0, textState.fontSize,
  35866. 0, textState.textRise];
  35867. if (font.isType3Font &&
  35868. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35869. textState.fontSize === 1) {
  35870. var glyphHeight = font.bbox[3] - font.bbox[1];
  35871. if (glyphHeight > 0) {
  35872. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35873. tsm[3] *= glyphHeight;
  35874. }
  35875. }
  35876. var trm = Util.transform(textState.ctm,
  35877. Util.transform(textState.textMatrix, tsm));
  35878. textContentItem.transform = trm;
  35879. if (!font.vertical) {
  35880. textContentItem.width = 0;
  35881. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35882. textContentItem.vertical = false;
  35883. } else {
  35884. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35885. textContentItem.height = 0;
  35886. textContentItem.vertical = true;
  35887. }
  35888. var a = textState.textLineMatrix[0];
  35889. var b = textState.textLineMatrix[1];
  35890. var scaleLineX = Math.sqrt(a * a + b * b);
  35891. a = textState.ctm[0];
  35892. b = textState.ctm[1];
  35893. var scaleCtmX = Math.sqrt(a * a + b * b);
  35894. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35895. textContentItem.lastAdvanceWidth = 0;
  35896. textContentItem.lastAdvanceHeight = 0;
  35897. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35898. if (spaceWidth) {
  35899. textContentItem.spaceWidth = spaceWidth;
  35900. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35901. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35902. textContentItem.fakeMultiSpaceMax =
  35903. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35904. // It's okay for monospace fonts to fake as much space as needed.
  35905. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35906. } else {
  35907. textContentItem.spaceWidth = 0;
  35908. textContentItem.fakeSpaceMin = Infinity;
  35909. textContentItem.fakeMultiSpaceMin = Infinity;
  35910. textContentItem.fakeMultiSpaceMax = 0;
  35911. textContentItem.textRunBreakAllowed = false;
  35912. }
  35913. textContentItem.initialized = true;
  35914. return textContentItem;
  35915. }
  35916. function replaceWhitespace(str) {
  35917. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35918. // alignment issues between the textLayer and the canvas if the text
  35919. // contains e.g. tabs (fixes issue6612.pdf).
  35920. var i = 0, ii = str.length, code;
  35921. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35922. i++;
  35923. }
  35924. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35925. }
  35926. function runBidiTransform(textChunk) {
  35927. var str = textChunk.str.join('');
  35928. var bidiResult = bidi(str, -1, textChunk.vertical);
  35929. return {
  35930. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35931. bidiResult.str),
  35932. dir: bidiResult.dir,
  35933. width: textChunk.width,
  35934. height: textChunk.height,
  35935. transform: textChunk.transform,
  35936. fontName: textChunk.fontName
  35937. };
  35938. }
  35939. function handleSetFont(fontName, fontRef) {
  35940. return self.loadFont(fontName, fontRef, xref, resources).
  35941. then(function (translated) {
  35942. textState.font = translated.font;
  35943. textState.fontMatrix = translated.font.fontMatrix ||
  35944. FONT_IDENTITY_MATRIX;
  35945. });
  35946. }
  35947. function buildTextContentItem(chars) {
  35948. var font = textState.font;
  35949. var textChunk = ensureTextContentItem();
  35950. var width = 0;
  35951. var height = 0;
  35952. var glyphs = font.charsToGlyphs(chars);
  35953. var defaultVMetrics = font.defaultVMetrics;
  35954. for (var i = 0; i < glyphs.length; i++) {
  35955. var glyph = glyphs[i];
  35956. var vMetricX = null;
  35957. var vMetricY = null;
  35958. var glyphWidth = null;
  35959. if (font.vertical) {
  35960. if (glyph.vmetric) {
  35961. glyphWidth = glyph.vmetric[0];
  35962. vMetricX = glyph.vmetric[1];
  35963. vMetricY = glyph.vmetric[2];
  35964. } else {
  35965. glyphWidth = glyph.width;
  35966. vMetricX = glyph.width * 0.5;
  35967. vMetricY = defaultVMetrics[2];
  35968. }
  35969. } else {
  35970. glyphWidth = glyph.width;
  35971. }
  35972. var glyphUnicode = glyph.unicode;
  35973. var NormalizedUnicodes = getNormalizedUnicodes();
  35974. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35975. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35976. }
  35977. glyphUnicode = reverseIfRtl(glyphUnicode);
  35978. // The following will calculate the x and y of the individual glyphs.
  35979. // if (font.vertical) {
  35980. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35981. // textState.fontMatrix[0];
  35982. // tsm[5] -= vMetricY * textState.fontSize *
  35983. // textState.fontMatrix[0];
  35984. // }
  35985. // var trm = Util.transform(textState.textMatrix, tsm);
  35986. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35987. // var x = pt[0];
  35988. // var y = pt[1];
  35989. var charSpacing = textState.charSpacing;
  35990. if (glyph.isSpace) {
  35991. var wordSpacing = textState.wordSpacing;
  35992. charSpacing += wordSpacing;
  35993. if (wordSpacing > 0) {
  35994. addFakeSpaces(wordSpacing, textChunk.str);
  35995. }
  35996. }
  35997. var tx = 0;
  35998. var ty = 0;
  35999. if (!font.vertical) {
  36000. var w0 = glyphWidth * textState.fontMatrix[0];
  36001. tx = (w0 * textState.fontSize + charSpacing) *
  36002. textState.textHScale;
  36003. width += tx;
  36004. } else {
  36005. var w1 = glyphWidth * textState.fontMatrix[0];
  36006. ty = w1 * textState.fontSize + charSpacing;
  36007. height += ty;
  36008. }
  36009. textState.translateTextMatrix(tx, ty);
  36010. textChunk.str.push(glyphUnicode);
  36011. }
  36012. if (!font.vertical) {
  36013. textChunk.lastAdvanceWidth = width;
  36014. textChunk.width += width * textChunk.textAdvanceScale;
  36015. } else {
  36016. textChunk.lastAdvanceHeight = height;
  36017. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  36018. }
  36019. return textChunk;
  36020. }
  36021. function addFakeSpaces(width, strBuf) {
  36022. if (width < textContentItem.fakeSpaceMin) {
  36023. return;
  36024. }
  36025. if (width < textContentItem.fakeMultiSpaceMin) {
  36026. strBuf.push(' ');
  36027. return;
  36028. }
  36029. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  36030. while (fakeSpaces-- > 0) {
  36031. strBuf.push(' ');
  36032. }
  36033. }
  36034. function flushTextContentItem() {
  36035. if (!textContentItem.initialized) {
  36036. return;
  36037. }
  36038. textContent.items.push(runBidiTransform(textContentItem));
  36039. textContentItem.initialized = false;
  36040. textContentItem.str.length = 0;
  36041. }
  36042. var timeSlotManager = new TimeSlotManager();
  36043. return new Promise(function promiseBody(resolve, reject) {
  36044. var next = function (promise) {
  36045. promise.then(function () {
  36046. try {
  36047. promiseBody(resolve, reject);
  36048. } catch (ex) {
  36049. reject(ex);
  36050. }
  36051. }, reject);
  36052. };
  36053. task.ensureNotTerminated();
  36054. timeSlotManager.reset();
  36055. var stop, operation = {}, args = [];
  36056. while (!(stop = timeSlotManager.check())) {
  36057. // The arguments parsed by read() are not used beyond this loop, so
  36058. // we can reuse the same array on every iteration, thus avoiding
  36059. // unnecessary allocations.
  36060. args.length = 0;
  36061. operation.args = args;
  36062. if (!(preprocessor.read(operation))) {
  36063. break;
  36064. }
  36065. textState = stateManager.state;
  36066. var fn = operation.fn;
  36067. args = operation.args;
  36068. var advance, diff;
  36069. switch (fn | 0) {
  36070. case OPS.setFont:
  36071. // Optimization to ignore multiple identical Tf commands.
  36072. var fontNameArg = args[0].name, fontSizeArg = args[1];
  36073. if (textState.font && fontNameArg === textState.fontName &&
  36074. fontSizeArg === textState.fontSize) {
  36075. break;
  36076. }
  36077. flushTextContentItem();
  36078. textState.fontName = fontNameArg;
  36079. textState.fontSize = fontSizeArg;
  36080. next(handleSetFont(fontNameArg, null));
  36081. return;
  36082. case OPS.setTextRise:
  36083. flushTextContentItem();
  36084. textState.textRise = args[0];
  36085. break;
  36086. case OPS.setHScale:
  36087. flushTextContentItem();
  36088. textState.textHScale = args[0] / 100;
  36089. break;
  36090. case OPS.setLeading:
  36091. flushTextContentItem();
  36092. textState.leading = args[0];
  36093. break;
  36094. case OPS.moveText:
  36095. // Optimization to treat same line movement as advance
  36096. var isSameTextLine = !textState.font ? false :
  36097. ((textState.font.vertical ? args[0] : args[1]) === 0);
  36098. advance = args[0] - args[1];
  36099. if (combineTextItems &&
  36100. isSameTextLine && textContentItem.initialized &&
  36101. advance > 0 &&
  36102. advance <= textContentItem.fakeMultiSpaceMax) {
  36103. textState.translateTextLineMatrix(args[0], args[1]);
  36104. textContentItem.width +=
  36105. (args[0] - textContentItem.lastAdvanceWidth);
  36106. textContentItem.height +=
  36107. (args[1] - textContentItem.lastAdvanceHeight);
  36108. diff = (args[0] - textContentItem.lastAdvanceWidth) -
  36109. (args[1] - textContentItem.lastAdvanceHeight);
  36110. addFakeSpaces(diff, textContentItem.str);
  36111. break;
  36112. }
  36113. flushTextContentItem();
  36114. textState.translateTextLineMatrix(args[0], args[1]);
  36115. textState.textMatrix = textState.textLineMatrix.slice();
  36116. break;
  36117. case OPS.setLeadingMoveText:
  36118. flushTextContentItem();
  36119. textState.leading = -args[1];
  36120. textState.translateTextLineMatrix(args[0], args[1]);
  36121. textState.textMatrix = textState.textLineMatrix.slice();
  36122. break;
  36123. case OPS.nextLine:
  36124. flushTextContentItem();
  36125. textState.carriageReturn();
  36126. break;
  36127. case OPS.setTextMatrix:
  36128. // Optimization to treat same line movement as advance.
  36129. advance = textState.calcTextLineMatrixAdvance(
  36130. args[0], args[1], args[2], args[3], args[4], args[5]);
  36131. if (combineTextItems &&
  36132. advance !== null && textContentItem.initialized &&
  36133. advance.value > 0 &&
  36134. advance.value <= textContentItem.fakeMultiSpaceMax) {
  36135. textState.translateTextLineMatrix(advance.width,
  36136. advance.height);
  36137. textContentItem.width +=
  36138. (advance.width - textContentItem.lastAdvanceWidth);
  36139. textContentItem.height +=
  36140. (advance.height - textContentItem.lastAdvanceHeight);
  36141. diff = (advance.width - textContentItem.lastAdvanceWidth) -
  36142. (advance.height - textContentItem.lastAdvanceHeight);
  36143. addFakeSpaces(diff, textContentItem.str);
  36144. break;
  36145. }
  36146. flushTextContentItem();
  36147. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  36148. args[4], args[5]);
  36149. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  36150. args[4], args[5]);
  36151. break;
  36152. case OPS.setCharSpacing:
  36153. textState.charSpacing = args[0];
  36154. break;
  36155. case OPS.setWordSpacing:
  36156. textState.wordSpacing = args[0];
  36157. break;
  36158. case OPS.beginText:
  36159. flushTextContentItem();
  36160. textState.textMatrix = IDENTITY_MATRIX.slice();
  36161. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  36162. break;
  36163. case OPS.showSpacedText:
  36164. var items = args[0];
  36165. var offset;
  36166. for (var j = 0, jj = items.length; j < jj; j++) {
  36167. if (typeof items[j] === 'string') {
  36168. buildTextContentItem(items[j]);
  36169. } else {
  36170. ensureTextContentItem();
  36171. // PDF Specification 5.3.2 states:
  36172. // The number is expressed in thousandths of a unit of text
  36173. // space.
  36174. // This amount is subtracted from the current horizontal or
  36175. // vertical coordinate, depending on the writing mode.
  36176. // In the default coordinate system, a positive adjustment
  36177. // has the effect of moving the next glyph painted either to
  36178. // the left or down by the given amount.
  36179. advance = items[j] * textState.fontSize / 1000;
  36180. var breakTextRun = false;
  36181. if (textState.font.vertical) {
  36182. offset = advance *
  36183. (textState.textHScale * textState.textMatrix[2] +
  36184. textState.textMatrix[3]);
  36185. textState.translateTextMatrix(0, advance);
  36186. breakTextRun = textContentItem.textRunBreakAllowed &&
  36187. advance > textContentItem.fakeMultiSpaceMax;
  36188. if (!breakTextRun) {
  36189. // Value needs to be added to height to paint down.
  36190. textContentItem.height += offset;
  36191. }
  36192. } else {
  36193. advance = -advance;
  36194. offset = advance * (
  36195. textState.textHScale * textState.textMatrix[0] +
  36196. textState.textMatrix[1]);
  36197. textState.translateTextMatrix(advance, 0);
  36198. breakTextRun = textContentItem.textRunBreakAllowed &&
  36199. advance > textContentItem.fakeMultiSpaceMax;
  36200. if (!breakTextRun) {
  36201. // Value needs to be subtracted from width to paint left.
  36202. textContentItem.width += offset;
  36203. }
  36204. }
  36205. if (breakTextRun) {
  36206. flushTextContentItem();
  36207. } else if (advance > 0) {
  36208. addFakeSpaces(advance, textContentItem.str);
  36209. }
  36210. }
  36211. }
  36212. break;
  36213. case OPS.showText:
  36214. buildTextContentItem(args[0]);
  36215. break;
  36216. case OPS.nextLineShowText:
  36217. flushTextContentItem();
  36218. textState.carriageReturn();
  36219. buildTextContentItem(args[0]);
  36220. break;
  36221. case OPS.nextLineSetSpacingShowText:
  36222. flushTextContentItem();
  36223. textState.wordSpacing = args[0];
  36224. textState.charSpacing = args[1];
  36225. textState.carriageReturn();
  36226. buildTextContentItem(args[2]);
  36227. break;
  36228. case OPS.paintXObject:
  36229. flushTextContentItem();
  36230. if (args[0].code) {
  36231. break;
  36232. }
  36233. if (!xobjs) {
  36234. xobjs = (resources.get('XObject') || Dict.empty);
  36235. }
  36236. var name = args[0].name;
  36237. if (xobjsCache.key === name) {
  36238. if (xobjsCache.texts) {
  36239. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  36240. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  36241. }
  36242. break;
  36243. }
  36244. var xobj = xobjs.get(name);
  36245. if (!xobj) {
  36246. break;
  36247. }
  36248. assert(isStream(xobj), 'XObject should be a stream');
  36249. var type = xobj.dict.get('Subtype');
  36250. assert(isName(type), 'XObject should have a Name subtype');
  36251. if ('Form' !== type.name) {
  36252. xobjsCache.key = name;
  36253. xobjsCache.texts = null;
  36254. break;
  36255. }
  36256. stateManager.save();
  36257. var matrix = xobj.dict.getArray('Matrix');
  36258. if (isArray(matrix) && matrix.length === 6) {
  36259. stateManager.transform(matrix);
  36260. }
  36261. next(self.getTextContent(xobj, task,
  36262. xobj.dict.get('Resources') || resources, stateManager,
  36263. normalizeWhitespace, combineTextItems).then(
  36264. function (formTextContent) {
  36265. Util.appendToArray(textContent.items, formTextContent.items);
  36266. Util.extendObj(textContent.styles, formTextContent.styles);
  36267. stateManager.restore();
  36268. xobjsCache.key = name;
  36269. xobjsCache.texts = formTextContent;
  36270. }));
  36271. return;
  36272. case OPS.setGState:
  36273. flushTextContentItem();
  36274. var dictName = args[0];
  36275. var extGState = resources.get('ExtGState');
  36276. if (!isDict(extGState) || !isName(dictName)) {
  36277. break;
  36278. }
  36279. var gState = extGState.get(dictName.name);
  36280. if (!isDict(gState)) {
  36281. break;
  36282. }
  36283. var gStateFont = gState.get('Font');
  36284. if (gStateFont) {
  36285. textState.fontName = null;
  36286. textState.fontSize = gStateFont[1];
  36287. next(handleSetFont(null, gStateFont[0]));
  36288. return;
  36289. }
  36290. break;
  36291. } // switch
  36292. } // while
  36293. if (stop) {
  36294. next(deferred);
  36295. return;
  36296. }
  36297. flushTextContentItem();
  36298. resolve(textContent);
  36299. });
  36300. },
  36301. extractDataStructures:
  36302. function PartialEvaluator_extractDataStructures(dict, baseDict,
  36303. xref, properties) {
  36304. // 9.10.2
  36305. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36306. var toUnicodePromise = toUnicode ?
  36307. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  36308. if (properties.composite) {
  36309. // CIDSystemInfo helps to match CID to glyphs
  36310. var cidSystemInfo = dict.get('CIDSystemInfo');
  36311. if (isDict(cidSystemInfo)) {
  36312. properties.cidSystemInfo = {
  36313. registry: cidSystemInfo.get('Registry'),
  36314. ordering: cidSystemInfo.get('Ordering'),
  36315. supplement: cidSystemInfo.get('Supplement')
  36316. };
  36317. }
  36318. var cidToGidMap = dict.get('CIDToGIDMap');
  36319. if (isStream(cidToGidMap)) {
  36320. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36321. }
  36322. }
  36323. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36324. // and depends on the font type. The base encoding and differences are
  36325. // read here, but the encoding that is actually used is chosen during
  36326. // glyph mapping in the font.
  36327. // TODO: Loading the built in encoding in the font would allow the
  36328. // differences to be merged in here not require us to hold on to it.
  36329. var differences = [];
  36330. var baseEncodingName = null;
  36331. var encoding;
  36332. if (dict.has('Encoding')) {
  36333. encoding = dict.get('Encoding');
  36334. if (isDict(encoding)) {
  36335. baseEncodingName = encoding.get('BaseEncoding');
  36336. baseEncodingName = (isName(baseEncodingName) ?
  36337. baseEncodingName.name : null);
  36338. // Load the differences between the base and original
  36339. if (encoding.has('Differences')) {
  36340. var diffEncoding = encoding.get('Differences');
  36341. var index = 0;
  36342. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36343. var data = xref.fetchIfRef(diffEncoding[j]);
  36344. if (isNum(data)) {
  36345. index = data;
  36346. } else if (isName(data)) {
  36347. differences[index++] = data.name;
  36348. } else {
  36349. error('Invalid entry in \'Differences\' array: ' + data);
  36350. }
  36351. }
  36352. }
  36353. } else if (isName(encoding)) {
  36354. baseEncodingName = encoding.name;
  36355. } else {
  36356. error('Encoding is not a Name nor a Dict');
  36357. }
  36358. // According to table 114 if the encoding is a named encoding it must be
  36359. // one of these predefined encodings.
  36360. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36361. baseEncodingName !== 'MacExpertEncoding' &&
  36362. baseEncodingName !== 'WinAnsiEncoding')) {
  36363. baseEncodingName = null;
  36364. }
  36365. }
  36366. if (baseEncodingName) {
  36367. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36368. } else {
  36369. encoding = (properties.type === 'TrueType' ?
  36370. WinAnsiEncoding : StandardEncoding);
  36371. // The Symbolic attribute can be misused for regular fonts
  36372. // Heuristic: we have to check if the font is a standard one also
  36373. if (!!(properties.flags & FontFlags.Symbolic)) {
  36374. encoding = MacRomanEncoding;
  36375. if (!properties.file) {
  36376. if (/Symbol/i.test(properties.name)) {
  36377. encoding = SymbolSetEncoding;
  36378. } else if (/Dingbats/i.test(properties.name)) {
  36379. encoding = ZapfDingbatsEncoding;
  36380. }
  36381. }
  36382. }
  36383. properties.defaultEncoding = encoding;
  36384. }
  36385. properties.differences = differences;
  36386. properties.baseEncodingName = baseEncodingName;
  36387. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  36388. properties.dict = dict;
  36389. return toUnicodePromise.then(function(toUnicode) {
  36390. properties.toUnicode = toUnicode;
  36391. return this.buildToUnicode(properties);
  36392. }.bind(this)).then(function (toUnicode) {
  36393. properties.toUnicode = toUnicode;
  36394. return properties;
  36395. });
  36396. },
  36397. /**
  36398. * Builds a char code to unicode map based on section 9.10 of the spec.
  36399. * @param {Object} properties Font properties object.
  36400. * @return {Promise} A Promise that is resolved with a
  36401. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  36402. */
  36403. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  36404. properties.hasIncludedToUnicodeMap =
  36405. !!properties.toUnicode && properties.toUnicode.length > 0;
  36406. // Section 9.10.2 Mapping Character Codes to Unicode Values
  36407. if (properties.hasIncludedToUnicodeMap) {
  36408. return Promise.resolve(properties.toUnicode);
  36409. }
  36410. // According to the spec if the font is a simple font we should only map
  36411. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  36412. // the differences array only contains adobe standard or symbol set names,
  36413. // in pratice it seems better to always try to create a toUnicode
  36414. // map based of the default encoding.
  36415. var toUnicode, charcode, glyphName;
  36416. if (!properties.composite /* is simple font */) {
  36417. toUnicode = [];
  36418. var encoding = properties.defaultEncoding.slice();
  36419. var baseEncodingName = properties.baseEncodingName;
  36420. // Merge in the differences array.
  36421. var differences = properties.differences;
  36422. for (charcode in differences) {
  36423. glyphName = differences[charcode];
  36424. if (glyphName === '.notdef') {
  36425. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  36426. // where there should be spaces (fixes issue5256.pdf).
  36427. continue;
  36428. }
  36429. encoding[charcode] = glyphName;
  36430. }
  36431. var glyphsUnicodeMap = getGlyphsUnicode();
  36432. for (charcode in encoding) {
  36433. // a) Map the character code to a character name.
  36434. glyphName = encoding[charcode];
  36435. // b) Look up the character name in the Adobe Glyph List (see the
  36436. // Bibliography) to obtain the corresponding Unicode value.
  36437. if (glyphName === '') {
  36438. continue;
  36439. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  36440. // (undocumented) c) Few heuristics to recognize unknown glyphs
  36441. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  36442. var code = 0;
  36443. switch (glyphName[0]) {
  36444. case 'G': // Gxx glyph
  36445. if (glyphName.length === 3) {
  36446. code = parseInt(glyphName.substr(1), 16);
  36447. }
  36448. break;
  36449. case 'g': // g00xx glyph
  36450. if (glyphName.length === 5) {
  36451. code = parseInt(glyphName.substr(1), 16);
  36452. }
  36453. break;
  36454. case 'C': // Cddd glyph
  36455. case 'c': // cddd glyph
  36456. if (glyphName.length >= 3) {
  36457. code = +glyphName.substr(1);
  36458. }
  36459. break;
  36460. default:
  36461. // 'uniXXXX'/'uXXXX{XX}' glyphs
  36462. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  36463. if (unicode !== -1) {
  36464. code = unicode;
  36465. }
  36466. }
  36467. if (code) {
  36468. // If |baseEncodingName| is one the predefined encodings,
  36469. // and |code| equals |charcode|, using the glyph defined in the
  36470. // baseEncoding seems to yield a better |toUnicode| mapping
  36471. // (fixes issue 5070).
  36472. if (baseEncodingName && code === +charcode) {
  36473. var baseEncoding = getEncoding(baseEncodingName);
  36474. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  36475. toUnicode[charcode] =
  36476. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36477. continue;
  36478. }
  36479. }
  36480. toUnicode[charcode] = String.fromCharCode(code);
  36481. }
  36482. continue;
  36483. }
  36484. toUnicode[charcode] =
  36485. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  36486. }
  36487. return Promise.resolve(new ToUnicodeMap(toUnicode));
  36488. }
  36489. // If the font is a composite font that uses one of the predefined CMaps
  36490. // listed in Table 118 (except Identity–H and Identity–V) or whose
  36491. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  36492. // Adobe-Korea1 character collection:
  36493. if (properties.composite && (
  36494. (properties.cMap.builtInCMap &&
  36495. !(properties.cMap instanceof IdentityCMap)) ||
  36496. (properties.cidSystemInfo.registry === 'Adobe' &&
  36497. (properties.cidSystemInfo.ordering === 'GB1' ||
  36498. properties.cidSystemInfo.ordering === 'CNS1' ||
  36499. properties.cidSystemInfo.ordering === 'Japan1' ||
  36500. properties.cidSystemInfo.ordering === 'Korea1')))) {
  36501. // Then:
  36502. // a) Map the character code to a character identifier (CID) according
  36503. // to the font’s CMap.
  36504. // b) Obtain the registry and ordering of the character collection used
  36505. // by the font’s CMap (for example, Adobe and Japan1) from its
  36506. // CIDSystemInfo dictionary.
  36507. var registry = properties.cidSystemInfo.registry;
  36508. var ordering = properties.cidSystemInfo.ordering;
  36509. // c) Construct a second CMap name by concatenating the registry and
  36510. // ordering obtained in step (b) in the format registry–ordering–UCS2
  36511. // (for example, Adobe–Japan1–UCS2).
  36512. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  36513. // d) Obtain the CMap with the name constructed in step (c) (available
  36514. // from the ASN Web site; see the Bibliography).
  36515. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  36516. null).then(
  36517. function (ucs2CMap) {
  36518. var cMap = properties.cMap;
  36519. toUnicode = [];
  36520. cMap.forEach(function(charcode, cid) {
  36521. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  36522. // e) Map the CID obtained in step (a) according to the CMap
  36523. // obtained in step (d), producing a Unicode value.
  36524. var ucs2 = ucs2CMap.lookup(cid);
  36525. if (ucs2) {
  36526. toUnicode[charcode] =
  36527. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  36528. ucs2.charCodeAt(1));
  36529. }
  36530. });
  36531. return new ToUnicodeMap(toUnicode);
  36532. });
  36533. }
  36534. // The viewer's choice, just use an identity map.
  36535. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  36536. properties.lastChar));
  36537. },
  36538. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36539. var cmapObj = toUnicode;
  36540. if (isName(cmapObj)) {
  36541. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36542. function (cmap) {
  36543. if (cmap instanceof IdentityCMap) {
  36544. return new IdentityToUnicodeMap(0, 0xFFFF);
  36545. }
  36546. return new ToUnicodeMap(cmap.getMap());
  36547. });
  36548. } else if (isStream(cmapObj)) {
  36549. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  36550. function (cmap) {
  36551. if (cmap instanceof IdentityCMap) {
  36552. return new IdentityToUnicodeMap(0, 0xFFFF);
  36553. }
  36554. var map = new Array(cmap.length);
  36555. // Convert UTF-16BE
  36556. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36557. // to iterate over all keys.
  36558. cmap.forEach(function(charCode, token) {
  36559. var str = [];
  36560. for (var k = 0; k < token.length; k += 2) {
  36561. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36562. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36563. str.push(w1);
  36564. continue;
  36565. }
  36566. k += 2;
  36567. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36568. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36569. }
  36570. map[charCode] = String.fromCharCode.apply(String, str);
  36571. });
  36572. return new ToUnicodeMap(map);
  36573. });
  36574. }
  36575. return Promise.resolve(null);
  36576. },
  36577. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36578. // Extract the encoding from the CIDToGIDMap
  36579. var glyphsData = cidToGidStream.getBytes();
  36580. // Set encoding 0 to later verify the font has an encoding
  36581. var result = [];
  36582. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36583. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36584. if (glyphID === 0) {
  36585. continue;
  36586. }
  36587. var code = j >> 1;
  36588. result[code] = glyphID;
  36589. }
  36590. return result;
  36591. },
  36592. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36593. descriptor,
  36594. properties) {
  36595. var glyphsWidths = [];
  36596. var defaultWidth = 0;
  36597. var glyphsVMetrics = [];
  36598. var defaultVMetrics;
  36599. var i, ii, j, jj, start, code, widths;
  36600. if (properties.composite) {
  36601. defaultWidth = dict.get('DW') || 1000;
  36602. widths = dict.get('W');
  36603. if (widths) {
  36604. for (i = 0, ii = widths.length; i < ii; i++) {
  36605. start = widths[i++];
  36606. code = xref.fetchIfRef(widths[i]);
  36607. if (isArray(code)) {
  36608. for (j = 0, jj = code.length; j < jj; j++) {
  36609. glyphsWidths[start++] = code[j];
  36610. }
  36611. } else {
  36612. var width = widths[++i];
  36613. for (j = start; j <= code; j++) {
  36614. glyphsWidths[j] = width;
  36615. }
  36616. }
  36617. }
  36618. }
  36619. if (properties.vertical) {
  36620. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36621. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36622. vmetrics = dict.get('W2');
  36623. if (vmetrics) {
  36624. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36625. start = vmetrics[i++];
  36626. code = xref.fetchIfRef(vmetrics[i]);
  36627. if (isArray(code)) {
  36628. for (j = 0, jj = code.length; j < jj; j++) {
  36629. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36630. }
  36631. } else {
  36632. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36633. for (j = start; j <= code; j++) {
  36634. glyphsVMetrics[j] = vmetric;
  36635. }
  36636. }
  36637. }
  36638. }
  36639. }
  36640. } else {
  36641. var firstChar = properties.firstChar;
  36642. widths = dict.get('Widths');
  36643. if (widths) {
  36644. j = firstChar;
  36645. for (i = 0, ii = widths.length; i < ii; i++) {
  36646. glyphsWidths[j++] = widths[i];
  36647. }
  36648. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36649. } else {
  36650. // Trying get the BaseFont metrics (see comment above).
  36651. var baseFontName = dict.get('BaseFont');
  36652. if (isName(baseFontName)) {
  36653. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36654. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36655. properties);
  36656. defaultWidth = metrics.defaultWidth;
  36657. }
  36658. }
  36659. }
  36660. // Heuristic: detection of monospace font by checking all non-zero widths
  36661. var isMonospace = true;
  36662. var firstWidth = defaultWidth;
  36663. for (var glyph in glyphsWidths) {
  36664. var glyphWidth = glyphsWidths[glyph];
  36665. if (!glyphWidth) {
  36666. continue;
  36667. }
  36668. if (!firstWidth) {
  36669. firstWidth = glyphWidth;
  36670. continue;
  36671. }
  36672. if (firstWidth !== glyphWidth) {
  36673. isMonospace = false;
  36674. break;
  36675. }
  36676. }
  36677. if (isMonospace) {
  36678. properties.flags |= FontFlags.FixedPitch;
  36679. }
  36680. properties.defaultWidth = defaultWidth;
  36681. properties.widths = glyphsWidths;
  36682. properties.defaultVMetrics = defaultVMetrics;
  36683. properties.vmetrics = glyphsVMetrics;
  36684. },
  36685. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36686. // Simulating descriptor flags attribute
  36687. var fontNameWoStyle = baseFontName.split('-')[0];
  36688. return (fontNameWoStyle in getSerifFonts()) ||
  36689. (fontNameWoStyle.search(/serif/gi) !== -1);
  36690. },
  36691. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36692. var defaultWidth = 0;
  36693. var widths = [];
  36694. var monospace = false;
  36695. var stdFontMap = getStdFontMap();
  36696. var lookupName = (stdFontMap[name] || name);
  36697. var Metrics = getMetrics();
  36698. if (!(lookupName in Metrics)) {
  36699. // Use default fonts for looking up font metrics if the passed
  36700. // font is not a base font
  36701. if (this.isSerifFont(name)) {
  36702. lookupName = 'Times-Roman';
  36703. } else {
  36704. lookupName = 'Helvetica';
  36705. }
  36706. }
  36707. var glyphWidths = Metrics[lookupName];
  36708. if (isNum(glyphWidths)) {
  36709. defaultWidth = glyphWidths;
  36710. monospace = true;
  36711. } else {
  36712. widths = glyphWidths(); // expand lazy widths array
  36713. }
  36714. return {
  36715. defaultWidth: defaultWidth,
  36716. monospace: monospace,
  36717. widths: widths
  36718. };
  36719. },
  36720. buildCharCodeToWidth:
  36721. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36722. properties) {
  36723. var widths = Object.create(null);
  36724. var differences = properties.differences;
  36725. var encoding = properties.defaultEncoding;
  36726. for (var charCode = 0; charCode < 256; charCode++) {
  36727. if (charCode in differences &&
  36728. widthsByGlyphName[differences[charCode]]) {
  36729. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36730. continue;
  36731. }
  36732. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36733. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36734. continue;
  36735. }
  36736. }
  36737. return widths;
  36738. },
  36739. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36740. var baseDict = dict;
  36741. var type = dict.get('Subtype');
  36742. assert(isName(type), 'invalid font Subtype');
  36743. var composite = false;
  36744. var uint8array;
  36745. if (type.name === 'Type0') {
  36746. // If font is a composite
  36747. // - get the descendant font
  36748. // - set the type according to the descendant font
  36749. // - get the FontDescriptor from the descendant font
  36750. var df = dict.get('DescendantFonts');
  36751. if (!df) {
  36752. error('Descendant fonts are not specified');
  36753. }
  36754. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36755. type = dict.get('Subtype');
  36756. assert(isName(type), 'invalid font Subtype');
  36757. composite = true;
  36758. }
  36759. var descriptor = dict.get('FontDescriptor');
  36760. if (descriptor) {
  36761. var hash = new MurmurHash3_64();
  36762. var encoding = baseDict.getRaw('Encoding');
  36763. if (isName(encoding)) {
  36764. hash.update(encoding.name);
  36765. } else if (isRef(encoding)) {
  36766. hash.update(encoding.toString());
  36767. } else if (isDict(encoding)) {
  36768. var keys = encoding.getKeys();
  36769. for (var i = 0, ii = keys.length; i < ii; i++) {
  36770. var entry = encoding.getRaw(keys[i]);
  36771. if (isName(entry)) {
  36772. hash.update(entry.name);
  36773. } else if (isRef(entry)) {
  36774. hash.update(entry.toString());
  36775. } else if (isArray(entry)) { // 'Differences' entry.
  36776. // Ideally we should check the contents of the array, but to avoid
  36777. // parsing it here and then again in |extractDataStructures|,
  36778. // we only use the array length for now (fixes bug1157493.pdf).
  36779. hash.update(entry.length.toString());
  36780. }
  36781. }
  36782. }
  36783. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36784. if (isStream(toUnicode)) {
  36785. var stream = toUnicode.str || toUnicode;
  36786. uint8array = stream.buffer ?
  36787. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36788. new Uint8Array(stream.bytes.buffer,
  36789. stream.start, stream.end - stream.start);
  36790. hash.update(uint8array);
  36791. } else if (isName(toUnicode)) {
  36792. hash.update(toUnicode.name);
  36793. }
  36794. var widths = dict.get('Widths') || baseDict.get('Widths');
  36795. if (widths) {
  36796. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36797. hash.update(uint8array);
  36798. }
  36799. }
  36800. return {
  36801. descriptor: descriptor,
  36802. dict: dict,
  36803. baseDict: baseDict,
  36804. composite: composite,
  36805. type: type.name,
  36806. hash: hash ? hash.hexdigest() : ''
  36807. };
  36808. },
  36809. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36810. xref) {
  36811. var baseDict = preEvaluatedFont.baseDict;
  36812. var dict = preEvaluatedFont.dict;
  36813. var composite = preEvaluatedFont.composite;
  36814. var descriptor = preEvaluatedFont.descriptor;
  36815. var type = preEvaluatedFont.type;
  36816. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36817. var cMapOptions = this.options.cMapOptions;
  36818. var properties;
  36819. if (!descriptor) {
  36820. if (type === 'Type3') {
  36821. // FontDescriptor is only required for Type3 fonts when the document
  36822. // is a tagged pdf. Create a barbebones one to get by.
  36823. descriptor = new Dict(null);
  36824. descriptor.set('FontName', Name.get(type));
  36825. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  36826. } else {
  36827. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36828. // FontDescriptor was not required.
  36829. // This case is here for compatibility.
  36830. var baseFontName = dict.get('BaseFont');
  36831. if (!isName(baseFontName)) {
  36832. error('Base font is not specified');
  36833. }
  36834. // Using base font name as a font name.
  36835. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36836. var metrics = this.getBaseFontMetrics(baseFontName);
  36837. // Simulating descriptor flags attribute
  36838. var fontNameWoStyle = baseFontName.split('-')[0];
  36839. var flags =
  36840. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36841. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36842. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36843. FontFlags.Nonsymbolic);
  36844. properties = {
  36845. type: type,
  36846. name: baseFontName,
  36847. widths: metrics.widths,
  36848. defaultWidth: metrics.defaultWidth,
  36849. flags: flags,
  36850. firstChar: 0,
  36851. lastChar: maxCharIndex
  36852. };
  36853. return this.extractDataStructures(dict, dict, xref, properties).then(
  36854. function (properties) {
  36855. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36856. properties);
  36857. return new Font(baseFontName, null, properties);
  36858. }.bind(this));
  36859. }
  36860. }
  36861. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36862. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36863. // to ignore this rule when a variant of a standard font is used.
  36864. // TODO Fill the width array depending on which of the base font this is
  36865. // a variant.
  36866. var firstChar = (dict.get('FirstChar') || 0);
  36867. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36868. var fontName = descriptor.get('FontName');
  36869. var baseFont = dict.get('BaseFont');
  36870. // Some bad PDFs have a string as the font name.
  36871. if (isString(fontName)) {
  36872. fontName = Name.get(fontName);
  36873. }
  36874. if (isString(baseFont)) {
  36875. baseFont = Name.get(baseFont);
  36876. }
  36877. if (type !== 'Type3') {
  36878. var fontNameStr = fontName && fontName.name;
  36879. var baseFontStr = baseFont && baseFont.name;
  36880. if (fontNameStr !== baseFontStr) {
  36881. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36882. '" but should be the same as the Font\'s BaseFont "' +
  36883. baseFontStr + '"');
  36884. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36885. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36886. if (fontNameStr && baseFontStr &&
  36887. baseFontStr.indexOf(fontNameStr) === 0) {
  36888. fontName = baseFont;
  36889. }
  36890. }
  36891. }
  36892. fontName = (fontName || baseFont);
  36893. assert(isName(fontName), 'invalid font name');
  36894. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36895. if (fontFile) {
  36896. if (fontFile.dict) {
  36897. var subtype = fontFile.dict.get('Subtype');
  36898. if (subtype) {
  36899. subtype = subtype.name;
  36900. }
  36901. var length1 = fontFile.dict.get('Length1');
  36902. var length2 = fontFile.dict.get('Length2');
  36903. var length3 = fontFile.dict.get('Length3');
  36904. }
  36905. }
  36906. properties = {
  36907. type: type,
  36908. name: fontName.name,
  36909. subtype: subtype,
  36910. file: fontFile,
  36911. length1: length1,
  36912. length2: length2,
  36913. length3: length3,
  36914. loadedName: baseDict.loadedName,
  36915. composite: composite,
  36916. wideChars: composite,
  36917. fixedPitch: false,
  36918. fontMatrix: (dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX),
  36919. firstChar: firstChar || 0,
  36920. lastChar: (lastChar || maxCharIndex),
  36921. bbox: descriptor.getArray('FontBBox'),
  36922. ascent: descriptor.get('Ascent'),
  36923. descent: descriptor.get('Descent'),
  36924. xHeight: descriptor.get('XHeight'),
  36925. capHeight: descriptor.get('CapHeight'),
  36926. flags: descriptor.get('Flags'),
  36927. italicAngle: descriptor.get('ItalicAngle'),
  36928. coded: false
  36929. };
  36930. var cMapPromise;
  36931. if (composite) {
  36932. var cidEncoding = baseDict.get('Encoding');
  36933. if (isName(cidEncoding)) {
  36934. properties.cidEncoding = cidEncoding.name;
  36935. }
  36936. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  36937. function (cMap) {
  36938. properties.cMap = cMap;
  36939. properties.vertical = properties.cMap.vertical;
  36940. });
  36941. } else {
  36942. cMapPromise = Promise.resolve(undefined);
  36943. }
  36944. return cMapPromise.then(function () {
  36945. return this.extractDataStructures(dict, baseDict, xref, properties);
  36946. }.bind(this)).then(function (properties) {
  36947. this.extractWidths(dict, xref, descriptor, properties);
  36948. if (type === 'Type3') {
  36949. properties.isType3Font = true;
  36950. }
  36951. return new Font(fontName.name, fontFile, properties);
  36952. }.bind(this));
  36953. }
  36954. };
  36955. return PartialEvaluator;
  36956. })();
  36957. var TranslatedFont = (function TranslatedFontClosure() {
  36958. function TranslatedFont(loadedName, font, dict) {
  36959. this.loadedName = loadedName;
  36960. this.font = font;
  36961. this.dict = dict;
  36962. this.type3Loaded = null;
  36963. this.sent = false;
  36964. }
  36965. TranslatedFont.prototype = {
  36966. send: function (handler) {
  36967. if (this.sent) {
  36968. return;
  36969. }
  36970. var fontData = this.font.exportData();
  36971. handler.send('commonobj', [
  36972. this.loadedName,
  36973. 'Font',
  36974. fontData
  36975. ]);
  36976. this.sent = true;
  36977. },
  36978. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36979. assert(this.font.isType3Font);
  36980. if (this.type3Loaded) {
  36981. return this.type3Loaded;
  36982. }
  36983. var translatedFont = this.font;
  36984. var loadCharProcsPromise = Promise.resolve();
  36985. var charProcs = this.dict.get('CharProcs');
  36986. var fontResources = this.dict.get('Resources') || resources;
  36987. var charProcKeys = charProcs.getKeys();
  36988. var charProcOperatorList = Object.create(null);
  36989. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36990. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36991. var glyphStream = charProcs.get(key);
  36992. var operatorList = new OperatorList();
  36993. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36994. operatorList).then(function () {
  36995. charProcOperatorList[key] = operatorList.getIR();
  36996. // Add the dependencies to the parent operator list so they are
  36997. // resolved before sub operator list is executed synchronously.
  36998. parentOperatorList.addDependencies(operatorList.dependencies);
  36999. }, function (reason) {
  37000. warn('Type3 font resource \"' + key + '\" is not available');
  37001. var operatorList = new OperatorList();
  37002. charProcOperatorList[key] = operatorList.getIR();
  37003. });
  37004. }.bind(this, charProcKeys[i]));
  37005. }
  37006. this.type3Loaded = loadCharProcsPromise.then(function () {
  37007. translatedFont.charProcOperatorList = charProcOperatorList;
  37008. });
  37009. return this.type3Loaded;
  37010. }
  37011. };
  37012. return TranslatedFont;
  37013. })();
  37014. var OperatorList = (function OperatorListClosure() {
  37015. var CHUNK_SIZE = 1000;
  37016. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  37017. function getTransfers(queue) {
  37018. var transfers = [];
  37019. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37020. for (var i = 0, ii = queue.length; i < ii; i++) {
  37021. switch (fnArray[i]) {
  37022. case OPS.paintInlineImageXObject:
  37023. case OPS.paintInlineImageXObjectGroup:
  37024. case OPS.paintImageMaskXObject:
  37025. var arg = argsArray[i][0]; // first param in imgData
  37026. if (!arg.cached) {
  37027. transfers.push(arg.data.buffer);
  37028. }
  37029. break;
  37030. }
  37031. }
  37032. return transfers;
  37033. }
  37034. function OperatorList(intent, messageHandler, pageIndex) {
  37035. this.messageHandler = messageHandler;
  37036. this.fnArray = [];
  37037. this.argsArray = [];
  37038. this.dependencies = Object.create(null);
  37039. this._totalLength = 0;
  37040. this.pageIndex = pageIndex;
  37041. this.intent = intent;
  37042. }
  37043. OperatorList.prototype = {
  37044. get length() {
  37045. return this.argsArray.length;
  37046. },
  37047. /**
  37048. * @returns {number} The total length of the entire operator list,
  37049. * since `this.length === 0` after flushing.
  37050. */
  37051. get totalLength() {
  37052. return (this._totalLength + this.length);
  37053. },
  37054. addOp: function(fn, args) {
  37055. this.fnArray.push(fn);
  37056. this.argsArray.push(args);
  37057. if (this.messageHandler) {
  37058. if (this.fnArray.length >= CHUNK_SIZE) {
  37059. this.flush();
  37060. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  37061. (fn === OPS.restore || fn === OPS.endText)) {
  37062. // heuristic to flush on boundary of restore or endText
  37063. this.flush();
  37064. }
  37065. }
  37066. },
  37067. addDependency: function(dependency) {
  37068. if (dependency in this.dependencies) {
  37069. return;
  37070. }
  37071. this.dependencies[dependency] = true;
  37072. this.addOp(OPS.dependency, [dependency]);
  37073. },
  37074. addDependencies: function(dependencies) {
  37075. for (var key in dependencies) {
  37076. this.addDependency(key);
  37077. }
  37078. },
  37079. addOpList: function(opList) {
  37080. Util.extendObj(this.dependencies, opList.dependencies);
  37081. for (var i = 0, ii = opList.length; i < ii; i++) {
  37082. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  37083. }
  37084. },
  37085. getIR: function() {
  37086. return {
  37087. fnArray: this.fnArray,
  37088. argsArray: this.argsArray,
  37089. length: this.length
  37090. };
  37091. },
  37092. flush: function(lastChunk) {
  37093. if (this.intent !== 'oplist') {
  37094. new QueueOptimizer().optimize(this);
  37095. }
  37096. var transfers = getTransfers(this);
  37097. var length = this.length;
  37098. this._totalLength += length;
  37099. this.messageHandler.send('RenderPageChunk', {
  37100. operatorList: {
  37101. fnArray: this.fnArray,
  37102. argsArray: this.argsArray,
  37103. lastChunk: lastChunk,
  37104. length: length
  37105. },
  37106. pageIndex: this.pageIndex,
  37107. intent: this.intent
  37108. }, transfers);
  37109. this.dependencies = Object.create(null);
  37110. this.fnArray.length = 0;
  37111. this.argsArray.length = 0;
  37112. }
  37113. };
  37114. return OperatorList;
  37115. })();
  37116. var StateManager = (function StateManagerClosure() {
  37117. function StateManager(initialState) {
  37118. this.state = initialState;
  37119. this.stateStack = [];
  37120. }
  37121. StateManager.prototype = {
  37122. save: function () {
  37123. var old = this.state;
  37124. this.stateStack.push(this.state);
  37125. this.state = old.clone();
  37126. },
  37127. restore: function () {
  37128. var prev = this.stateStack.pop();
  37129. if (prev) {
  37130. this.state = prev;
  37131. }
  37132. },
  37133. transform: function (args) {
  37134. this.state.ctm = Util.transform(this.state.ctm, args);
  37135. }
  37136. };
  37137. return StateManager;
  37138. })();
  37139. var TextState = (function TextStateClosure() {
  37140. function TextState() {
  37141. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37142. this.fontName = null;
  37143. this.fontSize = 0;
  37144. this.font = null;
  37145. this.fontMatrix = FONT_IDENTITY_MATRIX;
  37146. this.textMatrix = IDENTITY_MATRIX.slice();
  37147. this.textLineMatrix = IDENTITY_MATRIX.slice();
  37148. this.charSpacing = 0;
  37149. this.wordSpacing = 0;
  37150. this.leading = 0;
  37151. this.textHScale = 1;
  37152. this.textRise = 0;
  37153. }
  37154. TextState.prototype = {
  37155. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37156. var m = this.textMatrix;
  37157. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37158. },
  37159. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  37160. var m = this.textLineMatrix;
  37161. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  37162. },
  37163. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  37164. var m = this.textMatrix;
  37165. m[4] = m[0] * x + m[2] * y + m[4];
  37166. m[5] = m[1] * x + m[3] * y + m[5];
  37167. },
  37168. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  37169. var m = this.textLineMatrix;
  37170. m[4] = m[0] * x + m[2] * y + m[4];
  37171. m[5] = m[1] * x + m[3] * y + m[5];
  37172. },
  37173. calcTextLineMatrixAdvance:
  37174. function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  37175. var font = this.font;
  37176. if (!font) {
  37177. return null;
  37178. }
  37179. var m = this.textLineMatrix;
  37180. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  37181. return null;
  37182. }
  37183. var txDiff = e - m[4], tyDiff = f - m[5];
  37184. if ((font.vertical && txDiff !== 0) || (!font.vertical && tyDiff !== 0)) {
  37185. return null;
  37186. }
  37187. var tx, ty, denominator = a * d - b * c;
  37188. if (font.vertical) {
  37189. tx = -tyDiff * c / denominator;
  37190. ty = tyDiff * a / denominator;
  37191. } else {
  37192. tx = txDiff * d / denominator;
  37193. ty = -txDiff * b / denominator;
  37194. }
  37195. return { width: tx, height: ty, value: (font.vertical ? ty : tx), };
  37196. },
  37197. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  37198. // 9.4.4 Text Space Details
  37199. var tsm = [this.fontSize * this.textHScale, 0,
  37200. 0, this.fontSize,
  37201. 0, this.textRise];
  37202. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  37203. },
  37204. carriageReturn: function TextState_carriageReturn() {
  37205. this.translateTextLineMatrix(0, -this.leading);
  37206. this.textMatrix = this.textLineMatrix.slice();
  37207. },
  37208. clone: function TextState_clone() {
  37209. var clone = Object.create(this);
  37210. clone.textMatrix = this.textMatrix.slice();
  37211. clone.textLineMatrix = this.textLineMatrix.slice();
  37212. clone.fontMatrix = this.fontMatrix.slice();
  37213. return clone;
  37214. }
  37215. };
  37216. return TextState;
  37217. })();
  37218. var EvalState = (function EvalStateClosure() {
  37219. function EvalState() {
  37220. this.ctm = new Float32Array(IDENTITY_MATRIX);
  37221. this.font = null;
  37222. this.textRenderingMode = TextRenderingMode.FILL;
  37223. this.fillColorSpace = ColorSpace.singletons.gray;
  37224. this.strokeColorSpace = ColorSpace.singletons.gray;
  37225. }
  37226. EvalState.prototype = {
  37227. clone: function CanvasExtraState_clone() {
  37228. return Object.create(this);
  37229. },
  37230. };
  37231. return EvalState;
  37232. })();
  37233. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  37234. // Specifies properties for each command
  37235. //
  37236. // If variableArgs === true: [0, `numArgs`] expected
  37237. // If variableArgs === false: exactly `numArgs` expected
  37238. var getOPMap = getLookupTableFactory(function (t) {
  37239. // Graphic state
  37240. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  37241. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  37242. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  37243. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  37244. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  37245. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  37246. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  37247. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  37248. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  37249. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  37250. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  37251. // Path
  37252. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  37253. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  37254. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  37255. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  37256. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  37257. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  37258. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  37259. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  37260. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  37261. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37262. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  37263. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  37264. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  37265. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  37266. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  37267. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  37268. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  37269. // Clipping
  37270. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  37271. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  37272. // Text
  37273. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  37274. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  37275. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  37276. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  37277. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  37278. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  37279. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  37280. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  37281. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  37282. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  37283. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  37284. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  37285. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  37286. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  37287. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  37288. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  37289. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  37290. variableArgs: false };
  37291. // Type3 fonts
  37292. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  37293. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  37294. variableArgs: false };
  37295. // Color
  37296. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  37297. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  37298. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  37299. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  37300. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  37301. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  37302. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  37303. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  37304. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  37305. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  37306. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  37307. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  37308. // Shading
  37309. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  37310. // Images
  37311. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  37312. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  37313. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  37314. // XObjects
  37315. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  37316. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  37317. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  37318. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  37319. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  37320. variableArgs: false };
  37321. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  37322. // Compatibility
  37323. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  37324. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  37325. // (reserved partial commands for the lexer)
  37326. t['BM'] = null;
  37327. t['BD'] = null;
  37328. t['true'] = null;
  37329. t['fa'] = null;
  37330. t['fal'] = null;
  37331. t['fals'] = null;
  37332. t['false'] = null;
  37333. t['nu'] = null;
  37334. t['nul'] = null;
  37335. t['null'] = null;
  37336. });
  37337. function EvaluatorPreprocessor(stream, xref, stateManager) {
  37338. this.opMap = getOPMap();
  37339. // TODO(mduan): pass array of knownCommands rather than this.opMap
  37340. // dictionary
  37341. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  37342. this.stateManager = stateManager;
  37343. this.nonProcessedArgs = [];
  37344. }
  37345. EvaluatorPreprocessor.prototype = {
  37346. get savedStatesDepth() {
  37347. return this.stateManager.stateStack.length;
  37348. },
  37349. // |operation| is an object with two fields:
  37350. //
  37351. // - |fn| is an out param.
  37352. //
  37353. // - |args| is an inout param. On entry, it should have one of two values.
  37354. //
  37355. // - An empty array. This indicates that the caller is providing the
  37356. // array in which the args will be stored in. The caller should use
  37357. // this value if it can reuse a single array for each call to read().
  37358. //
  37359. // - |null|. This indicates that the caller needs this function to create
  37360. // the array in which any args are stored in. If there are zero args,
  37361. // this function will leave |operation.args| as |null| (thus avoiding
  37362. // allocations that would occur if we used an empty array to represent
  37363. // zero arguments). Otherwise, it will replace |null| with a new array
  37364. // containing the arguments. The caller should use this value if it
  37365. // cannot reuse an array for each call to read().
  37366. //
  37367. // These two modes are present because this function is very hot and so
  37368. // avoiding allocations where possible is worthwhile.
  37369. //
  37370. read: function EvaluatorPreprocessor_read(operation) {
  37371. var args = operation.args;
  37372. while (true) {
  37373. var obj = this.parser.getObj();
  37374. if (isCmd(obj)) {
  37375. var cmd = obj.cmd;
  37376. // Check that the command is valid
  37377. var opSpec = this.opMap[cmd];
  37378. if (!opSpec) {
  37379. warn('Unknown command "' + cmd + '"');
  37380. continue;
  37381. }
  37382. var fn = opSpec.id;
  37383. var numArgs = opSpec.numArgs;
  37384. var argsLength = args !== null ? args.length : 0;
  37385. if (!opSpec.variableArgs) {
  37386. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  37387. if (argsLength !== numArgs) {
  37388. var nonProcessedArgs = this.nonProcessedArgs;
  37389. while (argsLength > numArgs) {
  37390. nonProcessedArgs.push(args.shift());
  37391. argsLength--;
  37392. }
  37393. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  37394. if (!args) {
  37395. args = [];
  37396. }
  37397. args.unshift(nonProcessedArgs.pop());
  37398. argsLength++;
  37399. }
  37400. }
  37401. if (argsLength < numArgs) {
  37402. // If we receive too few args, it's not possible to possible
  37403. // to execute the command, so skip the command
  37404. info('Command ' + fn + ': because expected ' +
  37405. numArgs + ' args, but received ' + argsLength +
  37406. ' args; skipping');
  37407. args = null;
  37408. continue;
  37409. }
  37410. } else if (argsLength > numArgs) {
  37411. info('Command ' + fn + ': expected [0,' + numArgs +
  37412. '] args, but received ' + argsLength + ' args');
  37413. }
  37414. // TODO figure out how to type-check vararg functions
  37415. this.preprocessCommand(fn, args);
  37416. operation.fn = fn;
  37417. operation.args = args;
  37418. return true;
  37419. } else {
  37420. if (isEOF(obj)) {
  37421. return false; // no more commands
  37422. }
  37423. // argument
  37424. if (obj !== null) {
  37425. if (!args) {
  37426. args = [];
  37427. }
  37428. args.push(obj);
  37429. assert(args.length <= 33, 'Too many arguments');
  37430. }
  37431. }
  37432. }
  37433. },
  37434. preprocessCommand:
  37435. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  37436. switch (fn | 0) {
  37437. case OPS.save:
  37438. this.stateManager.save();
  37439. break;
  37440. case OPS.restore:
  37441. this.stateManager.restore();
  37442. break;
  37443. case OPS.transform:
  37444. this.stateManager.transform(args);
  37445. break;
  37446. }
  37447. }
  37448. };
  37449. return EvaluatorPreprocessor;
  37450. })();
  37451. var QueueOptimizer = (function QueueOptimizerClosure() {
  37452. function addState(parentState, pattern, fn) {
  37453. var state = parentState;
  37454. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37455. var item = pattern[i];
  37456. state = (state[item] || (state[item] = []));
  37457. }
  37458. state[pattern[pattern.length - 1]] = fn;
  37459. }
  37460. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37461. argsArray) {
  37462. // Handles special case of mainly LaTeX documents which use image masks to
  37463. // draw lines with the current fill style.
  37464. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37465. // have been found at iFirstSave.
  37466. var iFirstPIMXO = iFirstSave + 2;
  37467. for (var i = 0; i < count; i++) {
  37468. var arg = argsArray[iFirstPIMXO + 4 * i];
  37469. var imageMask = arg.length === 1 && arg[0];
  37470. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37471. (!imageMask.data.length ||
  37472. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37473. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37474. continue;
  37475. }
  37476. break;
  37477. }
  37478. return count - i;
  37479. }
  37480. var InitialState = [];
  37481. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37482. // sequences with one |paintInlineImageXObjectGroup| operation.
  37483. addState(InitialState,
  37484. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37485. function foundInlineImageGroup(context) {
  37486. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37487. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37488. var MAX_WIDTH = 1000;
  37489. var IMAGE_PADDING = 1;
  37490. var fnArray = context.fnArray, argsArray = context.argsArray;
  37491. var curr = context.iCurr;
  37492. var iFirstSave = curr - 3;
  37493. var iFirstTransform = curr - 2;
  37494. var iFirstPIIXO = curr - 1;
  37495. // Look for the quartets.
  37496. var i = iFirstSave + 4;
  37497. var ii = fnArray.length;
  37498. while (i + 3 < ii) {
  37499. if (fnArray[i] !== OPS.save ||
  37500. fnArray[i + 1] !== OPS.transform ||
  37501. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37502. fnArray[i + 3] !== OPS.restore) {
  37503. break; // ops don't match
  37504. }
  37505. i += 4;
  37506. }
  37507. // At this point, i is the index of the first op past the last valid
  37508. // quartet.
  37509. var count = Math.min((i - iFirstSave) / 4,
  37510. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37511. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37512. return i;
  37513. }
  37514. // assuming that heights of those image is too small (~1 pixel)
  37515. // packing as much as possible by lines
  37516. var maxX = 0;
  37517. var map = [], maxLineHeight = 0;
  37518. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37519. var q;
  37520. for (q = 0; q < count; q++) {
  37521. var transform = argsArray[iFirstTransform + (q << 2)];
  37522. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37523. if (currentX + img.width > MAX_WIDTH) {
  37524. // starting new line
  37525. maxX = Math.max(maxX, currentX);
  37526. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37527. currentX = 0;
  37528. maxLineHeight = 0;
  37529. }
  37530. map.push({
  37531. transform: transform,
  37532. x: currentX, y: currentY,
  37533. w: img.width, h: img.height
  37534. });
  37535. currentX += img.width + 2 * IMAGE_PADDING;
  37536. maxLineHeight = Math.max(maxLineHeight, img.height);
  37537. }
  37538. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37539. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37540. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37541. var imgRowSize = imgWidth << 2;
  37542. for (q = 0; q < count; q++) {
  37543. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37544. // Copy image by lines and extends pixels into padding.
  37545. var rowSize = map[q].w << 2;
  37546. var dataOffset = 0;
  37547. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37548. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37549. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37550. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37551. dataOffset += rowSize;
  37552. offset += imgRowSize;
  37553. }
  37554. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37555. while (offset >= 0) {
  37556. data[offset - 4] = data[offset];
  37557. data[offset - 3] = data[offset + 1];
  37558. data[offset - 2] = data[offset + 2];
  37559. data[offset - 1] = data[offset + 3];
  37560. data[offset + rowSize] = data[offset + rowSize - 4];
  37561. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37562. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37563. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37564. offset -= imgRowSize;
  37565. }
  37566. }
  37567. // Replace queue items.
  37568. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37569. argsArray.splice(iFirstSave, count * 4,
  37570. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37571. data: imgData }, map]);
  37572. return iFirstSave + 1;
  37573. });
  37574. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37575. // sequences with one |paintImageMaskXObjectGroup| or one
  37576. // |paintImageMaskXObjectRepeat| operation.
  37577. addState(InitialState,
  37578. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37579. function foundImageMaskGroup(context) {
  37580. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37581. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37582. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37583. var fnArray = context.fnArray, argsArray = context.argsArray;
  37584. var curr = context.iCurr;
  37585. var iFirstSave = curr - 3;
  37586. var iFirstTransform = curr - 2;
  37587. var iFirstPIMXO = curr - 1;
  37588. // Look for the quartets.
  37589. var i = iFirstSave + 4;
  37590. var ii = fnArray.length;
  37591. while (i + 3 < ii) {
  37592. if (fnArray[i] !== OPS.save ||
  37593. fnArray[i + 1] !== OPS.transform ||
  37594. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37595. fnArray[i + 3] !== OPS.restore) {
  37596. break; // ops don't match
  37597. }
  37598. i += 4;
  37599. }
  37600. // At this point, i is the index of the first op past the last valid
  37601. // quartet.
  37602. var count = (i - iFirstSave) / 4;
  37603. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37604. argsArray);
  37605. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37606. return i;
  37607. }
  37608. var q;
  37609. var isSameImage = false;
  37610. var iTransform, transformArgs;
  37611. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37612. if (argsArray[iFirstTransform][1] === 0 &&
  37613. argsArray[iFirstTransform][2] === 0) {
  37614. isSameImage = true;
  37615. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37616. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37617. iTransform = iFirstTransform + 4;
  37618. var iPIMXO = iFirstPIMXO + 4;
  37619. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37620. transformArgs = argsArray[iTransform];
  37621. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37622. transformArgs[0] !== firstTransformArg0 ||
  37623. transformArgs[1] !== 0 ||
  37624. transformArgs[2] !== 0 ||
  37625. transformArgs[3] !== firstTransformArg3) {
  37626. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37627. isSameImage = false;
  37628. } else {
  37629. count = q;
  37630. }
  37631. break; // different image or transform
  37632. }
  37633. }
  37634. }
  37635. if (isSameImage) {
  37636. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37637. var positions = new Float32Array(count * 2);
  37638. iTransform = iFirstTransform;
  37639. for (q = 0; q < count; q++, iTransform += 4) {
  37640. transformArgs = argsArray[iTransform];
  37641. positions[(q << 1)] = transformArgs[4];
  37642. positions[(q << 1) + 1] = transformArgs[5];
  37643. }
  37644. // Replace queue items.
  37645. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37646. argsArray.splice(iFirstSave, count * 4,
  37647. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37648. } else {
  37649. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37650. var images = [];
  37651. for (q = 0; q < count; q++) {
  37652. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37653. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37654. images.push({ data: maskParams.data, width: maskParams.width,
  37655. height: maskParams.height,
  37656. transform: transformArgs });
  37657. }
  37658. // Replace queue items.
  37659. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37660. argsArray.splice(iFirstSave, count * 4, [images]);
  37661. }
  37662. return iFirstSave + 1;
  37663. });
  37664. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37665. // with one paintImageXObjectRepeat operation, if the |transform| and
  37666. // |paintImageXObjectRepeat| ops are appropriate.
  37667. addState(InitialState,
  37668. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37669. function (context) {
  37670. var MIN_IMAGES_IN_BLOCK = 3;
  37671. var MAX_IMAGES_IN_BLOCK = 1000;
  37672. var fnArray = context.fnArray, argsArray = context.argsArray;
  37673. var curr = context.iCurr;
  37674. var iFirstSave = curr - 3;
  37675. var iFirstTransform = curr - 2;
  37676. var iFirstPIXO = curr - 1;
  37677. var iFirstRestore = curr;
  37678. if (argsArray[iFirstTransform][1] !== 0 ||
  37679. argsArray[iFirstTransform][2] !== 0) {
  37680. return iFirstRestore + 1; // transform has the wrong form
  37681. }
  37682. // Look for the quartets.
  37683. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37684. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37685. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37686. var i = iFirstSave + 4;
  37687. var ii = fnArray.length;
  37688. while (i + 3 < ii) {
  37689. if (fnArray[i] !== OPS.save ||
  37690. fnArray[i + 1] !== OPS.transform ||
  37691. fnArray[i + 2] !== OPS.paintImageXObject ||
  37692. fnArray[i + 3] !== OPS.restore) {
  37693. break; // ops don't match
  37694. }
  37695. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37696. argsArray[i + 1][1] !== 0 ||
  37697. argsArray[i + 1][2] !== 0 ||
  37698. argsArray[i + 1][3] !== firstTransformArg3) {
  37699. break; // transforms don't match
  37700. }
  37701. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37702. break; // images don't match
  37703. }
  37704. i += 4;
  37705. }
  37706. // At this point, i is the index of the first op past the last valid
  37707. // quartet.
  37708. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37709. if (count < MIN_IMAGES_IN_BLOCK) {
  37710. return i;
  37711. }
  37712. // Extract the (x,y) positions from all of the matching transforms.
  37713. var positions = new Float32Array(count * 2);
  37714. var iTransform = iFirstTransform;
  37715. for (var q = 0; q < count; q++, iTransform += 4) {
  37716. var transformArgs = argsArray[iTransform];
  37717. positions[(q << 1)] = transformArgs[4];
  37718. positions[(q << 1) + 1] = transformArgs[5];
  37719. }
  37720. // Replace queue items.
  37721. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37722. positions];
  37723. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37724. argsArray.splice(iFirstSave, count * 4, args);
  37725. return iFirstSave + 1;
  37726. });
  37727. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37728. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37729. // sequences, if the font for each one is the same.
  37730. addState(InitialState,
  37731. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37732. function (context) {
  37733. var MIN_CHARS_IN_BLOCK = 3;
  37734. var MAX_CHARS_IN_BLOCK = 1000;
  37735. var fnArray = context.fnArray, argsArray = context.argsArray;
  37736. var curr = context.iCurr;
  37737. var iFirstBeginText = curr - 4;
  37738. var iFirstSetFont = curr - 3;
  37739. var iFirstSetTextMatrix = curr - 2;
  37740. var iFirstShowText = curr - 1;
  37741. var iFirstEndText = curr;
  37742. // Look for the quintets.
  37743. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37744. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37745. var i = iFirstBeginText + 5;
  37746. var ii = fnArray.length;
  37747. while (i + 4 < ii) {
  37748. if (fnArray[i] !== OPS.beginText ||
  37749. fnArray[i + 1] !== OPS.setFont ||
  37750. fnArray[i + 2] !== OPS.setTextMatrix ||
  37751. fnArray[i + 3] !== OPS.showText ||
  37752. fnArray[i + 4] !== OPS.endText) {
  37753. break; // ops don't match
  37754. }
  37755. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37756. argsArray[i + 1][1] !== firstSetFontArg1) {
  37757. break; // fonts don't match
  37758. }
  37759. i += 5;
  37760. }
  37761. // At this point, i is the index of the first op past the last valid
  37762. // quintet.
  37763. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37764. if (count < MIN_CHARS_IN_BLOCK) {
  37765. return i;
  37766. }
  37767. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37768. // showText, endText), include that as well. (E.g. <something> might be
  37769. // |dependency|.)
  37770. var iFirst = iFirstBeginText;
  37771. if (iFirstBeginText >= 4 &&
  37772. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37773. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37774. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37775. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37776. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37777. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37778. count++;
  37779. iFirst -= 5;
  37780. }
  37781. // Remove (endText, beginText, setFont) trios.
  37782. var iEndText = iFirst + 4;
  37783. for (var q = 1; q < count; q++) {
  37784. fnArray.splice(iEndText, 3);
  37785. argsArray.splice(iEndText, 3);
  37786. iEndText += 2;
  37787. }
  37788. return iEndText + 1;
  37789. });
  37790. function QueueOptimizer() {}
  37791. QueueOptimizer.prototype = {
  37792. optimize: function QueueOptimizer_optimize(queue) {
  37793. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37794. var context = {
  37795. iCurr: 0,
  37796. fnArray: fnArray,
  37797. argsArray: argsArray
  37798. };
  37799. var state;
  37800. var i = 0, ii = fnArray.length;
  37801. while (i < ii) {
  37802. state = (state || InitialState)[fnArray[i]];
  37803. if (typeof state === 'function') { // we found some handler
  37804. context.iCurr = i;
  37805. // state() returns the index of the first non-matching op (if we
  37806. // didn't match) or the first op past the modified ops (if we did
  37807. // match and replace).
  37808. i = state(context);
  37809. state = undefined; // reset the state machine
  37810. ii = context.fnArray.length;
  37811. } else {
  37812. i++;
  37813. }
  37814. }
  37815. }
  37816. };
  37817. return QueueOptimizer;
  37818. })();
  37819. exports.OperatorList = OperatorList;
  37820. exports.PartialEvaluator = PartialEvaluator;
  37821. }));
  37822. (function (root, factory) {
  37823. {
  37824. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37825. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37826. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37827. }
  37828. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37829. coreColorSpace, coreObj, coreEvaluator) {
  37830. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37831. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  37832. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37833. var AnnotationType = sharedUtil.AnnotationType;
  37834. var OPS = sharedUtil.OPS;
  37835. var Util = sharedUtil.Util;
  37836. var isBool = sharedUtil.isBool;
  37837. var isString = sharedUtil.isString;
  37838. var isArray = sharedUtil.isArray;
  37839. var isInt = sharedUtil.isInt;
  37840. var isValidUrl = sharedUtil.isValidUrl;
  37841. var stringToBytes = sharedUtil.stringToBytes;
  37842. var stringToPDFString = sharedUtil.stringToPDFString;
  37843. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37844. var warn = sharedUtil.warn;
  37845. var Dict = corePrimitives.Dict;
  37846. var isDict = corePrimitives.isDict;
  37847. var isName = corePrimitives.isName;
  37848. var isRef = corePrimitives.isRef;
  37849. var Stream = coreStream.Stream;
  37850. var ColorSpace = coreColorSpace.ColorSpace;
  37851. var ObjectLoader = coreObj.ObjectLoader;
  37852. var FileSpec = coreObj.FileSpec;
  37853. var OperatorList = coreEvaluator.OperatorList;
  37854. /**
  37855. * @class
  37856. * @alias AnnotationFactory
  37857. */
  37858. function AnnotationFactory() {}
  37859. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37860. /**
  37861. * @param {XRef} xref
  37862. * @param {Object} ref
  37863. * @param {string} uniquePrefix
  37864. * @param {Object} idCounters
  37865. * @returns {Annotation}
  37866. */
  37867. create: function AnnotationFactory_create(xref, ref,
  37868. uniquePrefix, idCounters) {
  37869. var dict = xref.fetchIfRef(ref);
  37870. if (!isDict(dict)) {
  37871. return;
  37872. }
  37873. var id = isRef(ref) ? ref.toString() :
  37874. 'annot_' + (uniquePrefix || '') + (++idCounters.obj);
  37875. // Determine the annotation's subtype.
  37876. var subtype = dict.get('Subtype');
  37877. subtype = isName(subtype) ? subtype.name : null;
  37878. // Return the right annotation object based on the subtype and field type.
  37879. var parameters = {
  37880. xref: xref,
  37881. dict: dict,
  37882. ref: isRef(ref) ? ref : null,
  37883. subtype: subtype,
  37884. id: id,
  37885. };
  37886. switch (subtype) {
  37887. case 'Link':
  37888. return new LinkAnnotation(parameters);
  37889. case 'Text':
  37890. return new TextAnnotation(parameters);
  37891. case 'Widget':
  37892. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37893. fieldType = isName(fieldType) ? fieldType.name : null;
  37894. switch (fieldType) {
  37895. case 'Tx':
  37896. return new TextWidgetAnnotation(parameters);
  37897. case 'Ch':
  37898. return new ChoiceWidgetAnnotation(parameters);
  37899. }
  37900. warn('Unimplemented widget field type "' + fieldType + '", ' +
  37901. 'falling back to base field type.');
  37902. return new WidgetAnnotation(parameters);
  37903. case 'Popup':
  37904. return new PopupAnnotation(parameters);
  37905. case 'Highlight':
  37906. return new HighlightAnnotation(parameters);
  37907. case 'Underline':
  37908. return new UnderlineAnnotation(parameters);
  37909. case 'Squiggly':
  37910. return new SquigglyAnnotation(parameters);
  37911. case 'StrikeOut':
  37912. return new StrikeOutAnnotation(parameters);
  37913. case 'FileAttachment':
  37914. return new FileAttachmentAnnotation(parameters);
  37915. default:
  37916. if (!subtype) {
  37917. warn('Annotation is missing the required /Subtype.');
  37918. } else {
  37919. warn('Unimplemented annotation type "' + subtype + '", ' +
  37920. 'falling back to base annotation.');
  37921. }
  37922. return new Annotation(parameters);
  37923. }
  37924. }
  37925. };
  37926. var Annotation = (function AnnotationClosure() {
  37927. // 12.5.5: Algorithm: Appearance streams
  37928. function getTransformMatrix(rect, bbox, matrix) {
  37929. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37930. var minX = bounds[0];
  37931. var minY = bounds[1];
  37932. var maxX = bounds[2];
  37933. var maxY = bounds[3];
  37934. if (minX === maxX || minY === maxY) {
  37935. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37936. // just apply the transform for rect
  37937. return [1, 0, 0, 1, rect[0], rect[1]];
  37938. }
  37939. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37940. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37941. return [
  37942. xRatio,
  37943. 0,
  37944. 0,
  37945. yRatio,
  37946. rect[0] - minX * xRatio,
  37947. rect[1] - minY * yRatio
  37948. ];
  37949. }
  37950. function getDefaultAppearance(dict) {
  37951. var appearanceState = dict.get('AP');
  37952. if (!isDict(appearanceState)) {
  37953. return;
  37954. }
  37955. var appearance;
  37956. var appearances = appearanceState.get('N');
  37957. if (isDict(appearances)) {
  37958. var as = dict.get('AS');
  37959. if (as && appearances.has(as.name)) {
  37960. appearance = appearances.get(as.name);
  37961. }
  37962. } else {
  37963. appearance = appearances;
  37964. }
  37965. return appearance;
  37966. }
  37967. function Annotation(params) {
  37968. var dict = params.dict;
  37969. this.setFlags(dict.get('F'));
  37970. this.setRectangle(dict.getArray('Rect'));
  37971. this.setColor(dict.getArray('C'));
  37972. this.setBorderStyle(dict);
  37973. this.appearance = getDefaultAppearance(dict);
  37974. // Expose public properties using a data object.
  37975. this.data = {};
  37976. this.data.id = params.id;
  37977. this.data.subtype = params.subtype;
  37978. this.data.annotationFlags = this.flags;
  37979. this.data.rect = this.rectangle;
  37980. this.data.color = this.color;
  37981. this.data.borderStyle = this.borderStyle;
  37982. this.data.hasAppearance = !!this.appearance;
  37983. }
  37984. Annotation.prototype = {
  37985. /**
  37986. * @private
  37987. */
  37988. _hasFlag: function Annotation_hasFlag(flags, flag) {
  37989. return !!(flags & flag);
  37990. },
  37991. /**
  37992. * @private
  37993. */
  37994. _isViewable: function Annotation_isViewable(flags) {
  37995. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  37996. !this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
  37997. !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  37998. },
  37999. /**
  38000. * @private
  38001. */
  38002. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  38003. return this._hasFlag(flags, AnnotationFlag.PRINT) &&
  38004. !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
  38005. !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  38006. },
  38007. /**
  38008. * @return {boolean}
  38009. */
  38010. get viewable() {
  38011. if (this.flags === 0) {
  38012. return true;
  38013. }
  38014. return this._isViewable(this.flags);
  38015. },
  38016. /**
  38017. * @return {boolean}
  38018. */
  38019. get printable() {
  38020. if (this.flags === 0) {
  38021. return false;
  38022. }
  38023. return this._isPrintable(this.flags);
  38024. },
  38025. /**
  38026. * Set the flags.
  38027. *
  38028. * @public
  38029. * @memberof Annotation
  38030. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  38031. * characteristics
  38032. * @see {@link shared/util.js}
  38033. */
  38034. setFlags: function Annotation_setFlags(flags) {
  38035. this.flags = (isInt(flags) && flags > 0) ? flags : 0;
  38036. },
  38037. /**
  38038. * Check if a provided flag is set.
  38039. *
  38040. * @public
  38041. * @memberof Annotation
  38042. * @param {number} flag - Hexadecimal representation for an annotation
  38043. * characteristic
  38044. * @return {boolean}
  38045. * @see {@link shared/util.js}
  38046. */
  38047. hasFlag: function Annotation_hasFlag(flag) {
  38048. return this._hasFlag(this.flags, flag);
  38049. },
  38050. /**
  38051. * Set the rectangle.
  38052. *
  38053. * @public
  38054. * @memberof Annotation
  38055. * @param {Array} rectangle - The rectangle array with exactly four entries
  38056. */
  38057. setRectangle: function Annotation_setRectangle(rectangle) {
  38058. if (isArray(rectangle) && rectangle.length === 4) {
  38059. this.rectangle = Util.normalizeRect(rectangle);
  38060. } else {
  38061. this.rectangle = [0, 0, 0, 0];
  38062. }
  38063. },
  38064. /**
  38065. * Set the color and take care of color space conversion.
  38066. *
  38067. * @public
  38068. * @memberof Annotation
  38069. * @param {Array} color - The color array containing either 0
  38070. * (transparent), 1 (grayscale), 3 (RGB) or
  38071. * 4 (CMYK) elements
  38072. */
  38073. setColor: function Annotation_setColor(color) {
  38074. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  38075. if (!isArray(color)) {
  38076. this.color = rgbColor;
  38077. return;
  38078. }
  38079. switch (color.length) {
  38080. case 0: // Transparent, which we indicate with a null value
  38081. this.color = null;
  38082. break;
  38083. case 1: // Convert grayscale to RGB
  38084. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  38085. this.color = rgbColor;
  38086. break;
  38087. case 3: // Convert RGB percentages to RGB
  38088. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  38089. this.color = rgbColor;
  38090. break;
  38091. case 4: // Convert CMYK to RGB
  38092. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  38093. this.color = rgbColor;
  38094. break;
  38095. default:
  38096. this.color = rgbColor;
  38097. break;
  38098. }
  38099. },
  38100. /**
  38101. * Set the border style (as AnnotationBorderStyle object).
  38102. *
  38103. * @public
  38104. * @memberof Annotation
  38105. * @param {Dict} borderStyle - The border style dictionary
  38106. */
  38107. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  38108. this.borderStyle = new AnnotationBorderStyle();
  38109. if (!isDict(borderStyle)) {
  38110. return;
  38111. }
  38112. if (borderStyle.has('BS')) {
  38113. var dict = borderStyle.get('BS');
  38114. var dictType = dict.get('Type');
  38115. if (!dictType || isName(dictType, 'Border')) {
  38116. this.borderStyle.setWidth(dict.get('W'));
  38117. this.borderStyle.setStyle(dict.get('S'));
  38118. this.borderStyle.setDashArray(dict.getArray('D'));
  38119. }
  38120. } else if (borderStyle.has('Border')) {
  38121. var array = borderStyle.getArray('Border');
  38122. if (isArray(array) && array.length >= 3) {
  38123. this.borderStyle.setHorizontalCornerRadius(array[0]);
  38124. this.borderStyle.setVerticalCornerRadius(array[1]);
  38125. this.borderStyle.setWidth(array[2]);
  38126. if (array.length === 4) { // Dash array available
  38127. this.borderStyle.setDashArray(array[3]);
  38128. }
  38129. }
  38130. } else {
  38131. // There are no border entries in the dictionary. According to the
  38132. // specification, we should draw a solid border of width 1 in that
  38133. // case, but Adobe Reader did not implement that part of the
  38134. // specification and instead draws no border at all, so we do the same.
  38135. // See also https://github.com/mozilla/pdf.js/issues/6179.
  38136. this.borderStyle.setWidth(0);
  38137. }
  38138. },
  38139. /**
  38140. * Prepare the annotation for working with a popup in the display layer.
  38141. *
  38142. * @private
  38143. * @memberof Annotation
  38144. * @param {Dict} dict - The annotation's data dictionary
  38145. */
  38146. _preparePopup: function Annotation_preparePopup(dict) {
  38147. if (!dict.has('C')) {
  38148. // Fall back to the default background color.
  38149. this.data.color = null;
  38150. }
  38151. this.data.hasPopup = dict.has('Popup');
  38152. this.data.title = stringToPDFString(dict.get('T') || '');
  38153. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  38154. },
  38155. loadResources: function Annotation_loadResources(keys) {
  38156. return new Promise(function (resolve, reject) {
  38157. this.appearance.dict.getAsync('Resources').then(function (resources) {
  38158. if (!resources) {
  38159. resolve();
  38160. return;
  38161. }
  38162. var objectLoader = new ObjectLoader(resources.map,
  38163. keys,
  38164. resources.xref);
  38165. objectLoader.load().then(function() {
  38166. resolve(resources);
  38167. }, reject);
  38168. }, reject);
  38169. }.bind(this));
  38170. },
  38171. getOperatorList: function Annotation_getOperatorList(evaluator, task,
  38172. renderForms) {
  38173. if (!this.appearance) {
  38174. return Promise.resolve(new OperatorList());
  38175. }
  38176. var data = this.data;
  38177. var appearanceDict = this.appearance.dict;
  38178. var resourcesPromise = this.loadResources([
  38179. 'ExtGState',
  38180. 'ColorSpace',
  38181. 'Pattern',
  38182. 'Shading',
  38183. 'XObject',
  38184. 'Font'
  38185. // ProcSet
  38186. // Properties
  38187. ]);
  38188. var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
  38189. var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0 ,0];
  38190. var transform = getTransformMatrix(data.rect, bbox, matrix);
  38191. var self = this;
  38192. return resourcesPromise.then(function(resources) {
  38193. var opList = new OperatorList();
  38194. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  38195. return evaluator.getOperatorList(self.appearance, task,
  38196. resources, opList).
  38197. then(function () {
  38198. opList.addOp(OPS.endAnnotation, []);
  38199. self.appearance.reset();
  38200. return opList;
  38201. });
  38202. });
  38203. }
  38204. };
  38205. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  38206. annotations, opList, partialEvaluator, task, intent, renderForms) {
  38207. var annotationPromises = [];
  38208. for (var i = 0, n = annotations.length; i < n; ++i) {
  38209. if ((intent === 'display' && annotations[i].viewable) ||
  38210. (intent === 'print' && annotations[i].printable)) {
  38211. annotationPromises.push(
  38212. annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  38213. }
  38214. }
  38215. return Promise.all(annotationPromises).then(function(operatorLists) {
  38216. opList.addOp(OPS.beginAnnotations, []);
  38217. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  38218. opList.addOpList(operatorLists[i]);
  38219. }
  38220. opList.addOp(OPS.endAnnotations, []);
  38221. });
  38222. };
  38223. return Annotation;
  38224. })();
  38225. /**
  38226. * Contains all data regarding an annotation's border style.
  38227. *
  38228. * @class
  38229. */
  38230. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  38231. /**
  38232. * @constructor
  38233. * @private
  38234. */
  38235. function AnnotationBorderStyle() {
  38236. this.width = 1;
  38237. this.style = AnnotationBorderStyleType.SOLID;
  38238. this.dashArray = [3];
  38239. this.horizontalCornerRadius = 0;
  38240. this.verticalCornerRadius = 0;
  38241. }
  38242. AnnotationBorderStyle.prototype = {
  38243. /**
  38244. * Set the width.
  38245. *
  38246. * @public
  38247. * @memberof AnnotationBorderStyle
  38248. * @param {integer} width - The width
  38249. */
  38250. setWidth: function AnnotationBorderStyle_setWidth(width) {
  38251. if (width === (width | 0)) {
  38252. this.width = width;
  38253. }
  38254. },
  38255. /**
  38256. * Set the style.
  38257. *
  38258. * @public
  38259. * @memberof AnnotationBorderStyle
  38260. * @param {Object} style - The style object
  38261. * @see {@link shared/util.js}
  38262. */
  38263. setStyle: function AnnotationBorderStyle_setStyle(style) {
  38264. if (!style) {
  38265. return;
  38266. }
  38267. switch (style.name) {
  38268. case 'S':
  38269. this.style = AnnotationBorderStyleType.SOLID;
  38270. break;
  38271. case 'D':
  38272. this.style = AnnotationBorderStyleType.DASHED;
  38273. break;
  38274. case 'B':
  38275. this.style = AnnotationBorderStyleType.BEVELED;
  38276. break;
  38277. case 'I':
  38278. this.style = AnnotationBorderStyleType.INSET;
  38279. break;
  38280. case 'U':
  38281. this.style = AnnotationBorderStyleType.UNDERLINE;
  38282. break;
  38283. default:
  38284. break;
  38285. }
  38286. },
  38287. /**
  38288. * Set the dash array.
  38289. *
  38290. * @public
  38291. * @memberof AnnotationBorderStyle
  38292. * @param {Array} dashArray - The dash array with at least one element
  38293. */
  38294. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  38295. // We validate the dash array, but we do not use it because CSS does not
  38296. // allow us to change spacing of dashes. For more information, visit
  38297. // http://www.w3.org/TR/css3-background/#the-border-style.
  38298. if (isArray(dashArray) && dashArray.length > 0) {
  38299. // According to the PDF specification: the elements in a dashArray
  38300. // shall be numbers that are nonnegative and not all equal to zero.
  38301. var isValid = true;
  38302. var allZeros = true;
  38303. for (var i = 0, len = dashArray.length; i < len; i++) {
  38304. var element = dashArray[i];
  38305. var validNumber = (+element >= 0);
  38306. if (!validNumber) {
  38307. isValid = false;
  38308. break;
  38309. } else if (element > 0) {
  38310. allZeros = false;
  38311. }
  38312. }
  38313. if (isValid && !allZeros) {
  38314. this.dashArray = dashArray;
  38315. } else {
  38316. this.width = 0; // Adobe behavior when the array is invalid.
  38317. }
  38318. } else if (dashArray) {
  38319. this.width = 0; // Adobe behavior when the array is invalid.
  38320. }
  38321. },
  38322. /**
  38323. * Set the horizontal corner radius (from a Border dictionary).
  38324. *
  38325. * @public
  38326. * @memberof AnnotationBorderStyle
  38327. * @param {integer} radius - The horizontal corner radius
  38328. */
  38329. setHorizontalCornerRadius:
  38330. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  38331. if (radius === (radius | 0)) {
  38332. this.horizontalCornerRadius = radius;
  38333. }
  38334. },
  38335. /**
  38336. * Set the vertical corner radius (from a Border dictionary).
  38337. *
  38338. * @public
  38339. * @memberof AnnotationBorderStyle
  38340. * @param {integer} radius - The vertical corner radius
  38341. */
  38342. setVerticalCornerRadius:
  38343. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  38344. if (radius === (radius | 0)) {
  38345. this.verticalCornerRadius = radius;
  38346. }
  38347. }
  38348. };
  38349. return AnnotationBorderStyle;
  38350. })();
  38351. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  38352. function WidgetAnnotation(params) {
  38353. Annotation.call(this, params);
  38354. var dict = params.dict;
  38355. var data = this.data;
  38356. data.annotationType = AnnotationType.WIDGET;
  38357. data.fieldValue = Util.getInheritableProperty(dict, 'V',
  38358. /* getArray = */ true);
  38359. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  38360. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  38361. var fieldType = Util.getInheritableProperty(dict, 'FT');
  38362. data.fieldType = isName(fieldType) ? fieldType.name : null;
  38363. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  38364. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  38365. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  38366. data.fieldFlags = 0;
  38367. }
  38368. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  38369. // Hide signatures because we cannot validate them.
  38370. if (data.fieldType === 'Sig') {
  38371. this.setFlags(AnnotationFlag.HIDDEN);
  38372. }
  38373. // Building the full field name by collecting the field and
  38374. // its ancestors 'T' data and joining them using '.'.
  38375. var fieldName = [];
  38376. var namedItem = dict;
  38377. var ref = params.ref;
  38378. while (namedItem) {
  38379. var parent = namedItem.get('Parent');
  38380. var parentRef = namedItem.getRaw('Parent');
  38381. var name = namedItem.get('T');
  38382. if (name) {
  38383. fieldName.unshift(stringToPDFString(name));
  38384. } else if (parent && ref) {
  38385. // The field name is absent, that means more than one field
  38386. // with the same name may exist. Replacing the empty name
  38387. // with the '`' plus index in the parent's 'Kids' array.
  38388. // This is not in the PDF spec but necessary to id the
  38389. // the input controls.
  38390. var kids = parent.get('Kids');
  38391. var j, jj;
  38392. for (j = 0, jj = kids.length; j < jj; j++) {
  38393. var kidRef = kids[j];
  38394. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  38395. break;
  38396. }
  38397. }
  38398. fieldName.unshift('`' + j);
  38399. }
  38400. namedItem = parent;
  38401. ref = parentRef;
  38402. }
  38403. data.fullName = fieldName.join('.');
  38404. }
  38405. Util.inherit(WidgetAnnotation, Annotation, {
  38406. /**
  38407. * Check if a provided field flag is set.
  38408. *
  38409. * @public
  38410. * @memberof WidgetAnnotation
  38411. * @param {number} flag - Hexadecimal representation for an annotation
  38412. * field characteristic
  38413. * @return {boolean}
  38414. * @see {@link shared/util.js}
  38415. */
  38416. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  38417. return !!(this.data.fieldFlags & flag);
  38418. },
  38419. });
  38420. return WidgetAnnotation;
  38421. })();
  38422. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  38423. function TextWidgetAnnotation(params) {
  38424. WidgetAnnotation.call(this, params);
  38425. // The field value is always a string.
  38426. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  38427. // Determine the alignment of text in the field.
  38428. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  38429. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  38430. alignment = null;
  38431. }
  38432. this.data.textAlignment = alignment;
  38433. // Determine the maximum length of text in the field.
  38434. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  38435. if (!isInt(maximumLength) || maximumLength < 0) {
  38436. maximumLength = null;
  38437. }
  38438. this.data.maxLen = maximumLength;
  38439. // Process field flags for the display layer.
  38440. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  38441. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
  38442. !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) &&
  38443. !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) &&
  38444. !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) &&
  38445. this.data.maxLen !== null;
  38446. }
  38447. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  38448. getOperatorList:
  38449. function TextWidgetAnnotation_getOperatorList(evaluator, task,
  38450. renderForms) {
  38451. var operatorList = new OperatorList();
  38452. // Do not render form elements on the canvas when interactive forms are
  38453. // enabled. The display layer is responsible for rendering them instead.
  38454. if (renderForms) {
  38455. return Promise.resolve(operatorList);
  38456. }
  38457. if (this.appearance) {
  38458. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  38459. renderForms);
  38460. }
  38461. // Even if there is an appearance stream, ignore it. This is the
  38462. // behaviour used by Adobe Reader.
  38463. if (!this.data.defaultAppearance) {
  38464. return Promise.resolve(operatorList);
  38465. }
  38466. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  38467. return evaluator.getOperatorList(stream, task, this.fieldResources,
  38468. operatorList).
  38469. then(function () {
  38470. return operatorList;
  38471. });
  38472. }
  38473. });
  38474. return TextWidgetAnnotation;
  38475. })();
  38476. var ChoiceWidgetAnnotation = (function ChoiceWidgetAnnotationClosure() {
  38477. function ChoiceWidgetAnnotation(params) {
  38478. WidgetAnnotation.call(this, params);
  38479. // Determine the options. The options array may consist of strings or
  38480. // arrays. If the array consists of arrays, then the first element of
  38481. // each array is the export value and the second element of each array is
  38482. // the display value. If the array consists of strings, then these
  38483. // represent both the export and display value. In this case, we convert
  38484. // it to an array of arrays as well for convenience in the display layer.
  38485. this.data.options = [];
  38486. var options = params.dict.getArray('Opt');
  38487. if (isArray(options)) {
  38488. for (var i = 0, ii = options.length; i < ii; i++) {
  38489. var option = options[i];
  38490. this.data.options[i] = {
  38491. exportValue: isArray(option) ? option[0] : option,
  38492. displayValue: isArray(option) ? option[1] : option,
  38493. };
  38494. }
  38495. }
  38496. // Determine the field value. In this case, it may be a string or an
  38497. // array of strings. For convenience in the display layer, convert the
  38498. // string to an array of one string as well.
  38499. if (!isArray(this.data.fieldValue)) {
  38500. this.data.fieldValue = [this.data.fieldValue];
  38501. }
  38502. // Process field flags for the display layer.
  38503. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  38504. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  38505. }
  38506. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  38507. getOperatorList:
  38508. function ChoiceWidgetAnnotation_getOperatorList(evaluator, task,
  38509. renderForms) {
  38510. var operatorList = new OperatorList();
  38511. // Do not render form elements on the canvas when interactive forms are
  38512. // enabled. The display layer is responsible for rendering them instead.
  38513. if (renderForms) {
  38514. return Promise.resolve(operatorList);
  38515. }
  38516. return Annotation.prototype.getOperatorList.call(this, evaluator, task,
  38517. renderForms);
  38518. }
  38519. });
  38520. return ChoiceWidgetAnnotation;
  38521. })();
  38522. var TextAnnotation = (function TextAnnotationClosure() {
  38523. var DEFAULT_ICON_SIZE = 22; // px
  38524. function TextAnnotation(parameters) {
  38525. Annotation.call(this, parameters);
  38526. this.data.annotationType = AnnotationType.TEXT;
  38527. if (this.data.hasAppearance) {
  38528. this.data.name = 'NoIcon';
  38529. } else {
  38530. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  38531. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  38532. this.data.name = parameters.dict.has('Name') ?
  38533. parameters.dict.get('Name').name : 'Note';
  38534. }
  38535. this._preparePopup(parameters.dict);
  38536. }
  38537. Util.inherit(TextAnnotation, Annotation, {});
  38538. return TextAnnotation;
  38539. })();
  38540. var LinkAnnotation = (function LinkAnnotationClosure() {
  38541. function LinkAnnotation(params) {
  38542. Annotation.call(this, params);
  38543. var dict = params.dict;
  38544. var data = this.data;
  38545. data.annotationType = AnnotationType.LINK;
  38546. var action = dict.get('A'), url, dest;
  38547. if (action && isDict(action)) {
  38548. var linkType = action.get('S').name;
  38549. switch (linkType) {
  38550. case 'URI':
  38551. url = action.get('URI');
  38552. if (isName(url)) {
  38553. // Some bad PDFs do not put parentheses around relative URLs.
  38554. url = '/' + url.name;
  38555. } else if (url) {
  38556. url = addDefaultProtocolToUrl(url);
  38557. }
  38558. // TODO: pdf spec mentions urls can be relative to a Base
  38559. // entry in the dictionary.
  38560. break;
  38561. case 'GoTo':
  38562. dest = action.get('D');
  38563. break;
  38564. case 'GoToR':
  38565. var urlDict = action.get('F');
  38566. if (isDict(urlDict)) {
  38567. // We assume that we found a FileSpec dictionary
  38568. // and fetch the URL without checking any further.
  38569. url = urlDict.get('F') || null;
  38570. } else if (isString(urlDict)) {
  38571. url = urlDict;
  38572. }
  38573. // NOTE: the destination is relative to the *remote* document.
  38574. var remoteDest = action.get('D');
  38575. if (remoteDest) {
  38576. if (isName(remoteDest)) {
  38577. remoteDest = remoteDest.name;
  38578. }
  38579. if (isString(url)) {
  38580. var baseUrl = url.split('#')[0];
  38581. if (isString(remoteDest)) {
  38582. // In practice, a named destination may contain only a number.
  38583. // If that happens, use the '#nameddest=' form to avoid the link
  38584. // redirecting to a page, instead of the correct destination.
  38585. url = baseUrl + '#' +
  38586. (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  38587. } else if (isArray(remoteDest)) {
  38588. url = baseUrl + '#' + JSON.stringify(remoteDest);
  38589. }
  38590. }
  38591. }
  38592. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  38593. var newWindow = action.get('NewWindow');
  38594. if (isBool(newWindow)) {
  38595. data.newWindow = newWindow;
  38596. }
  38597. break;
  38598. case 'Named':
  38599. data.action = action.get('N').name;
  38600. break;
  38601. default:
  38602. warn('unrecognized link type: ' + linkType);
  38603. }
  38604. } else if (dict.has('Dest')) { // Simple destination link.
  38605. dest = dict.get('Dest');
  38606. }
  38607. if (url) {
  38608. if (isValidUrl(url, /* allowRelative = */ false)) {
  38609. data.url = tryConvertUrlEncoding(url);
  38610. }
  38611. }
  38612. if (dest) {
  38613. data.dest = isName(dest) ? dest.name : dest;
  38614. }
  38615. }
  38616. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38617. function addDefaultProtocolToUrl(url) {
  38618. if (isString(url) && url.indexOf('www.') === 0) {
  38619. return ('http://' + url);
  38620. }
  38621. return url;
  38622. }
  38623. function tryConvertUrlEncoding(url) {
  38624. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  38625. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  38626. try {
  38627. return stringToUTF8String(url);
  38628. } catch (e) {
  38629. return url;
  38630. }
  38631. }
  38632. Util.inherit(LinkAnnotation, Annotation, {});
  38633. return LinkAnnotation;
  38634. })();
  38635. var PopupAnnotation = (function PopupAnnotationClosure() {
  38636. function PopupAnnotation(parameters) {
  38637. Annotation.call(this, parameters);
  38638. this.data.annotationType = AnnotationType.POPUP;
  38639. var dict = parameters.dict;
  38640. var parentItem = dict.get('Parent');
  38641. if (!parentItem) {
  38642. warn('Popup annotation has a missing or invalid parent annotation.');
  38643. return;
  38644. }
  38645. this.data.parentId = dict.getRaw('Parent').toString();
  38646. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38647. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38648. if (!parentItem.has('C')) {
  38649. // Fall back to the default background color.
  38650. this.data.color = null;
  38651. } else {
  38652. this.setColor(parentItem.getArray('C'));
  38653. this.data.color = this.color;
  38654. }
  38655. // If the Popup annotation is not viewable, but the parent annotation is,
  38656. // that is most likely a bug. Fallback to inherit the flags from the parent
  38657. // annotation (this is consistent with the behaviour in Adobe Reader).
  38658. if (!this.viewable) {
  38659. var parentFlags = parentItem.get('F');
  38660. if (this._isViewable(parentFlags)) {
  38661. this.setFlags(parentFlags);
  38662. }
  38663. }
  38664. }
  38665. Util.inherit(PopupAnnotation, Annotation, {});
  38666. return PopupAnnotation;
  38667. })();
  38668. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38669. function HighlightAnnotation(parameters) {
  38670. Annotation.call(this, parameters);
  38671. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38672. this._preparePopup(parameters.dict);
  38673. // PDF viewers completely ignore any border styles.
  38674. this.data.borderStyle.setWidth(0);
  38675. }
  38676. Util.inherit(HighlightAnnotation, Annotation, {});
  38677. return HighlightAnnotation;
  38678. })();
  38679. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38680. function UnderlineAnnotation(parameters) {
  38681. Annotation.call(this, parameters);
  38682. this.data.annotationType = AnnotationType.UNDERLINE;
  38683. this._preparePopup(parameters.dict);
  38684. // PDF viewers completely ignore any border styles.
  38685. this.data.borderStyle.setWidth(0);
  38686. }
  38687. Util.inherit(UnderlineAnnotation, Annotation, {});
  38688. return UnderlineAnnotation;
  38689. })();
  38690. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38691. function SquigglyAnnotation(parameters) {
  38692. Annotation.call(this, parameters);
  38693. this.data.annotationType = AnnotationType.SQUIGGLY;
  38694. this._preparePopup(parameters.dict);
  38695. // PDF viewers completely ignore any border styles.
  38696. this.data.borderStyle.setWidth(0);
  38697. }
  38698. Util.inherit(SquigglyAnnotation, Annotation, {});
  38699. return SquigglyAnnotation;
  38700. })();
  38701. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38702. function StrikeOutAnnotation(parameters) {
  38703. Annotation.call(this, parameters);
  38704. this.data.annotationType = AnnotationType.STRIKEOUT;
  38705. this._preparePopup(parameters.dict);
  38706. // PDF viewers completely ignore any border styles.
  38707. this.data.borderStyle.setWidth(0);
  38708. }
  38709. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38710. return StrikeOutAnnotation;
  38711. })();
  38712. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  38713. function FileAttachmentAnnotation(parameters) {
  38714. Annotation.call(this, parameters);
  38715. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  38716. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  38717. this.data.file = file.serializable;
  38718. this._preparePopup(parameters.dict);
  38719. }
  38720. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  38721. return FileAttachmentAnnotation;
  38722. })();
  38723. exports.Annotation = Annotation;
  38724. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38725. exports.AnnotationFactory = AnnotationFactory;
  38726. }));
  38727. (function (root, factory) {
  38728. {
  38729. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38730. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38731. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38732. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38733. }
  38734. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38735. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38736. var MissingDataException = sharedUtil.MissingDataException;
  38737. var Util = sharedUtil.Util;
  38738. var assert = sharedUtil.assert;
  38739. var error = sharedUtil.error;
  38740. var info = sharedUtil.info;
  38741. var isArray = sharedUtil.isArray;
  38742. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38743. var isString = sharedUtil.isString;
  38744. var shadow = sharedUtil.shadow;
  38745. var stringToBytes = sharedUtil.stringToBytes;
  38746. var stringToPDFString = sharedUtil.stringToPDFString;
  38747. var warn = sharedUtil.warn;
  38748. var isSpace = sharedUtil.isSpace;
  38749. var Dict = corePrimitives.Dict;
  38750. var isDict = corePrimitives.isDict;
  38751. var isName = corePrimitives.isName;
  38752. var isStream = corePrimitives.isStream;
  38753. var NullStream = coreStream.NullStream;
  38754. var Stream = coreStream.Stream;
  38755. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38756. var Catalog = coreObj.Catalog;
  38757. var ObjectLoader = coreObj.ObjectLoader;
  38758. var XRef = coreObj.XRef;
  38759. var Linearization = coreParser.Linearization;
  38760. var calculateMD5 = coreCrypto.calculateMD5;
  38761. var OperatorList = coreEvaluator.OperatorList;
  38762. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38763. var Annotation = coreAnnotation.Annotation;
  38764. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38765. var Page = (function PageClosure() {
  38766. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38767. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38768. this.pdfManager = pdfManager;
  38769. this.pageIndex = pageIndex;
  38770. this.pageDict = pageDict;
  38771. this.xref = xref;
  38772. this.ref = ref;
  38773. this.fontCache = fontCache;
  38774. this.uniquePrefix = 'p' + this.pageIndex + '_';
  38775. this.idCounters = {
  38776. obj: 0
  38777. };
  38778. this.evaluatorOptions = pdfManager.evaluatorOptions;
  38779. this.resourcesPromise = null;
  38780. }
  38781. Page.prototype = {
  38782. getPageProp: function Page_getPageProp(key) {
  38783. return this.pageDict.get(key);
  38784. },
  38785. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38786. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38787. var MAX_LOOP_COUNT = 100;
  38788. // Always walk up the entire parent chain, to be able to find
  38789. // e.g. \Resources placed on multiple levels of the tree.
  38790. while (dict) {
  38791. var value = dict.get(key);
  38792. if (value) {
  38793. if (!valueArray) {
  38794. valueArray = [];
  38795. }
  38796. valueArray.push(value);
  38797. }
  38798. if (++loopCount > MAX_LOOP_COUNT) {
  38799. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38800. break;
  38801. }
  38802. dict = dict.get('Parent');
  38803. }
  38804. if (!valueArray) {
  38805. return Dict.empty;
  38806. }
  38807. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38808. loopCount > MAX_LOOP_COUNT) {
  38809. return valueArray[0];
  38810. }
  38811. return Dict.merge(this.xref, valueArray);
  38812. },
  38813. get content() {
  38814. return this.getPageProp('Contents');
  38815. },
  38816. get resources() {
  38817. // For robustness: The spec states that a \Resources entry has to be
  38818. // present, but can be empty. Some document omit it still, in this case
  38819. // we return an empty dictionary.
  38820. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38821. },
  38822. get mediaBox() {
  38823. var obj = this.getInheritedPageProp('MediaBox');
  38824. // Reset invalid media box to letter size.
  38825. if (!isArray(obj) || obj.length !== 4) {
  38826. obj = LETTER_SIZE_MEDIABOX;
  38827. }
  38828. return shadow(this, 'mediaBox', obj);
  38829. },
  38830. get view() {
  38831. var mediaBox = this.mediaBox;
  38832. var cropBox = this.getInheritedPageProp('CropBox');
  38833. if (!isArray(cropBox) || cropBox.length !== 4) {
  38834. return shadow(this, 'view', mediaBox);
  38835. }
  38836. // From the spec, 6th ed., p.963:
  38837. // "The crop, bleed, trim, and art boxes should not ordinarily
  38838. // extend beyond the boundaries of the media box. If they do, they are
  38839. // effectively reduced to their intersection with the media box."
  38840. cropBox = Util.intersect(cropBox, mediaBox);
  38841. if (!cropBox) {
  38842. return shadow(this, 'view', mediaBox);
  38843. }
  38844. return shadow(this, 'view', cropBox);
  38845. },
  38846. get rotate() {
  38847. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38848. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38849. if (rotate % 90 !== 0) {
  38850. rotate = 0;
  38851. } else if (rotate >= 360) {
  38852. rotate = rotate % 360;
  38853. } else if (rotate < 0) {
  38854. // The spec doesn't cover negatives, assume its counterclockwise
  38855. // rotation. The following is the other implementation of modulo.
  38856. rotate = ((rotate % 360) + 360) % 360;
  38857. }
  38858. return shadow(this, 'rotate', rotate);
  38859. },
  38860. getContentStream: function Page_getContentStream() {
  38861. var content = this.content;
  38862. var stream;
  38863. if (isArray(content)) {
  38864. // fetching items
  38865. var xref = this.xref;
  38866. var i, n = content.length;
  38867. var streams = [];
  38868. for (i = 0; i < n; ++i) {
  38869. streams.push(xref.fetchIfRef(content[i]));
  38870. }
  38871. stream = new StreamsSequenceStream(streams);
  38872. } else if (isStream(content)) {
  38873. stream = content;
  38874. } else {
  38875. // replacing non-existent page content with empty one
  38876. stream = new NullStream();
  38877. }
  38878. return stream;
  38879. },
  38880. loadResources: function Page_loadResources(keys) {
  38881. if (!this.resourcesPromise) {
  38882. // TODO: add async getInheritedPageProp and remove this.
  38883. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38884. }
  38885. return this.resourcesPromise.then(function resourceSuccess() {
  38886. var objectLoader = new ObjectLoader(this.resources.map,
  38887. keys,
  38888. this.xref);
  38889. return objectLoader.load();
  38890. }.bind(this));
  38891. },
  38892. getOperatorList: function Page_getOperatorList(handler, task, intent,
  38893. renderInteractiveForms) {
  38894. var self = this;
  38895. var pdfManager = this.pdfManager;
  38896. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38897. []);
  38898. var resourcesPromise = this.loadResources([
  38899. 'ExtGState',
  38900. 'ColorSpace',
  38901. 'Pattern',
  38902. 'Shading',
  38903. 'XObject',
  38904. 'Font'
  38905. // ProcSet
  38906. // Properties
  38907. ]);
  38908. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38909. handler, this.pageIndex,
  38910. this.uniquePrefix,
  38911. this.idCounters,
  38912. this.fontCache,
  38913. this.evaluatorOptions);
  38914. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38915. var pageListPromise = dataPromises.then(function(data) {
  38916. var contentStream = data[0];
  38917. var opList = new OperatorList(intent, handler, self.pageIndex);
  38918. handler.send('StartRenderPage', {
  38919. transparency: partialEvaluator.hasBlendModes(self.resources),
  38920. pageIndex: self.pageIndex,
  38921. intent: intent
  38922. });
  38923. return partialEvaluator.getOperatorList(contentStream, task,
  38924. self.resources, opList).then(function () {
  38925. return opList;
  38926. });
  38927. });
  38928. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38929. return Promise.all([pageListPromise, annotationsPromise]).then(
  38930. function(datas) {
  38931. var pageOpList = datas[0];
  38932. var annotations = datas[1];
  38933. if (annotations.length === 0) {
  38934. pageOpList.flush(true);
  38935. return pageOpList;
  38936. }
  38937. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38938. annotations, pageOpList, partialEvaluator, task, intent,
  38939. renderInteractiveForms);
  38940. return annotationsReadyPromise.then(function () {
  38941. pageOpList.flush(true);
  38942. return pageOpList;
  38943. });
  38944. });
  38945. },
  38946. extractTextContent: function Page_extractTextContent(task,
  38947. normalizeWhitespace,
  38948. combineTextItems) {
  38949. var handler = {
  38950. on: function nullHandlerOn() {},
  38951. send: function nullHandlerSend() {}
  38952. };
  38953. var self = this;
  38954. var pdfManager = this.pdfManager;
  38955. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38956. []);
  38957. var resourcesPromise = this.loadResources([
  38958. 'ExtGState',
  38959. 'XObject',
  38960. 'Font'
  38961. ]);
  38962. var dataPromises = Promise.all([contentStreamPromise,
  38963. resourcesPromise]);
  38964. return dataPromises.then(function(data) {
  38965. var contentStream = data[0];
  38966. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38967. handler, self.pageIndex,
  38968. self.uniquePrefix,
  38969. self.idCounters,
  38970. self.fontCache,
  38971. self.evaluatorOptions);
  38972. return partialEvaluator.getTextContent(contentStream,
  38973. task,
  38974. self.resources,
  38975. /* stateManager = */ null,
  38976. normalizeWhitespace,
  38977. combineTextItems);
  38978. });
  38979. },
  38980. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38981. var annotations = this.annotations;
  38982. var annotationsData = [];
  38983. for (var i = 0, n = annotations.length; i < n; ++i) {
  38984. if (intent) {
  38985. if (!(intent === 'display' && annotations[i].viewable) &&
  38986. !(intent === 'print' && annotations[i].printable)) {
  38987. continue;
  38988. }
  38989. }
  38990. annotationsData.push(annotations[i].data);
  38991. }
  38992. return annotationsData;
  38993. },
  38994. get annotations() {
  38995. var annotations = [];
  38996. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38997. var annotationFactory = new AnnotationFactory();
  38998. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38999. var annotationRef = annotationRefs[i];
  39000. var annotation = annotationFactory.create(this.xref, annotationRef,
  39001. this.uniquePrefix,
  39002. this.idCounters);
  39003. if (annotation) {
  39004. annotations.push(annotation);
  39005. }
  39006. }
  39007. return shadow(this, 'annotations', annotations);
  39008. }
  39009. };
  39010. return Page;
  39011. })();
  39012. /**
  39013. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  39014. * `PDFDoc`, this one doesn't have any job management code.
  39015. * Right now there exists one PDFDocument on the main thread + one object
  39016. * for each worker. If there is no worker support enabled, there are two
  39017. * `PDFDocument` objects on the main thread created.
  39018. */
  39019. var PDFDocument = (function PDFDocumentClosure() {
  39020. var FINGERPRINT_FIRST_BYTES = 1024;
  39021. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  39022. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  39023. function PDFDocument(pdfManager, arg, password) {
  39024. if (isStream(arg)) {
  39025. init.call(this, pdfManager, arg, password);
  39026. } else if (isArrayBuffer(arg)) {
  39027. init.call(this, pdfManager, new Stream(arg), password);
  39028. } else {
  39029. error('PDFDocument: Unknown argument type');
  39030. }
  39031. }
  39032. function init(pdfManager, stream, password) {
  39033. assert(stream.length > 0, 'stream must have data');
  39034. this.pdfManager = pdfManager;
  39035. this.stream = stream;
  39036. var xref = new XRef(this.stream, password, pdfManager);
  39037. this.xref = xref;
  39038. }
  39039. function find(stream, needle, limit, backwards) {
  39040. var pos = stream.pos;
  39041. var end = stream.end;
  39042. var strBuf = [];
  39043. if (pos + limit > end) {
  39044. limit = end - pos;
  39045. }
  39046. for (var n = 0; n < limit; ++n) {
  39047. strBuf.push(String.fromCharCode(stream.getByte()));
  39048. }
  39049. var str = strBuf.join('');
  39050. stream.pos = pos;
  39051. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  39052. if (index === -1) {
  39053. return false; /* not found */
  39054. }
  39055. stream.pos += index;
  39056. return true; /* found */
  39057. }
  39058. var DocumentInfoValidators = {
  39059. get entries() {
  39060. // Lazily build this since all the validation functions below are not
  39061. // defined until after this file loads.
  39062. return shadow(this, 'entries', {
  39063. Title: isString,
  39064. Author: isString,
  39065. Subject: isString,
  39066. Keywords: isString,
  39067. Creator: isString,
  39068. Producer: isString,
  39069. CreationDate: isString,
  39070. ModDate: isString,
  39071. Trapped: isName
  39072. });
  39073. }
  39074. };
  39075. PDFDocument.prototype = {
  39076. parse: function PDFDocument_parse(recoveryMode) {
  39077. this.setup(recoveryMode);
  39078. var version = this.catalog.catDict.get('Version');
  39079. if (isName(version)) {
  39080. this.pdfFormatVersion = version.name;
  39081. }
  39082. try {
  39083. // checking if AcroForm is present
  39084. this.acroForm = this.catalog.catDict.get('AcroForm');
  39085. if (this.acroForm) {
  39086. this.xfa = this.acroForm.get('XFA');
  39087. var fields = this.acroForm.get('Fields');
  39088. if ((!fields || !isArray(fields) || fields.length === 0) &&
  39089. !this.xfa) {
  39090. // no fields and no XFA -- not a form (?)
  39091. this.acroForm = null;
  39092. }
  39093. }
  39094. } catch (ex) {
  39095. info('Something wrong with AcroForm entry');
  39096. this.acroForm = null;
  39097. }
  39098. },
  39099. get linearization() {
  39100. var linearization = null;
  39101. if (this.stream.length) {
  39102. try {
  39103. linearization = Linearization.create(this.stream);
  39104. } catch (err) {
  39105. if (err instanceof MissingDataException) {
  39106. throw err;
  39107. }
  39108. info(err);
  39109. }
  39110. }
  39111. // shadow the prototype getter with a data property
  39112. return shadow(this, 'linearization', linearization);
  39113. },
  39114. get startXRef() {
  39115. var stream = this.stream;
  39116. var startXRef = 0;
  39117. var linearization = this.linearization;
  39118. if (linearization) {
  39119. // Find end of first obj.
  39120. stream.reset();
  39121. if (find(stream, 'endobj', 1024)) {
  39122. startXRef = stream.pos + 6;
  39123. }
  39124. } else {
  39125. // Find startxref by jumping backward from the end of the file.
  39126. var step = 1024;
  39127. var found = false, pos = stream.end;
  39128. while (!found && pos > 0) {
  39129. pos -= step - 'startxref'.length;
  39130. if (pos < 0) {
  39131. pos = 0;
  39132. }
  39133. stream.pos = pos;
  39134. found = find(stream, 'startxref', step, true);
  39135. }
  39136. if (found) {
  39137. stream.skip(9);
  39138. var ch;
  39139. do {
  39140. ch = stream.getByte();
  39141. } while (isSpace(ch));
  39142. var str = '';
  39143. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  39144. str += String.fromCharCode(ch);
  39145. ch = stream.getByte();
  39146. }
  39147. startXRef = parseInt(str, 10);
  39148. if (isNaN(startXRef)) {
  39149. startXRef = 0;
  39150. }
  39151. }
  39152. }
  39153. // shadow the prototype getter with a data property
  39154. return shadow(this, 'startXRef', startXRef);
  39155. },
  39156. get mainXRefEntriesOffset() {
  39157. var mainXRefEntriesOffset = 0;
  39158. var linearization = this.linearization;
  39159. if (linearization) {
  39160. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  39161. }
  39162. // shadow the prototype getter with a data property
  39163. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  39164. },
  39165. // Find the header, remove leading garbage and setup the stream
  39166. // starting from the header.
  39167. checkHeader: function PDFDocument_checkHeader() {
  39168. var stream = this.stream;
  39169. stream.reset();
  39170. if (find(stream, '%PDF-', 1024)) {
  39171. // Found the header, trim off any garbage before it.
  39172. stream.moveStart();
  39173. // Reading file format version
  39174. var MAX_VERSION_LENGTH = 12;
  39175. var version = '', ch;
  39176. while ((ch = stream.getByte()) > 0x20) { // SPACE
  39177. if (version.length >= MAX_VERSION_LENGTH) {
  39178. break;
  39179. }
  39180. version += String.fromCharCode(ch);
  39181. }
  39182. if (!this.pdfFormatVersion) {
  39183. // removing "%PDF-"-prefix
  39184. this.pdfFormatVersion = version.substring(5);
  39185. }
  39186. return;
  39187. }
  39188. // May not be a PDF file, continue anyway.
  39189. },
  39190. parseStartXRef: function PDFDocument_parseStartXRef() {
  39191. var startXRef = this.startXRef;
  39192. this.xref.setStartXRef(startXRef);
  39193. },
  39194. setup: function PDFDocument_setup(recoveryMode) {
  39195. this.xref.parse(recoveryMode);
  39196. var self = this;
  39197. var pageFactory = {
  39198. createPage: function (pageIndex, dict, ref, fontCache) {
  39199. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  39200. fontCache);
  39201. }
  39202. };
  39203. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  39204. },
  39205. get numPages() {
  39206. var linearization = this.linearization;
  39207. var num = linearization ? linearization.numPages : this.catalog.numPages;
  39208. // shadow the prototype getter
  39209. return shadow(this, 'numPages', num);
  39210. },
  39211. get documentInfo() {
  39212. var docInfo = {
  39213. PDFFormatVersion: this.pdfFormatVersion,
  39214. IsAcroFormPresent: !!this.acroForm,
  39215. IsXFAPresent: !!this.xfa
  39216. };
  39217. var infoDict;
  39218. try {
  39219. infoDict = this.xref.trailer.get('Info');
  39220. } catch (err) {
  39221. info('The document information dictionary is invalid.');
  39222. }
  39223. if (infoDict) {
  39224. var validEntries = DocumentInfoValidators.entries;
  39225. // Only fill the document info with valid entries from the spec.
  39226. for (var key in validEntries) {
  39227. if (infoDict.has(key)) {
  39228. var value = infoDict.get(key);
  39229. // Make sure the value conforms to the spec.
  39230. if (validEntries[key](value)) {
  39231. docInfo[key] = (typeof value !== 'string' ?
  39232. value : stringToPDFString(value));
  39233. } else {
  39234. info('Bad value in document info for "' + key + '"');
  39235. }
  39236. }
  39237. }
  39238. }
  39239. return shadow(this, 'documentInfo', docInfo);
  39240. },
  39241. get fingerprint() {
  39242. var xref = this.xref, hash, fileID = '';
  39243. var idArray = xref.trailer.get('ID');
  39244. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  39245. idArray[0] !== EMPTY_FINGERPRINT) {
  39246. hash = stringToBytes(idArray[0]);
  39247. } else {
  39248. if (this.stream.ensureRange) {
  39249. this.stream.ensureRange(0,
  39250. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  39251. }
  39252. hash = calculateMD5(this.stream.bytes.subarray(0,
  39253. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  39254. }
  39255. for (var i = 0, n = hash.length; i < n; i++) {
  39256. var hex = hash[i].toString(16);
  39257. fileID += hex.length === 1 ? '0' + hex : hex;
  39258. }
  39259. return shadow(this, 'fingerprint', fileID);
  39260. },
  39261. getPage: function PDFDocument_getPage(pageIndex) {
  39262. return this.catalog.getPage(pageIndex);
  39263. },
  39264. cleanup: function PDFDocument_cleanup() {
  39265. return this.catalog.cleanup();
  39266. }
  39267. };
  39268. return PDFDocument;
  39269. })();
  39270. exports.Page = Page;
  39271. exports.PDFDocument = PDFDocument;
  39272. }));
  39273. (function (root, factory) {
  39274. {
  39275. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  39276. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  39277. root.pdfjsCoreDocument);
  39278. }
  39279. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  39280. coreDocument) {
  39281. var NotImplementedException = sharedUtil.NotImplementedException;
  39282. var MissingDataException = sharedUtil.MissingDataException;
  39283. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39284. var Util = sharedUtil.Util;
  39285. var Stream = coreStream.Stream;
  39286. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  39287. var PDFDocument = coreDocument.PDFDocument;
  39288. var BasePdfManager = (function BasePdfManagerClosure() {
  39289. function BasePdfManager() {
  39290. throw new Error('Cannot initialize BaseManagerManager');
  39291. }
  39292. BasePdfManager.prototype = {
  39293. get docId() {
  39294. return this._docId;
  39295. },
  39296. onLoadedStream: function BasePdfManager_onLoadedStream() {
  39297. throw new NotImplementedException();
  39298. },
  39299. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  39300. return this.ensure(this.pdfDocument, prop, args);
  39301. },
  39302. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  39303. return this.ensure(this.pdfDocument.xref, prop, args);
  39304. },
  39305. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  39306. return this.ensure(this.pdfDocument.catalog, prop, args);
  39307. },
  39308. getPage: function BasePdfManager_getPage(pageIndex) {
  39309. return this.pdfDocument.getPage(pageIndex);
  39310. },
  39311. cleanup: function BasePdfManager_cleanup() {
  39312. return this.pdfDocument.cleanup();
  39313. },
  39314. ensure: function BasePdfManager_ensure(obj, prop, args) {
  39315. return new NotImplementedException();
  39316. },
  39317. requestRange: function BasePdfManager_requestRange(begin, end) {
  39318. return new NotImplementedException();
  39319. },
  39320. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  39321. return new NotImplementedException();
  39322. },
  39323. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  39324. return new NotImplementedException();
  39325. },
  39326. updatePassword: function BasePdfManager_updatePassword(password) {
  39327. this.pdfDocument.xref.password = this.password = password;
  39328. if (this._passwordChangedCapability) {
  39329. this._passwordChangedCapability.resolve();
  39330. }
  39331. },
  39332. passwordChanged: function BasePdfManager_passwordChanged() {
  39333. this._passwordChangedCapability = createPromiseCapability();
  39334. return this._passwordChangedCapability.promise;
  39335. },
  39336. terminate: function BasePdfManager_terminate() {
  39337. return new NotImplementedException();
  39338. }
  39339. };
  39340. return BasePdfManager;
  39341. })();
  39342. var LocalPdfManager = (function LocalPdfManagerClosure() {
  39343. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  39344. this._docId = docId;
  39345. this.evaluatorOptions = evaluatorOptions;
  39346. var stream = new Stream(data);
  39347. this.pdfDocument = new PDFDocument(this, stream, password);
  39348. this._loadedStreamCapability = createPromiseCapability();
  39349. this._loadedStreamCapability.resolve(stream);
  39350. }
  39351. Util.inherit(LocalPdfManager, BasePdfManager, {
  39352. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  39353. return new Promise(function (resolve, reject) {
  39354. try {
  39355. var value = obj[prop];
  39356. var result;
  39357. if (typeof value === 'function') {
  39358. result = value.apply(obj, args);
  39359. } else {
  39360. result = value;
  39361. }
  39362. resolve(result);
  39363. } catch (e) {
  39364. reject(e);
  39365. }
  39366. });
  39367. },
  39368. requestRange: function LocalPdfManager_requestRange(begin, end) {
  39369. return Promise.resolve();
  39370. },
  39371. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  39372. return;
  39373. },
  39374. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  39375. return this._loadedStreamCapability.promise;
  39376. },
  39377. terminate: function LocalPdfManager_terminate() {
  39378. return;
  39379. }
  39380. });
  39381. return LocalPdfManager;
  39382. })();
  39383. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  39384. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  39385. this._docId = docId;
  39386. this.msgHandler = args.msgHandler;
  39387. this.evaluatorOptions = evaluatorOptions;
  39388. var params = {
  39389. msgHandler: args.msgHandler,
  39390. url: args.url,
  39391. length: args.length,
  39392. disableAutoFetch: args.disableAutoFetch,
  39393. rangeChunkSize: args.rangeChunkSize
  39394. };
  39395. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  39396. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  39397. args.password);
  39398. }
  39399. Util.inherit(NetworkPdfManager, BasePdfManager, {
  39400. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  39401. var pdfManager = this;
  39402. return new Promise(function (resolve, reject) {
  39403. function ensureHelper() {
  39404. try {
  39405. var result;
  39406. var value = obj[prop];
  39407. if (typeof value === 'function') {
  39408. result = value.apply(obj, args);
  39409. } else {
  39410. result = value;
  39411. }
  39412. resolve(result);
  39413. } catch(e) {
  39414. if (!(e instanceof MissingDataException)) {
  39415. reject(e);
  39416. return;
  39417. }
  39418. pdfManager.streamManager.requestRange(e.begin, e.end).
  39419. then(ensureHelper, reject);
  39420. }
  39421. }
  39422. ensureHelper();
  39423. });
  39424. },
  39425. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  39426. return this.streamManager.requestRange(begin, end);
  39427. },
  39428. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  39429. this.streamManager.requestAllChunks();
  39430. },
  39431. sendProgressiveData:
  39432. function NetworkPdfManager_sendProgressiveData(chunk) {
  39433. this.streamManager.onReceiveData({ chunk: chunk });
  39434. },
  39435. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  39436. return this.streamManager.onLoadedStream();
  39437. },
  39438. terminate: function NetworkPdfManager_terminate() {
  39439. this.streamManager.abort();
  39440. }
  39441. });
  39442. return NetworkPdfManager;
  39443. })();
  39444. exports.LocalPdfManager = LocalPdfManager;
  39445. exports.NetworkPdfManager = NetworkPdfManager;
  39446. }));
  39447. (function (root, factory) {
  39448. {
  39449. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  39450. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  39451. }
  39452. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  39453. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39454. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39455. var MessageHandler = sharedUtil.MessageHandler;
  39456. var MissingPDFException = sharedUtil.MissingPDFException;
  39457. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39458. var PasswordException = sharedUtil.PasswordException;
  39459. var PasswordResponses = sharedUtil.PasswordResponses;
  39460. var UnknownErrorException = sharedUtil.UnknownErrorException;
  39461. var XRefParseException = sharedUtil.XRefParseException;
  39462. var arrayByteLength = sharedUtil.arrayByteLength;
  39463. var arraysToBytes = sharedUtil.arraysToBytes;
  39464. var assert = sharedUtil.assert;
  39465. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39466. var error = sharedUtil.error;
  39467. var info = sharedUtil.info;
  39468. var warn = sharedUtil.warn;
  39469. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  39470. var Ref = corePrimitives.Ref;
  39471. var LocalPdfManager = corePdfManager.LocalPdfManager;
  39472. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  39473. var globalScope = sharedUtil.globalScope;
  39474. var WorkerTask = (function WorkerTaskClosure() {
  39475. function WorkerTask(name) {
  39476. this.name = name;
  39477. this.terminated = false;
  39478. this._capability = createPromiseCapability();
  39479. }
  39480. WorkerTask.prototype = {
  39481. get finished() {
  39482. return this._capability.promise;
  39483. },
  39484. finish: function () {
  39485. this._capability.resolve();
  39486. },
  39487. terminate: function () {
  39488. this.terminated = true;
  39489. },
  39490. ensureNotTerminated: function () {
  39491. if (this.terminated) {
  39492. throw new Error('Worker task was terminated');
  39493. }
  39494. }
  39495. };
  39496. return WorkerTask;
  39497. })();
  39498. /** @implements {IPDFStream} */
  39499. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  39500. function PDFWorkerStream(params, msgHandler) {
  39501. this._queuedChunks = [];
  39502. var initialData = params.initialData;
  39503. if (initialData && initialData.length > 0) {
  39504. this._queuedChunks.push(initialData);
  39505. }
  39506. this._msgHandler = msgHandler;
  39507. this._isRangeSupported = !(params.disableRange);
  39508. this._isStreamingSupported = !(params.disableStream);
  39509. this._contentLength = params.length;
  39510. this._fullRequestReader = null;
  39511. this._rangeReaders = [];
  39512. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  39513. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  39514. }
  39515. PDFWorkerStream.prototype = {
  39516. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  39517. if (args.begin === undefined) {
  39518. if (this._fullRequestReader) {
  39519. this._fullRequestReader._enqueue(args.chunk);
  39520. } else {
  39521. this._queuedChunks.push(args.chunk);
  39522. }
  39523. } else {
  39524. var found = this._rangeReaders.some(function (rangeReader) {
  39525. if (rangeReader._begin !== args.begin) {
  39526. return false;
  39527. }
  39528. rangeReader._enqueue(args.chunk);
  39529. return true;
  39530. });
  39531. assert(found);
  39532. }
  39533. },
  39534. _onProgress: function PDFWorkerStream_onProgress(evt) {
  39535. if (this._rangeReaders.length > 0) {
  39536. // Reporting to first range reader.
  39537. var firstReader = this._rangeReaders[0];
  39538. if (firstReader.onProgress) {
  39539. firstReader.onProgress({loaded: evt.loaded});
  39540. }
  39541. }
  39542. },
  39543. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  39544. var i = this._rangeReaders.indexOf(reader);
  39545. if (i >= 0) {
  39546. this._rangeReaders.splice(i, 1);
  39547. }
  39548. },
  39549. getFullReader: function PDFWorkerStream_getFullReader() {
  39550. assert(!this._fullRequestReader);
  39551. var queuedChunks = this._queuedChunks;
  39552. this._queuedChunks = null;
  39553. return new PDFWorkerStreamReader(this, queuedChunks);
  39554. },
  39555. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  39556. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  39557. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  39558. this._rangeReaders.push(reader);
  39559. return reader;
  39560. },
  39561. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  39562. if (this._fullRequestReader) {
  39563. this._fullRequestReader.cancel(reason);
  39564. }
  39565. var readers = this._rangeReaders.slice(0);
  39566. readers.forEach(function (rangeReader) {
  39567. rangeReader.cancel(reason);
  39568. });
  39569. }
  39570. };
  39571. /** @implements {IPDFStreamReader} */
  39572. function PDFWorkerStreamReader(stream, queuedChunks) {
  39573. this._stream = stream;
  39574. this._done = false;
  39575. this._queuedChunks = queuedChunks || [];
  39576. this._requests = [];
  39577. this._headersReady = Promise.resolve();
  39578. stream._fullRequestReader = this;
  39579. this.onProgress = null; // not used
  39580. }
  39581. PDFWorkerStreamReader.prototype = {
  39582. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  39583. if (this._done) {
  39584. return; // ignore new data
  39585. }
  39586. if (this._requests.length > 0) {
  39587. var requestCapability = this._requests.shift();
  39588. requestCapability.resolve({value: chunk, done: false});
  39589. return;
  39590. }
  39591. this._queuedChunks.push(chunk);
  39592. },
  39593. get headersReady() {
  39594. return this._headersReady;
  39595. },
  39596. get isRangeSupported() {
  39597. return this._stream._isRangeSupported;
  39598. },
  39599. get isStreamingSupported() {
  39600. return this._stream._isStreamingSupported;
  39601. },
  39602. get contentLength() {
  39603. return this._stream._contentLength;
  39604. },
  39605. read: function PDFWorkerStreamReader_read() {
  39606. if (this._queuedChunks.length > 0) {
  39607. var chunk = this._queuedChunks.shift();
  39608. return Promise.resolve({value: chunk, done: false});
  39609. }
  39610. if (this._done) {
  39611. return Promise.resolve({value: undefined, done: true});
  39612. }
  39613. var requestCapability = createPromiseCapability();
  39614. this._requests.push(requestCapability);
  39615. return requestCapability.promise;
  39616. },
  39617. cancel: function PDFWorkerStreamReader_cancel(reason) {
  39618. this._done = true;
  39619. this._requests.forEach(function (requestCapability) {
  39620. requestCapability.resolve({value: undefined, done: true});
  39621. });
  39622. this._requests = [];
  39623. }
  39624. };
  39625. /** @implements {IPDFStreamRangeReader} */
  39626. function PDFWorkerStreamRangeReader(stream, begin, end) {
  39627. this._stream = stream;
  39628. this._begin = begin;
  39629. this._end = end;
  39630. this._queuedChunk = null;
  39631. this._requests = [];
  39632. this._done = false;
  39633. this.onProgress = null;
  39634. }
  39635. PDFWorkerStreamRangeReader.prototype = {
  39636. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  39637. if (this._done) {
  39638. return; // ignore new data
  39639. }
  39640. if (this._requests.length === 0) {
  39641. this._queuedChunk = chunk;
  39642. } else {
  39643. var requestsCapability = this._requests.shift();
  39644. requestsCapability.resolve({value: chunk, done: false});
  39645. this._requests.forEach(function (requestCapability) {
  39646. requestCapability.resolve({value: undefined, done: true});
  39647. });
  39648. this._requests = [];
  39649. }
  39650. this._done = true;
  39651. this._stream._removeRangeReader(this);
  39652. },
  39653. get isStreamingSupported() {
  39654. return false;
  39655. },
  39656. read: function PDFWorkerStreamRangeReader_read() {
  39657. if (this._queuedChunk) {
  39658. return Promise.resolve({value: this._queuedChunk, done: false});
  39659. }
  39660. if (this._done) {
  39661. return Promise.resolve({value: undefined, done: true});
  39662. }
  39663. var requestCapability = createPromiseCapability();
  39664. this._requests.push(requestCapability);
  39665. return requestCapability.promise;
  39666. },
  39667. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  39668. this._done = true;
  39669. this._requests.forEach(function (requestCapability) {
  39670. requestCapability.resolve({value: undefined, done: true});
  39671. });
  39672. this._requests = [];
  39673. this._stream._removeRangeReader(this);
  39674. }
  39675. };
  39676. return PDFWorkerStream;
  39677. })();
  39678. /** @type IPDFStream */
  39679. var PDFNetworkStream;
  39680. /**
  39681. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  39682. * @param {IPDFStream} cls - the PDF data transport.
  39683. */
  39684. function setPDFNetworkStreamClass(cls) {
  39685. PDFNetworkStream = cls;
  39686. }
  39687. var WorkerMessageHandler = {
  39688. setup: function wphSetup(handler, port) {
  39689. var testMessageProcessed = false;
  39690. handler.on('test', function wphSetupTest(data) {
  39691. if (testMessageProcessed) {
  39692. return; // we already processed 'test' message once
  39693. }
  39694. testMessageProcessed = true;
  39695. // check if Uint8Array can be sent to worker
  39696. if (!(data instanceof Uint8Array)) {
  39697. handler.send('test', 'main', false);
  39698. return;
  39699. }
  39700. // making sure postMessage transfers are working
  39701. var supportTransfers = data[0] === 255;
  39702. handler.postMessageTransfers = supportTransfers;
  39703. // check if the response property is supported by xhr
  39704. var xhr = new XMLHttpRequest();
  39705. var responseExists = 'response' in xhr;
  39706. // check if the property is actually implemented
  39707. try {
  39708. var dummy = xhr.responseType;
  39709. } catch (e) {
  39710. responseExists = false;
  39711. }
  39712. if (!responseExists) {
  39713. handler.send('test', false);
  39714. return;
  39715. }
  39716. handler.send('test', {
  39717. supportTypedArray: true,
  39718. supportTransfers: supportTransfers
  39719. });
  39720. });
  39721. handler.on('configure', function wphConfigure(data) {
  39722. setVerbosityLevel(data.verbosity);
  39723. });
  39724. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39725. return WorkerMessageHandler.createDocumentHandler(data, port);
  39726. });
  39727. },
  39728. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39729. // This context is actually holds references on pdfManager and handler,
  39730. // until the latter is destroyed.
  39731. var pdfManager;
  39732. var terminated = false;
  39733. var cancelXHRs = null;
  39734. var WorkerTasks = [];
  39735. var docId = docParams.docId;
  39736. var workerHandlerName = docParams.docId + '_worker';
  39737. var handler = new MessageHandler(workerHandlerName, docId, port);
  39738. // Ensure that postMessage transfers are correctly enabled/disabled,
  39739. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  39740. handler.postMessageTransfers = docParams.postMessageTransfers;
  39741. function ensureNotTerminated() {
  39742. if (terminated) {
  39743. throw new Error('Worker was terminated');
  39744. }
  39745. }
  39746. function startWorkerTask(task) {
  39747. WorkerTasks.push(task);
  39748. }
  39749. function finishWorkerTask(task) {
  39750. task.finish();
  39751. var i = WorkerTasks.indexOf(task);
  39752. WorkerTasks.splice(i, 1);
  39753. }
  39754. function loadDocument(recoveryMode) {
  39755. var loadDocumentCapability = createPromiseCapability();
  39756. var parseSuccess = function parseSuccess() {
  39757. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39758. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39759. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39760. Promise.all([numPagesPromise, fingerprintPromise,
  39761. encryptedPromise]).then(function onDocReady(results) {
  39762. var doc = {
  39763. numPages: results[0],
  39764. fingerprint: results[1],
  39765. encrypted: !!results[2],
  39766. };
  39767. loadDocumentCapability.resolve(doc);
  39768. },
  39769. parseFailure);
  39770. };
  39771. var parseFailure = function parseFailure(e) {
  39772. loadDocumentCapability.reject(e);
  39773. };
  39774. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39775. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39776. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39777. parseSuccess, parseFailure);
  39778. }, parseFailure);
  39779. }, parseFailure);
  39780. return loadDocumentCapability.promise;
  39781. }
  39782. function getPdfManager(data, evaluatorOptions) {
  39783. var pdfManagerCapability = createPromiseCapability();
  39784. var pdfManager;
  39785. var source = data.source;
  39786. if (source.data) {
  39787. try {
  39788. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  39789. evaluatorOptions);
  39790. pdfManagerCapability.resolve(pdfManager);
  39791. } catch (ex) {
  39792. pdfManagerCapability.reject(ex);
  39793. }
  39794. return pdfManagerCapability.promise;
  39795. }
  39796. var pdfStream;
  39797. try {
  39798. if (source.chunkedViewerLoading) {
  39799. pdfStream = new PDFWorkerStream(source, handler);
  39800. } else {
  39801. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  39802. pdfStream = new PDFNetworkStream(data);
  39803. }
  39804. } catch (ex) {
  39805. pdfManagerCapability.reject(ex);
  39806. return pdfManagerCapability.promise;
  39807. }
  39808. var fullRequest = pdfStream.getFullReader();
  39809. fullRequest.headersReady.then(function () {
  39810. if (!fullRequest.isStreamingSupported ||
  39811. !fullRequest.isRangeSupported) {
  39812. // If stream or range are disabled, it's our only way to report
  39813. // loading progress.
  39814. fullRequest.onProgress = function (evt) {
  39815. handler.send('DocProgress', {
  39816. loaded: evt.loaded,
  39817. total: evt.total
  39818. });
  39819. };
  39820. }
  39821. if (!fullRequest.isRangeSupported) {
  39822. return;
  39823. }
  39824. // We don't need auto-fetch when streaming is enabled.
  39825. var disableAutoFetch = source.disableAutoFetch ||
  39826. fullRequest.isStreamingSupported;
  39827. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  39828. msgHandler: handler,
  39829. url: source.url,
  39830. password: source.password,
  39831. length: fullRequest.contentLength,
  39832. disableAutoFetch: disableAutoFetch,
  39833. rangeChunkSize: source.rangeChunkSize
  39834. }, evaluatorOptions);
  39835. pdfManagerCapability.resolve(pdfManager);
  39836. cancelXHRs = null;
  39837. }).catch(function (reason) {
  39838. pdfManagerCapability.reject(reason);
  39839. cancelXHRs = null;
  39840. });
  39841. var cachedChunks = [], loaded = 0;
  39842. var flushChunks = function () {
  39843. var pdfFile = arraysToBytes(cachedChunks);
  39844. if (source.length && pdfFile.length !== source.length) {
  39845. warn('reported HTTP length is different from actual');
  39846. }
  39847. // the data is array, instantiating directly from it
  39848. try {
  39849. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  39850. evaluatorOptions);
  39851. pdfManagerCapability.resolve(pdfManager);
  39852. } catch (ex) {
  39853. pdfManagerCapability.reject(ex);
  39854. }
  39855. cachedChunks = [];
  39856. };
  39857. var readPromise = new Promise(function (resolve, reject) {
  39858. var readChunk = function (chunk) {
  39859. try {
  39860. ensureNotTerminated();
  39861. if (chunk.done) {
  39862. if (!pdfManager) {
  39863. flushChunks();
  39864. }
  39865. cancelXHRs = null;
  39866. return;
  39867. }
  39868. var data = chunk.value;
  39869. loaded += arrayByteLength(data);
  39870. if (!fullRequest.isStreamingSupported) {
  39871. handler.send('DocProgress', {
  39872. loaded: loaded,
  39873. total: Math.max(loaded, fullRequest.contentLength || 0)
  39874. });
  39875. }
  39876. if (pdfManager) {
  39877. pdfManager.sendProgressiveData(data);
  39878. } else {
  39879. cachedChunks.push(data);
  39880. }
  39881. fullRequest.read().then(readChunk, reject);
  39882. } catch (e) {
  39883. reject(e);
  39884. }
  39885. };
  39886. fullRequest.read().then(readChunk, reject);
  39887. });
  39888. readPromise.catch(function (e) {
  39889. pdfManagerCapability.reject(e);
  39890. cancelXHRs = null;
  39891. });
  39892. cancelXHRs = function () {
  39893. pdfStream.cancelAllRequests('abort');
  39894. };
  39895. return pdfManagerCapability.promise;
  39896. }
  39897. var setupDoc = function(data) {
  39898. var onSuccess = function(doc) {
  39899. ensureNotTerminated();
  39900. handler.send('GetDoc', { pdfInfo: doc });
  39901. };
  39902. var onFailure = function(e) {
  39903. if (e instanceof PasswordException) {
  39904. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39905. handler.send('NeedPassword', e);
  39906. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39907. handler.send('IncorrectPassword', e);
  39908. }
  39909. } else if (e instanceof InvalidPDFException) {
  39910. handler.send('InvalidPDF', e);
  39911. } else if (e instanceof MissingPDFException) {
  39912. handler.send('MissingPDF', e);
  39913. } else if (e instanceof UnexpectedResponseException) {
  39914. handler.send('UnexpectedResponse', e);
  39915. } else {
  39916. handler.send('UnknownError',
  39917. new UnknownErrorException(e.message, e.toString()));
  39918. }
  39919. };
  39920. ensureNotTerminated();
  39921. var cMapOptions = {
  39922. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  39923. packed: data.cMapPacked === true
  39924. };
  39925. var evaluatorOptions = {
  39926. forceDataSchema: data.disableCreateObjectURL,
  39927. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  39928. disableFontFace: data.disableFontFace,
  39929. cMapOptions: cMapOptions
  39930. };
  39931. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  39932. if (terminated) {
  39933. // We were in a process of setting up the manager, but it got
  39934. // terminated in the middle.
  39935. newPdfManager.terminate();
  39936. throw new Error('Worker was terminated');
  39937. }
  39938. pdfManager = newPdfManager;
  39939. handler.send('PDFManagerReady', null);
  39940. pdfManager.onLoadedStream().then(function(stream) {
  39941. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39942. });
  39943. }).then(function pdfManagerReady() {
  39944. ensureNotTerminated();
  39945. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39946. ensureNotTerminated();
  39947. // Try again with recoveryMode == true
  39948. if (!(ex instanceof XRefParseException)) {
  39949. if (ex instanceof PasswordException) {
  39950. // after password exception prepare to receive a new password
  39951. // to repeat loading
  39952. pdfManager.passwordChanged().then(pdfManagerReady);
  39953. }
  39954. onFailure(ex);
  39955. return;
  39956. }
  39957. pdfManager.requestLoadedStream();
  39958. pdfManager.onLoadedStream().then(function() {
  39959. ensureNotTerminated();
  39960. loadDocument(true).then(onSuccess, onFailure);
  39961. });
  39962. }, onFailure);
  39963. }, onFailure);
  39964. };
  39965. handler.on('GetPage', function wphSetupGetPage(data) {
  39966. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39967. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39968. var refPromise = pdfManager.ensure(page, 'ref');
  39969. var viewPromise = pdfManager.ensure(page, 'view');
  39970. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39971. function(results) {
  39972. return {
  39973. rotate: results[0],
  39974. ref: results[1],
  39975. view: results[2]
  39976. };
  39977. });
  39978. });
  39979. });
  39980. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39981. var ref = new Ref(data.ref.num, data.ref.gen);
  39982. var catalog = pdfManager.pdfDocument.catalog;
  39983. return catalog.getPageIndex(ref);
  39984. });
  39985. handler.on('GetDestinations',
  39986. function wphSetupGetDestinations(data) {
  39987. return pdfManager.ensureCatalog('destinations');
  39988. }
  39989. );
  39990. handler.on('GetDestination',
  39991. function wphSetupGetDestination(data) {
  39992. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39993. }
  39994. );
  39995. handler.on('GetPageLabels',
  39996. function wphSetupGetPageLabels(data) {
  39997. return pdfManager.ensureCatalog('pageLabels');
  39998. }
  39999. );
  40000. handler.on('GetAttachments',
  40001. function wphSetupGetAttachments(data) {
  40002. return pdfManager.ensureCatalog('attachments');
  40003. }
  40004. );
  40005. handler.on('GetJavaScript',
  40006. function wphSetupGetJavaScript(data) {
  40007. return pdfManager.ensureCatalog('javaScript');
  40008. }
  40009. );
  40010. handler.on('GetOutline',
  40011. function wphSetupGetOutline(data) {
  40012. return pdfManager.ensureCatalog('documentOutline');
  40013. }
  40014. );
  40015. handler.on('GetMetadata',
  40016. function wphSetupGetMetadata(data) {
  40017. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  40018. pdfManager.ensureCatalog('metadata')]);
  40019. }
  40020. );
  40021. handler.on('GetData', function wphSetupGetData(data) {
  40022. pdfManager.requestLoadedStream();
  40023. return pdfManager.onLoadedStream().then(function(stream) {
  40024. return stream.bytes;
  40025. });
  40026. });
  40027. handler.on('GetStats',
  40028. function wphSetupGetStats(data) {
  40029. return pdfManager.pdfDocument.xref.stats;
  40030. }
  40031. );
  40032. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  40033. pdfManager.updatePassword(data);
  40034. });
  40035. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  40036. return pdfManager.getPage(data.pageIndex).then(function(page) {
  40037. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  40038. });
  40039. });
  40040. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  40041. var pageIndex = data.pageIndex;
  40042. pdfManager.getPage(pageIndex).then(function(page) {
  40043. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  40044. startWorkerTask(task);
  40045. var pageNum = pageIndex + 1;
  40046. var start = Date.now();
  40047. // Pre compile the pdf page and fetch the fonts/images.
  40048. page.getOperatorList(handler, task, data.intent,
  40049. data.renderInteractiveForms).then(
  40050. function(operatorList) {
  40051. finishWorkerTask(task);
  40052. info('page=' + pageNum + ' - getOperatorList: time=' +
  40053. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  40054. }, function(e) {
  40055. finishWorkerTask(task);
  40056. if (task.terminated) {
  40057. return; // ignoring errors from the terminated thread
  40058. }
  40059. // For compatibility with older behavior, generating unknown
  40060. // unsupported feature notification on errors.
  40061. handler.send('UnsupportedFeature',
  40062. {featureId: UNSUPPORTED_FEATURES.unknown});
  40063. var minimumStackMessage =
  40064. 'worker.js: while trying to getPage() and getOperatorList()';
  40065. var wrappedException;
  40066. // Turn the error into an obj that can be serialized
  40067. if (typeof e === 'string') {
  40068. wrappedException = {
  40069. message: e,
  40070. stack: minimumStackMessage
  40071. };
  40072. } else if (typeof e === 'object') {
  40073. wrappedException = {
  40074. message: e.message || e.toString(),
  40075. stack: e.stack || minimumStackMessage
  40076. };
  40077. } else {
  40078. wrappedException = {
  40079. message: 'Unknown exception type: ' + (typeof e),
  40080. stack: minimumStackMessage
  40081. };
  40082. }
  40083. handler.send('PageError', {
  40084. pageNum: pageNum,
  40085. error: wrappedException,
  40086. intent: data.intent
  40087. });
  40088. });
  40089. });
  40090. }, this);
  40091. handler.on('GetTextContent', function wphExtractText(data) {
  40092. var pageIndex = data.pageIndex;
  40093. var normalizeWhitespace = data.normalizeWhitespace;
  40094. var combineTextItems = data.combineTextItems;
  40095. return pdfManager.getPage(pageIndex).then(function(page) {
  40096. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  40097. startWorkerTask(task);
  40098. var pageNum = pageIndex + 1;
  40099. var start = Date.now();
  40100. return page.extractTextContent(task, normalizeWhitespace,
  40101. combineTextItems).then(
  40102. function(textContent) {
  40103. finishWorkerTask(task);
  40104. info('text indexing: page=' + pageNum + ' - time=' +
  40105. (Date.now() - start) + 'ms');
  40106. return textContent;
  40107. }, function (reason) {
  40108. finishWorkerTask(task);
  40109. if (task.terminated) {
  40110. return; // ignoring errors from the terminated thread
  40111. }
  40112. throw reason;
  40113. });
  40114. });
  40115. });
  40116. handler.on('Cleanup', function wphCleanup(data) {
  40117. return pdfManager.cleanup();
  40118. });
  40119. handler.on('Terminate', function wphTerminate(data) {
  40120. terminated = true;
  40121. if (pdfManager) {
  40122. pdfManager.terminate();
  40123. pdfManager = null;
  40124. }
  40125. if (cancelXHRs) {
  40126. cancelXHRs();
  40127. }
  40128. var waitOn = [];
  40129. WorkerTasks.forEach(function (task) {
  40130. waitOn.push(task.finished);
  40131. task.terminate();
  40132. });
  40133. return Promise.all(waitOn).then(function () {
  40134. // Notice that even if we destroying handler, resolved response promise
  40135. // must be sent back.
  40136. handler.destroy();
  40137. handler = null;
  40138. });
  40139. });
  40140. handler.on('Ready', function wphReady(data) {
  40141. setupDoc(docParams);
  40142. docParams = null; // we don't need docParams anymore -- saving memory.
  40143. });
  40144. return workerHandlerName;
  40145. }
  40146. };
  40147. function initializeWorker() {
  40148. if (!('console' in globalScope)) {
  40149. var consoleTimer = {};
  40150. var workerConsole = {
  40151. log: function log() {
  40152. var args = Array.prototype.slice.call(arguments);
  40153. globalScope.postMessage({
  40154. targetName: 'main',
  40155. action: 'console_log',
  40156. data: args
  40157. });
  40158. },
  40159. error: function error() {
  40160. var args = Array.prototype.slice.call(arguments);
  40161. globalScope.postMessage({
  40162. targetName: 'main',
  40163. action: 'console_error',
  40164. data: args
  40165. });
  40166. throw 'pdf.js execution error';
  40167. },
  40168. time: function time(name) {
  40169. consoleTimer[name] = Date.now();
  40170. },
  40171. timeEnd: function timeEnd(name) {
  40172. var time = consoleTimer[name];
  40173. if (!time) {
  40174. error('Unknown timer name ' + name);
  40175. }
  40176. this.log('Timer:', name, Date.now() - time);
  40177. }
  40178. };
  40179. globalScope.console = workerConsole;
  40180. }
  40181. var handler = new MessageHandler('worker', 'main', self);
  40182. WorkerMessageHandler.setup(handler, self);
  40183. handler.send('ready', null);
  40184. }
  40185. // Worker thread (and not node.js)?
  40186. if (typeof window === 'undefined' &&
  40187. !(typeof module !== 'undefined' && module.require)) {
  40188. initializeWorker();
  40189. }
  40190. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  40191. exports.WorkerTask = WorkerTask;
  40192. exports.WorkerMessageHandler = WorkerMessageHandler;
  40193. }));
  40194. var NetworkManager = (function NetworkManagerClosure() {
  40195. var OK_RESPONSE = 200;
  40196. var PARTIAL_CONTENT_RESPONSE = 206;
  40197. function NetworkManager(url, args) {
  40198. this.url = url;
  40199. args = args || {};
  40200. this.isHttp = /^https?:/i.test(url);
  40201. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  40202. this.withCredentials = args.withCredentials || false;
  40203. this.getXhr = args.getXhr ||
  40204. function NetworkManager_getXhr() {
  40205. return new XMLHttpRequest();
  40206. };
  40207. this.currXhrId = 0;
  40208. this.pendingRequests = Object.create(null);
  40209. this.loadedRequests = Object.create(null);
  40210. }
  40211. function getArrayBuffer(xhr) {
  40212. var data = xhr.response;
  40213. if (typeof data !== 'string') {
  40214. return data;
  40215. }
  40216. var length = data.length;
  40217. var array = new Uint8Array(length);
  40218. for (var i = 0; i < length; i++) {
  40219. array[i] = data.charCodeAt(i) & 0xFF;
  40220. }
  40221. return array.buffer;
  40222. }
  40223. var supportsMozChunked = (function supportsMozChunkedClosure() {
  40224. try {
  40225. var x = new XMLHttpRequest();
  40226. // Firefox 37- required .open() to be called before setting responseType.
  40227. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  40228. // Even though the URL is not visited, .open() could fail if the URL is
  40229. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  40230. // When this error occurs, this feature detection method will mistakenly
  40231. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  40232. x.open('GET', 'https://example.com');
  40233. x.responseType = 'moz-chunked-arraybuffer';
  40234. return x.responseType === 'moz-chunked-arraybuffer';
  40235. } catch (e) {
  40236. return false;
  40237. }
  40238. })();
  40239. NetworkManager.prototype = {
  40240. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  40241. var args = {
  40242. begin: begin,
  40243. end: end
  40244. };
  40245. for (var prop in listeners) {
  40246. args[prop] = listeners[prop];
  40247. }
  40248. return this.request(args);
  40249. },
  40250. requestFull: function NetworkManager_requestFull(listeners) {
  40251. return this.request(listeners);
  40252. },
  40253. request: function NetworkManager_request(args) {
  40254. var xhr = this.getXhr();
  40255. var xhrId = this.currXhrId++;
  40256. var pendingRequest = this.pendingRequests[xhrId] = {
  40257. xhr: xhr
  40258. };
  40259. xhr.open('GET', this.url);
  40260. xhr.withCredentials = this.withCredentials;
  40261. for (var property in this.httpHeaders) {
  40262. var value = this.httpHeaders[property];
  40263. if (typeof value === 'undefined') {
  40264. continue;
  40265. }
  40266. xhr.setRequestHeader(property, value);
  40267. }
  40268. if (this.isHttp && 'begin' in args && 'end' in args) {
  40269. var rangeStr = args.begin + '-' + (args.end - 1);
  40270. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  40271. pendingRequest.expectedStatus = 206;
  40272. } else {
  40273. pendingRequest.expectedStatus = 200;
  40274. }
  40275. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  40276. if (useMozChunkedLoading) {
  40277. xhr.responseType = 'moz-chunked-arraybuffer';
  40278. pendingRequest.onProgressiveData = args.onProgressiveData;
  40279. pendingRequest.mozChunked = true;
  40280. } else {
  40281. xhr.responseType = 'arraybuffer';
  40282. }
  40283. if (args.onError) {
  40284. xhr.onerror = function(evt) {
  40285. args.onError(xhr.status);
  40286. };
  40287. }
  40288. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  40289. xhr.onprogress = this.onProgress.bind(this, xhrId);
  40290. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  40291. pendingRequest.onDone = args.onDone;
  40292. pendingRequest.onError = args.onError;
  40293. pendingRequest.onProgress = args.onProgress;
  40294. xhr.send(null);
  40295. return xhrId;
  40296. },
  40297. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  40298. var pendingRequest = this.pendingRequests[xhrId];
  40299. if (!pendingRequest) {
  40300. // Maybe abortRequest was called...
  40301. return;
  40302. }
  40303. if (pendingRequest.mozChunked) {
  40304. var chunk = getArrayBuffer(pendingRequest.xhr);
  40305. pendingRequest.onProgressiveData(chunk);
  40306. }
  40307. var onProgress = pendingRequest.onProgress;
  40308. if (onProgress) {
  40309. onProgress(evt);
  40310. }
  40311. },
  40312. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  40313. var pendingRequest = this.pendingRequests[xhrId];
  40314. if (!pendingRequest) {
  40315. // Maybe abortRequest was called...
  40316. return;
  40317. }
  40318. var xhr = pendingRequest.xhr;
  40319. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  40320. pendingRequest.onHeadersReceived();
  40321. delete pendingRequest.onHeadersReceived;
  40322. }
  40323. if (xhr.readyState !== 4) {
  40324. return;
  40325. }
  40326. if (!(xhrId in this.pendingRequests)) {
  40327. // The XHR request might have been aborted in onHeadersReceived()
  40328. // callback, in which case we should abort request
  40329. return;
  40330. }
  40331. delete this.pendingRequests[xhrId];
  40332. // success status == 0 can be on ftp, file and other protocols
  40333. if (xhr.status === 0 && this.isHttp) {
  40334. if (pendingRequest.onError) {
  40335. pendingRequest.onError(xhr.status);
  40336. }
  40337. return;
  40338. }
  40339. var xhrStatus = xhr.status || OK_RESPONSE;
  40340. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  40341. // "A server MAY ignore the Range header". This means it's possible to
  40342. // get a 200 rather than a 206 response from a range request.
  40343. var ok_response_on_range_request =
  40344. xhrStatus === OK_RESPONSE &&
  40345. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  40346. if (!ok_response_on_range_request &&
  40347. xhrStatus !== pendingRequest.expectedStatus) {
  40348. if (pendingRequest.onError) {
  40349. pendingRequest.onError(xhr.status);
  40350. }
  40351. return;
  40352. }
  40353. this.loadedRequests[xhrId] = true;
  40354. var chunk = getArrayBuffer(xhr);
  40355. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  40356. var rangeHeader = xhr.getResponseHeader('Content-Range');
  40357. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  40358. var begin = parseInt(matches[1], 10);
  40359. pendingRequest.onDone({
  40360. begin: begin,
  40361. chunk: chunk
  40362. });
  40363. } else if (pendingRequest.onProgressiveData) {
  40364. pendingRequest.onDone(null);
  40365. } else if (chunk) {
  40366. pendingRequest.onDone({
  40367. begin: 0,
  40368. chunk: chunk
  40369. });
  40370. } else if (pendingRequest.onError) {
  40371. pendingRequest.onError(xhr.status);
  40372. }
  40373. },
  40374. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  40375. for (var xhrId in this.pendingRequests) {
  40376. return true;
  40377. }
  40378. return false;
  40379. },
  40380. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  40381. return this.pendingRequests[xhrId].xhr;
  40382. },
  40383. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  40384. return !!(this.pendingRequests[xhrId].onProgressiveData);
  40385. },
  40386. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  40387. return xhrId in this.pendingRequests;
  40388. },
  40389. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  40390. return xhrId in this.loadedRequests;
  40391. },
  40392. abortAllRequests: function NetworkManager_abortAllRequests() {
  40393. for (var xhrId in this.pendingRequests) {
  40394. this.abortRequest(xhrId | 0);
  40395. }
  40396. },
  40397. abortRequest: function NetworkManager_abortRequest(xhrId) {
  40398. var xhr = this.pendingRequests[xhrId].xhr;
  40399. delete this.pendingRequests[xhrId];
  40400. xhr.abort();
  40401. }
  40402. };
  40403. return NetworkManager;
  40404. })();
  40405. (function (root, factory) {
  40406. {
  40407. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  40408. root.pdfjsCoreWorker);
  40409. }
  40410. }(this, function (exports, sharedUtil, coreWorker) {
  40411. var assert = sharedUtil.assert;
  40412. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40413. var isInt = sharedUtil.isInt;
  40414. var MissingPDFException = sharedUtil.MissingPDFException;
  40415. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  40416. /** @implements {IPDFStream} */
  40417. function PDFNetworkStream(options) {
  40418. this._options = options;
  40419. var source = options.source;
  40420. this._manager = new NetworkManager(source.url, {
  40421. httpHeaders: source.httpHeaders,
  40422. withCredentials: source.withCredentials
  40423. });
  40424. this._rangeChunkSize = source.rangeChunkSize;
  40425. this._fullRequestReader = null;
  40426. this._rangeRequestReaders = [];
  40427. }
  40428. PDFNetworkStream.prototype = {
  40429. _onRangeRequestReaderClosed:
  40430. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  40431. var i = this._rangeRequestReaders.indexOf(reader);
  40432. if (i >= 0) {
  40433. this._rangeRequestReaders.splice(i, 1);
  40434. }
  40435. },
  40436. getFullReader: function PDFNetworkStream_getFullReader() {
  40437. assert(!this._fullRequestReader);
  40438. this._fullRequestReader =
  40439. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  40440. return this._fullRequestReader;
  40441. },
  40442. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  40443. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  40444. begin, end);
  40445. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  40446. this._rangeRequestReaders.push(reader);
  40447. return reader;
  40448. },
  40449. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  40450. if (this._fullRequestReader) {
  40451. this._fullRequestReader.cancel(reason);
  40452. }
  40453. var readers = this._rangeRequestReaders.slice(0);
  40454. readers.forEach(function (reader) {
  40455. reader.cancel(reason);
  40456. });
  40457. }
  40458. };
  40459. /** @implements {IPDFStreamReader} */
  40460. function PDFNetworkStreamFullRequestReader(manager, options) {
  40461. this._manager = manager;
  40462. var source = options.source;
  40463. var args = {
  40464. onHeadersReceived: this._onHeadersReceived.bind(this),
  40465. onProgressiveData: source.disableStream ? null :
  40466. this._onProgressiveData.bind(this),
  40467. onDone: this._onDone.bind(this),
  40468. onError: this._onError.bind(this),
  40469. onProgress: this._onProgress.bind(this)
  40470. };
  40471. this._url = source.url;
  40472. this._fullRequestId = manager.requestFull(args);
  40473. this._headersReceivedCapability = createPromiseCapability();
  40474. this._disableRange = options.disableRange || false;
  40475. this._contentLength = source.length; // optional
  40476. this._rangeChunkSize = source.rangeChunkSize;
  40477. if (!this._rangeChunkSize && !this._disableRange) {
  40478. this._disableRange = true;
  40479. }
  40480. this._isStreamingSupported = false;
  40481. this._isRangeSupported = false;
  40482. this._cachedChunks = [];
  40483. this._requests = [];
  40484. this._done = false;
  40485. this._storedError = undefined;
  40486. this.onProgress = null;
  40487. }
  40488. PDFNetworkStreamFullRequestReader.prototype = {
  40489. _validateRangeRequestCapabilities: function
  40490. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  40491. if (this._disableRange) {
  40492. return false;
  40493. }
  40494. var networkManager = this._manager;
  40495. var fullRequestXhrId = this._fullRequestId;
  40496. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  40497. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  40498. return false;
  40499. }
  40500. var contentEncoding =
  40501. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  40502. if (contentEncoding !== 'identity') {
  40503. return false;
  40504. }
  40505. var length = fullRequestXhr.getResponseHeader('Content-Length');
  40506. length = parseInt(length, 10);
  40507. if (!isInt(length)) {
  40508. return false;
  40509. }
  40510. this._contentLength = length; // setting right content length
  40511. if (length <= 2 * this._rangeChunkSize) {
  40512. // The file size is smaller than the size of two chunks, so it does
  40513. // not make any sense to abort the request and retry with a range
  40514. // request.
  40515. return false;
  40516. }
  40517. return true;
  40518. },
  40519. _onHeadersReceived:
  40520. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  40521. if (this._validateRangeRequestCapabilities()) {
  40522. this._isRangeSupported = true;
  40523. }
  40524. var networkManager = this._manager;
  40525. var fullRequestXhrId = this._fullRequestId;
  40526. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  40527. // We can continue fetching when progressive loading is enabled,
  40528. // and we don't need the autoFetch feature.
  40529. this._isStreamingSupported = true;
  40530. } else if (this._isRangeSupported) {
  40531. // NOTE: by cancelling the full request, and then issuing range
  40532. // requests, there will be an issue for sites where you can only
  40533. // request the pdf once. However, if this is the case, then the
  40534. // server should not be returning that it can support range
  40535. // requests.
  40536. networkManager.abortRequest(fullRequestXhrId);
  40537. }
  40538. this._headersReceivedCapability.resolve();
  40539. },
  40540. _onProgressiveData:
  40541. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  40542. if (this._requests.length > 0) {
  40543. var requestCapability = this._requests.shift();
  40544. requestCapability.resolve({value: chunk, done: false});
  40545. } else {
  40546. this._cachedChunks.push(chunk);
  40547. }
  40548. },
  40549. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  40550. if (args) {
  40551. this._onProgressiveData(args.chunk);
  40552. }
  40553. this._done = true;
  40554. if (this._cachedChunks.length > 0) {
  40555. return;
  40556. }
  40557. this._requests.forEach(function (requestCapability) {
  40558. requestCapability.resolve({value: undefined, done: true});
  40559. });
  40560. this._requests = [];
  40561. },
  40562. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  40563. var url = this._url;
  40564. var exception;
  40565. if (status === 404 || status === 0 && /^file:/.test(url)) {
  40566. exception = new MissingPDFException('Missing PDF "' + url + '".');
  40567. } else {
  40568. exception = new UnexpectedResponseException(
  40569. 'Unexpected server response (' + status +
  40570. ') while retrieving PDF "' + url + '".', status);
  40571. }
  40572. this._storedError = exception;
  40573. this._headersReceivedCapability.reject(exception);
  40574. this._requests.forEach(function (requestCapability) {
  40575. requestCapability.reject(exception);
  40576. });
  40577. this._requests = [];
  40578. this._cachedChunks = [];
  40579. },
  40580. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  40581. if (this.onProgress) {
  40582. this.onProgress({
  40583. loaded: data.loaded,
  40584. total: data.lengthComputable ? data.total : this._contentLength
  40585. });
  40586. }
  40587. },
  40588. get isRangeSupported() {
  40589. return this._isRangeSupported;
  40590. },
  40591. get isStreamingSupported() {
  40592. return this._isStreamingSupported;
  40593. },
  40594. get contentLength() {
  40595. return this._contentLength;
  40596. },
  40597. get headersReady() {
  40598. return this._headersReceivedCapability.promise;
  40599. },
  40600. read: function PDFNetworkStreamFullRequestReader_read() {
  40601. if (this._storedError) {
  40602. return Promise.reject(this._storedError);
  40603. }
  40604. if (this._cachedChunks.length > 0) {
  40605. var chunk = this._cachedChunks.shift();
  40606. return Promise.resolve(chunk);
  40607. }
  40608. if (this._done) {
  40609. return Promise.resolve({value: undefined, done: true});
  40610. }
  40611. var requestCapability = createPromiseCapability();
  40612. this._requests.push(requestCapability);
  40613. return requestCapability.promise;
  40614. },
  40615. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  40616. this._done = true;
  40617. this._headersReceivedCapability.reject(reason);
  40618. this._requests.forEach(function (requestCapability) {
  40619. requestCapability.resolve({value: undefined, done: true});
  40620. });
  40621. this._requests = [];
  40622. if (this._manager.isPendingRequest(this._fullRequestId)) {
  40623. this._manager.abortRequest(this._fullRequestId);
  40624. }
  40625. this._fullRequestReader = null;
  40626. }
  40627. };
  40628. /** @implements {IPDFStreamRangeReader} */
  40629. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  40630. this._manager = manager;
  40631. var args = {
  40632. onDone: this._onDone.bind(this),
  40633. onProgress: this._onProgress.bind(this)
  40634. };
  40635. this._requestId = manager.requestRange(begin, end, args);
  40636. this._requests = [];
  40637. this._queuedChunk = null;
  40638. this._done = false;
  40639. this.onProgress = null;
  40640. this.onClosed = null;
  40641. }
  40642. PDFNetworkStreamRangeRequestReader.prototype = {
  40643. _close: function PDFNetworkStreamRangeRequestReader_close() {
  40644. if (this.onClosed) {
  40645. this.onClosed(this);
  40646. }
  40647. },
  40648. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  40649. var chunk = data.chunk;
  40650. if (this._requests.length > 0) {
  40651. var requestCapability = this._requests.shift();
  40652. requestCapability.resolve({value: chunk, done: false});
  40653. } else {
  40654. this._queuedChunk = chunk;
  40655. }
  40656. this._done = true;
  40657. this._requests.forEach(function (requestCapability) {
  40658. requestCapability.resolve({value: undefined, done: true});
  40659. });
  40660. this._requests = [];
  40661. this._close();
  40662. },
  40663. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  40664. if (!this.isStreamingSupported && this.onProgress) {
  40665. this.onProgress({
  40666. loaded: evt.loaded
  40667. });
  40668. }
  40669. },
  40670. get isStreamingSupported() {
  40671. return false; // TODO allow progressive range bytes loading
  40672. },
  40673. read: function PDFNetworkStreamRangeRequestReader_read() {
  40674. if (this._queuedChunk !== null) {
  40675. var chunk = this._queuedChunk;
  40676. this._queuedChunk = null;
  40677. return Promise.resolve({value: chunk, done: false});
  40678. }
  40679. if (this._done) {
  40680. return Promise.resolve({value: undefined, done: true});
  40681. }
  40682. var requestCapability = createPromiseCapability();
  40683. this._requests.push(requestCapability);
  40684. return requestCapability.promise;
  40685. },
  40686. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  40687. this._done = true;
  40688. this._requests.forEach(function (requestCapability) {
  40689. requestCapability.resolve({value: undefined, done: true});
  40690. });
  40691. this._requests = [];
  40692. if (this._manager.isPendingRequest(this._requestId)) {
  40693. this._manager.abortRequest(this._requestId);
  40694. }
  40695. this._close();
  40696. }
  40697. };
  40698. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  40699. exports.PDFNetworkStream = PDFNetworkStream;
  40700. exports.NetworkManager = NetworkManager;
  40701. }));
  40702. }).call(pdfjsLibs);
  40703. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  40704. }));